]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunList.php
9ba125bfa40bf71a3d0397352d228fef92d94f97
[bacula/bacula] / gui / baculum / protected / Portlets / JobRunList.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many 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  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
26 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
27 Prado::using('System.Web.UI.ActiveControls.TCallback');
28 Prado::using('Application.Portlets.ISlideWindow');
29 Prado::using('Application.Portlets.Portlets');
30
31 class JobRunList extends Portlets implements ISlideWindow {
32
33         public $ID;
34         public $buttonID;
35         public $windowTitle;
36         public $oldDirector;
37         private $jobStates;
38         private $jobTypes = array(
39                 'B' => 'Backup',
40                 'M' => 'Migrated',
41                 'V' => 'Verify',
42                 'R' => 'Restore',
43                 'I' => 'Internal',
44                 'D' => 'Admin',
45                 'A' => 'Archive',
46                 'C' => 'Copy',
47                 'g' => 'Migration'
48         );
49
50         public function setID($id) {
51                 $this->ID = $id;
52         }
53
54         public function getID($hideAutoID = true) {
55                 return $this->ID;
56         }
57
58         public function setButtonID($id) {
59                 $this->buttonID = $id;
60         }
61
62         public function getButtonID() {
63                 return $this->buttonID;
64         }
65
66         public function setWindowTitle($param) {
67                 $this->windowTitle = $param;
68         }
69
70         public function getWindowTitle() {
71                 return $this->windowTitle;
72         }
73
74         public function onLoad($param) {
75                 parent::onLoad($param);
76                 $this->prepareData();
77         }
78
79         public function prepareData($forceReload = false) {
80                 $allowedButtons = array('JobRunBtn');
81                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {
82                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {
83                                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
84                                 $jobTasks = $this->Application->getModule('api')->get($params)->output;
85                                 $jobs = $this->prepareJobs($jobTasks);
86                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobRunWindow->ID] == 'details';
87
88                                 if($isDetailView === true) {
89                                         $this->RepeaterShow->Visible = false;
90                                         $this->DataGridShow->Visible = true;
91                                         $this->DataGrid->DataSource = $jobs;
92                                         $this->DataGrid->dataBind();
93                                 } else {
94                                         $this->RepeaterShow->Visible = true;
95                                         $this->DataGridShow->Visible = false;
96                                         $this->Repeater->DataSource = $jobs;
97                                         $this->Repeater->dataBind();
98                                 }
99                         }
100                 }
101         }
102
103         private function prepareJobs($jobTasks) {
104                 $jobs = array();
105                 foreach($jobTasks as $director => $tasks) {
106                         for($i = 0; $i < count($tasks); $i++) {
107                                 $jobs[] = array('name' => $tasks[$i], 'director' => $director);
108                         }
109                 }
110                 return $jobs;
111         }
112
113         public function sortDataGrid($sender, $param) {
114                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
115                 $data = $this->Application->getModule('api')->get($params)->output;
116                 $data = $this->prepareJobs($data);
117                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
118                 $this->DataGrid->dataBind();
119         }
120
121         public function configure($sender, $param) {
122                 if($this->Page->IsCallBack) {
123                         $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter);
124                 }
125         }
126 }
127 ?>