* @author Eike Foken */ class Ajax extends MY_Controller { /** * Constructor. */ public function __construct() { parent::__construct(); // security check if (!$this->input->is_ajax_request()) { show_error(_('No AJAX request was made.')); } } /** * Load the notifications for the user. * * This is used for sending notifications to the user like * "There are new results for the project 'foobar'". */ public function get_notifications() { $tpl['messages'] = $this->messages->get(); $this->load->view('global/notifications', $tpl); } /** * */ public function check_jobs() { $this->load->model('job'); $unseen = $this->job->getUnseenResults(); foreach ($unseen as $job) { if ($job['notified'] == 0) { $this->job->update($job['id'], array('notified' => 1)); $experiment = anchor('experiments/detail/' . $job['experiment_id'], $job['experiment_name']); $project = anchor('projects/detail/' . $job['project_id'], $job['project_name']); $this->messages->add(sprintf(_('The job for %s in project %s is ready.'), $experiment, $project), 'success'); } } $data = array( 'jobs_finished' => count($unseen), 'jobs_running' => $this->job->countRunning(), 'jobs_pending' => $this->job->countPending(), 'shared_projects' => $this->share->countUnseen(), ); $this->output->set_output(json_encode($data)); } /** * Saves the projects description. * * @param string $projectId */ public function update_project($projectId) { $this->load->model('project'); $this->load->helper('typography'); $data['description'] = $this->input->post('description'); $this->project->update($data, $projectId); $this->output->set_output(auto_typography($data['description'])); } /** * * @param string $experimentId */ public function rename_project($projectId) { $this->load->model('project'); $this->project->update(array('name' => $this->input->post('title')), $projectId); $this->output->set_output(site_url('projects/detail/' . $projectId)); } /** * Saves the experiments description. * * @param string $experimentId */ public function update_experiment($experimentId) { $this->load->model('experiment'); $this->load->helper('typography'); $data['description'] = $this->input->post('description'); $this->experiment->update($data, $experimentId); $this->output->set_output(auto_typography($data['description'])); } /** * * @param string $experimentId */ public function rename_experiment($experimentId) { $this->load->model('experiment'); $this->experiment->update(array('name' => $this->input->post('title')), $experimentId); $this->output->set_output(site_url('experiments/detail/' . $experimentId)); } /** * Sorts a programs parameters. */ public function sort_parameters() { $this->load->model('parameter'); $this->parameter->sort($this->input->post('parameters')); } /** * Displays the description of parameters. * * @param string $parameterId */ public function parameter_help($parameterId) { $this->load->model('parameter'); $this->load->helper('typography'); $parameter = $this->parameter->getById($parameterId); $this->output->set_output(auto_typography($parameter['description'])); } }