public function testCaseNumberReadOnlyFieldNotRequired() { $parser = new GridLayoutMetaDataParser(MB_EDITVIEW, 'Cases'); $required_fields = $parser->getRequiredFields(); $vals = array_flip($required_fields); $this->assertTrue(isset($vals['"name"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function returns name as required'); $this->assertFalse(isset($vals['"case_number"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function does not return case_number as required'); $parser = new ListLayoutMetaDataParser(MB_LISTVIEW, 'Cases'); $required_fields = $parser->getRequiredFields(); $vals = array_flip($required_fields); $this->assertTrue(isset($vals['"name"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function returns name as required'); $this->assertFalse(isset($vals['"case_number"']), 'Assert that the AbstractMetaDataParser->getRequiredFields function does not return case_number as required'); }
protected function getButtons($history, $disableLayout, $params) { $buttons = array(); if (!$this->fromModuleBuilder) { $buttons[] = array('id' => 'saveBtn', 'text' => translate('LBL_BTN_SAVE'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'", 'disabled' => $disableLayout); $buttons[] = array('id' => 'publishBtn', 'text' => translate('LBL_BTN_SAVEPUBLISH'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout); } else { $buttons[] = array('id' => 'saveBtn', 'text' => $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout); } $buttons[] = array('id' => 'spacer', 'width' => '33px'); $buttons[] = array('id' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout); if (!$params) { $action = 'ModuleBuilder.history.revert(' . '"' . $this->editModule . '",' . '"' . $this->editLayout . '",' . '"' . $history->getLast() . '",' . '""' . ')'; } else { $action = 'ModuleBuilder.history.resetToDefault(' . '"' . $this->editModule . '",' . '"' . $this->editLayout . '"' . ')'; } $buttons[] = array('id' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => "onclick='{$action}'", 'disabled' => $disableLayout); $implementation = $this->parser->getImplementation(); if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) { $buttons[] = array('id' => 'copyFromEditView', 'text' => translate('LBL_COPY_FROM_EDITVIEW'), 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout); } elseif (!empty($GLOBALS['sugar_config']['roleBasedViews']) && !isModuleBWC($this->editModule) && ($this->editLayout == MB_RECORDVIEW || $this->editLayout == MB_WIRELESSEDITVIEW || $this->editLayout == MB_WIRELESSDETAILVIEW) && $implementation->isDeployed()) { $availableRoles = $this->getRoleList($implementation); $buttons[] = array('type' => 'spacer', 'width' => '33px'); $buttons[] = array('type' => 'label', "text" => translate('LBL_ROLE') . ":"); $buttons[] = array('id' => 'roleList', 'type' => 'enum', 'actionScript' => 'style="max-width:150px" onchange="ModuleBuilder.switchLayoutRole(this)"', "options" => $this->getAvailableRoleList($implementation), "selected" => empty($params['role']) ? "" : $params['role']); if (!empty($params['role'])) { $rolesWithMetadata = $this->getRoleListWithMetadata($availableRoles, $params['role']); $buttons[] = array('id' => 'copyBtn', 'text' => translate('LBL_BTN_COPY_FROM'), 'actionScript' => "onclick='ModuleBuilder.copyLayoutFromRole();'", 'disabled' => !count($rolesWithMetadata)); } } return $buttons; }
public function testCallsContactStudioViews() { $seed = new Call(); $def = $seed->field_defs['contact_name']; $this->assertTrue(ListLayoutMetaDataParser::isValidField($def['name'], $def)); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'editview')); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'detailview')); $this->assertFalse(GridLayoutMetaDataParser::validField($def, 'quickcreate')); }
function display() { $editModule = $_REQUEST['view_module']; if (!isset($_REQUEST['MB'])) { global $app_list_strings; $moduleNames = array_change_key_case($app_list_strings['moduleList']); $translatedEditModule = $moduleNames[strtolower($editModule)]; } $selected_lang = !empty($_REQUEST['selected_lang']) ? $_REQUEST['selected_lang'] : $_SESSION['authenticated_user_language']; if (empty($selected_lang)) { $selected_lang = $GLOBALS['sugar_config']['default_language']; } $smarty = new Sugar_Smarty(); global $mod_strings; $smarty->assign('mod_strings', $mod_strings); $smarty->assign('available_languages', get_languages()); global $beanList; $objectName = $beanList[$editModule]; if ($objectName == 'aCase') { $objectName = 'Case'; } VardefManager::loadVardef($editModule, $objectName); global $dictionary; $vnames = array(); //jchi 24557 . We should list all the lables in viewdefs(list,detail,edit,quickcreate) that the user can edit them. require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; $parser = new ListLayoutMetaDataParser(MB_LISTVIEW, $editModule); foreach ($parser->getLayout() as $key => $def) { if (isset($def['label'])) { $vnames[$def['label']] = $def['label']; } } require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php'; $variableMap = array(MB_EDITVIEW => 'EditView', MB_DETAILVIEW => 'DetailView', MB_QUICKCREATE => 'QuickCreate'); if ($editModule == 'KBDocuments') { $variableMap = array(); } foreach ($variableMap as $key => $value) { $gridLayoutMetaDataParserTemp = new GridLayoutMetaDataParser($value, $editModule); foreach ($gridLayoutMetaDataParserTemp->getLayout() as $panel) { foreach ($panel as $row) { foreach ($row as $fieldArray) { // fieldArray is an array('name'=>name,'label'=>label) if (isset($fieldArray['label'])) { $vnames[$fieldArray['label']] = $fieldArray['label']; } } } } } //end //Get Subpanel Labels: require_once 'include/SubPanel/SubPanel.php'; $subList = SubPanel::getModuleSubpanels($editModule); foreach ($subList as $subpanel => $titleLabel) { $vnames[$titleLabel] = $titleLabel; } foreach ($dictionary[$objectName]['fields'] as $name => $def) { if (isset($def['vname'])) { $vnames[$def['vname']] = $def['vname']; } } $formatted_mod_strings = array(); //we shouldn't set the $refresh=true here, or will lost template language mod_strings. //return_module_language($selected_lang, $editModule,false) : the mod_strings will be included from cache files here. foreach (return_module_language($selected_lang, $editModule, false) as $name => $label) { //#25294 if (isset($vnames[$name]) || preg_match('/lbl_city|lbl_country|lbl_billing_address|lbl_alt_address|lbl_shipping_address|lbl_postal_code|lbl_state$/si', $name)) { $formatted_mod_strings[$name] = htmlentities($label, ENT_QUOTES, 'UTF-8'); } } //Grab everything from the custom files $mod_bak = $mod_strings; $files = array("custom/modules/{$editModule}/language/{$selected_lang}.lang.php", "custom/modules/{$editModule}/Ext/Language/{$selected_lang}.lang.ext.php"); foreach ($files as $langfile) { $mod_strings = array(); if (is_file($langfile)) { include $langfile; foreach ($mod_strings as $key => $label) { $formatted_mod_strings[$key] = htmlentities($label, ENT_QUOTES, 'UTF-8'); } } } $mod_strings = $mod_bak; ksort($formatted_mod_strings); $smarty->assign('MOD', $formatted_mod_strings); $smarty->assign('view_module', $editModule); $smarty->assign('APP', $GLOBALS['app_strings']); $smarty->assign('selected_lang', $selected_lang); $smarty->assign('defaultHelp', 'labelsBtn'); $smarty->assign('assistant', array('key' => 'labels', 'group' => 'module')); $ajax = new AjaxCompose(); $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")'); $ajax->addCrumb($translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $editModule . '")'); $ajax->addCrumb($mod_strings['LBL_LABELS'], ''); $html = $smarty->fetch('modules/ModuleBuilder/tpls/labels.tpl'); $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_SECTION_EDLABELS'], $html); echo $ajax->getJavascript(); }
protected function saveFieldsToLayouts($basepath, $dummy, $relationshipName, $layoutAdditions) { require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php'; // these modules either lack editviews/detailviews or use custom mechanisms for the editview/detailview. In either case, we don't want to attempt to add a relate field to them // would be better if GridLayoutMetaDataParser could handle this gracefully, so we don't have to maintain this list here $invalidModules = array('emails', 'kbdocuments'); foreach ($layoutAdditions as $deployedModuleName => $fieldName) { if (!in_array(strtolower($deployedModuleName), $invalidModules)) { foreach (array(MB_EDITVIEW, MB_DETAILVIEW) as $view) { $GLOBALS['log']->info(get_class($this) . ": adding {$fieldName} to {$view} layout for module {$deployedModuleName}"); $parser = new GridLayoutMetaDataParser($view, $deployedModuleName); $parser->addField(array('name' => $fieldName)); $parser->handleSave(false); } } } }
/** * Added for bug #40941 * Deletes the field from DetailView and editView of the appropriate module * after the relatioship is deleted in delete() function above. * @param $relationship The relationship that is getting deleted * return null */ private function removeFieldsFromDeployedLayout($relationship) { // many-to-many relationships don't have fields so if we have a many-to-many we can just skip this... if ($relationship->getType() == MB_MANYTOMANY) { return false; } $successful = true; $layoutAdditions = $relationship->buildFieldsToLayouts(); require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php'; foreach ($layoutAdditions as $deployedModuleName => $fieldName) { foreach (array(MB_EDITVIEW, MB_DETAILVIEW) as $view) { $parser = new GridLayoutMetaDataParser($view, $deployedModuleName); $parser->removeField($fieldName); $parser->handleSave(false); } } return $successful; }
function getAvailableFields() { // Obtain the full list of valid fields in this module $availableFields = array(); foreach ($this->_fielddefs as $key => $def) { if (GridLayoutMetaDataParser::validField($def, $this->_view) || isset($this->_originalViewDef[$key])) { //If the field original label existing, we should use the original label instead the label in its fielddefs. if (isset($this->_originalViewDef[$key]) && is_array($this->_originalViewDef[$key]) && isset($this->_originalViewDef[$key]['label'])) { $availableFields[$key] = array('name' => $key, 'label' => $this->_originalViewDef[$key]['label']); } else { $availableFields[$key] = array('name' => $key, 'label' => isset($def['label']) ? $def['label'] : $def['vname']); // layouts use 'label' not 'vname' for the label entry } } } // Available fields are those that are in the Model and the original layout definition, but not already shown in the View // So, because the formats of the two are different we brute force loop through View and unset the fields we find in a copy of Model if (!empty($this->_viewdefs)) { foreach ($this->_viewdefs['panels'] as $panel) { foreach ($panel as $row) { foreach ($row as $field) { unset($availableFields[$field]); } } } } return $availableFields; }
private function updateUndeployedLayout($relationship, $actionAdd = true) { // many-to-many relationships don't have fields so if we have a many-to-many we can just skip this... if ($relationship->getType() == MB_MANYTOMANY) { return false; } $successful = true; $layoutAdditions = $relationship->buildFieldsToLayouts(); require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php'; foreach ($layoutAdditions as $deployedModuleName => $fieldName) { foreach (array(MB_EDITVIEW, MB_DETAILVIEW) as $view) { $parsedName = AbstractRelationships::parseDeployedModuleName($deployedModuleName); if (isset($parsedName['packageName'])) { $GLOBALS['log']->debug(get_class($this) . ": " . ($actionAdd ? "adding" : "removing") . " {$fieldName} on {$view} layout for undeployed module {$parsedName['moduleName']} in package {$parsedName['packageName']}"); $parser = new GridLayoutMetaDataParser($view, $parsedName['moduleName'], $parsedName['packageName']); if ($actionAdd ? $parser->addField(array('name' => $fieldName)) : $parser->removeField($fieldName)) { $parser->handleSave(false); } else { $GLOBALS['log']->debug(get_class($this) . ": couldn't " . ($actionAdd ? "add" : "remove") . " {$fieldName} on {$view} layout for undeployed module {$deployedModuleName}"); $successful = false; } } } } return $successful; }
public function testCanGetFieldsFromTargetPanel() { $parser = new GridLayoutMetaDataParser(MB_EDITVIEW, 'Contacts'); $fields = $parser->getFieldsInPanel('lbl_contact_information'); $this->assertSame(array("description", "(empty)"), $fields); }
/** * Gets valid field defs for a field name * * @param string $fieldname The fieldname to get the defs for * @return array */ protected function getViewDefFromFieldname($fieldname) { if (is_array($fieldname)) { if (isset($fieldname['name'])) { $field = $fieldname['name']; } elseif (isset($fieldname['type'])) { $field = $fieldname['type']; } if (isset($field)) { return $this->getViewDefFromFieldname($field); } // This indicates an empty or non field field that is not in the // right format. This should be handled by the code that calls this. return false; } return parent::getViewDefFromFieldname($fieldname); }
/** * Utility method that allows delegation of validation to child objects * * @param stirng $key The name of the field to check - used by child validators * @param array $def The field defs * @return bool */ protected function isValidField($key, array $def) { return GridLayoutMetaDataParser::validField($def, $this->_view, $this->client); }