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());
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
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);
     }
 }
 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);
     }
 }
 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);
 }
 /**
  * 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.º 10
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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }