All Data Structures Functions Variables Pages
RunJobView.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
40  class RunJobView extends View
41  {
42  protected $controllerId;
43 
44  protected $moduleId;
45 
46  protected $type;
47 
48  protected $timeLimit;
49 
50  protected $messageLoggerClassName;
51 
58  public function __construct($controllerId, $moduleId, $type, $timeLimit, $messageLoggerClassName)
59  {
60  assert('is_string($controllerId) && $controllerId != ""');
61  assert('is_string($moduleId) && $moduleId != ""');
62  assert('is_string($type)');
63  assert('is_int($timeLimit)');
64  assert('is_string($messageLoggerClassName)');
65  $this->controllerId = $controllerId;
66  $this->moduleId = $moduleId;
67  $this->type = $type;
68  $this->timeLimit = $timeLimit;
69  $this->messageLoggerClassName = $messageLoggerClassName;
70  }
71 
72  protected function getJobLabel()
73  {
74  $jobClassName = $this->type . 'Job';
75  return $jobClassName::getDisplayName();
76  }
77 
78  protected function renderContent()
79  {
80  $this->registerRunJobInBackgroundScript();
81  $imagePath = Yii::app()->themeManager->baseUrl . '/default/images/ajax-loader.gif';
82  $progressBarImageContent = ZurmoHtml::image($imagePath, 'Progress Bar');
83  $content = '<div class="wrapper">';
84  $content .= ZurmoHtml::tag('h1', array(), $this->getJobLabel());
85  $content .= '<div class="left-column full-width">';
86  $content .= '<div id="complete-table" style="display:none;">';
87  $content .= ZurmoHtml::tag('h3', array(), Zurmo::t('JobsManagerModule', 'The job has completed running.'));
88  $content .= '</div>';
89  $content .= '<div id="progress-table" class="progress-bar">';
90  $content .= Zurmo::t('JobsManagerModule', 'Job is running. Please wait.');
91  $content .= '<br/>';
92  $content .= $progressBarImageContent;
93  $content .= '</div>';
94  $content .= '<div id="logging-table">';
95  $content .= ZurmoHtml::tag('h3', array(), Zurmo::t('JobsManagerModule', 'Job Output:'));
96  $content .= ZurmoHtml::tag('ol', array(), '');
97  $content .= '</div>';
98  $content .= $this->renderButtonsContent();
99  $content .= '</div>';
100  $content .= '</div>';
101  return $content;
102  }
103 
104  protected function renderButtonsContent()
105  {
106  $jobClassName = $this->type . "Job";
107  $messageLoggerClassName = $jobClassName::getDefaultMessageLogger();
108  $runAgainUrl = Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/runJob/',
109  array('type' => $this->type, 'timeLimit' => $this->timeLimit,
110  'messageLoggerClassName' => $messageLoggerClassName));
111  $jobManagerUrl = Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/list/');
112  $content = ZurmoHtml::link(ZurmoHtml::wrapLabel(Zurmo::t('JobsManagerModule', 'Run Job Again')),
113  $runAgainUrl, array('class' => 'z-button'));
114  if (Yii::app()->jobQueue->isEnabled())
115  {
116  $queueJobUrl = Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/queueJob/',
117  array('type' => $this->type));
118  $content .= ZurmoHtml::link(ZurmoHtml::wrapLabel(Yii::app()->jobQueue->getQueueJobLabel()),
119  $queueJobUrl, array('class' => 'secondary-button'));
120  }
121  $content .= ZurmoHtml::link(ZurmoHtml::wrapLabel(Zurmo::t('JobsManagerModule', 'Job Manager')),
122  $jobManagerUrl, array('class' => 'secondary-button'));
123  $content = '<div class="float-bar"><div class="view-toolbar-container clearfix dock"><div class="form-toolbar">'
124  . $content . '</div></div></div>';
125  return $content;
126  }
127 
128  protected function registerRunJobInBackgroundScript()
129  {
130  $jobUrl = Yii::app()->createUrl('jobsManager/default/runAjaxJob/',
131  array('type' => $this->type, 'timeLimit' => $this->timeLimit, 'messageLoggerClassName' => $this->messageLoggerClassName));
132  // Begin Not Coding Standard
133  $script = <<<EOD
134  $(function()
135  {
136  $.ajax(
137  {
138  url : '$jobUrl',
139  type : 'GET',
140  data : {
141  },
142  dataType: 'html',
143  success : function(data)
144  {
145  $('#logging-table ol').append(data);
146  $("#progress-table").hide();
147  $("#complete-table").show();
148  },
149  error : function(jqXHR, textStatus, errorThrown)
150  {
151  $('#logging-table ol').append('The application has encountered an unknown error. Please check logs for more details!');
152  }
153  }
154  );
155  }
156  );
157 EOD;
158  // End Not Coding Standard
159  Yii::app()->getClientScript()->registerScript('RunJobInBackgroundScript', $script);
160  }
161  }
162 ?>
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
Definition: View.php:43
__construct($controllerId, $moduleId, $type, $timeLimit, $messageLoggerClassName)
Definition: RunJobView.php:58
Generated on Fri Jun 5 2020 07:10:33