Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
BaseBuilderElement.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  abstract class BaseBuilderElement
38  {
42  const OVERLAY_ACTION_MOVE = 'action-move';
43 
47  const OVERLAY_ACTION_EDIT = 'action-edit';
48 
52  const OVERLAY_ACTION_DELETE = 'action-delete';
53 
57  const OVERLAY_ACTIONS_CONTAINER_CLASS = 'builder-element-toolbar';
58 
62  const BUILDER_ELEMENT_CELL_DROPPABLE_CLASS = 'builder-element-cell-droppable';
63 
67  const BUILDER_ELEMENT_SORTABLE_ELEMENTS_CLASS = 'sortable-elements';
68 
72  const BUILDER_ELEMENT_SORTABLE_ROWS_CLASS = 'sortable-rows';
73 
77  protected $id;
78 
82  protected $properties;
83 
87  protected $content;
88 
92  protected $params;
93 
97  protected $model;
98 
105  protected $renderForCanvas = false;
106 
110  public static function isUIAccessible()
111  {
112  return false;
113  }
114 
120  public static final function resolveDroppableWidget($widgetWrapper = 'li')
121  {
122  $label = static::resolveLabel();
123  $label = ZurmoHtml::tag('span', array(), $label);
124  $icon = ZurmoHtml::tag('i', static::resolveThumbnailHtmlOptions(), '');
125  $widget = ZurmoHtml::tag('div', array('class' => 'clearfix'), $icon . $label);
126  return ZurmoHtml::tag($widgetWrapper, static::resolveWidgetHtmlOptions(), $widget);
127  }
128 
133  public static function isContainerType()
134  {
135  return false;
136  }
137 
142  public static final function getModelClassName()
143  {
144  return 'BuilderElementEditableModelForm';
145  }
146 
151  protected static function resolveLabel()
152  {
153  throw new NotImplementedException('Children element should specify their own label');
154  }
155 
160  protected static function resolveThumbnailName()
161  {
162  $name = strtolower(get_called_class());
163  $name = str_replace('element', '', $name);
164  $name = str_replace('builder', '', $name);
165  return $name;
166  }
167 
172  protected static function resolveThumbnailHtmlOptions()
173  {
174  return array('class' => 'icon-' . static::resolveThumbnailName());
175  }
176 
181  protected static function resolveWidgetHtmlOptions()
182  {
183  return array('data-class' => get_called_class(), 'class' => static::resolveWidgetClassesForHtmlOptions());
184  }
185 
186  protected static function resolveWidgetClassesForHtmlOptions()
187  {
188  $classes = 'builder-element builder-element-droppable';
189  if (!static::isContainerType())
190  {
191  $classes .= ' ' . static::BUILDER_ELEMENT_CELL_DROPPABLE_CLASS;
192  }
193  return $classes;
194  }
195 
203  public function __construct($renderForCanvas = false, $id = null, $properties = null, $content = null, $params = null)
204  {
205  $this->renderForCanvas = $renderForCanvas;
206  $this->initId($id);
207  $this->initProperties($properties);
208  $this->initContent($content);
209  $this->initParams($params);
210  $this->initModel();
211  $this->cleanUpProperties();
212  }
213 
218  public final function renderNonEditable()
219  {
221  $elementContent = $this->renderControlContentNonEditable();
222  $wrappedContent = $this->renderControlWrapperNonEditable($elementContent);
223  return $wrappedContent;
224  }
225 
230  public final function renderEditable()
231  {
232  if ($this->doesNotSupportEditable())
233  {
234  throw new NotSupportedException('This element does not support editable representation');
235  }
236  $formTitle = $this->resolveFormatterFormTitle();
237  $formContent = $this->renderFormContent();
238  $content = $formTitle . $formContent;
239  $content = ZurmoHtml::tag('div', array('class' => 'element-edit-form-overlay clearfix'), $content);
240  return $content;
241  }
242 
247  protected function doesNotSupportEditable()
248  {
249  return false;
250  }
251 
255  protected function registerNonEditableSnippets()
256  {
258  $this->registerNonEditableCss();
259  }
260 
264  protected function registerNonEditableScripts()
265  {
266  }
267 
271  protected function registerNonEditableCss()
272  {
273  }
274 
279  protected function renderControlContentNonEditable()
280  {
281  $content = $this->renderContentElement(null);
282  return $content;
283  }
284 
290  protected final function renderControlWrapperNonEditable($elementContent = '{{dummyContent}}')
291  {
292  $customDataAttributes = $this->resolveCustomDataAttributesNonEditable();
293  $actionsOverlay = $this->resolveNonEditableActions();
294  $content = $this->resolveWrapperNonEditable($elementContent, $customDataAttributes, $actionsOverlay);
295  return $content;
296  }
297 
305  protected function resolveWrapperNonEditable($elementContent, array $customDataAttributes,
306  $actionsOverlay)
307  {
308  $contentSuffix = null;
309  if (!empty($actionsOverlay))
310  {
311  $contentSuffix .= $actionsOverlay;
312  }
313  $content = $this->resolveWrapperNonEditableByContentAndProperties($elementContent, $customDataAttributes);
314  if ($contentSuffix !== null)
315  {
316  $content .= $contentSuffix;
317  $content = $this->wrapNonEditableElementContent($content);
318  }
319  return $content;
320  }
321 
327  protected function wrapNonEditableElementContent($content)
328  {
329  $content = ZurmoHtml::tag('div', array('class' => 'element-wrapper'), $content);
330  return $content;
331  }
332 
338  {
339  return array('class' => 'element-wrapper');
340  }
341 
348  protected function resolveWrapperNonEditableByContentAndProperties($content, array $customDataAttributes)
349  {
350  $options = $this->resolveNonEditableWrapperOptions($customDataAttributes);
351  $content = ZurmoHtml::tag('div', $options, $content);
352  return $content;
353  }
354 
360  {
361  $properties = array();
362  $frontendProperties = ArrayUtil::getArrayValue($this->properties, 'frontend');
363  if ($frontendProperties)
364  {
365  // we are not on canvas, may be preview or just generating final newsletter.
366  // do not render backend properties.
367  $properties = $frontendProperties;
368  }
369  $this->resolveInlineStylePropertiesNonEditable($properties);
370  return $properties;
371  }
372 
377  protected final function resolveInlineStylePropertiesNonEditable(array & $mergedProperties)
378  {
379  $mergedProperties['style'] = '';
380  $inlineStyles = $this->resolveInlineStylesForNonEditable($mergedProperties);
381  if ($inlineStyles)
382  {
383  unset($mergedProperties['inlineStyles']);
384  $mergedProperties['style'] = $this->stringifyProperties($inlineStyles, null, null, ':', ';');
385  }
386  $this->resolveInlineStylesFromBackendPropertiesNonEditable($mergedProperties);
387  }
388 
393  protected function resolveInlineStylesForNonEditable(array & $mergedProperties)
394  {
395  return ArrayUtil::getArrayValue($mergedProperties, 'inlineStyles');
396  }
397 
402  protected function resolveInlineStylesFromBackendPropertiesNonEditable(array & $mergedProperties)
403  {
404  $this->resolveInlineStylesForBorderDirectionNegationFromBackendPropertiesNonEditable($mergedProperties);
405  }
406 
407  protected function resolveInlineStylesForBorderDirectionNegationFromBackendPropertiesNonEditable(array & $mergedProperties)
408  {
409  $borderNegationStyles = ArrayUtil::getNestedValue($this->properties, 'backend[border-negation]');
410  if (!empty($borderNegationStyles))
411  {
412  $borderNegationKeys = array_keys($borderNegationStyles, 'none');
413  foreach ($borderNegationKeys as $borderNegationKey)
414  {
415  $mergedProperties['style'] .= "${borderNegationKey}:none;";
416  }
417  }
418  }
419 
429  protected final function stringifyProperties(array $properties, $keyPrefix = null, $keySuffix = null,
430  $valuePrefix = null, $valueSuffix = null)
431  {
432  $this->sanitizeProperties($properties);
433  $content = $this->stringifyArray($properties, $keyPrefix, $keySuffix, $valuePrefix, $valueSuffix);
434  return $content;
435  }
436 
446  protected final function stringifyArray(array $array, $keyPrefix = null, $keySuffix = null,
447  $valuePrefix = null, $valueSuffix = null)
448  {
449  $content = null;
450  foreach ($array as $key => $value)
451  {
452  $content .= $keyPrefix . $key . $keySuffix . $valuePrefix . $value . $valueSuffix;
453  }
454  return $content;
455  }
456 
461  protected final function resolveCustomDataAttributesNonEditable()
462  {
463  if (!$this->renderForCanvas)
464  {
465  return array();
466  }
467  $cda['data-class'] = get_class($this);
468  $cda['data-properties'] = CJSON::encode($this->properties);
469  $cda['data-content'] = CJSON::encode(array());
470  if (!$this->isContainerType())
471  {
472  // we don't want to bloat container type's data-content as it would be recompiled anyway.
473  $cda['data-content'] = CJSON::encode($this->content);
474  }
475  return $cda;
476  }
477 
482  protected final function resolveNonEditableActions()
483  {
484  if (!$this->renderForCanvas)
485  {
486  return null;
487  }
488  $overlayLinksContent = $this->resolveAvailableNonEditableActionLinkContent();
489  $overlayContent = ZurmoHtml::tag('div', $this->resolveNonEditableActionsHtmlOptions(), $overlayLinksContent);
490  return $overlayContent;
491  }
492 
498  {
499  return array('class' => static::OVERLAY_ACTIONS_CONTAINER_CLASS,
500  'id' => 'element-actions-' . $this->id);
501  }
502 
508  {
509  $availableActions = $this->resolveAvailableNonEditableActionsArray();
510  $overlayLinkContent = null;
511  foreach ($availableActions as $action)
512  {
513  $linkContent = $this->resolveAvailableNonEditableActionLinkSpan($action);
514  $overlayLinkContent .= $linkContent;
515  }
516  return $overlayLinkContent;
517  }
518 
519  protected function resolveAvailableNonEditableActionLinkSpan($action)
520  {
521  $iconContent = ZurmoHtml::tag('i', array('class' => 'icon-' . $action), '');
522  return ZurmoHtml::tag('span', array('class' => $action), $iconContent);
523  }
524 
530  {
531  return array(static::OVERLAY_ACTION_MOVE, static::OVERLAY_ACTION_EDIT, static::OVERLAY_ACTION_DELETE);
532  }
533 
539  {
540  return array('id' => $this->id, 'class' => 'builder-element-non-editable element-data');
541  }
542 
548  protected function resolveNonEditableWrapperOptions(array $customDataAttributes)
549  {
550  $htmlOptions = $this->resolveNonEditableWrapperHtmlOptions();
551  $frontendOptions = $this->resolveFrontendPropertiesNonEditable();
552  $options = CMap::mergeArray($htmlOptions, $frontendOptions, $customDataAttributes);
553  return $options;
554  }
555 
560  protected final function renderFormContent()
561  {
562  $this->registerActiveFormScripts();
563  $clipWidget = new ClipWidget();
564  list($form, $formStart) = $clipWidget->renderBeginWidget($this->resolveActiveFormClassName(),
565  $this->resolveActiveFormOptions());
566  $formInputContent = $this->renderFormInputsContent($form);
567  $formEnd = $this->renderFormActionLinks();
568  $formEnd .= $clipWidget->renderEndWidget();
569 
570  $content = $formStart;
571  $content .= $form->errorSummary($this->model);
572  $content .= $formInputContent;
573  $content .= $formEnd;
574  $content = ZurmoHtml::tag('div', array('class' => 'wide form'), $content);
575  $content = ZurmoHtml::tag('div', array('class' => 'wrapper'), $content);
576  $content .= $this->renderModalContainer($form);
577  return $content;
578  }
579 
580  protected function renderModalContainer($form)
581  {
582  return ZurmoHtml::tag('div', array(
583  'id' => ModelElement::MODAL_CONTAINER_PREFIX . '-' . $form->id
584  ), '');
585  }
586 
592  protected function renderFormInputsContent(ZurmoActiveForm $form)
593  {
594  $contentTabContent = $this->renderContentTab($form);
595 
596  $settingsTabContent = $this->renderSettingsTab($form);
597  if (isset($settingsTabContent))
598  {
599  $settingsTabContent = $this->wrapEditableContentFormContentInTable($settingsTabContent);
600  }
601 
602  $content = $this->renderBeforeFormLayout($form);
603  if (isset($contentTabContent, $settingsTabContent))
604  {
605  $content .= $this->renderWrappedContentAndSettingsTab($contentTabContent, $settingsTabContent);
606  }
607  else
608  {
609  $content = $contentTabContent . $settingsTabContent;
610  }
611  $content .= $this->renderHiddenFields($form);
612  $content .= $this->renderAfterFormLayout($form);
613  return $content;
614  }
615 
621  protected function renderContentTab(ZurmoActiveForm $form)
622  {
623  $content = $this->renderContentElement($form);
624  return $content;
625  }
626 
632  protected function wrapEditableContentFormContentInTable($content)
633  {
634  return ZurmoHtml::tag('table', array('class' => 'form-fields'), $content);
635  }
636 
640  protected function resolveFormTitle()
641  {
642  return static::resolveLabel();
643  }
644 
649  protected function resolveFormatterFormTitle()
650  {
651  $formTitle = ZurmoHtml::tag('h3', array(), $this->resolveFormTitle());
652  //$formTitle = ZurmoHtml::tag('center', array(), $formTitle);
653  return $formTitle;
654  }
655 
660  protected function resolveActiveFormClassName()
661  {
662  return 'ZurmoActiveForm';
663  }
664 
669  protected final function resolveActiveFormOptions()
670  {
671  $options = array('id' => $this->resolveFormId(),
672  'action' => $this->resolveFormActionUrl(),
673  'enableAjaxValidation' => $this->resolveEnableAjaxValidation(),
674  'clientOptions' => $this->resolveFormClientOptions(),
675  'htmlOptions' => $this->resolveFormHtmlOptions());
676  $customActiveFormOptions = $this->resolveActiveFormCustomOptions();
677  $options = CMap::mergeArray($options, $customActiveFormOptions);
678  return $options;
679  }
680 
685  protected function resolveFormId()
686  {
687  $formId = $this->id . '-edit-form';
688  return $formId;
689  }
690 
695  protected function resolveFormActionUrl()
696  {
697  return ComponentForEmailTemplateWizardView::resolveElementNonEditableActionUrl();
698  }
699 
705  protected function renderHiddenFields(ZurmoActiveForm $form)
706  {
707  $idHiddenInput = $this->renderHiddenField('id', $this->id);
708  $classNameHiddenInput = $this->renderHiddenField('className', get_class($this));
709  $hiddenFields = $idHiddenInput . $classNameHiddenInput;
710  return $hiddenFields;
711  }
712 
719  protected final function renderHiddenField($attributeName, $value)
720  {
721  return ZurmoHtml::hiddenField(ZurmoHtml::activeName($this->model, $attributeName),
722  $value,
723  array('id' => ZurmoHtml::activeId($this->model, $attributeName)));
724  }
725 
732  protected final function renderWrappedContentAndSettingsTab($contentTab, $settingsTab)
733  {
734  $contentTabClass = 'active-tab';
735  $settingsTabClass = null;
736 
737  $contentTabHyperLink = ZurmoHtml::link($this->renderContentTabLabel(), '#element-content',
738  array('class' => $contentTabClass));
739  $contentTabDiv = ZurmoHtml::tag('div', array('id' => 'element-content',
740  'class' => $contentTabClass . ' tab element-edit-form-content-tab'),
741  $contentTab);
742  $settingsTabHyperLink = ZurmoHtml::link($this->renderSettingsTabLabel(), '#element-settings',
743  array('class' => $settingsTabClass));
744  $settingsTabDiv = ZurmoHtml::tag('div', array('id' => 'element-settings',
745  'class' => $settingsTabClass . ' tab element-edit-form-settings-tab'),
746  $settingsTab);
748  $tabContent = ZurmoHtml::tag('div', array('class' => 'tabs-nav'),
749  $contentTabHyperLink . $settingsTabHyperLink);
750  $content = ZurmoHtml::tag('div', array('class' => 'edit-form-tab-content tabs-container'),
751  $tabContent . $contentTabDiv . $settingsTabDiv);
752  return $content;
753  }
754 
759  protected function renderContentTabLabel()
760  {
761  return Zurmo::t('Core', 'Content');
762  }
763 
768  protected function renderSettingsTabLabel()
769  {
770  return Zurmo::t('Core', 'Settings');
771  }
772 
776  protected function registerTabbedContentScripts()
777  {
778  $scriptName = 'element-edit-form-tab-switch-handler';
779  // Begin Not Coding Standard
780  Yii::app()->clientScript->registerScript($scriptName, "
781  $('.edit-form-tab-content .tabs-nav a:not(.simple-link)').click( function(event){
782  event.preventDefault();
783  if ( !$(this).hasClass('active-tab') )
784  {
785  //the menu items
786  $('.active-tab', $(this).parent()).removeClass('active-tab');
787  $(this).addClass('active-tab');
788  //the sections
789  var _old = $('.tab.active-tab'); //maybe add context here for tab-container
790  _old.fadeToggle();
791  _old.removeClass('active-tab');
792  var _new = $( $(this).attr('href') );
793  _new.fadeToggle(150, 'linear');
794  _new.addClass('active-tab');
795  }
796  });
797  ");
798  // End Not Coding Standard
799  }
800 
805  protected function renderFormActionLinks()
806  {
807  $content = $this->renderApplyLink();
808  $content .= $this->renderBackLink();
809  $content = ZurmoHtml::tag('div', array('class' => 'form-toolbar'), $content);
810  $content = ZurmoHtml::tag('div', array('class' => 'view-toolbar-container clearfix'), $content);
811  return $content;
812  }
813 
818  protected function renderBackLink()
819  {
820  $this->registerBackScript();
821  $label = ZurmoHtml::tag('span', array('class' => 'z-label'), $this->renderBackLinkLabel());
822  $link = ZurmoHtml::link($label, '#', $this->resolveBackLinkHtmlOptions());
823  return $link;
824  }
825 
830  protected function resolveBackLinkHtmlOptions()
831  {
832  return array('id' => $this->resolveBackLinkId(), 'class' => 'cancel-button');
833  }
834 
839  protected function resolveBackLinkId()
840  {
841  return 'elementEditFormBackLink';
842  }
843 
848  protected function renderBackLinkLabel()
849  {
850  return Zurmo::t('Core', 'Back');
851  }
852 
857  protected function renderApplyLink()
858  {
859  $this->registerApplyClickScript();
860  $label = $this->renderApplyLinkLabel();
861  $htmlOptions = $this->resolveApplyLinkHtmlOptions();
862  $wrappedLabel = ZurmoHtml::wrapLink($label);
863  $link = ZurmoHtml::link($wrappedLabel, '#', $htmlOptions);
864  return $link;
865  }
866 
871  protected function resolveApplyLinkHtmlOptions()
872  {
873  return array('id' => $this->resolveApplyLinkId(), 'class' => 'z-button');
874  }
875 
880  protected function resolveApplyLinkId()
881  {
882  return 'elementEditFormApplyLink';
883  }
884 
889  protected function renderApplyLinkLabel()
890  {
891  return Zurmo::t('Core', 'Apply');
892  }
893 
897  protected function registerActiveFormScripts()
898  {
899  $this->registerHideFormScript();
900  }
901 
905  protected function registerApplyClickScript()
906  {
907  Yii::app()->clientScript->registerScript('applyClick', "
908  $('#" . $this->resolveApplyLinkId() . "').unbind('click').bind('click', function()
909  {
910  jQuery.yii.submitForm(this, '', {}); return false;
911  });
912  ");
913  }
914 
920  {
921  $ajaxScript = '';
922  if ($this->isContainerType())
923  {
924  $ajaxScript = "emailTemplateEditor.initSortableElements(emailTemplateEditor.settings.sortableElementsSelector,
925  emailTemplateEditor.settings.sortableElementsSelector,
926  $('#" . BuilderCanvasWizardView::CANVAS_IFRAME_ID ."').contents());";
927  }
928  return $ajaxScript;
929  }
930 
934  protected function registerBackScript()
935  {
936  Yii::app()->clientScript->registerScript('backLinkClick', "
937  $('#" . $this->resolveBackLinkId() . "').unbind('click.backLinkClick').bind('click.backLinkClick', function()
938  {
939  hideElementEditFormOverlay();
940  $('#" . BuilderCanvasWizardView::ELEMENTS_CONTAINER_ID . "').show();
941  });
942  ");
943  }
944 
948  protected function registerHideFormScript()
949  {
950  Yii::app()->clientScript->registerScript('hideElementEditFormOverlay', "
951  function hideElementEditFormOverlay()
952  {
953  $('#" . BuilderCanvasWizardView::ELEMENT_EDIT_CONTAINER_ID . "').hide();
954  $('#" . BuilderCanvasWizardView::ELEMENT_EDIT_FORM_OVERLAY_CONTAINER_ID . "').empty();
955  $('.editing-element').removeClass('editing-element');
956  }
957  ");
958  }
959 
964  protected function resolveEnableAjaxValidation()
965  {
966  return true;
967  }
968 
973  protected function resolveFormClientOptions()
974  {
975  return array('beforeValidate' => 'js:$(this).beforeValidateAction',
976  'afterValidate' => 'js:$(this).afterValidateAjaxAction',
977  'afterValidateAjax' => $this->renderConfigSaveAjax(),
978  'summaryID' => WizardActiveForm::makeErrorsSummaryId($this->resolveFormId()),
979  'validateOnSubmit' => true,
980  'validateOnChange' => false);
981  }
982 
983  protected function renderConfigSaveAjax()
984  {
985  $ajaxOptions = $this->resolveAjaxPostForApplyClickAjaxOptions(); //todo; remove
986  return ZurmoHtml::ajax($ajaxOptions);
987  }
988 
994  {
995  $hiddenInputId = ZurmoHtml::activeId($this->model, 'id');
996  $message = Zurmo::t('EmailTemplatesModule', 'There was an error applying changes');
997  $ajaxArray = ComponentForEmailTemplateWizardView::resolveErrorAjaxCallback($message);
998  //$ajaxArray['cache'] = 'false'; //todo: should by default be used.
999  $ajaxArray['url'] = $this->resolveFormActionUrl();
1000  $ajaxArray['type'] = 'POST';
1001  // Begin Not Coding Standard
1002  $ajaxArray['data'] = 'js:$("#' . $this->resolveApplyLinkId() . '").closest("form").serialize()';
1003  $ajaxArray['beforeSend'] = "js:function()
1004  {
1005  emailTemplateEditor.freezeLayoutEditor();
1006  }";
1007  $ajaxArray['success'] = "js:function (html)
1008  {
1009  var replaceElementId = $('#" . $hiddenInputId . "').val();
1010  var replaceElementInIframe = $('#" . BuilderCanvasWizardView::CANVAS_IFRAME_ID . "')
1011  .contents().find('#' + replaceElementId).parent();
1012  replaceElementInIframe.replaceWith(html);
1013  " . $this->getAjaxScriptForInitSortableElements() . "
1014  emailTemplateEditor.unfreezeLayoutEditor();
1015  emailTemplateEditor.canvasChanged();
1016  emailTemplateEditor.addPlaceHolderForEmptyCells();
1017  }";
1018  // End Not Coding Standard
1019  return $ajaxArray;
1020  }
1021 
1026  protected function resolveFormHtmlOptions()
1027  {
1028  return array('class' => 'element-edit-form', 'onsubmit' => "return false;");
1029  }
1030 
1035  protected function resolveActiveFormCustomOptions()
1036  {
1037  return array();
1038  }
1039 
1044  protected function renderBeforeFormLayout(ZurmoActiveForm $form)
1045  {
1046  }
1047 
1052  protected function renderAfterFormLayout(ZurmoActiveForm $form)
1053  {
1054  }
1055 
1060  protected function generateId()
1061  {
1062  return (strtolower(get_class($this)) . '_' . uniqid(time() . '_'));
1063  }
1064 
1069  protected function resolveDefaultProperties()
1070  {
1071  return array();
1072  }
1073 
1078  protected function resolveDefaultParams()
1079  {
1080  return array();
1081  }
1082 
1087  protected function initId($id = null)
1088  {
1089  if (!isset($id))
1090  {
1091  $id = $this->generateId();
1092  }
1093  $this->id = $id;
1094  }
1095 
1100  protected function initProperties($properties = null)
1101  {
1102  if (!isset($properties))
1103  {
1104  $properties = $this->resolveDefaultProperties();
1105  }
1106  $this->properties = $properties;
1107  }
1108 
1112  protected function cleanUpProperties()
1113  {
1114  if (!ArrayUtil::getArrayValue($this->params, 'doNotCleanUpProperties'))
1115  {
1116  $this->properties = ArrayUtil::recursivelyRemoveEmptyValues($this->properties);
1117  }
1118  }
1119 
1124  protected function initContent($content = null)
1125  {
1126  if (!isset($content))
1127  {
1128  $content = $this->resolveDefaultContent();
1129  }
1130  $this->content = $content;
1131  }
1132 
1137  protected function initParams($params = null)
1138  {
1139  $defaultParams = $this->resolveDefaultParams();
1140  if (!isset($params))
1141  {
1142  $params = $defaultParams;
1143  }
1144  elseif (ArrayUtil::getArrayValue($params, 'mergeDefault'))
1145  {
1146  $params = CMap::mergeArray($defaultParams, $params);
1147  }
1148  $this->params = $params;
1149  }
1150 
1154  protected function initModel()
1155  {
1156  $this->model = $this->getModel();
1157  }
1158 
1163  protected function getModel()
1164  {
1165  $modelClassName = static::getModelClassName();
1166  return new $modelClassName($this->content, $this->properties);
1167  }
1168 
1174  protected final function renderContentElement(ZurmoActiveForm $form = null)
1175  {
1176  $elementClassName = $this->resolveContentElementClassName();
1177  $attributeName = $this->resolveContentElementAttributeName();
1178  $params = $this->resolveContentElementParams();
1179  $element = new $elementClassName($this->model, $attributeName, $form, $params);
1180  if (isset($form))
1181  {
1182  $this->resolveContentElementEditableTemplate($element);
1183  }
1184  else
1185  {
1187  }
1188  $content = $element->render();
1189  return $content;
1190  }
1191 
1196  protected function resolveContentElementEditableTemplate(Element $element)
1197  {
1198  $element->editableTemplate = str_replace('{error}', '', $element->editableTemplate);
1199  }
1200 
1206  {
1207  // we need to put wrapper div inside td else it breaks the table layout output.
1208  $element->nonEditableTemplate = '{content}';
1209  }
1210 
1214  protected function resolveContentElementParams()
1215  {
1217  }
1218 
1224  protected function resolveDefaultElementParamsForEditableForm($label = '')
1225  {
1227  return $params;
1228  }
1229 
1234  protected function resolveDefaultContent()
1235  {
1236  return array();
1237  }
1238 
1244  protected function renderSettingsTab(ZurmoActiveForm $form)
1245  {
1246  throw new NotImplementedException('Children elements should override it, or remove all calls made to it.');
1247  }
1248 
1253  protected function resolveContentElementClassName()
1254  {
1255  throw new NotImplementedException('Children elements should override it, or remove all calls made to it.');
1256  }
1257 
1263  {
1264  throw new NotImplementedException('Children elements should override it, or remove all calls made to it.');
1265  }
1266 
1271  public function getId()
1272  {
1273  return $this->id;
1274  }
1275 
1281  public function getContent($serialized = false)
1282  {
1283  if ($serialized)
1284  {
1285  return CJSON::encode($this->content);
1286  }
1287  return $this->content;
1288  }
1289 
1295  public function getProperties($serialized = false)
1296  {
1297  if ($serialized)
1298  {
1299  return CJSON::encode($this->properties);
1300  }
1301  return $this->properties;
1302  }
1303 
1308  public function getRenderForCanvas()
1309  {
1310  return $this->renderForCanvas;
1311  }
1312 
1317  public function getParams()
1318  {
1319  return $this->params;
1320  }
1321 
1322  public function validate($attribute, $value)
1323  {
1324  $rules = $this->getRules();
1325  if (isset($rules[$attribute]))
1326  {
1327  try
1328  {
1329  return call_user_func(array($this, $rules[$attribute]), $value);
1330  }
1331  catch (Exception $exception)
1332  {
1333  throw new NotImplementedException();
1334  }
1335  }
1336  return true;
1337  }
1338 
1339  protected function getRules()
1340  {
1341  return array('font-size' => 'validateInteger',
1342  'border-radius' => 'validateInteger',
1343  'border-width' => 'validateInteger',
1344  'line-height' => 'validateInteger',
1345  'border-top-width' => 'validateInteger',
1346  'divider-padding' => 'validateInteger',
1347  'height' => 'validateInteger',
1348  'href' => 'validateUrl');
1349  }
1350 
1351 //todo: properly use Cvalidator for this
1352  protected function validateInteger($value)
1353  {
1354  if ($value == null)
1355  {
1356  return true;
1357  }
1358  if (!preg_match('/^[0-9]*$/', $value))
1359  {
1360  return Zurmo::t('EmailTemplatesModule', 'Use only integers');
1361  }
1362  else
1363  {
1364  return true;
1365  }
1366  }
1367 
1368  protected function validateUrl($value)
1369  {
1370  if ($value == null)
1371  {
1372  return true;
1373  }
1374  $validator = new CUrlValidator();
1375  if (!$validator->validateValue($value))
1376  {
1377  return Zurmo::t('EmailTemplatesModule', 'Use a valid URL.');
1378  }
1379  return true;
1380  }
1381 
1382  public static function getPropertiesSuffixMappedArray()
1383  {
1384  //TODO: @sergio: We need to move this to some rules class
1385  $mappedArray = array(
1386  'line-height' => '%',
1387  'font-size' => 'px',
1388  'border-radius' => 'px',
1389  'border-width' => 'px',
1390  'border-top-width' => 'px',
1391  'divider-padding' => 'px',
1392  'height' => 'px',
1393  'width' => 'px',
1394  );
1395  return $mappedArray;
1396  }
1397 
1398  protected function sanitizeProperties(array & $properties)
1399  {
1400  $propertiesMappedArray = static::getPropertiesSuffixMappedArray();
1401  foreach ($properties as $key => $value)
1402  {
1403  if (isset($propertiesMappedArray[$key]))
1404  {
1405  $properties[$key] .= $propertiesMappedArray[$key];
1406  }
1407  }
1408  }
1409  }
1410 ?>
static recursivelyRemoveEmptyValues(array $haystack)
Definition: ArrayUtil.php:295
renderBeforeFormLayout(ZurmoActiveForm $form)
static resolveDroppableWidget($widgetWrapper= 'li')
renderContentElement(ZurmoActiveForm $form=null)
renderHiddenFields(ZurmoActiveForm $form)
renderControlWrapperNonEditable($elementContent= '{{dummyContent}}')
resolveWrapperNonEditableByContentAndProperties($content, array $customDataAttributes)
const BUILDER_ELEMENT_SORTABLE_ROWS_CLASS
renderHiddenField($attributeName, $value)
resolveInlineStylePropertiesNonEditable(array &$mergedProperties)
renderFormInputsContent(ZurmoActiveForm $form)
getProperties($serialized=false)
resolveNonEditableWrapperOptions(array $customDataAttributes)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
resolveContentElementEditableTemplate(Element $element)
wrapEditableContentFormContentInTable($content)
resolveContentElementNonEditableTemplate(Element $element)
resolveDefaultElementParamsForEditableForm($label= '')
static getNestedValue(array $array, $key)
Definition: ArrayUtil.php:275
stringifyArray(array $array, $keyPrefix=null, $keySuffix=null, $valuePrefix=null, $valueSuffix=null)
renderWrappedContentAndSettingsTab($contentTab, $settingsTab)
renderAfterFormLayout(ZurmoActiveForm $form)
__construct($renderForCanvas=false, $id=null, $properties=null, $content=null, $params=null)
renderSettingsTab(ZurmoActiveForm $form)
wrapNonEditableElementContent($content)
resolveWrapperNonEditable($elementContent, array $customDataAttributes, $actionsOverlay)
initContent($content=null)
const BUILDER_ELEMENT_SORTABLE_ELEMENTS_CLASS
initProperties($properties=null)
resolveInlineStylesFromBackendPropertiesNonEditable(array &$mergedProperties)
getContent($serialized=false)
stringifyProperties(array $properties, $keyPrefix=null, $keySuffix=null, $valuePrefix=null, $valueSuffix=null)
resolveInlineStylesForNonEditable(array &$mergedProperties)
const BUILDER_ELEMENT_CELL_DROPPABLE_CLASS
static resolveThumbnailHtmlOptions()
renderContentTab(ZurmoActiveForm $form)
static wrapLink($label)
Definition: ZurmoHtml.php:666
Generated on Sun Oct 25 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.