/** * @depends testIsStandardAttributeRequiredByDefault */ public function testSetMetadataFormLayoutWithAndWithOutRequiredCustomFieldForDropDownDependencyAttribute() { Yii::app()->user->userModel = User::getByUsername('super'); $education = array('aaaa', 'bbbb'); $education_labels = array('fr' => array('aaaa fr', 'bbbb fr'), 'de' => array('aaaa de', 'bbbb de')); $educationFieldData = CustomFieldData::getByName('Education'); $educationFieldData->serializedData = serialize($education); $this->assertTrue($educationFieldData->save()); $attributeForm = new DropDownAttributeForm(); $attributeForm->attributeName = 'testEducation'; $attributeForm->attributeLabels = array('de' => 'Test Education 2 de', 'en' => 'Test Education 2 en', 'es' => 'Test Education 2 es', 'fr' => 'Test Education 2 fr', 'it' => 'Test Education 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = false; $attributeForm->customFieldDataData = $education; $attributeForm->customFieldDataName = 'Education'; $attributeForm->customFieldDataLabels = $education_labels; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $stream = array('aaa1', 'aaa2', 'bbb1', 'bbb2'); $stream_labels = array('fr' => array('aaa1 fr', 'aaa2 fr', 'bbb1 fr', 'bbb2 fr'), 'de' => array('aaa1 de', 'aaa2 de', 'bbb1 de', 'bbb2 de')); $streamFieldData = CustomFieldData::getByName('Stream'); $streamFieldData->serializedData = serialize($stream); $this->assertTrue($streamFieldData->save()); $attributeForm = new DropDownAttributeForm(); $attributeForm->attributeName = 'testStream'; $attributeForm->attributeLabels = array('de' => 'Test Stream 2 de', 'en' => 'Test Stream 2 en', 'es' => 'Test Stream 2 es', 'fr' => 'Test Stream 2 fr', 'it' => 'Test Stream 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = true; $attributeForm->customFieldDataData = $stream; $attributeForm->customFieldDataName = 'Stream'; $attributeForm->customFieldDataLabels = $stream_labels; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $attributeName = "testQualification"; $attributeForm = new DropDownDependencyAttributeForm(); $attributeForm->attributeName = $attributeName; $attributeForm->attributeLabels = array('de' => 'Test Qualification Value 2 de', 'en' => 'Test Qualification Value 2 en', 'es' => 'Test Qualification Value 2 es', 'fr' => 'Test Qualification Value 2 fr', 'it' => 'Test Qualification Value 2 it'); $attributeForm->mappingData = array(array('attributeName' => 'testEducation'), array('attributeName' => 'testStream', 'valuesToParentValues' => array('aaa1' => 'aaaa', 'aaa2' => 'aaaa', 'bbb1' => 'bbbb', 'bbb2' => 'bbbb'))); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $layout = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry'))))))); $layout2 = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry'))), array('cells' => array(array('element' => 'testEducationCstm'), array('element' => 'testStreamCstm'))))))); $model = new Account(); $editableMetadata = AccountEditAndDetailsView::getMetadata(); $modelAttributesAdapter = new ModelAttributesAdapter($model); $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($modelAttributesAdapter->getAttributes(), new EditAndDetailsViewDesignerRules(), $editableMetadata); $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView', 'AccountsModule', $editableMetadata, new EditAndDetailsViewDesignerRules(), $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()); $this->assertFalse($adapter->setMetadataFromLayout($layout, array())); $this->assertNotEmpty($adapter->getMessage()); $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.'); $this->assertTrue($adapter->setMetadataFromLayout($layout2, array())); $this->assertEquals($adapter->getMessage(), 'Layout saved successfully.'); }
public function actionLayoutEdit() { assert('!empty($_GET["moduleClassName"])'); assert('!empty($_GET["viewClassName"])'); $viewClassName = $_GET['viewClassName']; $moduleClassName = $_GET['moduleClassName']; $modelClassName = $moduleClassName::getPrimaryModelName(); $editableMetadata = $viewClassName::getMetadata(); $designerRulesType = $viewClassName::getDesignerRulesType(); $designerRulesClassName = $designerRulesType . 'DesignerRules'; $designerRules = new $designerRulesClassName(); $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName); $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName); $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes()); $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata); if (isset($_POST['save'])) { $layoutMetadataAdapter = new LayoutMetadataAdapter($viewClassName, $moduleClassName, $editableMetadata, $designerRules, $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()); $savableMetadata = array(); if ($designerRules->canConfigureLayoutPanelsType() && !PanelsDisplayTypeLayoutMetadataUtil::populateSaveableMetadataFromPostData($savableMetadata, $_POST['LayoutPanelsTypeForm'])) { echo CJSON::encode(array('message' => Zurmo::t('DesignerModule', 'Invalid panel configuration type'), 'type' => 'error')); } elseif ($layoutMetadataAdapter->setMetadataFromLayout(ArrayUtil::getArrayValue($_POST, 'layout'), $savableMetadata)) { if ($designerRules->requireAllRequiredFieldsInLayout()) { RequiredAttributesValidViewUtil::setAsContainingRequiredAttributes($moduleClassName, $viewClassName); } echo CJSON::encode(array('message' => $layoutMetadataAdapter->getMessage(), 'type' => 'message')); } else { echo CJSON::encode(array('message' => $layoutMetadataAdapter->getMessage(), 'type' => 'error')); } Yii::app()->end(0, false); } $title = Zurmo::t('DesignerModule', 'Edit Layout') . ': ' . $designerRules->resolveDisplayNameByView($_GET['viewClassName']); $breadcrumbLinks = array($moduleClassName::getModuleLabelByTypeAndLanguage('Plural') . ': ' . Zurmo::t('DesignerModule', 'Layouts') => array('default/moduleLayoutsList', 'moduleClassName' => $_GET['moduleClassName']), $title); $canvasView = new MetadataViewEditView($this->getId(), $this->getModule()->getId(), $_GET['moduleClassName'], $_GET['viewClassName'], $editableMetadata, $designerRules, $attributeCollection, $attributesLayoutAdapter->makeDesignerLayoutAttributes(), $title); $view = new DesignerPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $canvasView, $breadcrumbLinks, 'DesignerBreadCrumbView')); echo $view->render(); }