Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DesignerLayoutEditor.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 
37  Yii::import('zii.widgets.jui.CJuiWidget');
38 
44  class DesignerLayoutEditor extends CJuiWidget
45  {
49  public $canAddPanels;
50 
54  public $canAddRows;
55 
59  public $canMergeAndSplitCells;
60 
64  public $canModifyCellSettings;
65 
69  public $canModifyPanelSettings;
70 
74  public $canMovePanels;
75 
79  public $canMoveRows;
80 
84  public $canRemovePanels;
85 
89  public $canRemoveRows;
90 
94  public $designerLayoutAttributes;
95 
99  public $maxCellsPerRow;
100 
104  public $mergeRowAndAttributePlacement;
105 
109  public $showRequiredAttributeSpan;
110 
114  public $viewMetadata;
115 
120  public $cssFile = null;
121 
122  protected function canRemoveElement()
123  {
124  return !$this->mergeRowAndAttributePlacement;
125  }
126 
127  protected function doesCellHaveAnyWideElements($cell)
128  {
129  if (is_array($cell['elements']))
130  {
131  foreach ($cell['elements'] as $elementInformation)
132  {
133  $elementParams = array_slice($elementInformation, 2);
134  if (isset($elementParams['wide']) && $elementParams['wide'])
135  {
136  return true;
137  }
138  }
139  }
140 
141  return false;
142  }
143 
144  protected function getCellSettingsDisplay($detailViewOnly, $cellIdName)
145  {
146  $content = '<div class="cell-settings modal-settings" title="'. Zurmo::t('Core', 'Cell Settings') .'">';
147  $content .= '<div class="wide form">';
148  $content .= '<table>';
149  $content .= TableUtil::getColGroupContent(1);
150  $content .= '<tr>';
151  $content .= '<th><label>' . Zurmo::t('Core', 'Detail View Only') . '</label></th>';
152  $content .= '<td>' . ZurmoHtml::checkBox( 'detailViewOnly_' . $cellIdName, $detailViewOnly,
153  array('class' => 'settings-form-field')
154  ) . '</td>';
155  $content .= '</tr>';
156 
157  $content .= '</table>';
158  $content .= '<div class="view-toolbar-container clearfix"><div class="form-toolbar">';
159  $content .= $this->renderSaveModalSettingsButton();
160  $content .= '</div></div>';
161  $content .= '</div>';
162  $content .= '</div>';
163  return $content;
164  }
165 
166  protected function getPanelSettingsDisplay($title, $detailViewOnly, $locked, $panelIdName)
167  {
168  assert('is_bool($locked) || $locked == null');
169  $content = '<div class="panel-settings modal-settings" title="'. Zurmo::t('Core', 'Panel Settings') .'">';
170  $content .= '<div class="wide form">';
171  $content .= '<table>';
172  $content .= TableUtil::getColGroupContent(1);
173  $content .= '<tr>';
174  $content .= '<th><label>' . Zurmo::t('Core', 'Panel Title') . '</label></th>';
175  $content .= '<td>' . ZurmoHtml::textField( 'title_' . $panelIdName,
176  $title, array('class' => 'panel-title settings-form-field')) .
177  ZurmoHtml::hiddenField( 'locked_' . $panelIdName,
178  $locked, array('class' => 'panel-title settings-form-field')) . '</td>';
179  $content .= '</tr>';
180  $content .= '<tr>';
181  $content .= '<th><label>' . Zurmo::t('Core', 'Detail View Only') . '</label></th>';
182  $content .= '<td>' . ZurmoHtml::checkBox( 'detailViewOnly_' . $panelIdName, $detailViewOnly,
183  array('class' => 'panel-title settings-form-field')
184  ) . '</td>';
185  $content .= '</tr>';
186 
187  $content .= '</table>';
188  $content .= '<div class="view-toolbar-container clearfix"><div class="form-toolbar">';
189  $content .= $this->renderSaveModalSettingsButton();
190  $content .= '</div></div>';
191  $content .= '</div>';
192  $content .= '</div>';
193  return $content;
194  }
195 
196  protected function renderSaveModalSettingsButton()
197  {
198  return ZurmoHtml::link(ZurmoHtml::wrapLink(Zurmo::t('Core', 'Save and Close')), '#',
199  array('class' => 'green-button', 'onclick' => '$(this).closest(".modal-settings").dialog("close");')); // Not Coding Standard
200  }
201 
205  public function init()
206  {
207  assert('$this->designerLayoutAttributes instanceof DesignerLayoutAttributes');
208  assert('is_bool($this->canAddRows)');
209  assert('is_bool($this->canMoveRows)');
210  assert('is_bool($this->canRemoveRows)');
211  assert('is_bool($this->canAddPanels)');
212  assert('is_bool($this->canModifyPanelSettings)');
213  assert('is_bool($this->canRemovePanels)');
214  assert('is_bool($this->canMovePanels)');
215  assert('is_bool($this->canModifyCellSettings)');
216  assert('is_bool($this->canMergeAndSplitCells)');
217  assert('is_bool($this->mergeRowAndAttributePlacement)');
218  assert('is_int($this->maxCellsPerRow)');
219  assert('is_bool($this->showRequiredAttributeSpan)');
220  assert('!empty($this->viewMetadata["global"]["panels"])');
221  if ($this->canMoveRows == false)
222  {
223  assert('!$this->canAddRows');
224  }
225  if ($this->canMovePanels == false)
226  {
227  assert('!$this->canAddPanels');
228  }
229  $this->registerScripts();
230  parent::init();
231  }
232 
233  protected function registerScripts()
234  {
235  $baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.core.widgets.assets'));
236  $cs = Yii::app()->getClientScript();
237  $cs->registerScriptFile($baseScriptUrl . '/designer/Designer.js', CClientScript::POS_END);
238  }
239 
240  protected function renderLayout()
241  {
242  $content = '<div id="layout-container">';
243  if ($this->canMovePanels)
244  {
245  $content .= '<ul class="sortable-panel-list panel-list">';
246  }
247  else
248  {
249  $content .= '<ul class="panel-list">';
250  }
251 
252  foreach ($this->viewMetadata['global']['panels'] as $panelNumber => $panel)
253  {
254  $content .= '<li id="panel_' . $panelNumber . '" class="ui-state-default sortable-panel">';
255  $content .= '<span class="panel-title-display">' .
256  ArrayUtil::getArrayValue($panel, 'title') . '&#160;</span>';
257  if ($this->canMovePanels)
258  {
259  if (!ArrayUtil::getArrayValue($panel, 'locked'))
260  {
261  $content .= '<span class="panel-handle-icon ui-icon ui-icon-arrow-4">&#160;</span>';
262  }
263  }
264  if ($this->canRemovePanels)
265  {
266  $content .= '<span class="panel-element-icon ui-icon ui-icon-trash">&#160;</span>';
267  }
268  if ($this->canModifyPanelSettings)
269  {
270  $content .= '<span class="panel-modify-settings-link panel-element-icon ui-icon ui-icon-wrench">&#160;</span>';
271  }
272  $content .= '<div class="sortable-row-list-container">';
273  if ($this->canMoveRows)
274  {
275  if (!ArrayUtil::getArrayValue($panel, 'locked'))
276  {
277  $content .= '<ul class="sortable-row-list sortable-row-list-helper sortable-row-connector">';
278  }
279  else
280  {
281  $content .= '<ul class="sortable-row-list-helper sortable-row-connector">';
282  }
283  }
284  else
285  {
286  $content .= '<ul class="sortable-row-connector">';
287  }
288  foreach ($panel['rows'] as $row)
289  {
290  $content .= '<li class="ui-state-default">';
291  if ($this->canMoveRows)
292  {
293  if (!ArrayUtil::getArrayValue($panel, 'locked'))
294  {
295  $content .= '<span class="row-handle-icon ui-icon ui-icon-arrow-4">&#160;</span>';
296  }
297  }
298  foreach ($row['cells'] as $cell)
299  {
300  if ($this->doesCellHaveAnyWideElements($cell) ||
301  $this->maxCellsPerRow == 1
302  )
303  {
304  $cssClassName = 'layout-single-column';
305  $cssCellMergeIconClassName = 'ui-icon-circle-plus';
306  }
307  else
308  {
309  $cssClassName = 'layout-double-column';
310  $cssCellMergeIconClassName = 'ui-icon-circle-minus';
311  }
312  if (!ArrayUtil::getArrayValue($panel, 'locked'))
313  {
314  $content .= '<div class="' . $cssClassName . ' droppable-cell-container droppable-cell-container-helper ui-state-hover">';
315  }
316  else
317  {
318  //droppable-cell-container must be present for save to work
319  $content .= '<div class="' . $cssClassName . ' droppable-cell-container-helper ui-state-hover">';
320  }
321 
322  if (is_array($cell['elements']))
323  {
324  assert('count($cell["elements"]) == 1');
325  $elementInformation = $cell['elements'][0];
326  if ($elementInformation['attributeName'] != null)
327  {
328  $attribute = $this->designerLayoutAttributes->getByAttributeNameAndType(
329  $elementInformation['attributeName'],
330  $elementInformation['type']
331  );
332  $divId = $attribute['attributeIdPrefix'] . '_Placed';
333  $content .= '<div id="' . $divId . '" ';
334  if ($this->mergeRowAndAttributePlacement)
335  {
336  $content .= 'class="cell-element">';
337  }
338  else
339  {
340  if (!ArrayUtil::getArrayValue($panel, 'locked'))
341  {
342  $content .= 'class="movable-cell-element cell-element">';
343  }
344  else
345  {
346  $content .= 'class="cell-element">';
347  }
348  }
349  if (!ArrayUtil::getArrayValue($panel, 'locked'))
350  {
351  $content .= '<span class="cell-handle-icon ui-icon ui-icon-arrow-4">&#160;</span>';
352  }
353  $content .= $attribute['attributeLabel'];
354  if ($this->showRequiredAttributeSpan && $attribute['isRequired'])
355  {
356  $content .= '<span class="required">*</span>';
357  }
358  if ($this->canRemoveElement())
359  {
360  if (!ArrayUtil::getArrayValue($panel, 'locked'))
361  {
362  $content .= '<span class="cell-element-icon ui-icon ui-icon-trash">&#160;</span>';
363  }
364  }
365  if ($this->canModifyCellSettings)
366  {
367  $content .= '<span class="cell-modify-settings-link cell-element-icon ui-icon ui-icon-wrench">&#160;</span>';
368  }
369  $content .= $this->getCellSettingsDisplay(
370  ArrayUtil::getArrayValue($cell, 'detailViewOnly'),
371  $divId
372  );
373  $content .= '</div>';
374  unset($divId);
375  }
376  unset($elementInformation);
377  }
378  $content .= '</div>';
379  }
380  if (!ArrayUtil::getArrayValue($panel, 'locked'))
381  {
382  $content .= '<span class="row-element-icon ui-icon ui-icon-trash">&#160;</span>';
383  }
384  if ($this->canMergeAndSplitCells)
385  {
386  $content .= '<span class="row-element-icon ui-icon ' . $cssCellMergeIconClassName .'">&#160;</span>';
387  }
388  $content .= '</li>';
389  }
390  $content .= '</ul>';
391  $content .= '</div>';
392 
393  $content .= $this->getPanelSettingsDisplay(
394  ArrayUtil::getArrayValue($panel, 'title'),
395  ArrayUtil::getArrayValue($panel, 'detailViewOnly'),
396  ArrayUtil::getArrayValue($panel, 'locked'),
397  $panelNumber
398  );
399  $content .= '</li>';
400  }
401  $content .= '</ul>';
402  $content .= '</div>';
403  return $content;
404  }
405 
406  protected function renderLayoutTools()
407  {
408  $content = '<div class = "sticky-anchor"></div>';
409  $content .= '<div class = "sticky">';
410  $content .= '<div class = "stickyD"></div>';
411  $content .= '<div class = "layout-parts-container">';
412  $content .= '<div class = "layout-parts">';
413  if ($this->canAddRows)
414  {
415  $content .= '<ul>';
416  $content .= '<li class = "rowToPlace ui-state-default">' . Zurmo::t('Core', 'Row') . '</li>';
417  $content .= '</ul>';
418  }
419  if ($this->canAddPanels)
420  {
421  $content .= '<ul>';
422  $content .= '<li class = "panelToPlace ui-state-default">' . Zurmo::t('Core', 'Panel') . '</li>';
423  $content .= '</ul>';
424  }
425  $content .= '</div>';
426  $content .= '<div class = "layout-elements">';
427  $startColumnDiv = true;
428  $endColumnDiv = false;
429  $columnDivCount = 0;
430  foreach ($this->designerLayoutAttributes->get() as $data)
431  {
432  $columnDivCount++;
433  if ($startColumnDiv)
434  {
435  $startColumnDiv = false;
436  $content .= '<div class = "layout-elements-column-container">';
437  }
438  if ($columnDivCount == 2)
439  {
440  $startColumnDiv = true;
441  $endColumnDiv = true;
442  $columnDivCount = 0;
443  }
444  if ($data['availableToSelect'])
445  {
446  $cssClass = 'ui-state-default';
447  }
448  else
449  {
450  $cssClass = 'ui-state-disabled';
451  }
452  $content .= '<div id = "' . $data['attributeIdPrefix'] . '_elementToPlace" class = "element-to-place ui-state-default ' . $cssClass . '">';
453  $content .= $data['attributeLabel'];
454  if ($this->showRequiredAttributeSpan && $data['isRequired'])
455  {
456  $content .= '<span class="required">*</span>';
457  }
458  $content .= '</div>';
459  if ($endColumnDiv)
460  {
461  $content .= '</div>';
462  $endColumnDiv = false;
463  }
464  }
465  if ($startColumnDiv == false)
466  {
467  $content .= '</div>';
468  unset($endColumnDiv);
469  }
470  $content .= '</div>';
471  $content .= '</div>';
472  $content .= '</div>';
473  return $content;
474  }
475 
480  public function run()
481  {
482  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->id,
483  "designer.init(
484  " . BooleanUtil::boolToString($this->canAddPanels) .",
485  " . BooleanUtil::boolToString($this->canModifyPanelSettings) .",
486  " . BooleanUtil::boolToString($this->canRemovePanels) .",
487  " . BooleanUtil::boolToString($this->canMovePanels) .",
488  " . BooleanUtil::boolToString($this->canAddRows) .",
489  " . BooleanUtil::boolToString($this->canMoveRows) .",
490  " . BooleanUtil::boolToString($this->canRemoveRows) .",
491  " . BooleanUtil::boolToString($this->canModifyCellSettings) .",
492  " . BooleanUtil::boolToString($this->canMergeAndSplitCells) .",
493  " . BooleanUtil::boolToString($this->mergeRowAndAttributePlacement) .",
494  " . $this->maxCellsPerRow . ",
495  '" . $this->getPanelSettingsDisplay(null, false, false, '{panelId}') . "',
496  '" . $this->getCellSettingsDisplay(false, '{cellId}') . "'
497  );");
498  echo $this->renderLayoutTools();
499  echo $this->renderLayout();
500  }
501  }
502 ?>
static checkBox($name, $checked=false, $htmlOptions=array())
Definition: ZurmoHtml.php:267
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static boolToString($var)
Definition: BooleanUtil.php:64
static wrapLink($label)
Definition: ZurmoHtml.php:666
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.