]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/JobRunList.php
baculum: Lists loading optiomalization and replace server side sorting to client...
[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
53                                 if($isDetailView === true) {
54                                         $this->RepeaterShow->Visible = false;
55                                         $this->DataGridShow->Visible = true;
56                                         $this->DataGrid->DataSource = $jobs;
57                                         $this->DataGrid->dataBind();
58                                 } else {
59                                         $this->RepeaterShow->Visible = true;
60                                         $this->DataGridShow->Visible = false;
61                                         $this->Repeater->DataSource = $jobs;
62                                         $this->Repeater->dataBind();
63                                 }
64                         }
65                 }
66         }
67
68         private function prepareJobs($jobTasks) {
69                 $jobs = array();
70                 foreach($jobTasks as $director => $tasks) {
71                         for($i = 0; $i < count($tasks); $i++) {
72                                 $jobs[] = array('name' => $tasks[$i], 'director' => $director);
73                         }
74                 }
75                 return $jobs;
76         }
77
78     public function sortDataGrid($sender, $param) {
79                 $params = $this->getUrlParams(array('jobs', 'tasks'), $this->getPage()->JobRunWindow->ID);
80                 $data = $this->Application->getModule('api')->get($params)->output;
81                 $data = $this->prepareJobs($data);
82                 $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID);
83                 $this->DataGrid->dataBind();
84         }
85
86         public function setShowID($ShowID) {
87                 $this->ShowID = $this->getMaster()->ShowID = $ShowID;
88         }
89
90         public function getShowID() {
91                 return $this->ShowID;
92         }
93
94         public function configure($sender, $param) {
95                 if($this->Page->IsCallBack) {
96                         $this->getPage()->JobRunConfiguration->configure($param->CallbackParameter);
97                 }
98         }
99 }
100 ?>