Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MassEditView.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  abstract class MassEditView extends MassActionView
41  {
42  protected static function getFormId()
43  {
44  return 'edit-form';
45  }
46 
47  protected function renderAlertMessage()
48  {
49  if (!empty($this->alertMessage))
50  {
51  JNotify::addMessage('FlashMessageBar', $this->alertMessage, 'MassEditAlertMessage');
52  }
53  }
54 
55  protected function renderPreActionElementBar($form)
56  {
57  return $this->renderFormLayout($form) . $this->renderAfterFormLayout($form);
58  }
59 
60  protected function renderOperationHighlight()
61  {
62  return null;
63  }
64 
65  protected function renderItemOperationType()
66  {
67  return 'updating';
68  }
69 
70  protected function renderItemLabel()
71  {
72  return LabelUtil::getUncapitalizedRecordLabelByCount($this->selectedRecordCount);
73  }
74 
84  protected function renderFormLayout($form = null)
85  {
86  $metadata = self::getMetadata();
87  $massEditScript = '';
88  $content = '<table class="form-fields">';
89  $content .= '<colgroup>';
90  $content .= '<col class="col-checkbox" style="width:36px"/><col style="width:20%" /><col/>';
91  $content .= '</colgroup>';
92  $content .= '<tbody>';
93  //loop through each panel
94  foreach ($metadata['global']['panels'] as $panel)
95  {
96  foreach ($panel['rows'] as $row)
97  {
98  foreach ($row['cells'] as $cell)
99  {
100  if (is_array($cell['elements']))
101  {
102  foreach ($cell['elements'] as $elementInformation)
103  {
104  $elementClassName = $elementInformation['type'] . 'Element';
105  $realAttributeName = $this->resolveRealAttributeName($elementClassName, $elementInformation['attributeName']);
106  if ($realAttributeName != null)
107  {
108  $content .= '<tr>';
109  $params = array_slice($elementInformation, 2);
110  if (empty($this->activeAttributes[$elementInformation['attributeName']]))
111  {
112  $params['disabled'] = true;
113  //The reason for adding the following loop is that in case of mass edit
114  //calendar need not be disabled but hidden as it is controlled using checkbox click
115  if ($elementInformation['type'] == 'DateTime' || $elementInformation['type'] == 'Date')
116  {
117  $params['datePickerDisabled'] = false;
118  }
119  $checked = false;
120  }
121  else
122  {
123  $checked = true;
124  }
125  if ($elementInformation['type'] == 'TagCloud')
126  {
127  $params['showTooltip'] = true;
128  }
129  $element = new $elementClassName($this->model, $elementInformation['attributeName'], $form, $params);
130  $content .= $this->renderActiveAttributesCheckBox($element->getEditableNameIds(),
131  $elementInformation, $checked, $realAttributeName);
132  $content .= $element->render();
133  $content .= '</tr>';
134  }
135  }
136  }
137  }
138  }
139  }
140  $content .= '</tbody>';
141  $content .= '</table>';
142  $this->renderDateTimeScript();
143  return $content;
144  }
145 
146  protected function renderActiveAttributesCheckBox($elementIds, $elementInformation, $checked, $realAttributeName)
147  {
148  $checkBoxHtmlOptions = array();
149  if ($elementInformation['type'] == 'DateTime' || $elementInformation['type'] == 'Date')
150  {
151  $checkBoxHtmlOptions['class'] = 'dateOrDateTime';
152  }
153  $checkBoxHtmlOptions['id'] = "MassEdit_" . $realAttributeName;
154  $enableInputsScript = "";
155  $disableInputsScript = "";
156  foreach ($elementIds as $id)
157  {
158  if ($elementInformation['type'] == 'DropDown' || $elementInformation['type'] == 'RadioDropDown')
159  {
160  $enableInputsScript .= "$('#" . $id . "').removeAttr('disabled'); \n";
161  $enableInputsScript .= "$('#" . $id . "').prev().removeClass('disabled-select-element'); \n";
162  $disableInputsScript .= "$('#" . $id . "').attr('disabled', 'disabled'); \n";
163  $disableInputsScript .= "$('#" . $id . "').prev().addClass('disabled-select-element'); \n";
164  }
165  elseif ($elementInformation['type'] == 'TagCloud')
166  {
167  $enableInputsScript .= "$('#token-input-" . $id . "').parent().parent().removeClass('disabled'); \n";
168  $disableInputsScript .= "$('#token-input-" . $id . "').parent().parent().addClass('disabled'); \n";
169  }
170  else
171  {
172  $enableInputsScript .= "$('#" . $id . "').removeAttr('disabled'); \n";
173  $enableInputsScript .= "if ($('#" . $id . "').attr('type') != 'button')
174  {
175  if ($('#" . $id . "').attr('href') != undefined)
176  {
177  $('#" . $id . "').css('display', '');
178  }
179  }; \n";
180  $disableInputsScript .= "$('#" . $id . "').attr('disabled', 'disabled'); \n";
181  $disableInputsScript .= "if ($('#" . $id . "').attr('type') != 'button')
182  {
183  if ($('#" . $id . "').attr('href') != undefined)
184  {
185  $('#" . $id . "').css('display', 'none');
186  }
187  $('#" . $id . "').val('');
188  }; \n";
189  }
190  }
191  $massEditScript = <<<END
192 $('#{$checkBoxHtmlOptions['id']}').click(function()
193  {
194  if (this.checked)
195  {
196  $enableInputsScript
197  }
198  else
199  {
200  $disableInputsScript
201  }
202  }
203 );
204 END;
205  Yii::app()->clientScript->registerScript($checkBoxHtmlOptions['id'], $massEditScript);
206  return "<th>" . ZurmoHtml::checkBox("MassEdit[" . $realAttributeName . "]", $checked, $checkBoxHtmlOptions) ."</th> \n";
207  }
208 
209  public static function getDesignerRulesType()
210  {
211  return 'MassEditView';
212  }
213 
222  protected function resolveRealAttributeName($elementClassName, $attributeName)
223  {
224  assert('is_string($elementClassName)');
225  if ($attributeName == 'null')
226  {
227  $classToEvaluate = new ReflectionClass($elementClassName);
228  if ($classToEvaluate->implementsInterface('DerivedElementInterface'))
229  {
230  $modelAttributeNames = $elementClassName::getModelAttributeNames();
231  if (count($modelAttributeNames) == 0 || count($modelAttributeNames) > 1)
232  {
233  return null;
234  }
235  return $modelAttributeNames[0];
236  }
237  else
238  {
239  return null;
240  }
241  }
242  else
243  {
244  return $attributeName;
245  }
246  }
247 
251  protected function renderDateTimeScript()
252  {
253  $script = "
254  $('.dateOrDateTime').click(function()
255  {
256  if ($(this).is(':checked'))
257  {
258  $(this).parent().parent().parent().find('.ui-datepicker-trigger').show();
259  }
260  else
261  {
262  $(this).parent().parent().parent().find('.ui-datepicker-trigger').hide();
263  }
264  });
265  $('.dateOrDateTime').each(
266  function(index)
267  {
268  if ($(this).is(':checked'))
269  {
270  $(this).parent().parent().parent().find('.ui-datepicker-trigger').show();
271  }
272  else
273  {
274  $(this).parent().parent().parent().find('.ui-datepicker-trigger').hide();
275  }
276  }
277  );
278  ";
279  Yii::app()->clientScript->registerScript('datetimescript', $script);
280  }
281 
282  protected function getOperationAdditionalMessage()
283  {
284  $message = "Please tick the boxes next to the fields you wish to update and then select the value you wish to be used.";
285  return $message;
286  }
287  }
288 ?>
static checkBox($name, $checked=false, $htmlOptions=array())
Definition: ZurmoHtml.php:267
renderFormLayout($form=null)
static addMessage($statusBarId, $text, $scriptId, $type= 'message')
Definition: JNotify.php:97
resolveRealAttributeName($elementClassName, $attributeName)
static getUncapitalizedRecordLabelByCount($count)
Definition: LabelUtil.php:46
Generated on Tue Jul 7 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.