All Data Structures Functions Variables Pages
ProgressView.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 
43  abstract class ProgressView extends View
44  {
45  abstract protected function headerLabelPrefixContent();
46 
50  protected $totalRecordCount;
51 
55  protected $pageSize;
56 
60  protected $progressBarId;
61 
66  public function __construct(
67  $controllerId,
68  $moduleId,
69  $model,
71  $start,
72  $pageSize,
73  $page,
74  $refreshActionId,
75  $title)
76  {
77  $this->controllerId = $controllerId;
78  $this->moduleId = $moduleId;
79  $this->model = $model;
80  $this->totalRecordCount = (int) $totalRecordCount;
81  $this->start = $start;
82  $this->pageSize = $pageSize;
83  $this->page = $page;
84  $this->refreshActionId = $refreshActionId;
85  $this->progressBarId = 'progressBar';
86  $this->title = $title;
87  }
88 
95  public function renderRefreshJSONScript()
96  {
97  return CJSON::encode($this->renderRefreshScript());
98  }
99 
100  public function renderRefreshScript()
101  {
102  $value = $this->getProgressValue();
103  if ($value < 100)
104  {
105  $callback = $this->getCreateProgressBarAjax($this->progressBarId);
106  $message = $this->getMessage();
107  }
108  else
109  {
110  $callback = null;
111  $this->onProgressComplete();
112  $message = $this->getCompleteMessage();
113  }
114 
115  $data = array(
116 
117  'callback' => $callback,
118  'value' => $value,
119  'message' => $message,
120  );
121  return $data;
122  }
123 
124  protected function renderContent()
125  {
126  $cClipWidget = new CClipWidget();
127  $cClipWidget->beginClip("ProgressBar");
128  $cClipWidget->widget('zii.widgets.jui.CJuiProgressBar', array(
129  'id' => $this->progressBarId,
130  'value' => $this->getProgressValue(),
131  'options' => array(
132  'create' => 'js:function(event, ui)
133  {
134  ' . $this->getCreateProgressBarAjax($this->progressBarId) . ';
135  $("#progress-percent").html( Math.ceil($(\'#' . $this->progressBarId . '\').progressbar("value")) + "&#37;");
136  }',
137  'change' => 'js:function(event, ui)
138  {
139  $("#progress-percent").html( Math.ceil($(\'#' . $this->progressBarId . '\').progressbar("value")) + "&#37;");
140  }',
141  'complete' => 'js:function(event, ui)
142  {
143  $(".progressbar-wrapper").fadeOut(250);
144  $(\'#' . $this->progressBarId . '-links\').show();
145  }',
146  ),
147  ));
148  $cClipWidget->endClip();
149  $progressBarContent = $cClipWidget->getController()->clips['ProgressBar'];
150  $content = "<div><h1>" . $this->headerLabelPrefixContent() . ' : ' . $this->title . '</h1>';
151  $content .= '<div class="progress-counter">';
152  $content .= '<h3><span id="' . $this->progressBarId . '-msg">' . $this->getMessage() . '</span></h3>';
153  $content .= '<div class="progressbar-wrapper"><span id="progress-percent">0&#37;</span>' . $progressBarContent . '</div>';
154  $content .= $this->renderFormLinks();
155  $content .= '</div>';
156  $content .= '</div>';
157  return $content;
158  }
159 
160  protected function getCreateProgressBarAjax($progressBarId)
161  {
162  return ZurmoHtml::ajax(array(
163  'type' => 'POST',
164  'dataType' => 'json',
165  'data' => Yii::app()->getUrlManager()->createPathInfo($_POST, '=', '&'),
166  'url' => Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/' . $this->refreshActionId,
167  array_merge($_GET, array( get_class($this->model) . '_page' => ($this->page + 1), 'totalCount' => $this->totalRecordCount))
168  ),
169  'success' => 'function(data)
170  {
171  $(\'#' . $progressBarId . '-msg\').html(data.message);
172  $(\'#' . $progressBarId . '\').progressbar({value: data.value});
173  eval(data.callback);
174  }',
175  ));
176  }
177 
178  protected function getProgressValue()
179  {
180  $value = ($this->getEndSize() / $this->totalRecordCount) * 100;
181  if ($value >= 100)
182  {
183  return 100;
184  }
185  else
186  {
187  return $value;
188  }
189  }
190 
191  protected function getEndSize()
192  {
193  $end = $this->start + $this->pageSize - 1;
194  if ($end > $this->totalRecordCount)
195  {
196  return $this->totalRecordCount;
197  }
198  return $end;
199  }
200 
205  protected function onProgressComplete()
206  {
207  }
208  }
209 ?>
__construct($controllerId, $moduleId, $model, $totalRecordCount, $start, $pageSize, $page, $refreshActionId, $title)
Definition: View.php:43
renderRefreshJSONScript()
Generated on Fri Jun 5 2020 07:10:29