]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunList.php
baculum: Tweak end of lines (CF+LF => LF)
[bacula/bacula] / gui / baculum / protected / Portlets / JobRunList.php
1 <?php
2 /**
3  * Bacula® - The Network Backup Solution
4  * Baculum - Bacula web interface
5  *
6  * Copyright (C) 2013-2014 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The main author of Bacula is Kern Sibbald, with contributions from many
10  * others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * Bacula® is a registered trademark of Kern Sibbald.
18  */
19
20 Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid');
21 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
22 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
23 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
24 Prado::using('System.Web.UI.ActiveControls.TCallback');
25 Prado::using('Application.Portlets.Portlets');
26
27 class JobRunList extends Portlets {
28
29         public $ShowID, $windowTitle, $oldDirector;
30
31         private $jobTypes = array('B' => 'Backup', 'M' => 'Migrated', 'V' => 'Verify', 'R' => 'Restore', 'I' => 'Internal', 'D' => 'Admin', 'A' => 'Archive', 'C' => 'Copy', 'g' => 'Migration');
32
33         private $jobStates;
34
35         public function onLoad($param) {
36                 parent::onLoad($param);
37                 $this->prepareData();
38         }
39
40         public function setWindowTitle($param) {
41                 $this->windowTitle = $param;
42         }
43
44         public function prepareData($forceReload = false) {
45                 $allowedButtons = array('JobRunBtn');
46                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {
47                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {
48                                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
49                                 $jobTasks = $this->Application->getModule('api')->get($params)->output;
50                                 $jobs = $this->prepareJobs($jobTasks);
51                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobRunWindow->ID] == 'details';
52                                 $this->RepeaterShow->Visible = !$isDetailView;
53                                 $this->Repeater->DataSource = $isDetailView === false ? $jobs : array();
54                                 $this->Repeater->dataBind();
55                                 $this->DataGridShow->Visible = $isDetailView;
56                                 $this->DataGrid->DataSource = $isDetailView === true ? $jobs : array();
57                                 $this->DataGrid->dataBind();
58                         }
59                 }
60         }
61
62         private function prepareJobs($jobTasks) {
63                 $jobs = array();
64                 foreach($jobTasks as $director => $tasks) {
65                         for($i = 0; $i < count($tasks); $i++) {
66                                 $jobs[] = array('name' => $tasks[$i], 'director' => $director);
67                         }
68                 }
69                 return $jobs;
70         }
71
72     public function sortDataGrid($sender, $param) {
73                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
74                 $data = $this->Application->getModule('api')->get($params)->output;
75                 $data = $this->prepareJobs($data);
76                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
77                 $this->DataGrid->dataBind();
78         }
79
80         public function setShowID($ShowID) {
81                 $this->ShowID = $this->getMaster()->ShowID = $ShowID;
82         }
83
84         public function getShowID() {
85                 return $this->ShowID;
86         }
87
88         public function configure($sender, $param) {
89                 if($this->Page->IsCallBack) {
90                         $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter);
91                 }
92         }
93 }
94 ?>