/**
  * Converts only listViewDefs.
  * Old format contains only default fields, current - default and enabled.
  */
 public function run()
 {
     if (!version_compare($this->from_version, '7.2', '<')) {
         return;
     }
     $sb = new StudioBrowser();
     $sb->loadModules();
     foreach ($sb->modules as $module => $defs) {
         if (!file_exists("custom/modules/{$module}/metadata/popupdefs.php")) {
             continue;
         }
         require "custom/modules/{$module}/metadata/popupdefs.php";
         if (!isset($popupMeta['listviewdefs'])) {
             continue;
         }
         $popupDefaultFieldNames = array();
         foreach ($popupMeta['listviewdefs'] as $key => $popupFieldDefs) {
             $popupDefaultFieldNames[] = isset($popupFieldDefs['name']) ? $popupFieldDefs['name'] : strtolower($key);
         }
         $sidecarParser = new SidecarListLayoutMetaDataParser(MB_SIDECARPOPUPVIEW, $module, null, 'base');
         $panel = $sidecarParser->getOriginalPanelDefs();
         $allFields = array_merge($sidecarParser->getAvailableFields(), $sidecarParser->getAdditionalFields());
         // Sidecar originally enabled and default fields.
         $newPanelDef = $panel[0]['fields'];
         // Reset all defaul fields to save available.
         array_walk($newPanelDef, function (&$val) {
             $val['default'] = false;
         });
         foreach ($popupDefaultFieldNames as $defaultFieldName) {
             // Populate with new default set.
             foreach ($newPanelDef as &$panelDef) {
                 if ($panelDef['name'] == $defaultFieldName) {
                     $panelDef['default'] = true;
                     continue 2;
                 }
             }
             // The field is hidden, populate the result defs with it.
             if (isset($allFields[$defaultFieldName])) {
                 $newPanelDef[] = array_merge($allFields[$defaultFieldName], array('default' => true, 'enabled' => true, 'name' => $defaultFieldName));
             }
         }
         $sidecarParser->setPanelFields($newPanelDef);
         $sidecarParser->handleSave(false);
     }
 }
Example #2
0
 public function display()
 {
     global $mod_strings, $locale;
     $ajax = new AjaxCompose();
     $smarty = new Sugar_Smarty();
     if (isset($_REQUEST['MB']) && $_REQUEST['MB'] == "1") {
         $smarty->assign("MB", $_REQUEST['MB']);
         $smarty->assign("view_package", $_REQUEST['view_package']);
     }
     if (!empty($_REQUEST['selected_lang'])) {
         $selected_lang = $_REQUEST['selected_lang'];
     } else {
         $selected_lang = $locale->getAuthenticatedUserLanguage();
     }
     if (empty($selected_lang)) {
         $selected_lang = $GLOBALS['sugar_config']['default_language'];
     }
     $smarty->assign('available_languages', get_languages());
     $smarty->assign('selected_lang', $selected_lang);
     ksort($this->properties);
     if (isset($this->properties['width'])) {
         $smarty->assign('defaultWidths', SidecarListLayoutMetaDataParser::getDefaultWidths());
     }
     // BWC modules width are in %, sidecar modules widths are in pixels.
     $smarty->assign('widthUnit', isModuleBWC($this->editModule) ? '%' : 'px');
     $smarty->assign("properties", $this->properties);
     $smarty->assign("mod_strings", $mod_strings);
     $smarty->assign('APP', $GLOBALS['app_strings']);
     $smarty->assign("view_module", $this->editModule);
     $smarty->assign("subpanel", $this->subpanel);
     if (isset($this->editPackage)) {
         $smarty->assign("view_package", $this->editPackage);
     }
     $ajax->addSection('east', translate('LBL_SECTION_PROPERTIES', 'ModuleBuilder'), $smarty->fetch('modules/ModuleBuilder/tpls/editProperty.tpl'));
     echo $ajax->getJavascript();
 }
Example #3
0
 public function action_listViewSave()
 {
     $GLOBALS['log']->info("action_listViewSave");
     if (isset($_REQUEST['PORTAL'])) {
         $this->view = 'portallistview';
         $parser = ParserFactory::getParser($this->view, $_REQUEST['view_module'], null, null, MB_PORTAL);
         //$parser->init ( $_REQUEST [ 'view_module' ] ) ; // removed init because MetaDataParsers don't use it
     } else {
         $packageName = isset($_REQUEST['view_package']) && strtolower($_REQUEST['view_package']) != 'studio' ? $_REQUEST['view_package'] : null;
         $subpanelName = !empty($_REQUEST['subpanel']) ? $_REQUEST['subpanel'] : null;
         $parser = ParserFactory::getParser($_REQUEST['view'], $_REQUEST['view_module'], $packageName, $subpanelName);
         $this->view = 'listView';
         // To make sure that dashlets can render customized list views on BWC
         // modules, we need to save list customizations for BWC modules in
         // the new style as well.
         if (isModuleBWC($_REQUEST['view_module']) && empty($packageName) && empty($subpanelName)) {
             $sidecarListParser = new SidecarListLayoutMetaDataParser(MB_SIDECARLISTVIEW, $_REQUEST['view_module'], null, 'base');
             $sidecarListParser->handleSave();
         }
     }
     // for backwards compatibility we need to parse the subpanel the old way as well
     // TODO: Remove this when all BWC Modules are converted
     if ($parser instanceof SidecarSubpanelLayoutMetaDataParser) {
         require_once 'modules/ModuleBuilder/parsers/views/SubpanelMetaDataParser.php';
         $oldSubpanelParser = new SubpanelMetaDataParser($subpanelName, $_REQUEST['view_module'], $packageName);
         $oldSubpanelParser->handleSave();
         unset($oldSubpanelParser);
     }
     $parser->handleSave();
     if (empty($packageName) && !empty($subpanelName)) {
         $rr = new RepairAndClear();
         $rr->show_output = false;
         $rr->rebuildExtensions();
     }
     // clear the cache for the linked module and requested module
     MetaDataManager::refreshModulesCache($parser->getAffectedModules());
 }
Example #4
0
 function constructSmarty($parser)
 {
     global $mod_strings;
     $isModuleBWC = isModuleBWC($this->editModule);
     $smarty = new Sugar_Smarty();
     $smarty->assign('translate', true);
     $smarty->assign('language', $parser->getLanguage());
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('module', "ModuleBuilder");
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $smarty->assign('action', 'listViewSave');
     $smarty->assign('view_module', $this->editModule);
     if (!empty($this->subpanel)) {
         $smarty->assign('subpanel', $this->subpanel);
         $smarty->assign('subpanelLabel', $this->subpanelLabel);
         if (!$this->fromModuleBuilder) {
             $subList = SubPanel::getModuleSubpanels($this->editModule);
             $subRef = $subList[strtolower($this->subpanel)];
             $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
             $subTitle = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
             $smarty->assign('subpanel_label', $subTitleKey);
             $smarty->assign('subpanel_title', $subTitle);
         }
     }
     $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
     $smarty->assign('helpName', $helpName);
     $smarty->assign('helpDefault', 'modify');
     $smarty->assign('title', $this->_constructTitle());
     $groups = array();
     foreach ($parser->columns as $column => $function) {
         // update this so that each field has a properties set
         // properties are name, value, title (optional)
         $groups[$GLOBALS['mod_strings'][$column]] = $parser->{$function}();
         // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
     }
     foreach ($groups as $groupKey => $group) {
         foreach ($group as $fieldKey => $field) {
             if (isset($field['width'])) {
                 if ($isModuleBWC) {
                     $width = intval($field['width']);
                     $unit = '%';
                 } else {
                     $isPercentage = strrpos($field['width'], '%') !== false;
                     if ($isPercentage) {
                         // We won't be bringing over the % definitions from metadata
                         $width = '';
                         $unit = '';
                     } else {
                         $width = intval($field['width']);
                         if ($width > 0) {
                             $unit = 'px';
                         } else {
                             // check if it is a valid string
                             $width = in_array($field['width'], SidecarListLayoutMetaDataParser::getDefaultWidths()) ? $field['width'] : '';
                             $unit = '';
                         }
                     }
                 }
                 $groups[$groupKey][$fieldKey]['width'] = $width;
                 $groups[$groupKey][$fieldKey]['units'] = $unit;
             }
         }
     }
     $smarty->assign('groups', $groups);
     $smarty->assign('from_mb', $this->fromModuleBuilder);
     global $image_path;
     $imageSave = SugarThemeRegistry::current()->getImage('studio_save', '', null, null, '.gif', $mod_strings['LBL_BTN_SAVE']);
     //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
     $history = $parser->getHistory();
     $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")";
     if ($this->subpanel) {
         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")";
     }
     $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
     if ($this->subpanel) {
         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
     }
     $buttons = array();
     $buttons[] = array('id' => 'savebtn', 'name' => 'savebtn', 'image' => $imageSave, 'text' => !$this->fromModuleBuilder ? $GLOBALS['mod_strings']['LBL_BTN_SAVEPUBLISH'] : $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");if (countListFields()==0) ModuleBuilder.layoutValidation.popup() ; else ModuleBuilder.handleSave(\"edittabs\" )'");
     $buttons[] = array('id' => 'spacer', 'width' => '50px');
     $buttons[] = array('id' => 'historyBtn', 'name' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='{$histaction}'");
     $buttons[] = array('id' => 'historyDefault', 'name' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => $restoreAction);
     $smarty->assign('buttons', $this->_buildImageButtons($buttons));
     $editImage = SugarThemeRegistry::current()->getImage('edit_inline', '', null, null, '.gif', $mod_strings['LBL_EDIT']);
     $smarty->assign('editImage', $editImage);
     $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline', '', null, null, '.gif', $mod_strings['LBL_MB_DELETE']);
     $smarty->assign('deleteImage', $deleteImage);
     $smarty->assign('MOD', $GLOBALS['mod_strings']);
     if ($this->fromModuleBuilder) {
         $smarty->assign('MB', true);
         $smarty->assign('view_package', $_REQUEST['view_package']);
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
         if ($this->subpanel) {
             if (isset($_REQUEST['local'])) {
                 $smarty->assign('local', '1');
             }
             $smarty->assign("subpanel", $this->subpanel);
         } else {
             $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
         }
     } else {
         if ($this->subpanel) {
             $smarty->assign("subpanel", "{$this->subpanel}");
         } else {
             $smarty->assign('description', $GLOBALS['mod_strings']['LBL_LISTVIEW_DESCRIPTION']);
         }
     }
     return $smarty;
 }
 /**
  * Sidecar specific method that delegates validity checking to client
  * specific methods if they exists, otherwise passes through to the parent
  * checker.
  *
  * @param string $key The field name.
  * @param array $def The field defs for key.
  * @return bool `true` if valid, `false` otherwise.
  */
 public function isValidField($key, array $def)
 {
     if (parent::isValidField($key, $def)) {
         // Predefined filters are valid 'fields'
         if (!empty($def['predefined_filter'])) {
             return true;
         }
         if (empty($def['type'])) {
             return false;
         }
         if (!empty($this->operators[$def['type']])) {
             return true;
         }
     }
     return false;
 }