1 JSON = YAHOO.lang.JSON;
3 SUGAR.quickCompose= {};
5 SUGAR.quickCompose = function() {
11 loadingMessgPanl : null,
13 resourcesLoaded: false,
17 * Get the required compose package in an ajax call required for
19 * @method initComposePackage
20 * @param {Array} c Options containing compose package and full return url.
23 initComposePackage: function(c)
25 //Init fix for YUI 2.7.0 datatable sort.
26 SUGAR.email2.addressBook.initFixForDatatableSort();
28 //JS resources must have been loaded if we reach this step.
29 SUGAR.quickCompose.resourcesLoaded = true;
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');
40 if(YAHOO.env.ua.ie > 0) //IE hack
41 scriptTag.text = responseData.jsData;
43 scriptTag.appendChild(document.createTextNode(responseData.jsData));
45 document.getElementsByTagName("head")[0].appendChild(scriptTag);
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');
53 //Set the flag that we loaded the compose package.
54 SUGAR.quickCompose.frameLoaded = true;
56 SUGAR.quickCompose.initUI(c.data);
60 if(!SUGAR.quickCompose.frameLoaded)
61 YAHOO.util.Connect.asyncRequest('GET', 'index.php?entryPoint=GenerateQuickComposeFrame', callback, null);
63 SUGAR.quickCompose.initUI(c.data);
67 * Initalize the UI for the quick compose
69 * @method initComposePackage
70 * @param {Array} options Options containing compose package and full return url.
73 initUI: function(options)
75 var SQ = SUGAR.quickCompose;
76 this.options = options;
78 //Hide the loading div
79 loadingMessgPanl.hide();
81 dce_mode = (typeof this.dceMenuPanel != 'undefined' && this.dceMenuPanel != null) ? true : false;
83 //Destroy the previous quick compose panel to get a clean slate
84 if (SQ.parentPanel != null)
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;
94 theme = SUGAR.themes.theme_name;
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.
100 //Get template engine with template
101 if (!SE.composeLayout.composeTemplate)
102 SE.composeLayout.composeTemplate = new YAHOO.SUGAR.Template(SE.templates['compose']);
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;
113 SQ.parentPanel = new YAHOO.widget.Panel("container1", {
116 constraintoviewport: panel_constrain,
118 height : panel_height,
119 shadow : panel_shadow,
120 draggable : panel_draggable,
121 resize: panel_resize,
126 SQ.parentPanel.setHeader( SUGAR.language.get('app_strings','LBL_EMAIL_QUICK_COMPOSE')) ;
129 SQ.parentPanel.setBody("<div class='email'><div id='htmleditordiv" + idx + "'></div></div>");
131 var composePanel = SE.composeLayout.getQuickComposeLayout(SQ.parentPanel,this.options);
134 var resize = new YAHOO.util.Resize('container1', {
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);
148 SE.composeLayout.resizeEditor(SE.composeLayout.currentInstanceId);
149 }, SQ.parentPanel, true);
152 YAHOO.util.Dom.setStyle("container1", "z-index", 1);
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;
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
176 SQ.tinyLoaded = true;
179 SQ.parentPanel.show();
181 //Re-declare the close function to handle appropriattely.
182 SUGAR.email2.composeLayout.forceCloseCompose = function(o){SUGAR.quickCompose.parentPanel.hide(); }
187 SQ.parentPanel.center();
191 * Display a loading pannel and start retrieving the quick compose requirements.
193 * @param {Array} o Options containing compose package and full return url.
198 if(typeof o.menu_id != 'undefined') {
199 this.dceMenuPanel = o.menu_id;
201 this.dceMenuPanel = null;
204 loadingMessgPanl = new YAHOO.widget.SimpleDialog('loading', {
210 constraintoviewport: true,
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();
219 //If JS files havn't been loaded, perform the load.
220 if(! SUGAR.quickCompose.resourcesLoaded )
221 this.loadResources(o);
226 * Pull in all the required js files.
227 * @method loadResources
228 * @param {Array} o Options containing compose package and full return url.
231 loadResources: function(o)
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({
239 skin: { base: 'blank', defaultSkin: '' },
241 onSuccess: this.initComposePackage,
243 base: "include/javascript/yui/build/"
246 //TiinyMCE cannot be added into the sugar_grp_quickcomp file as it breaks the build, needs to be loaded
252 fullpath: "include/javascript/tiny_mce/tiny_mce.js"
255 //Load the Sugar widgets with dependancies on the yui library.
257 name :"sugarwidgets",
259 fullpath: "include/javascript/sugarwidgets/SugarYUIWidgets.js",
260 varName: "YAHOO.SUGAR",
261 requires: ["datatable", "dragdrop", "treeview", "tabview"]
264 //Load the main components for the quick create compose screen.
266 name :"sugarquickcompose",
268 varName: "SUGAR.email2.complexLayout",
269 requires: ["layout", "sugarwidgets", "tinymce"],
270 fullpath: "include/javascript/sugar_grp_quickcomp.js"
273 //Load the css needed for the quickCompose.
275 name :"sugarquickcomposecss",
277 fullpath: "modules/Emails/EmailUI.css"