]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.dashlet.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.dashlet.php
1 <?php
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-2012 SugarCRM Inc.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39
40
41
42
43 require_once ('modules/ModuleBuilder/views/view.listview.php') ;
44 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
45
46 class ViewDashlet extends ViewListView
47 {
48     function __construct()
49     {
50         $this->editModule = $_REQUEST [ 'view_module' ] ;
51         $this->editLayout = $_REQUEST [ 'view' ] ;
52         if(isset ( $_REQUEST [ 'view_package' ] ) && ! empty ( $_REQUEST [ 'view_package' ] ))
53             $this->editPackage = $_REQUEST [ 'view_package' ];
54         else
55             $this->editPackage = null;
56
57         $this->fromModuleBuilder = isset ( $_REQUEST [ 'MB' ] ) || (isset($_REQUEST['view_package']) && $_REQUEST['view_package'] && $_REQUEST['view_package'] != 'studio') ;
58
59         if (!$this->fromModuleBuilder)
60         {
61             global $app_list_strings ;
62             $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
63             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
64         }
65     }
66
67     /**
68          * @see SugarView::_getModuleTitleParams()
69          */
70         protected function _getModuleTitleParams($browserTitle = false)
71         {
72             global $mod_strings;
73             
74         return array(
75            translate('LBL_MODULE_NAME','Administration'),
76            ModuleBuilderController::getModuleTitle(),
77            );
78     }
79
80     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
81     function preDisplay()
82     {
83     }
84
85     function display(
86         $preview = false
87         )
88     {
89
90
91         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
92         $parser = ParserFactory::getParser ( $this->editLayout, $this->editModule, $this->editPackage) ;
93
94         $smarty = $this->constructSmarty ( $parser ) ;
95         if ($preview)
96         {
97                 echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
98         } else
99         {
100                 $ajax = $this->constructAjax () ;
101                 $ajax->addSection ( 'center', translate('LBL_DASHLET'), $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
102                 echo $ajax->getJavascript () ;
103         }
104     }
105
106     function constructAjax()
107     {
108         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
109         $ajax = new AjaxCompose ( ) ;
110
111         if ($this->fromModuleBuilder)
112         {
113             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
114             $ajax->addCrumb ( $_REQUEST [ 'view_package' ], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->editPackage . '")' ) ;
115             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->editPackage . '&view_module=' . $this->editModule . '")' ) ;
116             $ajax->addCrumb ( translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&layouts=1&MB=1&view_package='.$this->editPackage.'&view_module=' . $this->editModule . '")');
117             $ajax->addCrumb ( translate('LBL_DASHLET', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=dashlet&MB=1&view_package='.$this->editPackage.'&view_module=' . $this->editModule . '")' );
118
119             $ViewLabel = ($this->editLayout == MB_DASHLET) ? 'LBL_DASHLETLISTVIEW' : 'LBL_DASHLETSEARCHVIEW';
120             $ajax->addCrumb ( translate ($ViewLabel, 'ModuleBuilder' ), '' ) ;
121         }else{
122             $ajax->addCrumb ( translate($this->editModule), 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_module=' . $this->editModule . '")' ) ;
123             $ajax->addCrumb ( translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&layouts=1&view_module=' . $this->editModule . '")');
124             $ajax->addCrumb ( translate('LBL_DASHLET', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=dashlet&view_module=' . $this->editModule . '")' );
125             $ViewLabel = ($this->editLayout == MB_DASHLET) ? 'LBL_DASHLETLISTVIEW' : 'LBL_DASHLETSEARCHVIEW';
126             $ajax->addCrumb ( translate ($ViewLabel, 'ModuleBuilder' ), '' ) ;
127         }
128         return $ajax ;
129     }
130
131     function constructSmarty($parser)
132     {
133         $smarty = new Sugar_Smarty ( ) ;
134         $smarty->assign ( 'translate', true ) ;
135         $smarty->assign ( 'language', $parser->getLanguage () ) ;
136                 
137         $smarty->assign ( 'view', $this->editLayout ) ;
138         $smarty->assign ( 'action', 'dashletSave' ) ;
139         $smarty->assign( 'module', 'ModuleBuilder');
140         $smarty->assign ( 'view_module', $this->editModule ) ;
141         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
142         $helpName = (isset( $_REQUEST['view']) && $_REQUEST['view']=='dashletsearch') ? 'searchViewEditor' : 'listViewEditor';
143         $smarty->assign ( 'helpName', $helpName ) ;
144         $smarty->assign ( 'helpDefault', 'modify' ) ;
145         if ($this->fromModuleBuilder) {
146                         $mb = new ModuleBuilder ( ) ;
147             $module = & $mb->getPackageModule ( $this->editPackage, $this->editModule ) ;
148                     $smarty->assign('current_mod_strings', $module->getModStrings());
149                 }
150         $smarty->assign ( 'title', $this->_constructTitle () ) ;
151         $groups = array ( ) ;
152         foreach ( $parser->columns as $column => $function )
153         {
154             // update this so that each field has a properties set
155             // properties are name, value, title (optional)
156             $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
157         }
158         foreach ( $groups as $groupKey => $group )
159         {
160             foreach ( $group as $fieldKey => $field )
161             {
162                 if (isset ( $field [ 'width' ] ))
163                 {
164                     if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
165                     {
166
167                         $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
168                     }
169                 }
170             }
171         }
172
173         $smarty->assign ( 'groups', $groups ) ;
174
175         global $image_path, $mod_strings;
176         $imageSave = SugarThemeRegistry::current()->getImage('studio_save','',null,null,'.gif',$mod_strings['LBL_BTN_SAVE']) ;
177
178 //        $imageHelp = SugarThemeRegistry::current()->getImage('help','',null,null,'.gif',$mod_strings['LBL_SECTION_HELP']) ;
179
180
181         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
182         if (isset($this->searchlayout))
183             $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->searchlayout}\")" ;
184
185         $buttons = array ( ) ;
186         if (! $this->fromModuleBuilder)
187         {
188             $buttons [] = array ( 'name' => 'savebtn' , 'image' => $imageSave , 'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVEPUBLISH' ] , 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");ModuleBuilder.state.isDirty=false;ModuleBuilder.submitForm(\"edittabs\" )'" ) ;
189         } else
190         {
191             $buttons [] = array ( 'name' => 'mbsavebtn' , 'image' => $imageSave , 'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");ModuleBuilder.state.isDirty=false;ModuleBuilder.submitForm(\"edittabs\" )'" ) ;
192         }
193         $buttons [] = array ( 'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
194         $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
195         $editImage = SugarThemeRegistry::current()->getImage('edit_inline','',null,null,'.gif',$mod_strings['LBL_EDIT']) ;
196
197         $smarty->assign ( 'editImage', $editImage ) ;
198         $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline','',null,null,'.gif',$mod_strings['LBL_MB_DELETE']) ;
199
200         $smarty->assign ( 'deleteImage', $deleteImage ) ;
201         $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
202
203         if ($this->fromModuleBuilder)
204         {
205             $smarty->assign ( 'MB', true ) ;
206             $smarty->assign ( 'view_package', $this->editPackage ) ;
207             $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
208
209         } else
210         {
211             $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
212         }
213
214         return $smarty ;
215     }
216
217     function _constructTitle()
218     {
219         global $app_list_strings ;
220
221         if ($this->fromModuleBuilder)
222             $title = $this->editModule ;
223         else
224             $title =  $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
225         
226         return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ':&nbsp;' . $title ;
227     }
228 }