protected function actionInlineEditValidate($model)
 {
     $postData = PostUtil::getData();
     $postFormData = ArrayUtil::getArrayValue($postData, get_class($model));
     $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $postFormData);
     $model->setAttributes($sanitizedPostData);
     $model->validate();
     $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
     echo CJSON::encode($errorData);
     Yii::app()->end(0, false);
 }
Ejemplo n.º 2
0
 public function testMakeErrorsDataAndResolveForOwnedModelAttributes()
 {
     $user = UserTestHelper::createBasicUser('TestUser');
     $account = new Account();
     $account->owner = $user;
     $account->name = '';
     $account->officePhone = '1234567890';
     $account->primaryEmail->emailAddress = 'testaccountzurmocom';
     $this->assertFalse($account->save());
     $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($account);
     $this->assertEquals('Name cannot be blank.', $errorData['Account_name'][0]);
     $this->assertEquals('Email Address is not a valid email address.', $errorData['Account_primaryEmail_emailAddress'][0]);
     $account->name = 'Test Account';
     $account->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($account->save());
 }
 public function actionLogin()
 {
     $formModel = new LoginForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'login-form') {
         echo ZurmoActiveForm::validate($formModel);
         Yii::app()->end(0, false);
     } elseif (isset($_POST['LoginForm'])) {
         $formModel->attributes = $_POST['LoginForm'];
         if ($formModel->validate() && $formModel->login()) {
             $this->redirect(Yii::app()->user->returnUrl);
         }
     }
     $extraHeaderContent = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'loginViewExtraHeaderContent');
     $view = new LoginPageView($this, $formModel, $extraHeaderContent);
     echo $view->render();
 }
Ejemplo n.º 4
0
 /**
  * Render a hidden field to filter models by starred only
  * @param  ZurmoActiveForm $form
  * @return string
  */
 protected function renderStarredFilterHidenField($form)
 {
     $content = null;
     if (StarredUtil::modelHasStarredInterface($this->model->getModel())) {
         $content .= $form->hiddenField($this->model, 'filterByStarred', array('class' => $form->id . '_filterByStarred'));
     }
     return $content;
 }
 protected function actionValidateCreateEmailMessage($postData, CreateEmailMessageForm $emailMessageForm)
 {
     if (isset($postData['ajax']) && $postData['ajax'] == 'edit-form') {
         $emailMessageForm->setAttributes($postData[get_class($emailMessageForm)]);
         if ($emailMessageForm->validate()) {
             Yii::app()->end(false);
         } else {
             $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($emailMessageForm);
             echo CJSON::encode($errorData);
         }
         Yii::app()->end(false);
     }
 }
 /**
  * Validates post data in the ajax call
  * @param RedBeanModel $model
  * @param string $postVariableName
  */
 public function validateAjaxFromPost($model, $postVariableName)
 {
     $savedSuccessfully = false;
     $modelToStringValue = null;
     if (isset($_POST[$postVariableName])) {
         $postData = $_POST[$postVariableName];
         $model = $this->saveModelFromPost($postData, $model, $savedSuccessfully, $modelToStringValue, true);
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
 public function actionModalEdit($id)
 {
     if (!Yii::app()->request->isAjaxRequest) {
         throw new NotSupportedException();
     }
     $form = new ImageEditForm();
     $imageFileModel = ImageFileModel::getById((int) $id);
     Yii::app()->getClientScript()->setToAjaxMode();
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'image-edit-form') {
         $errors = ZurmoActiveForm::validate($form);
         if ($form->hasErrors()) {
             echo $errors;
             Yii::app()->end();
         }
     } elseif (isset($_POST['ImageEditForm'])) {
         $tempFilePath = tempnam(sys_get_temp_dir(), 'edit_image_');
         $form->attributes = $_POST['ImageEditForm'];
         $originalImageFileModel = ImageFileModel::getById((int) $id);
         $contents = WideImage::load($originalImageFileModel->fileContent->content)->resize($form->imageWidth, $form->imageHeight)->crop($form->cropX, $form->cropY, $form->cropWidth, $form->cropHeight)->asString(str_replace('image/', '', $originalImageFileModel->type));
         file_put_contents($tempFilePath, $contents);
         $imageProperties = getimagesize($tempFilePath);
         $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($tempFilePath, ImageFileModelUtil::getImageFileNameWithDimensions($originalImageFileModel->name, (int) $imageProperties[0], (int) $imageProperties[1]));
         echo CJSON::encode($fileUploadData);
     } else {
         $modalListLinkProvider = $this->getModalListLinkProvider();
         $form->id = $imageFileModel->id;
         $form->imageWidth = $imageFileModel->width;
         $form->imageHeight = $imageFileModel->height;
         $form->cropX = 0;
         $form->cropY = 0;
         $form->cropWidth = $imageFileModel->width;
         $form->cropHeight = $imageFileModel->height;
         $form->lockImageProportion = true;
         if ($imageFileModel->isEditableByCurrentUser()) {
             $view = new ImageEditView($this, $form, $imageFileModel, $modalListLinkProvider);
             $view = new ModalView($this, $view);
         } else {
             $view = new AccessFailureView();
         }
         echo $view->render();
     }
 }
Ejemplo n.º 8
0
 protected function attemptToValidate($contactWebForm)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') {
         $contact = new Contact();
         $contact->setAttributes($_POST['Contact']);
         $contact->state = $contactWebForm->defaultState;
         $contact->owner = $contactWebForm->defaultOwner;
         $this->resolveContactWebFormEntry($contactWebForm, $contact);
         if ($contact->validate()) {
             $response = CJSON::encode(array());
         } else {
             $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($contact);
             $response = CJSON::encode($errorData);
         }
         $this->renderResponse($response);
     }
 }
 /**
  * Validates and save from modal details
  * @param Task $task
  */
 protected function attemptToValidateAndSaveFromModalDetails(Task $task)
 {
     if (isset($_POST['ajax']) && ($_POST['ajax'] == 'task-left-column-form-data' || $_POST['ajax'] == 'task-right-column-form-data')) {
         $task = $this->attemptToSaveModelFromPost($task, null, false);
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($task);
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
 /**
  * Supports sanitizing date attributes
  * @see ModalConfigEditView::validate()
  */
 public function validate()
 {
     $this->setMetadataFromPost(ArrayUtil::getArrayValue($_POST, $this->getPostArrayName()));
     echo ZurmoActiveForm::validate($this->model, null, false);
 }
 /**
  * Render a checkBox to filter models by starred only
  * @param  ZurmoActiveForm $form
  * @return string
  */
 protected function renderStarredFilterHidenField($model, $form)
 {
     $content = null;
     $modelsImplementsStarredInterface = false;
     if (isset($this->modelClassName) && StarredUtil::modelHasStarredInterface($this->modelClassName)) {
         $modelsImplementsStarredInterface = true;
     }
     if ($modelsImplementsStarredInterface) {
         $content .= $form->hiddenField($model, 'filterByStarred', array('class' => $form->id . '_filterByStarred'));
     }
     return $content;
 }
Ejemplo n.º 12
0
 protected function actionModuleValidate($moduleForm)
 {
     echo ZurmoActiveForm::validate($moduleForm);
     Yii::app()->end(0, false);
 }
 protected function resolveRenderHiddenModelClassNameElement(ZurmoActiveForm $form)
 {
     if ($this->model->type == EmailTemplate::TYPE_CONTACT) {
         return $form->hiddenField($this->model, 'modelClassName', array());
     }
 }
Ejemplo n.º 14
0
 /**
  * Render a hidden field to filter models by starred only
  * @param  ZurmoActiveForm $form
  * @return string
  */
 protected function renderStarredFilterHidenField($form)
 {
     $content = null;
     if (in_array('StarredInterface', class_implements($this->model->getModel()))) {
         $content .= $form->hiddenField($this->model, 'filterByStarred', array('class' => $form->id . '_filterByStarred'));
     }
     return $content;
 }
 public function validate()
 {
     echo ZurmoActiveForm::validate($this->model);
 }
Ejemplo n.º 16
0
 /**
  * Override to handle userStatus validation
  * @param User | ModelForm $model
  * @param string $postVariableName
  */
 protected function attemptToValidateAjaxFromPost($model, $postVariableName)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') {
         $sanitizedPostdata = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $_POST[$postVariableName]);
         $model->setAttributes($sanitizedPostdata);
         $model->validate();
         $userStatus = UserStatusUtil::makeByPostData($_POST[$postVariableName]);
         if ($model instanceof User) {
             if ($userStatus == null) {
                 $userStatus = UserStatusUtil::makeByUser($model);
             }
             Yii::app()->licenseManager->resolveValidationOnCreateOrEditUser($model, $userStatus);
         } elseif ($model instanceof ModelForm) {
             if ($userStatus == null) {
                 $userStatus = UserStatusUtil::makeByUser($model->getModel());
             }
             Yii::app()->licenseManager->resolveValidationOnCreateOrEditUser($model->getModel(), $userStatus);
         }
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
Ejemplo n.º 17
0
 protected function attemptToValidateAjaxFromPost($model, $postVariableName)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') {
         $model->setAttributes($_POST[$postVariableName]);
         $model->validate();
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
Ejemplo n.º 18
0
 protected function validateCreateModalPostData()
 {
     $costbook = new Costbook();
     if (isset($_POST['ajax']) && Yii::app()->request->isAjaxRequest) {
         $costbook = $this->attemptToSaveModelFromPost($costbook, null, false, true);
         echo CJSON::encode(ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($costbook));
         Yii::app()->end(0, false);
     }
 }
 /**
  * Override to handle report filters
  * @param SavedCalendar | ModelForm $model
  * @param string $postVariableName
  * @throws NotSupportedException();
  */
 protected function attemptToValidateAjaxFromPost($model, $postVariableName)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') {
         $postData = PostUtil::getData();
         $readyToUsePostData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($_POST[$postVariableName]);
         $sanitizedPostdata = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $readyToUsePostData);
         $sanitizedOwnerPostData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($sanitizedPostdata, 'owner');
         $sanitizedPostDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($sanitizedPostdata, 'owner');
         $model->setAttributes($sanitizedPostDataWithoutOwner);
         if ($model->validate()) {
             $modelToStringValue = strval($model);
             if ($sanitizedOwnerPostData != null) {
                 $model->setAttributes($sanitizedOwnerPostData);
             }
             if ($model instanceof OwnedSecurableItem) {
                 $model->validate(array('owner'));
             }
         }
         $wizardFormClassName = ReportToWizardFormAdapter::getFormClassNameByType(Report::TYPE_ROWS_AND_COLUMNS);
         if (!isset($postData[$wizardFormClassName])) {
             throw new NotSupportedException();
         }
         $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($model);
         DataToReportUtil::resolveFiltersStructure($postData[$wizardFormClassName], $report);
         DataToReportUtil::resolveFilters($postData[$wizardFormClassName], $report);
         //This would do the filter and filter structure validation
         $reportToWizardFormAdapter = new ReportToWizardFormAdapter($report);
         $reportForm = $reportToWizardFormAdapter->makeFormByType();
         $postData['validationScenario'] = $wizardFormClassName::FILTERS_VALIDATION_SCENARIO;
         $filtersErrorData = ReportUtil::validateReportWizardForm($postData, $reportForm);
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
         $errorData = array_merge($errorData, $filtersErrorData);
         echo CJSON::encode($errorData);
         Yii::app()->end(0, false);
     }
 }
Ejemplo n.º 20
0
 protected function actionInlineEditValidate($model)
 {
     $readyToUsePostData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($_POST[get_class($model)]);
     $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $readyToUsePostData);
     $sanitizedOwnerPostData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($sanitizedPostData, 'owner');
     $sanitizedPostDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($sanitizedPostData, 'owner');
     $model->setAttributes($sanitizedPostDataWithoutOwner);
     if ($model->validate()) {
         $modelToStringValue = strval($model);
         if ($sanitizedOwnerPostData != null) {
             $model->setAttributes($sanitizedOwnerPostData);
         }
         if ($model instanceof OwnedSecurableItem) {
             $model->validate(array('owner'));
         }
     }
     $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model);
     echo CJSON::encode($errorData);
     Yii::app()->end(0, false);
 }
 protected function validateContactWebFormModelForm(ContactWebForm $contactWebForm, ContactWebFormsModelForm $contactWebFormModelForm)
 {
     $this->resolveContactWebFormEntry($contactWebForm, $contactWebFormModelForm);
     if ($contactWebFormModelForm->validate()) {
         $response = CJSON::encode(array());
     } else {
         $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($contactWebFormModelForm);
         $response = CJSON::encode($errorData);
     }
     $this->renderResponse($response);
 }
 protected static function renderActiveCheckBoxContent(ZurmoActiveForm $form, Currency $currency)
 {
     $htmlOptions = array();
     $htmlOptions['id'] = 'CurrencyCollection_' . $currency->code . '_active';
     $htmlOptions['name'] = 'CurrencyCollection[' . $currency->code . '][active]';
     return $form->checkBox($currency, 'active', $htmlOptions);
 }
 /**
  * Render a checkBox to filter models by starred only
  * @param  ZurmoActiveForm $form
  * @return string
  */
 protected function renderStarredFilterHidenField($model, $form)
 {
     $content = null;
     $modelsImplementsStarredInterface = false;
     if (isset($this->modelClassName)) {
         $modelsImplementsStarredInterface = in_array('StarredInterface', class_implements(new $this->modelClassName()));
     }
     if ($modelsImplementsStarredInterface) {
         $content .= $form->hiddenField($model, 'filterByStarred', array('class' => $form->id . '_filterByStarred'));
     }
     return $content;
 }