2 var JSON = YAHOO.lang.JSON;
4 SUGAR.quickCompose = {};
6 SUGAR.quickCompose = function() {
12 loadingMessgPanl : null,
14 resourcesLoaded: false,
18 * Get the required compose package in an ajax call required for
20 * @method initComposePackage
21 * @param {Array} c Options containing compose package and full return url.
24 initComposePackage: function(c)
26 //Init fix for YUI 2.7.0 datatable sort.
27 SUGAR.email2.addressBook.initFixForDatatableSort();
29 //JS resources must have been loaded if we reach this step.
30 SUGAR.quickCompose.resourcesLoaded = true;
35 var responseData = JSON.parse(o.responseText);
36 //Create and insert the necessary script tag
37 var scriptTag = document.createElement('script');
38 scriptTag.id = 'quickComposeScript';
39 scriptTag.setAttribute('type','text/javascript');
41 if(YAHOO.env.ua.ie > 0) //IE hack
42 scriptTag.text = responseData.jsData;
44 scriptTag.appendChild(document.createTextNode(responseData.jsData));
46 document.getElementsByTagName("head")[0].appendChild(scriptTag);
48 //Create and insert the necessary div elements and html markup
49 var divTag = document.createElement("div");
50 divTag.innerHTML = responseData.divData;
51 divTag.id = 'quickCompose';
52 YAHOO.util.Dom.insertBefore(divTag, 'footer');
54 //Set the flag that we loaded the compose package.
55 SUGAR.quickCompose.frameLoaded = true;
57 SUGAR.quickCompose.initUI(c.data);
61 if(!SUGAR.quickCompose.frameLoaded)
62 YAHOO.util.Connect.asyncRequest('GET', 'index.php?entryPoint=GenerateQuickComposeFrame', callback, null);
64 SUGAR.quickCompose.initUI(c.data);
68 * Initalize the UI for the quick compose
70 * @method initComposePackage
71 * @param {Array} options Options containing compose package and full return url.
74 initUI: function(options)
76 var SQ = SUGAR.quickCompose;
77 this.options = options;
79 //Hide the loading div
80 loadingMessgPanl.hide();
82 var dce_mode = (typeof this.dceMenuPanel != 'undefined' && this.dceMenuPanel != null) ? true : false;
84 //Destroy the previous quick compose panel to get a clean slate
85 if (SQ.parentPanel != null)
87 //First clean up the tinyMCE instance
88 tinyMCE.execCommand('mceRemoveControl', false, SUGAR.email2.tinyInstances.currentHtmleditor);
89 SUGAR.email2.tinyInstances[SUGAR.email2.tinyInstances.currentHtmleditor] = null;
90 SUGAR.email2.tinyInstances.currentHtmleditor = "";
91 SQ.parentPanel.destroy();
92 SQ.parentPanel = null;
95 var theme = SUGAR.themes.theme_name;
97 //The quick compose utalizes the EmailUI compose functionality which allows for multiple compose
98 //tabs. Quick compose always has only one compose screen with an index of 0.
101 //Get template engine with template
102 if (!SE.composeLayout.composeTemplate)
103 SE.composeLayout.composeTemplate = new YAHOO.SUGAR.Template(SE.templates['compose']);
105 var panel_modal = dce_mode ? false : true,
106 panel_width = '880px',
107 panel_constrain = dce_mode ? false : true,
108 panel_height = dce_mode ? 'auto' : '400px',
109 panel_shadow = dce_mode ? false : true,
110 panel_draggable = dce_mode ? false : true,
111 panel_resize = dce_mode ? false : true,
112 panel_close = dce_mode ? false : true;
114 SQ.parentPanel = new YAHOO.widget.Panel("container1", {
117 constraintoviewport: panel_constrain,
119 height : panel_height,
120 shadow : panel_shadow,
121 draggable : panel_draggable,
122 resize: panel_resize,
127 SQ.parentPanel.setHeader( SUGAR.language.get('app_strings','LBL_EMAIL_QUICK_COMPOSE')) ;
130 SQ.parentPanel.setBody("<div class='email'><div id='htmleditordiv" + idx + "'></div></div>");
132 var composePanel = SE.composeLayout.getQuickComposeLayout(SQ.parentPanel,this.options);
135 var resize = new YAHOO.util.Resize('container1', {
143 resize.on('resize', function(args) {
144 var panelHeight = args.height;
145 this.cfg.setProperty("height", panelHeight + "px");
146 var layout = SE.composeLayout[SE.composeLayout.currentInstanceId];
147 layout.set("height", panelHeight - 50);
149 SE.composeLayout.resizeEditor(SE.composeLayout.currentInstanceId);
150 }, SQ.parentPanel, true);
152 SUGAR.util.doWhen("typeof SE.composeLayout[SE.composeLayout.currentInstanceId] != 'undefined'", function(){
153 var panelHeight = 400;
154 SQ.parentPanel.cfg.setProperty("height", panelHeight + "px");
155 var layout = SE.composeLayout[SE.composeLayout.currentInstanceId];
156 layout.set("height", panelHeight);
158 SE.composeLayout.resizeEditor(SE.composeLayout.currentInstanceId);
162 YAHOO.util.Dom.setStyle("container1", "z-index", 1);
166 //TinyMCE bug, since we are loading the js file dynamically we need to let tiny know that the
167 //dom event has fired.
168 tinymce.dom.Event.domLoaded = true;
171 convert_urls : false,
172 theme_advanced_toolbar_align : tinyConfig.theme_advanced_toolbar_align,
173 valid_children : tinyConfig.valid_children,
174 width: tinyConfig.width,
175 theme: tinyConfig.theme,
176 theme_advanced_toolbar_location : tinyConfig.theme_advanced_toolbar_location,
177 theme_advanced_buttons1 : tinyConfig.theme_advanced_buttons1,
178 theme_advanced_buttons2 : tinyConfig.theme_advanced_buttons2,
179 theme_advanced_buttons3 : tinyConfig.theme_advanced_buttons3,
180 plugins : tinyConfig.plugins,
181 elements : tinyConfig.elements,
182 language : tinyConfig.language,
183 extended_valid_elements : tinyConfig.extended_valid_elements,
184 mode: tinyConfig.mode,
185 strict_loading_mode : true,
186 gecko_spellcheck : tinyConfig.gecko_spellcheck
188 SQ.tinyLoaded = true;
191 SQ.parentPanel.show();
193 //Re-declare the close function to handle appropriattely.
194 SUGAR.email2.composeLayout.forceCloseCompose = function(o){SUGAR.quickCompose.parentPanel.hide(); }
199 SQ.parentPanel.center();
203 * Display a loading pannel and start retrieving the quick compose requirements.
205 * @param {Array} o Options containing compose package and full return url.
210 if(typeof o.menu_id != 'undefined') {
211 this.dceMenuPanel = o.menu_id;
213 this.dceMenuPanel = null;
216 loadingMessgPanl = new YAHOO.widget.SimpleDialog('loading', {
222 constraintoviewport: true,
226 loadingMessgPanl.setHeader(SUGAR.language.get('app_strings','LBL_EMAIL_PERFORMING_TASK'));
227 loadingMessgPanl.setBody(SUGAR.language.get('app_strings','LBL_EMAIL_ONE_MOMENT'));
228 loadingMessgPanl.render(document.body);
229 loadingMessgPanl.show();
231 //If JS files havn't been loaded, perform the load.
232 if(! SUGAR.quickCompose.resourcesLoaded )
233 this.loadResources(o);
238 * Pull in all the required js files.
239 * @method loadResources
240 * @param {Array} o Options containing compose package and full return url.
243 loadResources: function(o)
245 //IE Bug fix for TinyMCE when pulling in the js file dynamically.
246 window.skipTinyMCEInitPhase = true;
247 var require = ["layout", "element", "tabview", "menu","cookie","tinymce","sugarwidgets","sugarquickcompose","sugarquickcomposecss"];
248 var loader = new YAHOO.util.YUILoader({
251 skin: { base: 'blank', defaultSkin: '' },
253 onSuccess: this.initComposePackage,
255 base: "include/javascript/yui/build/"
258 //TiinyMCE cannot be added into the sugar_grp_quickcomp file as it breaks the build, needs to be loaded
264 fullpath: "include/javascript/tiny_mce/tiny_mce.js"
267 //Load the Sugar widgets with dependancies on the yui library.
269 name :"sugarwidgets",
271 fullpath: "include/javascript/sugarwidgets/SugarYUIWidgets.js",
272 varName: "YAHOO.SUGAR",
273 requires: ["datatable", "dragdrop", "treeview", "tabview"]
276 //Load the main components for the quick create compose screen.
278 name :"sugarquickcompose",
280 varName: "SUGAR.email2.complexLayout",
281 requires: ["layout", "sugarwidgets", "tinymce"],
282 fullpath: "cache/include/javascript/sugar_grp_quickcomp.js"
285 //Load the css needed for the quickCompose.
287 name :"sugarquickcomposecss",
289 fullpath: "modules/Emails/EmailUI.css"