]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/quickCompose.js
Release 6.2.2
[Github/sugarcrm.git] / jssource / src_files / include / javascript / quickCompose.js
1 JSON = YAHOO.lang.JSON;
2
3 SUGAR.quickCompose= {};
4
5 SUGAR.quickCompose = function() {
6         return {
7                 
8                 parentPanel : null,
9                 dceMenuPanel : null,
10                 options: null,
11                 loadingMessgPanl : null,
12                 frameLoaded : false,
13                 resourcesLoaded: false,
14                 tinyLoaded : false,
15                 
16                 /**
17                  * Get the required compose package in an ajax call required for 
18                  * the quick compose.
19                  * @method initComposePackage
20                  * @param {Array} c Options containing compose package and full return url.
21                  * @return {} none
22                  **/
23                 initComposePackage: function(c)
24                 {
25                     //Init fix for YUI 2.7.0 datatable sort.
26                 SUGAR.email2.addressBook.initFixForDatatableSort();
27                 
28                     //JS resources must have been loaded if we reach this step.
29                     SUGAR.quickCompose.resourcesLoaded = true;
30             var callback = 
31                 { 
32                    success: function(o) 
33                    {
34                        var responseData = YAHOO.lang.JSON.parse(o.responseText);
35                        //Create and insert the necessary script tag
36                        var scriptTag = document.createElement('script');
37                        scriptTag.id = 'quickComposeScript';
38                    scriptTag.setAttribute('type','text/javascript');
39                    
40                    if(YAHOO.env.ua.ie > 0) //IE hack
41                                 scriptTag.text = responseData.jsData;
42                    else  //Everybody else
43                                 scriptTag.appendChild(document.createTextNode(responseData.jsData));
44                    
45                    document.getElementsByTagName("head")[0].appendChild(scriptTag);
46                    
47                    //Create and insert the necessary div elements and html markup
48                        var divTag = document.createElement("div");
49                        divTag.innerHTML = responseData.divData;
50                        divTag.id = 'quickCompose';
51                        YAHOO.util.Dom.insertBefore(divTag, 'footer');
52                        
53                        //Set the flag that we loaded the compose package.
54                        SUGAR.quickCompose.frameLoaded = true;
55                        //Init the UI
56                    SUGAR.quickCompose.initUI(c.data);
57                    }
58                } 
59                
60                if(!SUGAR.quickCompose.frameLoaded)
61                       YAHOO.util.Connect.asyncRequest('GET', 'index.php?entryPoint=GenerateQuickComposeFrame', callback, null);   
62                    else
63                       SUGAR.quickCompose.initUI(c.data);
64                        
65                 },
66                 /**
67                  * Initalize the UI for the quick compose
68                  * the quick compose.
69                  * @method initComposePackage
70                  * @param {Array} options Options containing compose package and full return url.
71                  * @return {} none
72                  **/
73                 initUI: function(options)
74                 {
75                         var SQ = SUGAR.quickCompose;
76                         this.options = options;
77                      
78                         //Hide the loading div
79                         loadingMessgPanl.hide();
80                         
81                 dce_mode = (typeof this.dceMenuPanel != 'undefined' && this.dceMenuPanel != null) ? true : false;                       
82                         
83                         //Destroy the previous quick compose panel to get a clean slate
84                 if (SQ.parentPanel != null)
85                 {
86                         //First clean up the tinyMCE instance
87                         tinyMCE.execCommand('mceRemoveControl', false, SUGAR.email2.tinyInstances.currentHtmleditor);
88                         SUGAR.email2.tinyInstances[SUGAR.email2.tinyInstances.currentHtmleditor] = null;
89                         SUGAR.email2.tinyInstances.currentHtmleditor = "";
90                         SQ.parentPanel.destroy();
91                         SQ.parentPanel = null;
92                 }
93                 
94                         theme = SUGAR.themes.theme_name;
95         
96                         //The quick compose utalizes the EmailUI compose functionality which allows for multiple compose
97                         //tabs.  Quick compose always has only one compose screen with an index of 0.
98                         var idx = 0;  
99
100                     //Get template engine with template
101                 if (!SE.composeLayout.composeTemplate) 
102                         SE.composeLayout.composeTemplate = new YAHOO.SUGAR.Template(SE.templates['compose']);
103                 
104                 panel_modal = dce_mode ? false : true;
105                 panel_width = '880px';
106                         panel_constrain = dce_mode ? false : true;
107                 panel_height = dce_mode ? '450px' : '400px';
108                 panel_shadow = dce_mode ? false : true;
109                 panel_draggable = dce_mode ? false : true;
110                 panel_resize = dce_mode ? false : true;
111                 panel_close = dce_mode ? false : true;
112                 
113                 SQ.parentPanel = new YAHOO.widget.Panel("container1", {
114                 modal: panel_modal,
115                                 visible: true,
116                 constraintoviewport: panel_constrain,
117                 width   : panel_width,
118                 height : panel_height,
119                 shadow  : panel_shadow,
120                 draggable : panel_draggable,
121                                 resize: panel_resize,
122                                 close: panel_close
123             });
124                 
125                 if(!dce_mode) {
126                         SQ.parentPanel.setHeader( SUGAR.language.get('app_strings','LBL_EMAIL_QUICK_COMPOSE')) ;
127                 }
128                 
129             SQ.parentPanel.setBody("<div class='email'><div id='htmleditordiv" + idx + "'></div></div>");
130                         
131                         var composePanel = SE.composeLayout.getQuickComposeLayout(SQ.parentPanel,this.options);
132                         
133                         if(!dce_mode) {                 
134                                 var resize = new YAHOO.util.Resize('container1', { 
135                     handles: ['br'], 
136                     autoRatio: false, 
137                     minWidth: 400, 
138                     minHeight: 350, 
139                     status: false
140                 });
141                 
142                 resize.on('resize', function(args) { 
143                     var panelHeight = args.height; 
144                     this.cfg.setProperty("height", panelHeight + "px");
145                                         var layout = SE.composeLayout[SE.composeLayout.currentInstanceId];
146                                         layout.set("height", panelHeight - 50);
147                                         layout.resize(true);
148                                         SE.composeLayout.resizeEditor(SE.composeLayout.currentInstanceId);
149                 }, SQ.parentPanel, true);
150                         }
151                         
152                         YAHOO.util.Dom.setStyle("container1", "z-index", 1);
153                         
154                         if (!SQ.tinyLoaded)
155                         {
156                                 //TinyMCE bug, since we are loading the js file dynamically we need to let tiny know that the
157                                 //dom event has fired.  
158                                 tinymce.dom.Event.domLoaded = true;
159
160                                 tinyMCE.init({
161                                          convert_urls : false,
162                                  theme_advanced_toolbar_align : tinyConfig.theme_advanced_toolbar_align,
163                                  width: tinyConfig.width,
164                                  theme: tinyConfig.theme,
165                                  theme_advanced_toolbar_location : tinyConfig.theme_advanced_toolbar_location,
166                                  theme_advanced_buttons1 : tinyConfig.theme_advanced_buttons1,
167                                  theme_advanced_buttons2 : tinyConfig.theme_advanced_buttons2,
168                                  theme_advanced_buttons3 : tinyConfig.theme_advanced_buttons3,
169                                  plugins : tinyConfig.plugins,
170                                  elements : tinyConfig.elements,
171                                  language : tinyConfig.language,
172                                  extended_valid_elements : tinyConfig.extended_valid_elements,
173                                  mode: tinyConfig.mode,
174                                  strict_loading_mode : true
175                          });
176                                 SQ.tinyLoaded = true;
177                         }
178                         
179                         SQ.parentPanel.show();
180                         
181                         //Re-declare the close function to handle appropriattely.
182                         SUGAR.email2.composeLayout.forceCloseCompose = function(o){SUGAR.quickCompose.parentPanel.hide(); }
183                                 
184                         
185                         
186                         if(!dce_mode) {
187                                 SQ.parentPanel.center();
188                         }
189                 },
190                 /**
191                  * Display a loading pannel and start retrieving the quick compose requirements.
192                  * @method init
193                  * @param {Array} o Options containing compose package and full return url.
194                  * @return {} none
195                  **/
196                 init: function(o) {
197
198                           if(typeof o.menu_id != 'undefined') {
199                              this.dceMenuPanel = o.menu_id;
200                           } else {
201                              this.dceMenuPanel = null;
202                           }
203                          
204               loadingMessgPanl = new YAHOO.widget.SimpleDialog('loading', {
205                                 width: '200px',
206                                 close: true,
207                                 modal: true,
208                                 visible:  true,
209                                 fixedcenter: true,
210                         constraintoviewport: true,
211                         draggable: false
212                       });                        
213                          
214               loadingMessgPanl.setHeader(SUGAR.language.get('app_strings','LBL_EMAIL_PERFORMING_TASK'));
215                       loadingMessgPanl.setBody(SUGAR.language.get('app_strings','LBL_EMAIL_ONE_MOMENT'));
216                       loadingMessgPanl.render(document.body);
217                       loadingMessgPanl.show();
218                  
219                       //If JS files havn't been loaded, perform the load.
220                       if(! SUGAR.quickCompose.resourcesLoaded )
221                           this.loadResources(o);
222                       else
223                           this.initUI(o);
224                 },
225                 /**
226                  * Pull in all the required js files.
227                  * @method loadResources
228                  * @param {Array} o Options containing compose package and full return url.
229                  * @return {} none
230                  **/
231                 loadResources: function(o)
232                 {
233                         //IE Bug fix for TinyMCE when pulling in the js file dynamically.
234                         window.skipTinyMCEInitPhase = true;
235                     var require = ["layout", "element", "tabview", "menu","cookie","tinymce","sugarwidgets","sugarquickcompose","sugarquickcomposecss"];
236                         var loader = new YAHOO.util.YUILoader({
237                                     require : require,
238                                     loadOptional: true,
239                                     skin: { base: 'blank', defaultSkin: '' },
240                                     data: o,
241                                     onSuccess: this.initComposePackage,
242                                     allowRollup: true,
243                                     base: "include/javascript/yui/build/"
244                                 });
245                                 
246                                 //TiinyMCE cannot be added into the sugar_grp_quickcomp file as it breaks the build, needs to be loaded 
247                                 //seperately.
248                                 loader.addModule({
249                                     name :"tinymce",
250                                     type : "js",
251                                     varName: "TinyMCE",
252                                     fullpath: "include/javascript/tiny_mce/tiny_mce.js"
253                                 });
254                                 
255                                 //Load the Sugar widgets with dependancies on the yui library.
256                                 loader.addModule({
257                                     name :"sugarwidgets",
258                                     type : "js",
259                                     fullpath: "include/javascript/sugarwidgets/SugarYUIWidgets.js",
260                                     varName: "YAHOO.SUGAR",
261                                     requires: ["datatable", "dragdrop", "treeview", "tabview"]
262                                 });
263                         
264                                 //Load the main components for the quick create compose screen.
265                                 loader.addModule({
266                                     name :"sugarquickcompose",
267                                     type : "js",
268                                     varName: "SUGAR.email2.complexLayout",
269                                     requires: ["layout", "sugarwidgets", "tinymce"],
270                                     fullpath: "include/javascript/sugar_grp_quickcomp.js"
271                                 });
272                                 
273                                 //Load the css needed for the quickCompose.
274                                 loader.addModule({
275                                     name :"sugarquickcomposecss",
276                                     type : "css",
277                                     fullpath: "modules/Emails/EmailUI.css"
278                                 });
279                                 
280                                 loader.insert();
281             }
282         };
283 }();