]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobList.php
12cd790a5b712d7fe5b8f3bfc00ce83d835b2db1
[bacula/bacula] / gui / baculum / protected / Portlets / JobList.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.ISlideWindow');
26 Prado::using('Application.Portlets.Portlets');
27
28 class JobList extends Portlets implements ISlideWindow {
29
30         public $ID;
31         public $buttonID;
32         public $windowTitle;
33         public $jobLevels;
34         public $jobStates;
35         public $jobTypes;
36
37         public function setID($id) {
38                 $this->ID = $id;
39         }
40
41         public function getID($hideAutoID = true) {
42                 return $this->ID;
43         }
44
45         public function setButtonID($id) {
46                 $this->buttonID = $id;
47         }
48
49         public function getButtonID() {
50                 return $this->buttonID;
51         }
52
53         public function setWindowTitle($param) {
54                 $this->windowTitle = $param;
55         }
56
57         public function getWindowTitle() {
58                 return $this->windowTitle;
59         }
60
61         public function onLoad($param) {
62                 parent::onLoad($param);
63                 $this->prepareData();
64                 $misc = $this->Application->getModule('misc');
65                 $this->jobLevels = $misc->getJobLevels();
66                 $this->jobStates = $misc->getJobState();
67                 $this->jobTypes = $misc->getJobType();
68         }
69
70         public function prepareData($forceReload = false) {
71                 $allowedButtons = array('JobBtn', 'ReloadJobs', 'Run');
72                 if($this->Page->IsPostBack || $this->Page->IsCallBack || $forceReload) {
73                         if(in_array($this->getPage()->CallBackEventTarget->ID, $allowedButtons) || $forceReload) {
74                                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
75                                 $jobs = $this->Application->getModule('api')->get($params);
76                                 $isDetailView = $_SESSION['view' . $this->getPage()->JobWindow->ID] == 'details';
77                                 if($isDetailView === true) {
78                                         $this->RepeaterShow->Visible = false;
79                                         $this->DataGridShow->Visible = true;
80                                         $this->DataGrid->DataSource = $this->Application->getModule('misc')->objectToArray($jobs->output);
81                                         $this->DataGrid->dataBind();
82                                 } else {
83                                         $this->RepeaterShow->Visible = true;
84                                         $this->DataGridShow->Visible = false;
85                                         $this->Repeater->DataSource = $jobs->output;
86                                         $this->Repeater->dataBind();
87                                 }
88                         }
89                 }
90         }
91
92         public function sortDataGrid($sender, $param) {
93                 $params = $this->getUrlParams('jobs', $this->getPage()->JobWindow->ID);
94                 $data = $this->Application->getModule('api')->get($params)->output;
95                 $data = $this->Application->getModule('misc')->objectToArray($data);
96                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
97                 $this->DataGrid->dataBind();
98         }
99
100         public function configure($sender, $param) {
101                 if($this->Page->IsCallBack) {
102                         $this->getPage()->JobConfiguration->configure($param->CallbackParameter);
103                 }
104         }
105
106         public function executeAction($action) {
107                 $params = explode(';', $this->CheckedValues->Value);
108                 $commands = array();
109                 switch($action) {
110                         case 'delete': {
111                                 for($i = 0; $i < count($params); $i++) {
112                                         $cmd = array('delete');
113                                         $cmd[] = 'jobid="' . $params[$i] . '"';
114                                         $cmd[] = 'yes';
115                                         $cmd[] = PHP_EOL;
116                                         $commands[] = implode(' ', $cmd);
117                                 }
118                                 $this->getPage()->Console->CommandLine->Text = implode(' ', $commands);
119                                 $this->getPage()->Console->sendCommand(null, null);
120                                 break;
121                         }
122                 }
123                 $this->CheckedValues->Value = "";
124         }
125 }
126 ?>