2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3 die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 //Load the parent view class if it exists. Check for custom file first
41 loadParentView('edit');
43 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44 require_once ('include/SubPanel/SubPanel.php') ;
46 class ViewListView extends ViewEdit
49 * @see SugarView::_getModuleTitleParams()
51 protected function _getModuleTitleParams($browserTitle = false)
56 translate('LBL_MODULE_NAME','Administration'),
57 ModuleBuilderController::getModuleTitle(),
62 * Pseudo-constructor to enable subclasses to call a parent's constructor without knowing the parent in PHP4
64 function __construct()
66 $this->editModule = $_REQUEST [ 'view_module' ] ;
67 $this->editLayout = $_REQUEST [ 'view' ] ;
68 $this->subpanel = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : false ;
69 $this->subpanelLabel = (! empty ( $_REQUEST [ 'subpanelLabel' ] )) ? $_REQUEST [ 'subpanelLabel' ] : false ;
71 $this->fromModuleBuilder = ! empty ( $_REQUEST [ 'view_package' ] ) ;
72 if (! $this->fromModuleBuilder)
74 $moduleNames = array_change_key_case ( $GLOBALS['app_list_strings'] [ 'moduleList' ] ) ;
75 $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
79 // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
80 function preDisplay ()
84 function display ($preview = false)
87 $packageName = (! empty ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
88 $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
89 require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
90 $parser = ParserFactory::getParser ( $this->editLayout , $this->editModule , $packageName, $subpanelName ) ;
91 $smarty = $this->constructSmarty ( $parser ) ;
95 echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
98 $ajax = $this->constructAjax () ;
99 $ajax->addSection ( 'center', $this->translatedViewType, $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
101 echo $ajax->getJavascript () ;
105 function constructAjax ()
107 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
108 $ajax = new AjaxCompose ( ) ;
110 $layoutLabel = 'LBL_LAYOUTS' ;
111 $layoutView = 'layouts' ;
115 MB_LISTVIEW => 'LBL_LISTVIEW' ,
117 $translatedViewType = '' ;
118 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
119 $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
120 $this->translatedViewType = $translatedViewType;
122 if ($this->fromModuleBuilder)
124 $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
125 $ajax->addCrumb ( $_REQUEST [ 'view_package' ], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
126 $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $_REQUEST [ 'view_package' ] . '&view_module=' . $_REQUEST [ 'view_module' ] . '")' ) ;
127 if ($this->subpanel != "")
129 $ajax->addCrumb ( translate ( 'LBL_AVAILABLE_SUBPANELS', 'ModuleBuilder' ), '' ) ;
130 if ($this->subpanelLabel)
132 $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
133 $this->translatedViewType = $this->subpanelLabel . " " . translate("LBL_SUBPANEL", "ModuleBuilder");
136 $ajax->addCrumb ( $this->subpanel, '' ) ;
137 $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
141 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view_module=' . $_REQUEST [ 'view_module' ] . '&view_package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
142 $ajax->addCrumb ( $translatedViewType, '' ) ;
146 $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")' ) ;
147 $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
151 $ajax->addCrumb ( translate ( 'LBL_SUBPANELS', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=subpanels&view_module=' . $this->editModule . '")' ) ;
152 if ($this->subpanelLabel)
154 $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
155 $this->translatedViewType = $this->subpanelLabel . " " . translate("LBL_SUBPANEL", "ModuleBuilder");
158 $ajax->addCrumb ( $this->subpanel, '' ) ;
159 $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
163 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
164 $ajax->addCrumb ( $translatedViewType, '' ) ;
170 function constructSmarty ($parser)
172 $smarty = new Sugar_Smarty ( ) ;
173 $smarty->assign ( 'translate', true ) ;
174 $smarty->assign ( 'language', $parser->getLanguage () ) ;
176 $smarty->assign ( 'view', $this->editLayout ) ;
177 $smarty->assign ( 'module', "ModuleBuilder" ) ;
178 $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
179 $smarty->assign ( 'action', 'listViewSave' ) ;
180 $smarty->assign ( 'view_module', $this->editModule ) ;
181 if (!empty ( $this->subpanel ) )
183 $smarty->assign ( 'subpanel', $this->subpanel ) ;
184 if (!$this->fromModuleBuilder) {
185 $subList = SubPanel::getModuleSubpanels ( $this->editModule);
186 $subRef = $subList[strtolower($this->subpanel)];
187 $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
188 $subTitle = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
189 $smarty->assign ( 'subpanel_label', $subTitleKey ) ;
190 $smarty->assign ( 'subpanel_title', $subTitle ) ;
193 $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
194 $smarty->assign ( 'helpName', $helpName ) ;
195 $smarty->assign ( 'helpDefault', 'modify' ) ;
197 $smarty->assign ( 'title', $this->_constructTitle () ) ;
198 $groups = array ( ) ;
199 foreach ( $parser->columns as $column => $function )
201 // update this so that each field has a properties set
202 // properties are name, value, title (optional)
203 $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
205 foreach ( $groups as $groupKey => $group )
207 foreach ( $group as $fieldKey => $field )
209 if (isset ( $field [ 'width' ] ))
211 if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
214 $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
220 $smarty->assign ( 'groups', $groups ) ;
221 $smarty->assign('from_mb', $this->fromModuleBuilder);
224 $imageSave = SugarThemeRegistry::current()->getImage('studio_save') ;
225 // $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
227 $history = $parser->getHistory () ;
229 $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
231 $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
233 $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
235 $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
237 $buttons = array ( ) ;
238 $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\" )'" ) ;
239 $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
240 $buttons [] = array ( 'id' =>'historyBtn', 'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
241 $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault', 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ;
243 $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
245 $editImage = SugarThemeRegistry::current()->getImage('edit_inline') ;
246 $smarty->assign ( 'editImage', $editImage ) ;
247 $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline') ;
248 $smarty->assign ( 'deleteImage', $deleteImage ) ;
249 $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
251 if ($this->fromModuleBuilder)
253 $smarty->assign ( 'MB', true ) ;
254 $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
255 $mb = new ModuleBuilder ( ) ;
256 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ;
257 $smarty->assign('current_mod_strings', $module->getModStrings());
260 if (isset ( $_REQUEST [ 'local' ] ))
262 $smarty->assign ( 'local', '1' ) ;
264 $smarty->assign ( "subpanel", $this->subpanel ) ;
267 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
275 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
278 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
285 function _constructTitle ()
289 global $app_list_strings ;
291 if ($this->fromModuleBuilder)
293 $title = $this->editModule ;
294 if ($this->subpanel != "")
296 $title .= ":$this->subpanel" ;
300 $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
302 return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ': ' . $title ;
306 function _buildImageButtons ($buttons , $horizontal = true)
308 $text = '<table cellspacing=2><tr>' ;
309 foreach ( $buttons as $button )
311 if (empty($button['id'])) {
312 $button['id'] = $button['name'];
316 $text .= '</tr><tr>' ;
318 if ($button['id'] == "spacer") {
319 $text .= "<td style='width:{$button['width']}'> </td>";
323 if (! empty ( $button [ 'plain' ] ))
326 <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
332 <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default' {$button['actionScript']}
335 $text .= "value=\"{$button['text']}\"/></td>" ;
337 $text .= '</tr></table>' ;