]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/ajax.js
Release 6.5.8
[Github/sugarcrm.git] / modules / Emails / javascript / ajax.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37 if (typeof console == "undefined")
38         console = { log: function(o) {alert(o)} };
39
40 var AjaxObject = {
41         ret : '',
42         currentRequestObject : null,
43         //timeout : 30000, // 30 second timeout default
44         timeout : 9999999999, // 30 second timeout default
45         forceAbort : false,
46         trail : new Array(),
47
48         /**
49          */
50         _reset : function() {
51                 this.timeout = 30000;
52                 this.forceAbort = false;
53         },
54
55         folderRenameCleanup : function() {
56                 SUGAR.email2.folders.setSugarFolders();
57         },
58
59         fullSyncCleanup : function(o) {
60                 this.folders.checkMailCleanup(o);
61                 SUGAR.email2.settings.settingsDialog.hide();
62         },
63
64         /**
65          */
66         composeCache : function(o) {
67                 var idx = SUGAR.email2.composeLayout.currentInstanceId; // post instance increment
68                 // get email templates and user signatures
69                 var ret = YAHOO.lang.JSON.parse(o.responseText);
70
71                 SUGAR.email2.composeLayout.emailTemplates = ret.emailTemplates;
72                 SUGAR.email2.composeLayout.signatures = ret.signatures;
73                 SUGAR.email2.composeLayout.fromAccounts = ret.fromAccounts;
74
75                 SUGAR.email2.composeLayout.setComposeOptions(idx);
76
77                 //Set the error array so we can notify the user when they try to hit send if any errors
78                 //are present.  We will also notify them now (after hitting compose button).
79                 SUGAR.email2.composeLayout.outboundAccountErrors = ret.errorArray;
80
81
82                 //if error element is returning an array, then check the length to make sure we have error messages
83                 if (typeof(ret.errorArray)=='object' && ret.errorArray instanceof Array && ret.errorArray.length > 0){
84                         //add error messages for display
85                         for(i in ret.errorArray)
86                                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorArray[i], 'alert');
87                 }else if (typeof(ret.errorArray)=='object' && ret.errorArray!=null && ret.errorArray!='' ) {
88                         //if error element is returning an object, and the object value is not empty or null, then display error message
89                         for(i in ret.errorArray)
90                                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorArray[i], 'alert');
91                 }
92
93                 //YUI bug with IE6 - Wont restore visibility property for nested select elements.
94                 if(SUGAR.isIE) {
95                         var overlayPanel = YAHOO.SUGAR.MessageBox.panel;
96                         if(overlayPanel) {
97                           overlayPanel.subscribe('hide',function() { YAHOO.util.Dom.setStyle('addressFrom' + idx,'visibility','');});
98                         }
99                 }
100         },
101
102
103         handleDeleteSignature : function(o) {
104                 SUGAR.hideMessageBox();
105         var ret = YAHOO.lang.JSON.parse(o.responseText);
106                 SUGAR.email2.composeLayout.signatures = ret.signatures;
107         var field = document.getElementById('signature_id');
108                 SUGAR.email2.util.emptySelectOptions(field);
109
110                 for(var i in ret.signatures) { // iterate through assoc array
111                         var opt = new Option(ret.signatures[i], i);
112                         field.options.add(opt);
113                 }
114                 setSigEditButtonVisibility();
115         },
116
117         /**
118          */
119         handleDeleteReturn : function(o) {
120                 // force refresh ListView
121                 SUGAR.hideMessageBox();
122                 if(document.getElementById('focusEmailMbox')) {
123                         YAHOO.namespace('frameFolders').selectednode = SUGAR.email2.folders.getNodeFromMboxPath(document.getElementById('focusEmailMbox').innerHTML);
124                 }
125
126                 // need to display success message before calling next async call?
127                 document.getElementById(this.target).innerHTML = o.responseText;
128         },
129
130         /**
131          */
132     handleFailure : function(o) {
133                 // Failure handler
134                 SUGAR.showMessageBox('Exception occurred...', o.statusText, 'alert');
135                 if(document.getElementById('saveButton')) {
136                         document.getElementById('saveButton').disabled = false;
137                 }
138         },
139
140         handleReplyForward : function(o) {
141                 var a = YAHOO.lang.JSON.parse(o.responseText);
142                 globalA = a;
143                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
144
145                 document.getElementById('email_id' + idx).value = a.uid;
146                 document.getElementById('emailSubject' + idx).value = a.name;
147                 document.getElementById('addressTO' + idx).value = a.from;
148                 document.getElementById('uid' + idx).value = a.uid;
149                 if(a.cc) {
150                         document.getElementById('addressCC' + idx).value = a.cc;
151                         SE.composeLayout.showHiddenAddress('cc', idx);
152                 }
153
154                 if(a.type) {
155                         document.getElementById('type' + idx).value = a.type;
156                 }
157
158                 // apply attachment values
159                 SUGAR.email2.composeLayout.loadAttachments(a.attachments);
160
161                 setTimeout("callbackReplyForward.finish(globalA);", 500);
162         },
163
164         handleReplyForwardForDraft : function(o) {
165                 var a = YAHOO.lang.JSON.parse(o.responseText);
166                 globalA = a;
167                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
168
169                 document.getElementById('email_id' + idx).value = a.uid;
170                 document.getElementById('emailSubject' + idx).value = a.name;
171                 document.getElementById('addressTO' + idx).value = a.to;
172
173                 if(a.cc) {
174                         document.getElementById('addressCC' + idx).value = a.cc;
175                         SUGAR.email2.composeLayout.showHiddenAddress('cc',idx);
176                 }
177
178                 if(a.bcc) {
179                         document.getElementById('addressBCC' + idx).value = a.bcc;
180                         SUGAR.email2.composeLayout.showHiddenAddress('bcc',idx);
181                 }
182
183
184                 if(a.type) {
185                         document.getElementById('type' + idx).value = a.type;
186                 }
187
188
189                 // apply attachment values
190                 SUGAR.email2.composeLayout.loadAttachments(a.attachments);
191
192                 setTimeout("callbackReplyForward.finish(globalA,0,1);", 500);
193         },
194
195         /**
196          */
197         handleSuccess : function(o) {
198                 document.getElementById(this.target).innerHTML = o.responseText;
199                 SUGAR.hideMessageBox();
200         },
201
202         /**
203          */
204         ieDeleteSuccess : function(o) {
205                 SUGAR.hideMessageBox();
206                 SUGAR.email2.accounts.refreshInboundAccountTable();
207                 alert(app_strings.LBL_EMAIL_IE_DELETE_SUCCESSFUL);
208                 SUGAR.email2.accounts.rebuildFolderList();
209         },
210
211         /**
212          */
213         ieSaveSuccess : function(o) {
214                 document.getElementById('saveButton').disabled = false;
215                 var a = YAHOO.lang.JSON.parse(o.responseText);
216                 if (a) {
217                         if(a.error) {
218                                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_CHECK_IE_SETTINGS, 'alert');
219                                 SUGAR.email2.accounts.ieAccountError(SUGAR.email2.accounts.errorStyle);
220                         } else {
221                                 resp = YAHOO.lang.JSON.parse(o.responseText);
222                                 SUGAR.email2.accounts.refreshInboundAccountTable();
223                                 SUGAR.email2.accounts.refreshOuboundAccountTable();
224                                 SUGAR.email2.folders.startEmailCheckOneAccount(resp.id, true);
225                                 SUGAR.email2.accounts.inboundAccountEditDialog.hide();
226                         }
227                 } else {
228                      SUGAR.hideMessageBox();
229                      SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_SAVE_ACCOUNT, 'alert');
230                 }
231
232         },
233
234         /**
235          */
236         loadAttachments : function(o) {
237                 var result = YAHOO.lang.JSON.parse(o.responseText);
238
239                 SUGAR.email2.composeLayout.loadAttachments(result);
240         },
241
242         /**
243          */
244         loadSignature : function(o) {
245                 var ret = YAHOO.lang.JSON.parse(o.responseText);
246                 SUGAR.email2.signatures[ret.id] = ret.signature_html;
247                 SUGAR.email2.composeLayout.setSignature(SUGAR.email2.signatures.targetInstance);
248         },
249
250         /**
251          * Follow up to mark email read|unread|flagged
252          */
253         markEmailCleanup : function(o) {
254                 var ret = YAHOO.lang.JSON.parse(o.responseText);
255                 if (!ret['status']) {
256                 SUGAR.hideMessageBox();
257                         SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, ret['message'], 'alert');
258                 } else {
259                         SUGAR.email2.contextMenus.markEmailCleanup();
260                 } // else
261         },
262
263         /**
264          */
265         rebuildShowFolders : function(o) {
266                 var t = YAHOO.lang.JSON.parse(o.responseText);
267                 var show = document.getElementById('ieAccountListShow');
268
269                 SUGAR.email2.util.emptySelectOptions(show);
270
271                 for(i=0; i<t.length; i++) { // iterate through assoc array
272                         var opt = new Option(t[i].text, t[i].value, t[i].selected);
273                         opt.selected = t[i].selected;
274                         show.options.add(opt);
275                 }
276
277                 SUGAR.email2.accounts.renderTree();
278         },
279         /**
280          */
281         saveListViewSortOrderPart2 : function() {
282                 // create the JSON string the func expects
283                 focusFolderPath = '[ "Home", "' + ieName + '"';
284
285                 var f = new String(focusFolder);
286                 var fEx = f.split('.');
287
288                 for(i=0; i<fEx.length; i++) {
289                         focusFolderPath += ', "' + fEx[i] +'"'
290                 }
291
292                 focusFolderPath += ']';
293
294                 YAHOO.namespace('frameFolders').selectednode = SUGAR.email2.folders.getNodeFromMboxPath(focusFolderPath);
295                 SUGAR.email2.listView.populateListFrame(YAHOO.namespace('frameFolders').selectednode, ieId, 'true');
296         },
297
298         /**
299          *
300          */
301         sendEmailCleanUp : function(o) {
302         var ret;
303         SUGAR.hideMessageBox();
304
305         try {
306             ret = YAHOO.lang.JSON.parse(o.responseText);
307             SUGAR.email2.composeLayout.forceCloseCompose(ret.composeLayoutId);
308             //SUGAR.email2.addressBook.showContactMatches(ret.possibleMatches);
309         } catch(err) {
310             if (o.responseText) {
311                 SUGAR.showMessageBox(mod_strings.LBL_SEND_EMAIL_FAIL_TITLE, o.responseText, 'alert');
312                     }
313             // Else we have an error here.
314         }        
315
316                 if (typeof(SE.grid) != 'undefined')
317                         SE.listView.refreshGrid();
318                 //Disabled while address book is disabled
319
320                 //If this call back was initiated by quick compose from a Detail View page, refresh the
321                 //history subpanel.  If it was initiated by quickcreate from shortcut bar, then
322                 //close the shortcut bar menu
323                 if ( (typeof(action_sugar_grp1) != 'undefined')) {
324                         if(action_sugar_grp1 == 'DetailView') {
325                                 showSubPanel('history',null,true);
326                         } else if(action_sugar_grp1 == 'quickcreate') {
327                                 closeEmailOverlay();
328                         }
329                 }
330
331         },
332
333         ieSendSuccess : function(o) {
334                 SUGAR.hideMessageBox();
335                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_TEST_OUTBOUND_SETTINGS_SENT, app_strings.LBL_EMAIL_TEST_NOTIFICATION_SENT, 'plain');
336         },
337
338         /**
339          */
340         settingsFolderRefresh : function(o) {
341                 //SUGAR.email2.accounts.rebuildFolderList(); // refresh frameFolder
342                 var ret = YAHOO.lang.JSON.parse(o.responseText);
343                 var user = document.getElementById('userFolders');
344
345                 SUGAR.email2.util.emptySelectOptions(user);
346
347                 for(i=0; i<ret.userFolders.length; i++) {
348                         var display = ret.userFolders[i].name;
349                         var value = ret.userFolders[i].id;
350                         var selected = (ret.userFolders[i].selected != "") ? true : false;
351                         var opt = new Option(display, value, selected);
352                         opt.selected = selected;
353                         user.options.add(opt);
354                 }
355         },
356
357         /**
358          */
359         startRequest : function(callback, args, forceAbort) {
360                 if(this.currentRequestObject != null) {
361                         if(this.forceAbort == true) {
362                                 YAHOO.util.Connect.abort(this.currentRequestObject, null, false);
363                         }
364                 }
365                 this.currentRequestObject = YAHOO.util.Connect.asyncRequest('POST', "./index.php", callback, args);
366                 this._reset();
367         },
368
369         requestInProgress : function() {
370                 return (YAHOO.util.Connect.isCallInProgress(this.currentRequestObject));
371         },
372
373         /**
374          */
375         updateFolderSubscriptions : function() {
376                 SUGAR.email2.folders.lazyLoadSettings(); // refresh view in Settings overlay
377                 SUGAR.email2.folders.setSugarFolders(1000);// refresh view in TreeView
378                 SUGAR.hideMessageBox();
379         },
380
381         /**
382          */
383         updateFrameFolder : function() {
384                 SUGAR.email2.folders.checkEmailAccounts();
385         },
386
387         /**
388          */
389         updateUserPrefs : function(o) {
390                 SUGAR.email2.userPrefs = YAHOO.lang.JSON.parse(o.responseText);
391                 SUGAR.email2.folders.startCheckTimer(); // starts the auto-check interval
392         },
393
394         /**
395          */
396         uploadAttachmentSuccessful : function(o) {
397                 // clear out field
398                 document.getElementById('email_attachment').value = '';
399                 
400                 var ret = YAHOO.lang.JSON.parse(o.responseText);
401                 ret.name = escape(ret.name);
402                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
403                 var overall = document.getElementById('addedFiles' + idx);
404                 var index = overall.childNodes.length;
405                 var out =
406                         "<div id='email_attachment_bucket" + idx + index + "'>" +
407                                 // remove button
408                                 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=minus.gif' " +
409                                         "style='cursor:pointer' align='absmiddle' onclick='SUGAR.email2.composeLayout.deleteUploadAttachment(\"" +
410                                         idx + index + "\",\"" + ret.guid + ret.name + "\");'/>" +
411                                 // file icon
412                                 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=attachment.gif' " +
413                                         "id='email_attachmentImage'" + idx + index + "align='absmiddle' />" +
414                                 // hidden id field
415                                 "<input type='hidden' value='" + ret.guid + ret.name + "' name='email_attachment" + index + "' id='email_attachment" + idx + index + "' />" +
416                                 // file name
417                                 ((ret.nameForDisplay != null) ? ret.nameForDisplay + "&nbsp;" : ret.name + "&nbsp;") +
418                                 "<br/>" +
419                         "</div>";
420                 overall.innerHTML += out;
421                 if(SUGAR.email2.util.isIe()) {
422                         document.getElementById('addedFiles' + idx).innerHTML = document.getElementById('addedFiles' + idx).innerHTML;
423                 }
424
425                 // hide popup
426                 SUGAR.email2.addFileDialog.hide();
427                 // focus attachments
428                 SUGAR.email2.composeLayout.showAttachmentPanel(idx);
429         }
430 };
431
432
433 ///////////////////////////////////////////////////////////////////////////
434 ////    PER MODULE CALLBACK OBJECTS
435 AjaxObject.accounts = {
436         saveOutboundCleanup : function(o) {
437                 SUGAR.email2.accounts.refreshOuboundAccountTable();
438                 SUGAR.email2.accounts.outboundDialog.hide();
439                 var id = o.responseText;
440                 SUGAR.email2.accounts.newAddedOutboundId = id;
441                 },
442         saveDefaultOutboundCleanup: function(o){
443
444         },
445         callbackEditOutbound : {
446                 success : function(o)
447                 {
448                         var ret = YAHOO.lang.JSON.parse(o.responseText);
449                         // show overlay
450                         SUGAR.email2.accounts.showAddSmtp();
451
452                         // fill values
453                         document.getElementById("mail_id").value = ret.id;
454                         document.getElementById("type").value = ret.type;
455                         document.getElementById("mail_sendtype").value = ret.mail_sendtype;
456                         document.getElementById("mail_name").value = ret.name;
457                         document.getElementById("mail_smtpserver").value = ret.mail_smtpserver;
458                         document.getElementById("outboundEmailForm").mail_smtptype.value = ret.mail_smtptype;
459                         document.getElementById("mail_smtpport").value = ret.mail_smtpport;
460                         document.getElementById("mail_smtpuser").value = ret.mail_smtpuser;
461                         document.getElementById("mail_smtpauth_req").checked = (ret.mail_smtpauth_req == 1) ? true : false;
462                         SUGAR.email2.accounts.smtp_authenticate_field_display();
463                         document.getElementById("mail_smtpssl").options[ret.mail_smtpssl].selected = true;
464
465             if(ret.type == 'system-override') {
466                              SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(true);
467                              SUGAR.email2.accounts.changeEmailScreenDisplay(ret.mail_smtptype,true);
468             }
469             else {
470                              SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(false);
471                              SUGAR.email2.accounts.changeEmailScreenDisplay(ret.mail_smtptype,false);
472             }
473             SUGAR.util.setEmailPasswordDisplay('mail_smtppass', ret.has_password);
474
475                 },
476                 failure : AjaxObject.handleFailure,
477                 timeout : AjaxObject.timeout,
478                 scope   : AjaxObject
479         },
480         callbackDeleteOutbound : {
481                 success : function(o) {
482                     var ret = YAHOO.lang.JSON.parse(o.responseText);
483                     if(ret.is_error)
484                     {
485                         if(confirm(ret.error_message))
486                 {
487                     SUGAR.showMessageBox(app_strings.LBL_EMAIL_IE_DELETE, app_strings.LBL_EMAIL_ONE_MOMENT);
488                     AjaxObject.startRequest(AjaxObject.accounts.callbackDeleteOutbound, urlStandard + "&emailUIAction=deleteOutbound&confirm=true&outbound_email=" + ret.outbound_email);
489                 }
490                 else
491                     SUGAR.hideMessageBox();
492                     }
493                     else
494                     {
495                              SUGAR.hideMessageBox();
496                              SUGAR.email2.accounts.refreshOuboundAccountTable();
497                     }
498                 },
499
500                 failure : AjaxObject.handleFailure,
501                 timeout : AjaxObject.timeout,
502                 scope   : AjaxObject
503         },
504
505         callbackCheckMailProgress : {
506            success : function(o) {
507                if (typeof(SUGAR.email2.accounts.totalMsgCount) == "undefined") {
508                    SUGAR.email2.accounts.totalMsgCount = -1;
509                }
510
511                //Check for server timeout / errors
512                var ret = YAHOO.lang.JSON.parse(o.responseText);
513                var done = false;
514
515                if (typeof(o.responseText) == 'undefined' || o.responseText == "" || ret == false) {
516                    SUGAR.hideMessageBox();
517                    SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_TIMEOUT, 'alert');
518                    SUGAR.email2.accounts.totalMsgCount = -1;
519                //SUGAR.email2.folders.rebuildFolders();
520                done = true;
521                }
522
523                var currIeId = ret['ieid'];
524
525
526                var serverCount = ret.count;
527
528                if (ret['status'] == 'done') {
529                    for(i=0; i < SUGAR.email2.accounts.ieIds.length; i++) {
530                        if (i == SUGAR.email2.accounts.ieIds.length - 1) {
531                            //We are all done
532                            done = true;
533                            break;
534                        } else if (SUGAR.email2.accounts.ieIds[i] == currIeId) {
535                            //Go to next account
536                            currIeId = SUGAR.email2.accounts.ieIds[i+1];
537                            ret.count = 0;
538                            SUGAR.email2.accounts.totalMsgCount = -1;
539                            break;
540                        }
541                    }
542                }
543                else if (ret.mbox && ret.totalcount && ret.count) {
544                    SUGAR.email2.accounts.totalMsgCount = ret.totalcount;
545                    if (ret.count >= ret.totalcount) {
546                        serverCount = 0;
547                    }
548                } else if (SUGAR.email2.accounts.totalMsgCount < 0 && ret.totalcount) {
549                    SUGAR.email2.accounts.totalMsgCount = ret.totalcount;
550                } else {
551                        SUGAR.hideMessageBox();
552                SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_TIMEOUT, 'alert');
553                SUGAR.email2.accounts.totalMsgCount = -1;
554                done = true;
555                    }
556
557                if (done) {
558                    SUGAR.email2.accounts.totalMsgCount = -1;
559                    SUGAR.hideMessageBox();
560                    SUGAR.email2.folders.rebuildFolders();
561                    SE.listView.refreshGrid();
562                } else if (SUGAR.email2.accounts.totalMsgCount < 0) {
563                YAHOO.SUGAR.MessageBox.updateProgress(0, mod_strings.LBL_CHECKING_ACCOUNT + ' '+ (i + 2) + ' '+ mod_strings.LBL_OF + ' ' + SUGAR.email2.accounts.ieIds.length);
564                AjaxObject.startRequest(AjaxObject.accounts.callbackCheckMailProgress, urlStandard +
565                                 '&emailUIAction=checkEmailProgress&ieId=' + currIeId + "&currentCount=0&synch=" + ret.synch);
566            } else {
567                YAHOO.SUGAR.MessageBox.updateProgress((ret.count / SUGAR.email2.accounts.totalMsgCount) * 100,
568                    app_strings.LBL_EMAIL_DOWNLOAD_STATUS.replace(/\[\[count\]\]/, ret.count).replace(/\[\[total\]\]/, SUGAR.email2.accounts.totalMsgCount));
569                    AjaxObject.startRequest(AjaxObject.accounts.callbackCheckMailProgress, urlStandard +
570                    '&emailUIAction=checkEmailProgress&ieId=' + currIeId + "&currentCount=" + serverCount +
571                    '&mbox=' + ret.mbox + '&synch=' + ret.synch + '&totalcount=' + SUGAR.email2.accounts.totalMsgCount);
572                }
573            },
574            failure : AjaxObject.handleFailure,
575        timeout : AjaxObject.timeout,
576        scope   : AjaxObject
577         }
578 };
579
580 ///////////////////////////////////////////////////////////////////////////////
581 ////    COMPOSE LAYOUT
582 AjaxObject.composeLayout = {
583         /**
584          * Populates the record id
585          */
586     saveDraftCleanup : function(o) {
587         var ret;
588         SUGAR.hideMessageBox();
589
590         try {
591             ret = YAHOO.lang.JSON.parse(o.responseText);
592             SUGAR.email2.composeLayout.forceCloseCompose(ret.composeLayoutId);
593         } catch(err) {
594             if (o.responseText) {
595                 SUGAR.showMessageBox(mod_strings.LBL_ERROR_SAVING_DRAFT, o.responseText, 'alert');
596             }
597         }
598     }
599 };
600
601 AjaxObject.composeLayout.callback = {
602         saveDraft : {
603                 success : AjaxObject.composeLayout.saveDraftCleanup,
604                 failure : AjaxObject.handleFailure,
605                 timeout : AjaxObject.timeout,
606                 scope   : AjaxObject
607         }
608 };
609
610 AjaxObject.detailView = {
611         /**
612          * Pops-up a printable view of an email
613          */
614         displayPrintable : function(o) {
615                 var ret = YAHOO.lang.JSON.parse(o.responseText);
616                 var displayTemplate = new YAHOO.SUGAR.Template(SUGAR.email2.templates['viewPrintable']);
617                 // 2 below must be in global context
618                 meta = ret.meta;
619                 meta['panelId'] = SUGAR.email2.util.getPanelId();
620                 email = ret.meta.email;
621                 if (typeof(email.cc) == 'undefined') {
622                   email.cc = "";
623                 }
624
625                 var out = displayTemplate.exec({
626                         'app_strings'   : app_strings,
627                         'theme'                 : theme,
628                         'idx'                   : 'Preview',
629                         'meta'                  : meta,
630                         'email'                 : meta.email
631                 });
632
633                 // open popup window
634                 var popup = window.open('modules/Emails/templates/_blank.html', 'printwin' ,
635                     'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
636
637                 popup.document.write(out);
638                 popup.document.close();
639         },
640
641         /**
642          * Takes formatted response and creates a modal pop-over containing a title and content
643          */
644         displayView : function(o) {
645                 var SED = SUGAR.email2.detailView;
646                 var ret = YAHOO.lang.JSON.parse(o.responseText);
647
648                 if(!SED.viewDialog) {
649                         SED.viewDialog = new YAHOO.widget.Dialog("viewDialog", {
650                                 modal:true,
651                 visible:true,
652                 fixedcenter:true,
653                 constraintoviewport: true,
654                                 shadow  : true
655                         });
656             SED.viewDialog.renderEvent.subscribe(function() {
657                 var content = this.body.firstChild;
658                 var viewH = YAHOO.util.Dom.getViewportHeight();
659                 if (content) {
660                         this.body.style.overflow = "auto";
661                         this.body.style.width = "800px";
662                         this.body.style.height = (viewH - 75 > content.clientHeight ? (content.clientHeight) : (viewH - 75)) + "px";
663                 }
664             }, SED.viewDialog);
665                 } // end lazy load
666                 SED.viewDialog.setHeader(ret.title);
667                 SED.viewDialog.setBody(ret.html);
668                 SED.viewDialog.render();
669                 SED.viewDialog.show();
670         },
671
672         /**
673          * Generates a modal popup to populate with the contents of bean's full EditView
674          */
675         showQuickCreateForm : function(o) {
676                 var SED = SUGAR.email2.detailView;
677                 var ret = YAHOO.lang.JSON.parse(o.responseText);
678
679                 if(!SED.quickCreateDialog) {
680                         SED.quickCreateDialog = new YAHOO.widget.Dialog("quickCreateForEmail", {
681                                 modal:true,
682                                 visible:true,
683                 fixedcenter:true,
684                 constraintoviewport: true,
685                                 shadow  : true
686                         });
687
688             SED.quickCreateDialog.renderEvent.subscribe(function() {
689                 var viewH = YAHOO.util.Dom.getViewportHeight();
690                 var contH = 0;
691                 for (var i in this.body.childNodes) {
692                         if (this.body.childNodes[i].clientHeight) {
693                                 contH += this.body.childNodes[i].clientHeight;
694                         } else if (this.body.childNodes[i].offsetHeight) {
695                                 contH += this.body.childNodes[i].offsetHeight;
696                         } // if
697                 }
698                         this.body.style.width = "800px";
699                         this.body.style.height = (viewH - 75 > contH ? (contH + 10) : (viewH - 75)) + "px";
700                         this.body.style.overflow = "auto";
701             }, SED.quickCreateDialog);
702
703             SED.quickCreateDialog.hideEvent.subscribe(function(){
704                                 var qsFields = YAHOO.util.Dom.getElementsByClassName('.sqsEnabled', null, this.body);
705                                 /*for(var qsField in qsFields){
706                                         if (typeof QSFieldsArray[qsFields[qsField].id] != 'undefined')
707                                         Ext.getCmp('combobox_'+qsFields[qsField].id).destroy();
708                                 }*/
709                         });
710             SED.quickCreateDialog.setHeader(app_strings.LBL_EMAIL_QUICK_CREATE);
711                 } // end lazy load
712                 if (ret.html) {
713                         ret.html = ret.html.replace('<script type="text/javascript" src="include/SugarEmailAddress/SugarEmailAddress.js"></script>', "");
714                 }
715                 SED.quickCreateDialog.setBody(ret.html ? ret.html : "&nbsp;");
716                 SED.quickCreateDialog.render();
717                 SUGAR.util.evalScript(ret.html + '<script language="javascript">enableQS(true);</script>');
718
719                 SED.quickCreateDialog.ieId = ret.ieId;
720                 SED.quickCreateDialog.uid = ret.uid;
721         SED.quickCreateDialog.mbox = ret.mbox;
722         SED.quickCreateDialog.qcmodule = ret.module;
723
724         SED.quickCreateDialog.show();
725
726                 var editForm = document.getElementById('form_EmailQCView_' + ret.module);
727                 if (editForm) {
728                   editForm.module.value = 'Emails';
729                   var count = SUGAR.EmailAddressWidget.count[ret.module] ? SUGAR.EmailAddressWidget.count[ret.module] : 0;
730           var tableId = YAHOO.util.Dom.getElementsByClassName('emailaddresses', 'table', editForm)[0];
731           tableId = tableId ? tableId.id : tableId;
732                   var instId = ret.module + (count - 1);
733                   SED.quickCreateEmailsToAdd = ret.emailAddress;
734                   SED.quickCreateEmailCallback = function(instId, tableId) {
735               //try to fill up the email address if and only if emailwidget is existed in the form
736               if(tableId) {
737                   var eaw = SUGAR.EmailAddressWidget.instances[instId];
738                   if (eaw) {
739                       eaw.prefillEmailAddresses(tableId, SUGAR.email2.detailView.quickCreateEmailsToAdd);
740                   } else {
741                       window.setTimeout(function() {
742                           SUGAR.email2.detailView.quickCreateEmailCallback(instId, tableId);
743                       }, 100);
744
745                   }
746               }
747                   }
748                   window.setTimeout(function() {
749               SUGAR.email2.detailView.quickCreateEmailCallback(instId, tableId);
750             }, 100);
751                 }
752         },
753
754         saveQuickCreateForm : function(o) {
755             SUGAR.hideMessageBox();
756                 SUGAR.email2.detailView.quickCreateDialog.hide();
757                 validate['EditView'] = [ ];
758         },
759
760         saveQuickCreateFormAndReply : function(o) {
761         SUGAR.hideMessageBox();
762         var ret = YAHOO.lang.JSON.parse(o.responseText);
763         SUGAR.email2.detailView.quickCreateDialog.hide();
764         var qcd = SUGAR.email2.detailView.quickCreateDialog;
765         var type = (qcd.qcmodule == 'Cases') ? 'replyCase' : 'reply';
766         if (ret) {
767             var emailID = ret.id;
768             SUGAR.email2.composeLayout.c0_replyForwardEmail(null, ret.id, 'sugar::Emails', type);
769         } else {
770             SUGAR.email2.composeLayout.c0_replyForwardEmail(qcd.ieId, qcd.uid, qcd.mbox, type);
771         }
772         //Cean the validate cache to prevent errors on the next call
773         validate['EditView'] = [ ];
774     },
775
776         saveQuickCreateFormAndAddToAddressBook : function(o) {
777            SUGAR.hideMessageBox();
778                 SUGAR.email2.detailView.quickCreateDialog.hide();
779                 SUGAR.email2.complexLayout.findPanel('contactsTab').show();
780                 validate['EditView'] = [ ];
781         },
782
783         handleAssignmentDialogAssignAction : function() {
784
785
786             var assign_user_id = window.document.forms['Distribute'].elements['assigned_user_id'].value;
787
788             var dist = 'direct';
789             var users = false;
790             var rules = false;
791             var get = "";
792             var found_teams = false;
793             var warning_message = mod_strings.LBL_WARN_NO_USERS;
794             if(!found_teams && assign_user_id == '' )
795             {
796                 alert(warning_message);
797                 return;
798             }
799
800             var emailUids = SUGAR.email2.listView.getUidsFromSelection();
801             var uids = "";
802             for(i=0; i<emailUids.length; i++) {
803                 if(uids != '') {
804                     uids += app_strings.LBL_EMAIL_DELIMITER;
805                 }
806                 uids += emailUids[i];
807             }
808
809             var row = SUGAR.email2.grid.getSelectedRows()[0];
810             var data = SUGAR.email2.grid.getRecord(row).getData();
811             var ieid = data.ieId;
812             var mbox = data.mbox;
813             AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentAssign&uids=" + uids + "&ieId=" + ieid + "&folder=" + mbox + "&distribute_method=" + dist + "&users=" +assign_user_id + get);
814             SUGAR.email2.contextMenus.assignToDialogue.hide();
815             SUGAR.showMessageBox('Assignment', app_strings.LBL_EMAIL_ONE_MOMENT);
816
817         },
818
819         handleAssignmentDialogDeleteAction : function() {
820                 // TO pass list of UIDS/emailIds
821                 var uids = SUGAR.email2.listView.getUidsFromSelection();
822                 var row = SUGAR.email2.grid.getSelections()[0];
823                 var ieid = row.data.ieId;
824             var mbox = row.data.mbox;
825         AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentDelete&uids=" + uids + "&ieId=" + ieId + "&folder=" + mbox);
826         SUGAR.email2.contextMenus.assignmentDialog.hide();
827                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
828
829                 // AJAX Call
830
831         },
832
833         showEmailDetailView : function(o) {
834         SUGAR.hideMessageBox();
835         var SED = SUGAR.email2.detailView;
836                 var ret = YAHOO.lang.JSON.parse(o.responseText);
837
838                 if(!SED.quickCreateDialog) {
839                         SED.quickCreateDialog = new YAHOO.widget.Dialog("emailDetailDialog", {
840                                 modal:true,
841                                 visible:true,
842                 //fixedcenter:true,
843                 constraintoviewport: true,
844                 draggable: true,
845                                 autofillheight: "body",
846                                 shadow  : true
847                         });
848                         SED.quickCreateDialog.renderEvent.subscribe(function() {
849                 var viewHeight = YAHOO.util.Dom.getViewportHeight();
850                 var contH = 0;
851                 for (var i in this.body.childNodes) {
852                         if (this.body.childNodes[i].offsetHeight)
853                                 contH += this.body.childNodes[i].offsetHeight;
854                 }
855                         this.body.style.overflow = "auto";
856                         this.body.style.width = "800px";
857                         this.body.style.height = (viewHeight - 75 > contH ? (contH + 10) : (viewHeight - 75)) + "px";
858                         this.center();
859             }, SED.quickCreateDialog);
860                 }
861                 SED.quickCreateDialog.setHeader(app_strings.LBL_EMAIL_RECORD);
862                 SED.quickCreateDialog.setBody(ret.html);
863                 SED.quickCreateDialog.render();
864         SUGAR.util.evalScript(ret.html);
865         SED.quickCreateDialog.show();
866         },
867
868         showAssignmentDialogWithData : function(o) {
869         var SEC = SUGAR.email2.contextMenus;
870                 SUGAR.hideMessageBox();
871         var ret = YAHOO.lang.JSON.parse(o.responseText);
872         if (!SEC.assignmentDialog) {
873                 SEC.assignmentDialog = new YAHOO.widget.Dialog("assignmentDialog", {
874                         visible:false,
875                 fixedcenter:true,
876                 constraintoviewport: true,
877                         modal   : true
878                 });
879                 SEC.assignmentDialog.setBody("");
880                 SEC.assignmentDialog.setHeader(app_strings.LBL_EMAIL_ASSIGNMENT);
881                 SEC.assignmentDialog.renderEvent.subscribe(function() {
882                 var iev = YAHOO.util.Dom.get("Distribute");
883                 if (iev) {
884                         this.body.style.width = "700px";
885                 }
886             },  SEC.assignmentDialog);
887                 SEC.assignmentDialog.render();
888         }
889         SEC.assignmentDialog.setBody(ret);
890         SEC.assignmentDialog.render();
891         validate = [];
892         SEC.assignmentDialog.show();
893         SUGAR.util.evalScript(ret);
894         },
895
896         showImportForm : function(o) {
897                 var SED = SUGAR.email2.detailView;
898                 var ret = YAHOO.lang.JSON.parse(o.responseText);
899         
900         document.getElementById('quickCreateContent').innerHTML = "";
901         SUGAR.hideMessageBox();
902         if (!ret) {
903             return false;
904         }
905
906         if(!SED.importDialog) {
907             SED.importDialog = new YAHOO.widget.Dialog("importDialog", {
908                 modal:true,
909                 visible:false,
910                 fixedcenter:true,
911                 constraintoviewport: true,
912                 buttons : [{
913                         text: app_strings.LBL_EMAIL_ARCHIVE_TO_SUGAR, isDefault: true, handler: function(){
914                                 AjaxObject.detailView.getImportAction(SED.importDialog.ret); }
915                 }]//,
916                 //scroll : true
917             });
918             SED.importDialog.setHeader(app_strings.LBL_EMAIL_IMPORT_SETTINGS);
919             SED.importDialog.setBody("");
920             SED.importDialog.hideEvent.subscribe(function(){
921                 for(var i in QSFieldsArray) {
922                         if (QSFieldsArray[i] != null && typeof(QSFieldsArray[i]) == "object") {
923                                 QSFieldsArray[i].destroy();
924                                 delete QSFieldsArray[i];
925                         }
926                         if (QSProcessedFieldsArray[i]) {
927                                 QSProcessedFieldsArray[i] = false;
928                         } // if
929                                 }
930             });
931             SED.importDialog.renderEvent.subscribe(function() {
932                 var iev = YAHOO.util.Dom.get("ImportEditView");
933                 if (iev) {
934                         //this.body.style.height = (iev.clientHeight + 10) + "px";
935                         this.body.style.width = "600px";
936                 }
937             }, SED.importDialog);
938             SED.importDialog.render();
939         } // end lazy load
940         SED.importDialog.setBody(ret.html);
941         SED.importDialog.ret = ret;
942         SUGAR.util.evalScript(ret.html);
943         SED.importDialog.render();
944         validate = [];
945         SED.importDialog.show();
946         SED.importDialog.focusFirstButton();
947     },
948     getImportAction : function(ret) {
949         if (!check_form('ImportEditView')) return false;
950         if (!SUGAR.collection.prototype.validateTemSet('ImportEditView', 'team_name')) {
951                 alert(mod_strings.LBL_EMAILS_NO_PRIMARY_TEAM_SPECIFIED);
952                 return false;
953         } // if
954                 var get = "";
955         var editView = document.getElementById('ImportEditView');
956         if (editView.assigned_user_id != null) {
957             get = get + "&user_id=" + editView.assigned_user_id.value
958             //var user_id = editView.assigned_user_id.value;
959         }
960         var parent_id = editView.parent_id.value;
961         var parent_type = editView.parent_type.value;
962         var row = SUGAR.email2.grid.getSelectedRows()[0];
963         row = SUGAR.email2.grid.getRecord(row);
964         var data = row.getData();
965         var ieId = data.ieId;
966         var mbox = data.mbox;
967         var serverDelete = editView.serverDelete.checked;
968         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
969         var uids = "";
970         for(i=0; i<emailUids.length; i++) {
971             if(uids != '') {
972                 uids += app_strings.LBL_EMAIL_DELIMITER;
973             }
974             uids += emailUids[i];
975         }
976
977         var action = 'importEmail&uid=';
978         if (ret.move) {
979             action = 'moveEmails';
980             action = action + '&sourceFolder=' + ret['srcFolder'];
981             action = action + '&sourceIeId=' + ret['srcIeId'];
982             action = action + '&destinationFolder=' + ret['dstFolder'];
983             action = action + '&destinationIeId=' + ret['dstIeId'];
984             action = action + '&emailUids=';
985         }
986         if (action.search(/importEmail/) != -1) {
987             SUGAR.showMessageBox(app_strings.LBL_EMAIL_IMPORTING_EMAIL, app_strings.LBL_EMAIL_ONE_MOMENT);
988         } else {
989             SUGAR.showMessageBox("Moving Email(s)", app_strings.LBL_EMAIL_ONE_MOMENT);
990         }
991
992         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=' + action + uids + "&ieId=" + ieId + "&mbox=" + mbox +
993         get + "&parent_id=" + parent_id + "&parent_type=" + parent_type + '&delete=' + serverDelete);
994         SUGAR.email2.detailView.importDialog.hide();
995         document.getElementById('importDialogContent').innerHTML = "";
996
997     },
998     showRelateForm : function(o) {
999         var SED = SUGAR.email2.detailView;
1000         var ret = YAHOO.lang.JSON.parse(o.responseText);
1001         document.getElementById('quickCreateContent').innerHTML = "";
1002         SUGAR.hideMessageBox();
1003         if (!ret) {
1004             return false;
1005         }
1006         dialog_loaded = true;
1007
1008         if(!SED.relateDialog) {
1009             SED.relateDialog = new YAHOO.widget.Dialog('relateDialog', {
1010                                 modal:true,
1011                                 visible:true,
1012                 fixedcenter:true,
1013                 width: '800px',
1014                 constraintoviewport: true,
1015                                 buttons : [{
1016                         text: app_strings.LBL_EMAIL_RELATE_TO, isDefault: true, handler: function(){
1017                                         if (!check_form('RelateEditView')) return false;
1018                                         var get = "";
1019                         var editView = document.getElementById('RelateEditView');
1020                         var parent_id = editView.parent_id.value;
1021                         var parent_type = editView.parent_type.value;
1022                         var row = SUGAR.email2.grid.getSelectedRows()[0];
1023                         row  = SUGAR.email2.grid.getRecord(row);
1024                         var ieId = row.getData().ieId;
1025                         var mbox = row.getData().mbox;
1026                         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
1027                         var uids = "";
1028                         for(i=0; i<emailUids.length; i++) {
1029                             if(uids != '') {
1030                                 uids += app_strings.LBL_EMAIL_DELIMITER;
1031                             }
1032                             uids += emailUids[i];
1033                         }
1034                         SUGAR.showMessageBox(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
1035                         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=relateEmails&uid=' + uids
1036                             + "&ieId=" + ieId + "&mbox=" + mbox + "&parent_id=" + parent_id + "&parent_type=" + parent_type);
1037                         SED.relateDialog.hide();
1038                         document.getElementById('relateDialogContent').innerHTML = "";
1039                         }
1040                 }]
1041                         });
1042
1043             SED.relateDialog.hideEvent.subscribe(function(){
1044                 if (QSFieldsArray['ImportEditView_parent_name'] != null) {
1045                         QSFieldsArray['ImportEditView_parent_name'].destroy();
1046                         delete QSFieldsArray['ImportEditView_parent_name'];
1047                 } // if
1048                                 if (QSProcessedFieldsArray['ImportEditView_parent_name']) {
1049                                         QSProcessedFieldsArray['ImportEditView_parent_name'] = false;
1050                                 } // if
1051             });
1052
1053             SED.relateDialog.renderEvent.subscribe(function() {
1054                 var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
1055                 var contH = 0;
1056                 for (var i in this.body.childNodes) {
1057                         if (this.body.childNodes[i].clientHeight)
1058                                 contH += this.body.childNodes[i].clientHeight;
1059                 }
1060             }, SED.relateDialog);
1061             SED.relateDialog.setHeader(app_strings.LBL_EMAIL_RELATE_EMAIL);
1062                 } // end lazy load
1063
1064         SED.relateDialog.setBody(ret.html);
1065         SED.relateDialog.render();
1066         SUGAR.util.evalScript(ret.html);
1067         SED.relateDialog.show();
1068     }
1069 };
1070 /**
1071  * DetailView callbacks
1072  */
1073 AjaxObject.detailView.callback = {
1074         emailDetail : {
1075                 success : function(o) {
1076                         SUGAR.email2.o = o;
1077                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1078                         SUGAR.email2.detailView.consumeMetaDetail(ret);
1079                 },
1080                 argument: [targetDiv],
1081                 failure : AjaxObject.handleFailure,
1082                 timeout : 0,
1083                 scope   : AjaxObject
1084         },
1085         emailPreview : {
1086                 success : function(o) {
1087                         SUGAR.email2.o = o;
1088                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1089                         SUGAR.email2.detailView.consumeMetaPreview(ret);
1090                 },
1091                 failure : AjaxObject.handleFailure,
1092                 timeout : 0,
1093                 scope   : AjaxObject
1094         },
1095         viewPrint : {
1096                 success : AjaxObject.detailView.displayPrintable,
1097                 failure : AjaxObject.handleFailure,
1098                 timeout : AjaxObject.timeout,
1099                 scope   : AjaxObject
1100         },
1101         viewRaw : {
1102                 success : AjaxObject.detailView.displayView,
1103                 failure : AjaxObject.handleFailure,
1104                 timeout : AjaxObject.timeout,
1105                 scope   : AjaxObject
1106         }
1107 };
1108
1109
1110
1111
1112
1113 AjaxObject.folders = {
1114         /**
1115          * check-mail post actions
1116          */
1117         checkMailCleanup : function(o) {
1118                 SUGAR.hideMessageBox();
1119                 AjaxObject.folders.rebuildFolders(o); // rebuild TreeView
1120
1121                 // refresh focus ListView
1122                 SE.listView.refreshGrid();
1123                 SUGAR.email2.folders.startCheckTimer(); // resets the timer
1124         },
1125
1126         /**
1127          */
1128         rebuildFolders : function(o) {
1129                 SUGAR.hideMessageBox();
1130
1131                 var data = YAHOO.lang.JSON.parse(o.responseText);
1132
1133                 email2treeinit(SUGAR.email2.tree, data.tree_data, 'frameFolders', data.param);
1134                 SUGAR.email2.folders.setSugarFolders();
1135         }
1136 };
1137 AjaxObject.folders.callback = {
1138         checkMail : {
1139                 success : AjaxObject.folders.checkMailCleanup,
1140                 failure : AjaxObject.handleFailure,
1141                 timeout : 600000, // 5 mins
1142                 scope   : AjaxObject
1143         }
1144 }
1145
1146 AjaxObject.rules = {
1147         loadRulesForSettings : function(o) {
1148                 document.getElementById("rulesListCell").innerHTML = o.responseText;
1149                 // assume we have the class we need
1150                 SUGAR.routing.getStrings();
1151                 SUGAR.routing.getDependentDropdowns();
1152         }
1153 };
1154 ////    END PER MODULE CALLBACK OBJECTS
1155 ///////////////////////////////////////////////////////////////////////////
1156
1157
1158 var callback = {
1159         success : AjaxObject.handleSuccess,
1160         failure : AjaxObject.handleFailure,
1161         timeout : AjaxObject.timeout,
1162         scope   : AjaxObject
1163 };
1164 var callbackAccount = {
1165         success : AjaxObject.ieSaveSuccess,
1166         failure : AjaxObject.handleFailure,
1167         timeout : AjaxObject.timeout,
1168         scope   : AjaxObject
1169 };
1170 var callbackAccountDelete = {
1171         success : AjaxObject.ieDeleteSuccess,
1172         failure : AjaxObject.handleFailure,
1173         timeout : AjaxObject.timeout,
1174         scope   : AjaxObject
1175 };
1176 var callbackOutboundTest = {
1177         success : AjaxObject.ieSendSuccess,
1178         failure : AjaxObject.handleFailure,
1179         timeout : AjaxObject.timeout,
1180         scope   : AjaxObject
1181 };
1182
1183
1184
1185 var callbackTeamInfoForSettings = {
1186 success : function (o) {
1187         var data = YAHOO.lang.JSON.parse(o.responseText);
1188         document.getElementById('EditViewGroupFolderTeamTD').innerHTML = data.defaultgroupfolder;
1189 },
1190 failure : AjaxObject.handleFailure,
1191 timeout : AjaxObject.timeout,
1192 scope   : AjaxObject
1193
1194 };
1195
1196 var callbackStatusForImport = {
1197 success : function (o) {
1198         SUGAR.hideMessageBox();
1199         if (o.responseText != "")  {
1200                 var statusString = "";
1201                 var data = YAHOO.lang.JSON.parse(o.responseText);
1202                 for(i=0; i<data.length; i++) {
1203                         statusString = statusString + data[i] + '<br/>';
1204                 }
1205                 SUGAR.showMessageBox(SUGAR.language.get('Emails','LBL_IMPORT_STATUS_TITLE'), statusString, 'alert');
1206         }
1207         SE.listView.refreshGrid();
1208
1209 },
1210 failure : AjaxObject.handleFailure,
1211 timeout : AjaxObject.timeout,
1212 scope   : AjaxObject
1213
1214 };
1215 var callbackComposeCache = {
1216         success : AjaxObject.composeCache,
1217         failure : AjaxObject.handleFailure,
1218         timeout : AjaxObject.timeout,
1219         scope   : AjaxObject
1220 };
1221 var callbackDelete = {
1222         success : AjaxObject.handleDeleteReturn,
1223         failure : AjaxObject.handleFailure,
1224         timeout : AjaxObject.timeout,
1225         scope   : AjaxObject
1226 };
1227 var callbackEmailDetailMultiple = {
1228         success : function(o) {
1229                 SUGAR.hideMessageBox();
1230         var retMulti = YAHOO.lang.JSON.parse(o.responseText);
1231                 var ret = new Object();
1232
1233                 for(var i=0; i<retMulti.length; i++) {
1234                         ret = retMulti[i];
1235
1236                         SUGAR.email2._setDetailCache(ret);
1237                         SUGAR.email2.detailView.populateDetailView(ret.meta.uid, ret.meta.mbox, ret.meta.ieId, true, SUGAR.email2.innerLayout);
1238                 }
1239         },
1240         failure : AjaxObject.handleFailure,
1241         timeout : 0,
1242         scope   : AjaxObject
1243 };
1244 var callbackListViewSortOrderChange = {
1245         success : AjaxObject.saveListViewSortOrderPart2,
1246         failure : AjaxObject.handleFailure,
1247         timeout : AjaxObject.timeout,
1248         scope   : AjaxObject,
1249         argument        : [ieId, ieName, focusFolder]
1250 };
1251 var callbackEmptyTrash = {
1252         success : function(o) {
1253                 SUGAR.hideMessageBox();
1254                 AjaxObject.folderRenameCleanup;
1255         },
1256         failure : AjaxObject.handleFailure,
1257         timeout : AjaxObject.timeout,
1258         scope   : AjaxObject
1259 };
1260 var callbackClearCacheFiles = {
1261         success : function(o) {
1262                 SUGAR.hideMessageBox();
1263         },
1264         failure : AjaxObject.handleFailure,
1265         timeout : AjaxObject.timeout,
1266         scope   : AjaxObject
1267 };
1268 var callbackFolderRename = {
1269         success : function(o) {SUGAR.hideMessageBox();SUGAR.email2.folders.rebuildFolders();},
1270         failure : AjaxObject.handleFailure,
1271         timeout : AjaxObject.timeout,
1272         scope   : AjaxObject
1273 };
1274 var callbackFolderDelete = {
1275         success : function(o) {
1276                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1277                 if (ret.status) {
1278                     if (ret.folder_id) {
1279                         var node = SUGAR.email2.folders.getNodeFromId(ret.folder_id);
1280                         if(node)
1281                                 SUGAR.email2.tree.removeNode(node, true);
1282                     } else if (ret.ieId && ret.mbox) {
1283                         var node = SUGAR.email2.folders.getNodeFromIeIdAndMailbox(ret.ieId, ret.mbox);
1284                         if(node)
1285                                 SUGAR.email2.tree.removeNode(node, true);
1286                     }
1287                         SUGAR.hideMessageBox();
1288                         //SUGAR.email2.folders.loadSettingFolder();
1289                 } else {
1290                         SUGAR.hideMessageBox();
1291                         SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorMessage, 'alert');
1292                 } // else
1293         },
1294         failure : AjaxObject.handleFailure,
1295         timeout : AjaxObject.timeout,
1296         scope   : AjaxObject
1297 };
1298 var callbackFolderSave = {
1299         success : function(o) {
1300                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1301
1302                 switch(ret.action) {
1303                         case 'newFolderSave':
1304                                 SUGAR.email2.folders.rebuildFolders();
1305                         break;
1306                 }
1307         },
1308         failure : AjaxObject.handleFailure,
1309         timeout : AjaxObject.timeout,
1310         scope   : AjaxObject
1311 };
1312 var callbackFolderSubscriptions = {
1313         success : AjaxObject.updateFolderSubscriptions,
1314         failure : AjaxObject.handleFailure,
1315         timeout : AjaxObject.timeout,
1316         scope   : AjaxObject
1317 };
1318 var callbackFolderUpdate = {
1319         success : AjaxObject.updateFrameFolder,
1320         failure : AjaxObject.handleFailure,
1321         timeout : AjaxObject.timeout,
1322         scope   : AjaxObject
1323 };
1324 var callbackFolders = {
1325         success : AjaxObject.folders.rebuildFolders,
1326         //success : void(true),
1327         failure : AjaxObject.handleFailure,
1328         timeout : AjaxObject.timeout,
1329         scope   : AjaxObject
1330 };
1331 var callbackFullSync = {
1332         success : AjaxObject.fullSyncCleanup,
1333         failure : AjaxObject.handleFailure,
1334         timeout : 9999999999999,
1335         scope   : AjaxObject
1336 };
1337 var callbackGeneric = {
1338         success : function() {
1339                 SUGAR.hideMessageBox();
1340         },
1341         failure : AjaxObject.handleFailure,
1342         timeout : AjaxObject.timeout,
1343         scope   : AjaxObject
1344 };
1345 var callbackIeAccountRetrieve = {
1346         success : function(o) {
1347                 // return JSON encoding
1348                 SUGAR.hideMessageBox();
1349                 SUGAR.email2.accounts.fillIeAccount(o.responseText);
1350                 SUGAR.email2.accounts.showEditInboundAccountDialogue(false);
1351         },
1352         failure : AjaxObject.handleFailure,
1353         timeout : AjaxObject.timeout,
1354         scope   : AjaxObject
1355 };
1356 var callbackImportOneEmail = {
1357         success :  AjaxObject.detailView.showImportForm,
1358         failure : AjaxObject.handleFailure,
1359         timeout : AjaxObject.timeout,
1360         scope   : AjaxObject
1361 };
1362 var callbackRelateEmail = {
1363     success : AjaxObject.detailView.showRelateForm,
1364     failure : AjaxObject.handleFailure,
1365     timeout : AjaxObject.timeout,
1366     scope   : AjaxObject
1367 }
1368 var callbackEmailDetailView = {
1369     success : AjaxObject.detailView.showEmailDetailView,
1370     failure : AjaxObject.handleFailure,
1371     timeout : AjaxObject.timeout,
1372     scope   : AjaxObject
1373 }
1374 var callbackAssignmentDialog = {
1375         success :  AjaxObject.detailView.showAssignmentDialogWithData,
1376         failure : AjaxObject.handleFailure,
1377         timeout : AjaxObject.timeout,
1378         scope   : AjaxObject
1379 };
1380 var callbackAssignmentAction = {
1381         success :  function(o) {
1382                 SE.listView.refreshGrid();
1383                 SUGAR.hideMessageBox();
1384                 if(o.responseText != '') {
1385                SUGAR.showMessageBox('Assignment action result', o.responseText, 'alert');
1386             } // if
1387         } ,
1388         failure : AjaxObject.handleFailure,
1389         timeout : AjaxObject.timeout,
1390         scope   : AjaxObject
1391 };
1392 var callbackMoveEmails = {
1393         success :  function(o) {
1394             SE.listView.refreshGrid();
1395                 SUGAR.hideMessageBox();
1396                 if(o.responseText != '') {
1397                SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, o.responseText, 'alert');
1398             } // if
1399         } ,
1400         failure : AjaxObject.handleFailure,
1401         timeout : AjaxObject.timeout,
1402         scope   : AjaxObject
1403 };
1404 var callbackLoadAttachments = {
1405         success : AjaxObject.loadAttachments,
1406         failure : AjaxObject.handleFailure,
1407         timeout : AjaxObject.timeout,
1408         scope   : AjaxObject
1409 };
1410 var callbackLoadRules = {
1411         success : AjaxObject.rules.loadRulesForSettings,
1412         failure : AjaxObject.handleFailure,
1413         timeout : AjaxObject.timeout,
1414         scope   : AjaxObject
1415 };
1416 var callbackLoadSignature = {
1417         success : AjaxObject.loadSignature,
1418         failure : AjaxObject.handleFailure,
1419         timeout : AjaxObject.timeout,
1420         scope   : AjaxObject
1421 };
1422 var callbackDeleteSignature = {
1423         success : AjaxObject.handleDeleteSignature,
1424         failure : AjaxObject.handleFailure,
1425         timeout : AjaxObject.timeout,
1426         scope   : AjaxObject
1427 };
1428 /*var callbackMoveEmails = {
1429     success : function(o) { SUGAR.email2.listView.moveEmailsCleanup(o) },
1430     failure : AjaxObject.handleFailure,
1431     timeout : AjaxObject.timeout,
1432     scope   : AjaxObject
1433 }*/
1434 var callbackOutboundSave = {
1435         success : AjaxObject.accounts.saveOutboundCleanup,
1436         failure : AjaxObject.handleFailure,
1437         timeout : AjaxObject.timeout,
1438         scope   : AjaxObject
1439 };
1440 var callbackDefaultOutboundSave = {
1441         success : AjaxObject.accounts.saveDefaultOutboundCleanup,
1442         failure : AjaxObject.handleFailure,
1443         timeout : AjaxObject.timeout,
1444         scope   : AjaxObject
1445 };
1446 var callbackQuickCreate = {
1447         success : AjaxObject.detailView.showQuickCreateForm,
1448         failure : AjaxObject.handleFailure,
1449         timeout : AjaxObject.timeout,
1450         scope   : AjaxObject
1451 };
1452 var callbackQuickCreateSave = {
1453         success : AjaxObject.detailView.saveQuickCreateForm,
1454         failure : AjaxObject.handleFailure,
1455         timeout : AjaxObject.timeout,
1456         scope   : AjaxObject
1457 };
1458 var callbackQuickCreateSaveAndAddToAddressBook = {
1459         success : AjaxObject.detailView.saveQuickCreateFormAndAddToAddressBook,
1460         failure : AjaxObject.handleFailure,
1461         timeout : AjaxObject.timeout,
1462         scope   : AjaxObject
1463 };
1464 var callbackQuickCreateSaveAndReply = {
1465     success : AjaxObject.detailView.saveQuickCreateFormAndReply,
1466     failure : AjaxObject.handleFailure,
1467     timeout : AjaxObject.timeout,
1468     scope   : AjaxObject
1469 }
1470 var callbackQuickCreateSaveAndReplyCase = {
1471     success : AjaxObject.detailView.saveQuickCreateFormAndReplyCase,
1472     failure : AjaxObject.handleFailure,
1473     timeout : AjaxObject.timeout,
1474     scope   : AjaxObject
1475 }
1476 var callbackRebuildShowAccountList = {
1477         success : AjaxObject.rebuildShowFolders,
1478         failure : AjaxObject.handleFailure,
1479         timeout : AjaxObject.timeout,
1480         scope   : AjaxObject
1481 };
1482
1483 var callbackRefreshSugarFolders = {
1484         success : function(o) {
1485                 var t = YAHOO.lang.JSON.parse(o.responseText);
1486                 SUGAR.email2.folders.setSugarFoldersEnd(t);
1487         },
1488         failure : AjaxObject.handleFailure,
1489         timeout : AjaxObject.timeout,
1490         scope   : AjaxObject
1491 };
1492 var callbackReplyForward = {
1493         success : AjaxObject.handleReplyForward,
1494         finish : function(a, retryCount,isReOrFwDraft) {
1495                 if (typeof(retryCount) == 'undefined') {
1496                         retryCount = 0;
1497                 } else {
1498                         retryCount++;
1499                 }
1500                 if (typeof(isReOrFwDraft) == 'undefined') {
1501                         isReOrFwDraft = 0;
1502                 }
1503                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
1504                 var t = tinyMCE.getInstanceById('htmleditor' + idx);
1505         try {
1506                         var html = t.getContent();
1507
1508             html = "&nbsp;";
1509             //add hr tag if this is not a reply draft or forward draft
1510             if(!isReOrFwDraft){
1511                 html += "<div><hr></div>";
1512             }
1513             html +=  a.description;
1514
1515                         t.setContent(html);//
1516
1517             if (a.type != 'draft') {
1518                 // Next step, attach signature
1519                 SUGAR.email2.composeLayout.resizeEditorSetSignature(idx,true);
1520             }
1521
1522                 } catch(e) {
1523                         if (retryCount < 5) {
1524                                 setTimeout("callbackReplyForward.finish(globalA, " + retryCount + ");", 500);
1525                                 return;
1526                         }
1527                 }
1528                 var tabArray = SUGAR.email2.innerLayout.get("tabs");
1529                 if (tabArray != null && tabArray.length > 0) {
1530                         for (i = 0 ; i < tabArray.length ; i++) {
1531                                 var tabObject = tabArray[i];
1532                                 if (tabObject.get("id") == ("composeTab" + idx)) {
1533                                         var tabLabel = a.name;
1534                                 if (tabLabel != null && tabLabel.length > 25) {
1535                                         tabLabel = tabLabel.substring(0, 25) + "...";
1536                                 } // if
1537                                         tabObject.get("labelEl").firstChild.data = tabLabel;
1538                                         break;
1539                                 }
1540                         }
1541                 }
1542
1543                 //SUGAR.email2.innerLayout.regions.center.getPanel('composeLayout' + idx).setTitle(a.name);
1544                 if (a.parent_name != null && a.parent_name != "") {
1545                         document.getElementById('data_parent_name' + idx).value = a.parent_name;
1546                 }
1547                 if (a.parent_type != null && a.parent_type != "") {
1548                         document.getElementById('data_parent_type' + idx).value = a.parent_type;
1549                 }
1550                 if (a.parent_id != null && a.parent_id != "") {
1551                         document.getElementById('data_parent_id' + idx).value = a.parent_id;
1552                 }
1553                 if (a.fromAccounts.status) {
1554                         var addressFrom = document.getElementById('addressFrom' + idx);
1555                 SUGAR.email2.util.emptySelectOptions(addressFrom);
1556                 var fromAccountOpts = a.fromAccounts.data;
1557                 for(i=0; i<fromAccountOpts.length; i++) {
1558                       var key = fromAccountOpts[i].value;
1559                       var display = fromAccountOpts[i].text;
1560                       var opt = new Option(display, key);
1561                       if (fromAccountOpts[i].selected) {
1562                         opt.selected = true;
1563                       }
1564                       addressFrom.options.add(opt);
1565                 }
1566                 } // if
1567                 SUGAR.hideMessageBox();
1568
1569         },
1570         failure : AjaxObject.handleFailure,
1571         timeout : AjaxObject.timeout,
1572         scope   : AjaxObject,
1573         argument        : [sendType]
1574 };
1575 var callbackSendEmail = {
1576         success : AjaxObject.sendEmailCleanUp,
1577         failure : AjaxObject.handleFailure,
1578         timeout : AjaxObject.timeout,
1579         scope   : AjaxObject
1580 };
1581 var callbackSettings = {
1582         success : AjaxObject.updateUserPrefs,
1583         failure : AjaxObject.handleFailure,
1584         timeout : AjaxObject.timeout,
1585         scope   : AjaxObject
1586 };
1587 var callbackSettingsFolderRefresh = {
1588         success : AjaxObject.settingsFolderRefresh,
1589         failure : AjaxObject.handleFailure,
1590         timeout : AjaxObject.timeout,
1591         scope   : AjaxObject
1592 };
1593 var callbackLoadSettingFolder = {
1594         success : function(o) {
1595                 AjaxObject.settingsFolderRefresh(o);
1596                 SUGAR.email2.accounts.rebuildFolderList(); // refresh frameFolder
1597         },
1598         failure : AjaxObject.handleFailure,
1599         timeout : AjaxObject.timeout,
1600         scope   : AjaxObject
1601
1602 };
1603 var callbackUploadAttachment = {
1604         success : AjaxObject.uploadAttachmentSuccessful,
1605         upload  : AjaxObject.uploadAttachmentSuccessful,
1606         failure : AjaxObject.handleFailure,
1607         timeout : AjaxObject.timeout,
1608         scope   : AjaxObject
1609 };
1610 var callbackUserPrefs = {
1611         success : function(o) {
1612                 SUGAR.email2.userPrefs = YAHOO.lang.JSON.parse(o.responseText);
1613         },
1614         failure : AjaxObject.handleFailure,
1615         timeout : AjaxObject.timeout,
1616         scope   : AjaxObject
1617 };
1618
1619 var callbackContextmenus = {
1620         markUnread : {
1621                 success : AjaxObject.markEmailCleanup,
1622                 failure : AjaxObject.handleFailure,
1623                 timeout : AjaxObject.timeout,
1624                 scope   : AjaxObject
1625         }
1626 };
1627
1628 var callbackCheckEmail2 = {
1629         success : function(o) {
1630         var ret = YAHOO.lang.JSON.parse(o.responseText);
1631                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_CHECKING_NEW, ret.text);
1632
1633
1634         },
1635         failure : AjaxObject.handleFailure,
1636         timeout : AjaxObject.timeout,
1637         scope   : AjaxObject
1638 }