protected function renderCheckboxWithHiddenInput($label, $attribute, $renderHidden = false)
 {
     $checkboxLabelFor = $attribute;
     if ($renderHidden) {
         $attribute = $this->resolveCheckboxInputAttributeName($attribute);
         $checkboxLabelFor = ZurmoHtml::activeId($this->model, $attribute);
     }
     $checkboxLabelHtmlOptions = array();
     $checkboxLabel = ZurmoHtml::label($label, $checkboxLabelFor, $checkboxLabelHtmlOptions);
     $checkboxHtmlOptions = $this->resolveCheckBoxHtmlOptions($renderHidden);
     $content = null;
     if ($renderHidden) {
         $content .= $this->form->checkBox($this->model, $attribute, $checkboxHtmlOptions);
     } else {
         $content .= ZurmoHtml::checkBox($attribute, false, $checkboxHtmlOptions);
     }
     $content .= $checkboxLabel;
     return $content;
 }
 public function actionValidateSendTestEmail()
 {
     $this->throwAccessDeniedExceptionIfModuleIsInaccessible();
     if (!Yii::app()->request->isPostRequest) {
         throw new CHttpException(400);
     }
     $form = new SendTestEmailForm();
     $ajax = Yii::app()->request->getPost('ajax');
     if ($ajax == 'send-test-form') {
         $form->setAttributes($_POST[get_class($form)]);
         $errorData = array();
         if (!$form->validate()) {
             foreach ($form->getErrors() as $attribute => $errors) {
                 $errorData[ZurmoHtml::activeId($form, $attribute)] = $errors;
             }
         }
         echo CJSON::encode($errorData);
     }
     Yii::app()->end(0, false);
 }
Exemplo n.º 3
0
 /**
  * Override to allow for optional live binding of yiiactiveform. @see $bindAsLive.
  */
 public function run()
 {
     if (is_array($this->focus)) {
         $this->focus = "#" . ZurmoHtml::activeId($this->focus[0], $this->focus[1]);
     }
     echo ZurmoHtml::endForm();
     $cs = Yii::app()->clientScript;
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.zurmoinc.framework.views.assets')) . '/FormUtils.js', CClientScript::POS_END);
     if (!$this->enableAjaxValidation && !$this->enableClientValidation || empty($this->attributes)) {
         if ($this->focus !== null) {
             $cs->registerCoreScript('jquery');
             $cs->registerScript('CActiveForm#focus', "\n                        if (!window.location.hash)\n                            { \$('" . $this->focus . "').focus(); }\n                    ");
         }
         return;
     }
     $options = $this->clientOptions;
     if (isset($this->clientOptions['validationUrl']) && is_array($this->clientOptions['validationUrl'])) {
         $options['validationUrl'] = ZurmoHtml::normalizeUrl($this->clientOptions['validationUrl']);
     }
     $options['attributes'] = array_values($this->attributes);
     if ($this->summaryID !== null) {
         $options['summaryID'] = $this->summaryID;
     }
     if ($this->focus !== null) {
         $options['focus'] = $this->focus;
     }
     $options = CJavaScript::encode($options);
     //Not registering via coreScript because it does not properly register when using ajax non-minified
     //on home page myList config view.  Needs a better solution
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('system.web.js.source')) . '/jquery.yii.js', CClientScript::POS_END);
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('system.web.js.source')) . '/jquery.yiiactiveform.js', CClientScript::POS_END);
     $id = $this->id;
     if ($this->bindAsLive) {
         $cs->registerScript(__CLASS__ . '#' . $id, "\$('#{$id}').live('focus', function(e)\n                {\n                    if (\$(this).data('settings') == undefined)\n                    {\n                        \$(this).yiiactiveform({$options});\n                    }\n                });\n                ");
     } else {
         $cs->registerScript(__CLASS__ . '#' . $id, "\$('#{$id}').yiiactiveform({$options});");
     }
 }
 protected function actionValidatePopulateContactEmailBeforeCreating($postData, ContactPrimaryEmailForm $contactForm)
 {
     if (isset($postData['ajax']) && $postData['ajax'] == 'edit-form') {
         $contactForm->setAttributes($postData[get_class($contactForm)]);
         if ($contactForm->validate()) {
             Yii::app()->end(false);
         } else {
             $errorData = array();
             foreach ($contactForm->getErrors() as $attribute => $errors) {
                 $errorData[ZurmoHtml::activeId($contactForm, $attribute)] = $errors;
             }
             echo CJSON::encode($errorData);
         }
         Yii::app()->end(false);
     }
 }
 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 renderHiddenField(&$hiddenElements, $attributeName, $value = null)
 {
     $hiddenElements .= ZurmoHtml::hiddenField(ZurmoHtml::activeName($this->model, $attributeName), $value, array('id' => ZurmoHtml::activeId($this->model, $attributeName)));
 }
 public function actionApplyRuntimeFilters($id)
 {
     $postData = PostUtil::getData();
     $savedReport = SavedReport::getById((int) $id);
     ControllerSecurityUtil::resolveCanCurrentUserAccessModule($savedReport->moduleClassName);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($savedReport);
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $wizardFormClassName = ReportToWizardFormAdapter::getFormClassNameByType($report->getType());
     if (!isset($postData[$wizardFormClassName])) {
         throw new NotSupportedException();
     }
     DataToReportUtil::resolveFilters($postData[$wizardFormClassName], $report, true);
     if (isset($postData['ajax']) && $postData['ajax'] == 'edit-form') {
         $adapter = new ReportToWizardFormAdapter($report);
         $reportWizardForm = $adapter->makeFormByType();
         $reportWizardForm->setScenario(reportWizardForm::FILTERS_VALIDATION_SCENARIO);
         if (!$reportWizardForm->validate()) {
             $errorData = array();
             foreach ($reportWizardForm->getErrors() as $attribute => $errors) {
                 $errorData[ZurmoHtml::activeId($reportWizardForm, $attribute)] = $errors;
             }
             echo CJSON::encode($errorData);
             Yii::app()->end(0, false);
         }
     }
     $filtersData = ArrayUtil::getArrayValue($postData[$wizardFormClassName], ComponentForReportForm::TYPE_FILTERS);
     $sanitizedFiltersData = DataToReportUtil::sanitizeFiltersData($report->getModuleClassName(), $report->getType(), $filtersData);
     $stickyData = array(ComponentForReportForm::TYPE_FILTERS => $sanitizedFiltersData);
     StickyReportUtil::setDataByKeyAndData($report->getId(), $stickyData);
 }
Exemplo n.º 8
0
 /**
  * Validates report wizard form against the post data
  * @param type $postData
  * @param ReportWizardForm $model
  * @throws NotSupportedException
  */
 public static function validateReportWizardForm($postData, ReportWizardForm $model)
 {
     if (isset($postData['validationScenario']) && $postData['validationScenario'] != null) {
         $model->setScenario($postData['validationScenario']);
     } else {
         throw new NotSupportedException();
     }
     $model->validate();
     $errorData = array();
     foreach ($model->getErrors() as $attribute => $errors) {
         $errorData[ZurmoHtml::activeId($model, $attribute)] = $errors;
     }
     return $errorData;
 }
 protected function registerSendTestEmailScriptsForEditView()
 {
     $scriptName = $this->modelClassName . '-compile-send-test-email-data-for-campaign-edit-view';
     if (Yii::app()->clientScript->isScriptRegistered($scriptName)) {
         return;
     } else {
         $functionName = SendTestEmailModalEditView::COMPILE_SEND_TEST_EMAIL_DATA_JS_FUNCTION_NAME;
         // Begin Not Coding Standard
         Yii::app()->clientScript->registerScript($scriptName, "\n                window.{$functionName} = function ()\n                    {\n                        var testData    = {\n                            fromName            : \$('#" . ZurmoHtml::activeId($this->model, 'fromName') . "').val(),\n                            fromAddress         : \$('#" . ZurmoHtml::activeId($this->model, 'fromAddress') . "').val(),\n                            subject             : \$('#" . ZurmoHtml::activeId($this->model, 'subject') . "').val(),\n                            textContent         : \$('#" . ZurmoHtml::activeId($this->model, 'textContent') . "').val(),\n                            htmlContent         : \$('#" . ZurmoHtml::activeId($this->model, 'htmlContent') . "').val(),\n                            marketingListId     : \$('#" . ZurmoHtml::activeId($this->model, '_marketingList_id') . "').val(),\n                            enableTracking      : \$('input:checkbox[name*=enableTracking]').prop('checked') ? 1 : 0,\n                            supportsRichText    : \$('input:checkbox[name*=supportsRichText]').prop('checked') ? 1 : 0,\n                            attachmentIds\t    : new Array()\n                        };\n                        \$(':input[name*=filesIds]').each(function()\n                        {\n                            testData.attachmentIds.push(\$(this).val());\n                        });\n                        return testData;\n                    }\n                    ");
         // End Not Coding Standard
     }
 }
 protected function registerTrashSomeDataOnModuleChangeScript()
 {
     if (!$this->model->isWorkflowTemplate()) {
         return;
     }
     // Begin Not Coding Standard
     Yii::app()->clientScript->registerScript('trashSomeDataOnModuleChangeScript', "\n                \$('" . $this->resolveModuleClassNameJQuerySelector() . "').unbind('change.trashSomeDataOnModuleChange')\n                                                                .bind('change.trashSomeDataOnModuleChange', function()\n                {\n                    \$('#" . ZurmoHtml::activeId($this->model, 'textContent') . "').val('');\n                    if (" . intval($this->model->isPastedHtmlTemplate()) . ")\n                    {\n                        var htmlContentElement  = \$('#" . ZurmoHtml::activeId($this->model, 'htmlContent') . "');\n                        \$(htmlContentElement).redactor('set', '');\n                    }\n\n                    else if (" . intval($this->model->isBuilderTemplate()) . ")\n                    {\n                        \$('" . $this->resolveIsDraftHiddenInputJQuerySelector() . "').val(1);\n                        resetBaseTemplateId();\n                        resetOriginalBaseBaseTemplateId();\n                        resetSerializedDomData();\n                        \$('#" . SelectBaseTemplateForEmailTemplateWizardView::TEMPLATES_DIV_ID . "').find('.pills').children(':first').click();\n                    }\n                });\n                ");
     // End Not Coding Standard
 }
 /**
  * Render sendgrid editable text field
  * @param CModel $model
  * @param CFormModel $form
  * @param string $attribute
  * @param boolean $isPassword
  * @return string
  */
 public function renderSendGridEditableTextField($model, $form, $attribute, $isPassword = false)
 {
     $id = ZurmoHtml::activeId($model, $attribute);
     $name = ZurmoHtml::activeName($model, $attribute);
     $htmlOptions = array('name' => $name, 'id' => $id);
     $label = $form->labelEx($model, $attribute, array('for' => $id));
     if (!$isPassword) {
         $textField = $form->textField($model, $attribute, $htmlOptions);
     } else {
         $textField = $form->passwordField($model, $attribute, $htmlOptions);
     }
     $error = $form->error($model, $attribute);
     return '<div>' . $label . $textField . $error . '</div>';
 }
Exemplo n.º 12
0
 protected function actionValidate($postData, EmailTemplateWizardForm $model)
 {
     if (isset($postData['validationScenario']) && $postData['validationScenario'] != null) {
         $model->setScenario($postData['validationScenario']);
     } else {
         throw new NotSupportedException();
     }
     $errorData = array();
     $validated = $model->validate();
     if ($validated === false) {
         foreach ($model->getErrors() as $attribute => $errors) {
             $errorData[ZurmoHtml::activeId($model, $attribute)] = $errors;
         }
     }
     echo CJSON::encode($errorData);
     Yii::app()->end(0, false);
 }
Exemplo n.º 13
0
 protected function attemptToValidateAjaxFromPost($model, $postVariableName)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') {
         $model->setAttributes($_POST[$postVariableName]);
         $model->validate();
         $errorData = array();
         foreach ($model->getErrors() as $attribute => $errors) {
             $errorData[ZurmoHtml::activeId($model, $attribute)] = $errors;
         }
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
 public function actionValidateDynamicSearch($viewClassName, $modelClassName, $formModelClassName)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'search-form' && isset($_POST[$formModelClassName])) {
         $model = new $modelClassName(false);
         $model->setScenario('searchModel');
         $searchForm = new $formModelClassName($model);
         $sourceData = $_POST;
         if (isset($_POST[$formModelClassName][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME])) {
             $searchForm->setAnyMixedAttributesScope($_POST[$formModelClassName][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME]);
             unset($_POST[$formModelClassName][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME]);
         }
         if (isset($_POST[$formModelClassName][SearchForm::SELECTED_LIST_ATTRIBUTES])) {
             $listAttributesSelector = new ListAttributesSelector($viewClassName, $model->getModuleClassName(), $modelClassName);
             $listAttributesSelector->setSelected($_POST[$formModelClassName][SearchForm::SELECTED_LIST_ATTRIBUTES]);
             $searchForm->setListAttributesSelector($listAttributesSelector);
             unset($_POST[$formModelClassName][SearchForm::SELECTED_LIST_ATTRIBUTES]);
         }
         if (isset($_POST[$formModelClassName]['filterByStarred'])) {
             $searchForm->filterByStarred = $_POST[$formModelClassName]['filterByStarred'];
             unset($_POST[$formModelClassName]['filterByStarred']);
         }
         if (isset($_POST[$formModelClassName][KanbanBoard::GROUP_BY_ATTRIBUTE_VISIBLE_VALUES])) {
             unset($_POST[$formModelClassName][KanbanBoard::GROUP_BY_ATTRIBUTE_VISIBLE_VALUES]);
         }
         if (isset($_POST[$formModelClassName][KanbanBoard::SELECTED_THEME])) {
             unset($_POST[$formModelClassName][KanbanBoard::SELECTED_THEME]);
         }
         if (isset($_POST[$formModelClassName]['filteredBy'])) {
             $searchForm->filterByStarred = $_POST[$formModelClassName]['filteredBy'];
             unset($_POST[$formModelClassName]['filteredBy']);
         }
         $sanitizedSearchData = $this->resolveAndSanitizeDynamicSearchAttributesByPostData($_POST[$formModelClassName], $searchForm);
         $searchForm->setAttributes($sanitizedSearchData);
         if (isset($_POST['save']) && $_POST['save'] == 'saveSearch') {
             $searchForm->setScenario('validateSaveSearch');
             if ($searchForm->validate()) {
                 $savedSearch = $this->processSaveSearch($searchForm, $viewClassName);
                 echo CJSON::encode(array('id' => $savedSearch->id, 'name' => $savedSearch->name, 'sortAttribute' => $this->getSortAttributeFromSavedSearchData($savedSearch), 'sortDescending' => $this->getSortDescendingFromSavedSearchData($savedSearch)));
                 Yii::app()->end(0, false);
             }
         } else {
             $searchForm->setScenario('validateDynamic');
         }
         if (!$searchForm->validate()) {
             $errorData = array();
             foreach ($searchForm->getErrors() as $attribute => $errors) {
                 $errorData[ZurmoHtml::activeId($searchForm, $attribute)] = $errors;
             }
             echo CJSON::encode($errorData);
             Yii::app()->end(0, false);
         }
         $this->setStickyData($searchForm, $viewClassName, true, $sourceData);
     }
 }
Exemplo n.º 15
0
 /**
  * Resolve Ajax options for when clicking apply on editable form.
  * @return array
  */
 protected function resolveAjaxPostForApplyClickAjaxOptions()
 {
     $hiddenInputId = ZurmoHtml::activeId($this->model, 'id');
     $message = Zurmo::t('EmailTemplatesModule', 'There was an error applying changes');
     $ajaxArray = ComponentForEmailTemplateWizardView::resolveErrorAjaxCallback($message);
     //$ajaxArray['cache']         = 'false'; //todo: should by default be used.
     $ajaxArray['url'] = $this->resolveFormActionUrl();
     $ajaxArray['type'] = 'POST';
     // Begin Not Coding Standard
     $ajaxArray['data'] = 'js:$("#' . $this->resolveApplyLinkId() . '").closest("form").serialize()';
     $ajaxArray['beforeSend'] = "js:function()\n                                        {\n                                            emailTemplateEditor.freezeLayoutEditor();\n                                        }";
     $ajaxArray['success'] = "js:function (html)\n                                        {\n                                            var replaceElementId        = \$('#" . $hiddenInputId . "').val();\n                                            var replaceElementInIframe  = \$('#" . BuilderCanvasWizardView::CANVAS_IFRAME_ID . "')\n                                                                            .contents().find('#' + replaceElementId).parent();\n                                            replaceElementInIframe.replaceWith(html);\n                                            " . $this->getAjaxScriptForInitSortableElements() . "\n                                            emailTemplateEditor.unfreezeLayoutEditor();\n                                            emailTemplateEditor.canvasChanged();\n                                            emailTemplateEditor.addPlaceHolderForEmptyCells();\n                                        }";
     // End Not Coding Standard
     return $ajaxArray;
 }
 protected function registerSendTestEmailScriptsForWizardView()
 {
     $scriptName = 'compile-send-test-email-data-for-email-template-wizard-view';
     if (Yii::app()->clientScript->isScriptRegistered($scriptName)) {
         return;
     } else {
         $functionName = SendTestEmailModalEditView::COMPILE_SEND_TEST_EMAIL_DATA_JS_FUNCTION_NAME;
         // Begin Not Coding Standard
         Yii::app()->clientScript->registerScript($scriptName, "\n                window.{$functionName} = function ()\n                    {\n                        var testData    = {\n                                subject         : \$('#" . ZurmoHtml::activeId($this->model, 'subject') . "').val(),\n                                textContent     : \$('#" . ZurmoHtml::activeId($this->model, 'textContent') . "').val(),\n                                language        : \$('#" . ZurmoHtml::activeId($this->model, 'language') . "').val(),\n                                type            : \$('#" . ZurmoHtml::activeId($this->model, 'type') . "').val(),\n                                attachmentIds   : new Array()\n                        };\n                        \$(':input[name*=filesIds]').each(function()\n                        {\n                            testData.attachmentIds.push(\$(this).val());\n                        });\n                        if (" . intval($this->model->isPastedHtmlTemplate()) . ")\n                        {\n                            testData.htmlContent        = \$('#" . ZurmoHtml::activeId($this->model, 'htmlContent') . "').val();\n                        }\n                        else if (" . intval($this->model->isBuilderTemplate()) . ")\n                        {\n                            testData.serializedData = JSON.stringify({dom: \$.parseJSON(emailTemplateEditor.compileSerializedData())});\n                        }\n                        return testData;\n                    }\n                    ");
         // End Not Coding Standard
     }
 }
Exemplo n.º 17
0
 protected function actionValidateSettings($model)
 {
     $model->setAttributes($_POST[get_class($model)]);
     $model->validate();
     $errorData = array();
     foreach ($model->getErrors() as $attribute => $errors) {
         $errorData[ZurmoHtml::activeId($model, $attribute)] = $errors;
     }
     echo CJSON::encode($errorData);
     Yii::app()->end(0, false);
 }
 public static function resolveOriginalBaseTemplateIdHiddenInputJQuerySelector()
 {
     $id = ZurmoHtml::activeId(new BuilderEmailTemplateWizardForm(), 'originalBaseTemplateId');
     return '#' . $id;
 }
 /**
  * Resolve id for a given property
  * @param CModel $model
  * @param $property
  * @param bool $doNotWrapInSquareBrackets
  * @return string
  */
 public static function resolveAttributeId(CModel $model, $property, $doNotWrapInSquareBrackets = false)
 {
     static::resolvePropertyWithSquareBrackets($property, $doNotWrapInSquareBrackets);
     $attribute = static::resolveAttributeName($property);
     $attribute = ZurmoHtml::activeId($model, $attribute);
     return $attribute;
 }