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 width: tinyConfig.width,
174 theme: tinyConfig.theme,
175 theme_advanced_toolbar_location : tinyConfig.theme_advanced_toolbar_location,
176 theme_advanced_buttons1 : tinyConfig.theme_advanced_buttons1,
177 theme_advanced_buttons2 : tinyConfig.theme_advanced_buttons2,
178 theme_advanced_buttons3 : tinyConfig.theme_advanced_buttons3,
179 plugins : tinyConfig.plugins,
180 elements : tinyConfig.elements,
181 language : tinyConfig.language,
182 extended_valid_elements : tinyConfig.extended_valid_elements,
183 mode: tinyConfig.mode,
184 strict_loading_mode : true
186 SQ.tinyLoaded = true;
189 SQ.parentPanel.show();
191 //Re-declare the close function to handle appropriattely.
192 SUGAR.email2.composeLayout.forceCloseCompose = function(o){SUGAR.quickCompose.parentPanel.hide(); }
197 SQ.parentPanel.center();
201 * Display a loading pannel and start retrieving the quick compose requirements.
203 * @param {Array} o Options containing compose package and full return url.
208 if(typeof o.menu_id != 'undefined') {
209 this.dceMenuPanel = o.menu_id;
211 this.dceMenuPanel = null;
214 loadingMessgPanl = new YAHOO.widget.SimpleDialog('loading', {
220 constraintoviewport: true,
224 loadingMessgPanl.setHeader(SUGAR.language.get('app_strings','LBL_EMAIL_PERFORMING_TASK'));
225 loadingMessgPanl.setBody(SUGAR.language.get('app_strings','LBL_EMAIL_ONE_MOMENT'));
226 loadingMessgPanl.render(document.body);
227 loadingMessgPanl.show();
229 //If JS files havn't been loaded, perform the load.
230 if(! SUGAR.quickCompose.resourcesLoaded )
231 this.loadResources(o);
236 * Pull in all the required js files.
237 * @method loadResources
238 * @param {Array} o Options containing compose package and full return url.
241 loadResources: function(o)
243 //IE Bug fix for TinyMCE when pulling in the js file dynamically.
244 window.skipTinyMCEInitPhase = true;
245 var require = ["layout", "element", "tabview", "menu","cookie","tinymce","sugarwidgets","sugarquickcompose","sugarquickcomposecss"];
246 var loader = new YAHOO.util.YUILoader({
249 skin: { base: 'blank', defaultSkin: '' },
251 onSuccess: this.initComposePackage,
253 base: "include/javascript/yui/build/"
256 //TiinyMCE cannot be added into the sugar_grp_quickcomp file as it breaks the build, needs to be loaded
262 fullpath: "include/javascript/tiny_mce/tiny_mce.js"
265 //Load the Sugar widgets with dependancies on the yui library.
267 name :"sugarwidgets",
269 fullpath: "include/javascript/sugarwidgets/SugarYUIWidgets.js",
270 varName: "YAHOO.SUGAR",
271 requires: ["datatable", "dragdrop", "treeview", "tabview"]
274 //Load the main components for the quick create compose screen.
276 name :"sugarquickcompose",
278 varName: "SUGAR.email2.complexLayout",
279 requires: ["layout", "sugarwidgets", "tinymce"],
280 fullpath: "cache/include/javascript/sugar_grp_quickcomp.js"
283 //Load the css needed for the quickCompose.
285 name :"sugarquickcomposecss",
287 fullpath: "modules/Emails/EmailUI.css"