Add ability to create new trials
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
||||||
*
|
*
|
||||||
@@ -26,6 +25,7 @@
|
|||||||
* Trials are used to store different variations of the same project.
|
* Trials are used to store different variations of the same project.
|
||||||
*
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
|
* @author Eike Foken <kontakt@eikefoken.de>
|
||||||
*/
|
*/
|
||||||
class Trials extends CI_Controller {
|
class Trials extends CI_Controller {
|
||||||
|
|
||||||
@@ -34,57 +34,68 @@ class Trials extends CI_Controller {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('trial');
|
$this->load->library('form_validation');
|
||||||
|
$this->load->model('parameter');
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
$this->load->model('project');
|
$this->load->model('project');
|
||||||
|
$this->load->model('trial');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new project.
|
* Create a new project.
|
||||||
*/
|
*/
|
||||||
public function create() {
|
public function create($projectId = '') {
|
||||||
$this->load->library('form_validation');
|
$project = $this->project->getByID($projectId);
|
||||||
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
|
|
||||||
|
if (empty($projectId) || !isset($project['id'])){
|
||||||
|
show_404();
|
||||||
|
}
|
||||||
|
|
||||||
$programs = $this->program->getAll();
|
$programs = $this->program->getAll();
|
||||||
|
|
||||||
// Get the parameters for a specific program
|
// get the parameters for a specific program
|
||||||
foreach ($programs as $program)
|
foreach ($programs as $program) {
|
||||||
$parameters[$program['id']] = $this->program->getParameters($program['id']);
|
$parameters[$program['id']] = $this->parameter->getAll($program['id']);
|
||||||
|
}
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
array(
|
array(
|
||||||
'field' => 'name',
|
'field' => 'name',
|
||||||
'label' => 'Projektname',
|
'label' => _('Trial name'),
|
||||||
'rules' => 'trim|required|min_length[3]|max_length[100]|xss_clean',
|
'rules' => 'required|min_length[3]|max_length[60]|trim',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'description',
|
'field' => 'description',
|
||||||
'label' => 'Beschreibung',
|
'label' => _('Description'),
|
||||||
'rules' => 'trim|required|xss_clean',
|
'rules' => 'required|trim',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->form_validation->set_rules($config);
|
$this->form_validation->set_rules($config);
|
||||||
|
|
||||||
|
if ($this->form_validation->run() === true) {
|
||||||
if ($this->form_validation->run() == FALSE) {
|
|
||||||
$tpl['parameters'] = $parameters;
|
|
||||||
$tpl['programs'] = $programs;
|
|
||||||
$this->load->view('trial/new', $tpl);
|
|
||||||
} else {
|
|
||||||
// TODO: handle file upload
|
// TODO: handle file upload
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => $this->input->post('name'),
|
'name' => $this->input->post('name'),
|
||||||
'description' => $this->input->post('description'),
|
'description' => $this->input->post('description'),
|
||||||
|
'program_id' => $this->input->post('program_id'),
|
||||||
|
'project_id' => $projectId,
|
||||||
|
'creator_id' => $this->session->userdata('user_id'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $this->trial->create($data);
|
$result = $this->trial->create($data);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) {
|
||||||
|
$param['parameter_id'] = substr($key, 6, 16);
|
||||||
|
$param['value'] = $this->input->post($key);
|
||||||
|
$this->trial->addParameter($param, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
|
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
|
||||||
$projectpath = $userpath . $data['project_id'] . '/';
|
$projectpath = $userpath . $projectId . '/';
|
||||||
$trialpath = $projectpath . $data['trial_id'] . '/';
|
$trialpath = $projectpath . $result . '/';
|
||||||
if(!is_dir($trialpath)) {
|
if(!is_dir($trialpath)) {
|
||||||
if (!is_dir($projectpath)) {
|
if (!is_dir($projectpath)) {
|
||||||
if(!is_dir($userpath)) {
|
if(!is_dir($userpath)) {
|
||||||
@@ -98,11 +109,19 @@ class Trials extends CI_Controller {
|
|||||||
chmod($trialpath, 0777);
|
chmod($trialpath, 0777);
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect('/trial/detail/' . $result, 'refresh');
|
redirect('trials/detail/' . $result, 'refresh');
|
||||||
} else {
|
} else {
|
||||||
$this->messages->add(_('The trial could not be created.'), 'error');
|
$this->messages->add(_('The trial could not be created.'), 'error');
|
||||||
$this->load->view('trial/new', $tpl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tpl['parameters'] = $parameters;
|
||||||
|
$tpl['programs'] = $programs;
|
||||||
|
$tpl['project'] = $project;
|
||||||
|
|
||||||
|
$this->load->view('trial/new', $tpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* End of file trials.php */
|
||||||
|
/* Location: ./application/controllers/trials.php */
|
||||||
|
|||||||
@@ -56,6 +56,28 @@ class Trial extends CI_Model {
|
|||||||
return $this->db->delete('trials', array('id' => $trial_id));
|
return $this->db->delete('trials', array('id' => $trial_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a parameter for a specific trial.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param string $trialId
|
||||||
|
* @return boolean Returns TRUE if the parameter was added successfully.
|
||||||
|
*/
|
||||||
|
public function addParameter($data, $trialId) {
|
||||||
|
if (!isset($data['parameter_id'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trial = $this->get($trialId);
|
||||||
|
$parameter = $this->db->get_where('parameters', array('id' => $data['parameter_id']))->row_array();
|
||||||
|
|
||||||
|
if (isset($trial['id']) && $trial['program_id'] == $parameter['program_id']) {
|
||||||
|
$data['trial_id'] = $trialId;
|
||||||
|
$this->db->insert('trials_parameters', $data);
|
||||||
|
}
|
||||||
|
return $this->db->affected_rows() == 1 ? $trialId : false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a trial by id.
|
* Get a trial by id.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,48 +1,49 @@
|
|||||||
<?php $this->load->view('header'); ?>
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h2><?= _('Create a new trial') ?></h2>
|
<h2><?=_('Create a new trial');?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form name="newtrial" method="post" action="<?=site_url('trials/create')?>">
|
<form name="newTrial" method="post" action="<?=site_url('trials/create/' . $project['id']);?>">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
||||||
|
<h3><?=_('Required information');?></h3>
|
||||||
<h3><?= _('Required information') ?></h3>
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<h4><?= _('Trial name') ?> <span class="req">*</span></h4>
|
<?=form_label(_('Trial name'), 'name');?>
|
||||||
|
<span class="req">*</span>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="name" class="short text" value="<?=set_value('name')?>">
|
<input type="text" name="name" id="name" class="short text" value="<?=set_value('name');?>" />
|
||||||
<?=form_error('name')?>
|
<?=form_error('name');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<h4><?= _('Description') ?></h4>
|
<?=form_label(_('Description'), 'description');?>
|
||||||
<label class="note"><?= _('A description is useful if you want to share this trial with co-workers.') ?></label>
|
<span class="req">*</span>
|
||||||
<div>
|
<div>
|
||||||
<textarea name="description" rows="6" cols="60" class="textarea"><?=set_value('description')?></textarea>
|
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description');?></textarea>
|
||||||
<?=form_error('description')?>
|
<?=form_error('description');?>
|
||||||
</div>
|
</div>
|
||||||
|
<label class="note"><?=_('A description is useful if you want to share this trial with co-workers.');?></label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<h4><?= _('3D model') ?></h4>
|
<h4><?=_('3D model');?></h4>
|
||||||
<?
|
<?
|
||||||
$defaultmodel = "foo";
|
$defaultmodel = 'foo';
|
||||||
if(isset($defaultmodel)):
|
if (isset($defaultmodel)):
|
||||||
?>
|
?>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
<strong><?= _('There is a default model set for this project.') ?></strong><br />
|
<strong><?=_('There is a default model set for this project.');?></strong><br />
|
||||||
<?= _('If you want to use a different model for this trial, you can upload it here.') ?>
|
<?=_('If you want to use a different model for this trial, you can upload it here.');?>
|
||||||
</div>
|
</div>
|
||||||
<?
|
<?
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" class="file" name="defaultmodel" value="<?=set_value('defaultmodel')?>">
|
<input type="file" class="file" name="defaultmodel" value="<?=set_value('defaultmodel');?>" />
|
||||||
<?=form_error('defaultmodel')?>
|
<?=form_error('defaultmodel');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -50,63 +51,65 @@
|
|||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
||||||
<h3><?= _('Application-specific parameters') ?></h3>
|
<h3><?=_('Application-specific parameters');?></h3>
|
||||||
<?
|
<?
|
||||||
$defaultconfig = "foo";
|
$defaultconfig = 'foo';
|
||||||
if(isset($defaultconfig)):
|
if (isset($defaultconfig)):
|
||||||
?>
|
?>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
<strong><?= _('There is a default configuration set for this project.') ?></strong><br />
|
<strong><?=_('There is a default configuration set for this project.');?></strong><br />
|
||||||
<?= _('This form contains the default values. You can adjust them for this trial.') ?><br />
|
<?=_('This form contains the default values. You can adjust them for this trial.');?><br />
|
||||||
<?= _('The default configuration will not be modified.') ?>
|
<?=_('The default configuration will not be modified.');?>
|
||||||
</div>
|
</div>
|
||||||
<?
|
<?
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<h4><?= _('Application to use for the computation') ?></h4>
|
<h4><?=_('Application to use for the computation');?></h4>
|
||||||
|
<input type="hidden" name="program_id" id="program_id" value="<?=set_value('program_id');?>" />
|
||||||
<p>
|
<p>
|
||||||
<?
|
<?
|
||||||
foreach($programs as $program):
|
foreach ($programs as $program):
|
||||||
?><a class="button" onclick="$('.program-parameters').hide();$('#<?=$program['id']?>-params').show();$('.button').removeClass('locked');$(this).addClass('locked');return false;" href="#"><?=$program['name']?></a>
|
?>
|
||||||
|
<a class="button" href="javascript:void(0);" onclick="$('.program-parameters').hide();$('#<?=$program['id'];?>-params').show();$('.button').removeClass('locked');$(this).addClass('locked');$('input[name=program_id]').val('<?=$program['id'];?>');return false;"><?=$program['name'];?></a>
|
||||||
<?
|
<?
|
||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<?
|
<?
|
||||||
foreach($programs as $program):
|
foreach ($programs as $program):
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="program-parameters" id="<?=$program['id']?>-params" style="display:none">
|
<div class="program-parameters" id="<?=$program['id'];?>-params" style="display:none">
|
||||||
<h4><?= sprintf(_('Parameters for %s'), $program['name'])?></h4>
|
<h4><?=sprintf(_('Parameters for %s'), $program['name']);?></h4>
|
||||||
<p>
|
<p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" width="40%"><?= _('Parameter') ?></th>
|
<th scope="col" width="40%"><?=_('Parameter');?></th>
|
||||||
<th scope="col" width="40%"><?= _('Value') ?></th>
|
<th scope="col" width="40%"><?=_('Value');?></th>
|
||||||
<th scope="col"><?= _('Unit') ?></th>
|
<th scope="col"><?=_('Unit');?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?
|
<?
|
||||||
foreach($parameters[$program['id']] as $param):
|
foreach ($parameters[$program['id']] as $param):
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?=$param['readable'];?></td>
|
<td><?=$param['readable'];?></td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="<?=$param['name']?>" class="long text" value="<?=set_value($param['name'])?>" />
|
<input type="text" name="param-<?=$param['id'];?>" class="long text" value="<?=(!empty($_POST['param-' . $param['id']]) ? $this->input->post('param-' . $param['id']) : $param['default_value']);?>" />
|
||||||
<?php
|
<?php
|
||||||
if ($param['description'] != ''):
|
if (!empty($param['description'])):
|
||||||
?>
|
?>
|
||||||
<span class="form_info">
|
<span class="form_info">
|
||||||
<a href="<?=site_url('ajax/parameter_help/' . $param['id']);?>" name="<?=_('Description');?>" id="<?=$param['id'];?>" class="jTip"> </a>
|
<a href="<?=site_url('ajax/parameter_help/' . $param['id']);?>" name="<?=_('Description');?>" id="<?=$param['id'];?>" class="jtip"> </a>
|
||||||
</span>
|
</span>
|
||||||
<?php
|
<?php
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<?=form_error($param['name'])?>
|
<?=form_error('params');?>
|
||||||
</td>
|
</td>
|
||||||
<td><?=$param['unit']?></td>
|
<td><?=$param['unit'];?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?
|
<?
|
||||||
endforeach;
|
endforeach;
|
||||||
@@ -119,11 +122,11 @@
|
|||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
<a class="button save-big big" href="#" onclick="document.forms.newtrial.submit();"><?= _('Save') ?></a>
|
<a class="button save-big big" href="javascript:void(0);" onclick="$('form[name=newTrial]').submit();"><?=_('Save');?></a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php $this->load->view('footer'); ?>
|
<?php $this->load->view('footer');?>
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ $(document).ready(JT_init);
|
|||||||
* Initializes JTip.
|
* Initializes JTip.
|
||||||
*/
|
*/
|
||||||
function JT_init() {
|
function JT_init() {
|
||||||
$('a.jTip').hover(function() {
|
$('a.jtip').hover(function() {
|
||||||
JT_show(this.href, this.id, this.name);
|
JT_show(this.href, this.id, this.name);
|
||||||
}, function() {
|
}, function() {
|
||||||
$('#JT').remove();
|
$('#jt').remove();
|
||||||
}).click(function() {
|
}).click(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -54,17 +54,17 @@ function JT_show(url, linkId, title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasArea > (params['width'] * 1) + 75) {
|
if (hasArea > (params['width'] * 1) + 75) {
|
||||||
$('body').append('<div id="JT" style="width: ' + params['width'] * 1 + 'px;"><div id="JT_arrow_left"></div><div id="JT_close_left">' + title + '</div><div id="JT_copy"><div class="JT_loader"><div></div></div>'); // right side
|
$('body').append('<div id="jt" style="width: ' + params['width'] * 1 + 'px;"><div id="jt_arrow_left"></div><div id="jt_close_left">' + title + '</div><div id="jt_copy"><div class="jt_loader"><div></div></div>'); // right side
|
||||||
var arrowOffset = getElementWidth(linkId) + 11;
|
var arrowOffset = getElementWidth(linkId) + 11;
|
||||||
clickElementX = getAbsoluteLeft(linkId) + arrowOffset; // set x position
|
clickElementX = getAbsoluteLeft(linkId) + arrowOffset; // set x position
|
||||||
} else {
|
} else {
|
||||||
$('body').append('<div id="JT" style="width: ' + params['width'] * 1 + 'px;"><div id="JT_arrow_right" style="left: ' + ((params['width'] * 1) + 1) + 'px;"></div><div id="JT_close_right">' + title + '</div><div id="JT_copy"><div class="JT_loader"><div></div></div>'); // left side
|
$('body').append('<div id="jt" style="width: ' + params['width'] * 1 + 'px;"><div id="jt_arrow_right" style="left: ' + ((params['width'] * 1) + 1) + 'px;"></div><div id="jt_close_right">' + title + '</div><div id="jt_copy"><div class="jt_loader"><div></div></div>'); // left side
|
||||||
clickElementX = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
|
clickElementX = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#JT').css({ left: clickElementX + 'px', top: clickElementY + 'px' });
|
$('#jt').css({ left: clickElementX + 'px', top: clickElementY + 'px' });
|
||||||
$('#JT').show();
|
$('#jt').show();
|
||||||
$('#JT_copy').load(url);
|
$('#jt_copy').load(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user