Begin implementing programs management
This commit is contained in:
@@ -117,6 +117,19 @@ $config['users/edit'] = array(
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Rules for editing programs.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
$config['programs/edit'] = array(
|
||||
array(
|
||||
'field' => 'name',
|
||||
'label' => _('Name of the program'),
|
||||
'rules' => 'required|max_length[100]|trim',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Rules for the settings page.
|
||||
*
|
||||
|
||||
50
application/controllers/admin/programs.php
Normal file
50
application/controllers/admin/programs.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Eike Foken <kontakt@eikefoken.de>
|
||||
*/
|
||||
class Programs extends CI_Controller {
|
||||
|
||||
/**
|
||||
* Calls the parent constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('form_validation');
|
||||
$this->load->model('program');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a list of all available programs.
|
||||
*/
|
||||
public function index() {
|
||||
$data['programs'] = $this->program->getAll();
|
||||
$this->load->view('admin/programs/list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows admins to edit a program.
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function edit($id = '') {
|
||||
$program = $this->program->getByID($id);
|
||||
|
||||
if (!isset($program) || !is_array($program)){
|
||||
show_404();
|
||||
}
|
||||
|
||||
if ($this->form_validation->run('programs/edit') === true) {
|
||||
if ($this->program->update($this->input->post('name'), $id)) {
|
||||
$this->messages->add(sprintf(_("The program '%s' has been updated successfully"), $this->input->post('name')), 'success');
|
||||
redirect('admin/programs', 303);
|
||||
}
|
||||
}
|
||||
|
||||
$data['program'] = $program;
|
||||
$data['parameters'] = $this->program->getParameters($program['id']);
|
||||
|
||||
$this->load->view('admin/programs/edit', $data);
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,15 @@ class Ajax extends CI_Controller {
|
||||
$data['description'] = $this->input->post('content');
|
||||
$this->project->update($this->session->userdata('active_project'), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a programs parameters.
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function sort_parameters($programId) {
|
||||
$this->load->model('program');
|
||||
$this->program->sortParameters($this->input->post('parameters'), $programId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
||||
*
|
||||
@@ -26,27 +25,56 @@
|
||||
* Programs are used to do the actual calculation of a trial.
|
||||
*
|
||||
* @author Karsten Heiken <karsten@disposed.de>
|
||||
* @author Eike Foken <kontakt@eikefoken.de>
|
||||
*/
|
||||
class Program extends CI_Model {
|
||||
|
||||
/**
|
||||
* Create a new program.
|
||||
*
|
||||
* @param array $data the data of the new program
|
||||
* @return bool was the insert successful
|
||||
* Calls the parent constructor.
|
||||
*/
|
||||
public function create($data) {
|
||||
// TODO: stub
|
||||
return FALSE;
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a program.
|
||||
* @param string the program id to delete
|
||||
* @return bool was the deletion successful
|
||||
* Creates a new program.
|
||||
*
|
||||
* @param string $name The name of the new program
|
||||
* @return string|boolean Returns the ID of the new program, or FALSE if
|
||||
* the insert was unsuccessful.
|
||||
*/
|
||||
public function delete($program_id) {
|
||||
return $this->db->delete('programs', array('id' => $program_id));
|
||||
public function create($name) {
|
||||
$this->load->helper('hash');
|
||||
|
||||
do { // generate unique hash
|
||||
$id = random_hash('16');
|
||||
} while ($this->db->where('id', $id)->from('programs')->count_all_results() > 0);
|
||||
|
||||
$this->db->insert('programs', array('id' => $id, 'name' => $name));
|
||||
|
||||
return $this->db->affected_rows() > 0 ? $id : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a program.
|
||||
*
|
||||
* @param string $name The new name of the program
|
||||
* @param string $id The ID of the program to update
|
||||
* @return boolean Returns TRUE if the update was successful
|
||||
*/
|
||||
public function update($name, $id) {
|
||||
$this->db->update('programs', array('name' => $name), array('id' => $id));
|
||||
return $this->db->affected_rows() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a program.
|
||||
*
|
||||
* @param string $programId The program ID to delete
|
||||
* @return boolean Returns TRUE if the deletion was successful
|
||||
*/
|
||||
public function delete($programId) {
|
||||
return $this->db->delete('programs', array('id' => $programId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,13 +87,13 @@ class Program extends CI_Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific program.
|
||||
* Gets a specific program.
|
||||
*
|
||||
* @param string $prg_id The id of the program to get from the database
|
||||
* @param string $id The id of the program to get from the database
|
||||
* @return array Declarative array with all available information of the program.
|
||||
*/
|
||||
public function getById($prg_id) {
|
||||
return $this->db->get_where('programs', array('id' => $prg_id))->row_array();
|
||||
public function getById($id) {
|
||||
return $this->db->get_where('programs', array('id' => $id))->row_array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,13 +115,23 @@ class Program extends CI_Model {
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @param type $program_id The program for which we want to get the parameters.
|
||||
* @param string $id The program for which we want to get the parameters.
|
||||
* @return array The parameters
|
||||
*/
|
||||
public function getParameters($program_id) {
|
||||
$query = $this->db->select('id, fieldname, readable, unit, description, type')
|
||||
->get_where('configuration_fields', array('program_id' => $program_id));
|
||||
public function getParameters($id) {
|
||||
$query = $this->db->order_by('order ASC')
|
||||
->get_where('parameters', array('program_id' => $id));
|
||||
|
||||
return $query->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $programId
|
||||
*/
|
||||
public function sortParameters($order, $programId) {
|
||||
foreach ($order as $key => $value) {
|
||||
$this->db->update('parameters', array('order' => $key), array('id' => $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
78
application/views/admin/programs/edit.php
Normal file
78
application/views/admin/programs/edit.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php $this->load->view('header');?>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#parameters').tableDnD({
|
||||
onDrop: function(table, row) {
|
||||
/*var rows = table.tBodies[0].rows;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
$(rows[i]).children().find('input[type=hidden]').val(i + 1);
|
||||
}*/
|
||||
$.post(SITE_URL + 'ajax/sort_parameters/<?=$program['id'];?>', $.tableDnD.serialize());
|
||||
},
|
||||
dragHandle: 'drag_handle'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<div id="debug"></div>
|
||||
|
||||
<div class="title">
|
||||
<h2><?php printf(_("Edit program '%s'"), $program['name']);?></h2>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<form name="createUser" method="post" action="<?=site_url('admin/programs/edit/' . $program['id'])?>">
|
||||
<h3><?=_('Required information');?></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<?=form_label(_('Name of the program'), 'name');?>
|
||||
<span class="req">*</span>
|
||||
<div>
|
||||
<input type="text" name="name" id="name" class="medium text" value="<?=set_value('name', $program['name']);?>" />
|
||||
<?=form_error('name')?>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p>
|
||||
<a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();"><?=_('Save');?></a>
|
||||
<a class="button cancel" href="<?=site_url('admin/programs');?>"><?=_('Cancel');?></a>
|
||||
</p>
|
||||
|
||||
<h3><?=_('Parameters');?></h3>
|
||||
<table class="tableList sortable" id="parameters">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"> </th>
|
||||
<th scope="col"><?=_('Readable name');?></th>
|
||||
<th scope="col"><?=_('Unit');?></th>
|
||||
<th scope="col"><?=_('Type');?></th>
|
||||
<th scope="col"><?=_('Actions');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($parameters as $parameter):
|
||||
?>
|
||||
<tr id="<?=$parameter['id'];?>">
|
||||
<td class="drag_handle"></td>
|
||||
<td><?=$parameter['readable'];?></td>
|
||||
<td><?=$parameter['unit'];?></td>
|
||||
<td><?=$parameter['type'];?></td>
|
||||
<td><?=anchor('admin/programs/edit_parameter/' . $parameter['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('admin/programs/delete_parameter/' . $parameter['id']);?>');"><?=_('Delete');?></a></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<a class="button add" href="<?=site_url('admin/programs/add_parameter');?>"><?=_('Add new parameter');?></a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $this->load->view('footer');?>
|
||||
36
application/views/admin/programs/list.php
Normal file
36
application/views/admin/programs/list.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php $this->load->view('header');?>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<div class="title">
|
||||
<h2><?=_('Programs');?></h2>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<h3><?=_('Available programs');?></h3>
|
||||
<table class="tableList paginated">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?=_('Name');?></th>
|
||||
<th scope="col"><?=_('Actions');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($programs as $program):
|
||||
?>
|
||||
<tr>
|
||||
<td><?=$program['name'];?></td>
|
||||
<td><?=anchor('admin/programs/edit/' . $program['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('admin/programs/delete/' . $program['id']);?>');"><?=_('Delete');?></a></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><a class="button add" href="<?=site_url('admin/users/create')?>"><?=_('Create new user')?></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $this->load->view('footer');?>
|
||||
@@ -59,7 +59,7 @@ p.success {
|
||||
color: #008000;
|
||||
}
|
||||
|
||||
p.error, p.req {
|
||||
p.error, span.req {
|
||||
color: #d8122d;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@@ -48,3 +48,12 @@ table tbody tr:nth-child(even) {
|
||||
table tbody tr:nth-child(odd) {
|
||||
background: #f6f6f6;
|
||||
}
|
||||
|
||||
td.drag_handle {
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
td.drag_handle-show {
|
||||
background: url(../images/icons/arrow-resize-090.png) center center no-repeat;
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,18 @@ $(document).ready(function() {
|
||||
table.trigger('repaginate');
|
||||
});
|
||||
|
||||
$('.sortable').tableDnD();
|
||||
/*
|
||||
* Sortable tables
|
||||
*/
|
||||
$('.sortable').tableDnD({
|
||||
dragHandle: 'drag_handle'
|
||||
});
|
||||
|
||||
$('.sortable tr').hover(function() {
|
||||
$(this).find('td.drag_handle').addClass('drag_handle-show');
|
||||
}, function() {
|
||||
$(this).find('td.drag_handle').removeClass('drag_handle-show');
|
||||
});
|
||||
|
||||
/*
|
||||
* In-place editor
|
||||
|
||||
Reference in New Issue
Block a user