/**
  * @depends testRenderElementEditableWithClassNameAndIdAndContentForCanvas
  */
 public function testRenderElementEditableWithClassNameAndIdAndContentAndPropertiesForCanvas()
 {
     $formClassName = BaseBuilderElement::getModelClassName();
     $className = 'BuilderTitleElement';
     $content = array('text' => 'dummyContent');
     $id = __FUNCTION__ . __LINE__;
     $renderForCanvas = true;
     $properties = array('frontend' => array('inlineStyles' => array('color' => '#cccccc')), 'backend' => array('headingLevel' => 'h3'));
     $params = null;
     $expectedContent = BuilderElementRenderUtil::renderEditable($className, $renderForCanvas, $id, $properties, $content, $params);
     $this->setPostArray(array($formClassName => array('className' => $className, 'content' => $content, 'properties' => $properties, 'params' => $params, 'id' => $id), 'renderForCanvas' => $renderForCanvas));
     $content = $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/renderElementEditable');
     // need to get rid of script from the content controller returned as we don't get that when using util
     static::sanitizeStringOfScript($content);
     $this->assertEquals($expectedContent, $content);
 }
 public static function validateEditableForm()
 {
     $builderModelForm = Yii::app()->request->getPost(BaseBuilderElement::getModelClassName());
     if (isset($builderModelForm['properties'])) {
         $properties = $builderModelForm['properties'];
     } else {
         $properties = array();
     }
     if (isset($builderModelForm['content'])) {
         $content = $builderModelForm['content'];
     } else {
         $content = array();
     }
     if (is_string($content)) {
         $content = CJSON::decode($content);
     }
     $modelForm = new BuilderElementEditableModelForm($content, $properties);
     $errorData = array();
     $modelForm->setAttributes($builderModelForm);
     if (!$modelForm->validate()) {
         foreach ($modelForm->getErrors() as $attribute => $errors) {
             $errorData[ZurmoHtml::activeId($modelForm, $attribute)] = $errors;
         }
     }
     echo CJSON::encode($errorData);
     Yii::app()->end(0, false);
 }
 protected function actionRenderElement($editable = false)
 {
     Yii::app()->clientScript->setToAjaxMode();
     $editableForm = Yii::app()->request->getPost(BaseBuilderElement::getModelClassName());
     $className = ArrayUtil::getArrayValue($editableForm, 'className');
     $id = ArrayUtil::getArrayValue($editableForm, 'id');
     $properties = ArrayUtil::getArrayValue($editableForm, 'properties');
     $content = ArrayUtil::getArrayValue($editableForm, 'content');
     $params = ArrayUtil::getArrayValue($editableForm, 'params');
     $renderForCanvas = Yii::app()->request->getPost('renderForCanvas', !$editable);
     $wrapElementInRow = Yii::app()->request->getPost('wrapElementInRow', BuilderElementRenderUtil::DO_NOT_WRAP_IN_ROW);
     // at bare minimum we should have classname. Without it, it does not make sense.
     if (!Yii::app()->request->isPostRequest || !isset($className)) {
         Yii::app()->end(0, false);
     }
     if ($editable) {
         $content = BuilderElementRenderUtil::renderEditable($className, $renderForCanvas, $id, $properties, $content, $params);
     } else {
         $content = BuilderElementRenderUtil::renderNonEditable($className, $renderForCanvas, $wrapElementInRow, $id, $properties, $content, $params);
     }
     Yii::app()->clientScript->render($content);
     echo $content;
 }
 protected function registerInitializeEmailTemplateEditorScript()
 {
     $elementsContainerId = '#' . static::ELEMENTS_CONTAINER_ID;
     $elementsToPlaceSelector = '#' . static::UL_ELEMENT_TO_PLACE_ID;
     $iframeSelector = '#' . static::CANVAS_IFRAME_ID;
     $editSelector = '#' . static::ELEMENT_EDIT_CONTAINER_ID;
     $editFormSelector = '#' . static::ELEMENT_EDIT_FORM_OVERLAY_CONTAINER_ID;
     $editActionSelector = 'span.' . BaseBuilderElement::OVERLAY_ACTION_EDIT;
     $moveActionSelector = 'span.' . BaseBuilderElement::OVERLAY_ACTION_MOVE;
     $deleteActionSelector = 'span.' . BaseBuilderElement::OVERLAY_ACTION_DELETE;
     $sortableRowsClass = BaseBuilderElement::BUILDER_ELEMENT_SORTABLE_ROWS_CLASS;
     $sortableElementsClass = BaseBuilderElement::BUILDER_ELEMENT_SORTABLE_ELEMENTS_CLASS;
     $cellDroppableClass = BaseBuilderElement::BUILDER_ELEMENT_CELL_DROPPABLE_CLASS;
     $iframeOverlaySelector = '#' . static::ELEMENT_IFRAME_OVERLAY_ID;
     $cachedSerializedSelector = static::resolveCachedSerializedDataHiddenInputJQuerySelector();
     $errorOnDeleteMessage = Zurmo::t('EmailTemplatesModule', 'Cannot delete last row');
     $dropHereMessage = Zurmo::t('Core', 'Drop here');
     $csrfToken = Yii::app()->request->csrfToken;
     $doNotWrapInRow = BuilderElementRenderUtil::DO_NOT_WRAP_IN_ROW;
     $wrapInRow = BuilderElementRenderUtil::WRAP_IN_ROW;
     $wrapInHeaderRow = BuilderElementRenderUtil::WRAP_IN_HEADER_ROW;
     $modelClassName = BaseBuilderElement::getModelClassName();
     $editableActionUrl = static::resolveElementEditableActionUrl();
     $nonEditableActionUrl = static::resolveElementNonEditableActionUrl();
     Yii::app()->getClientScript()->registerScript('initializeEmailTemplateEditor', "\n                initEmailTemplateEditor = function () {\n                    emailTemplateEditor.init(\n                        '{$elementsContainerId}',\n                        '{$elementsToPlaceSelector}',\n                        '{$iframeSelector}',\n                        '{$editSelector}',\n                        '{$editFormSelector}',\n                        '{$editActionSelector}',\n                        '{$moveActionSelector}',\n                        '{$deleteActionSelector}',\n                        '{$sortableRowsClass}',\n                        '{$sortableElementsClass}',\n                        '{$cellDroppableClass}',\n                        '{$iframeOverlaySelector}',\n                        '{$cachedSerializedSelector}',\n                        '{$editableActionUrl}',\n                        '{$nonEditableActionUrl}',\n                        '{$errorOnDeleteMessage}',\n                        '{$dropHereMessage}',\n                        '{$csrfToken}',\n                        {$doNotWrapInRow},\n                        {$wrapInRow},\n                        {$wrapInHeaderRow},\n                        '{$modelClassName}'\n                    );\n                };\n                ", CClientScript::POS_END);
 }