]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/ajax.js
Release 6.5.11
[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-2013 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 = 0;
730           if (SUGAR.EmailAddressWidget.count[ret.module]) {
731               count = SUGAR.EmailAddressWidget.count[ret.module] - 1;
732           }
733           var tableId = YAHOO.util.Dom.getElementsByClassName('emailaddresses', 'table', editForm)[0];
734           tableId = tableId ? tableId.id : tableId;
735                   var instId = ret.module + count;
736                   SED.quickCreateEmailsToAdd = ret.emailAddress;
737                   SED.quickCreateEmailCallback = function(instId, tableId) {
738               //try to fill up the email address if and only if emailwidget is existed in the form
739               if(tableId) {
740                   var eaw = SUGAR.EmailAddressWidget.instances[instId];
741                   if (eaw) {
742                       eaw.prefillEmailAddresses(tableId, SUGAR.email2.detailView.quickCreateEmailsToAdd);
743                   } else {
744                       window.setTimeout(function() {
745                           SUGAR.email2.detailView.quickCreateEmailCallback(instId, tableId);
746                       }, 100);
747
748                   }
749               }
750                   }
751                   window.setTimeout(function() {
752               SUGAR.email2.detailView.quickCreateEmailCallback(instId, tableId);
753             }, 100);
754                 }
755         },
756
757         saveQuickCreateForm : function(o) {
758             SUGAR.hideMessageBox();
759                 SUGAR.email2.detailView.quickCreateDialog.hide();
760                 validate['EditView'] = [ ];
761         },
762
763         saveQuickCreateFormAndReply : function(o) {
764         SUGAR.hideMessageBox();
765         var ret = YAHOO.lang.JSON.parse(o.responseText);
766         SUGAR.email2.detailView.quickCreateDialog.hide();
767         var qcd = SUGAR.email2.detailView.quickCreateDialog;
768         var type = (qcd.qcmodule == 'Cases') ? 'replyCase' : 'reply';
769         if (ret) {
770             var emailID = ret.id;
771             SUGAR.email2.composeLayout.c0_replyForwardEmail(null, ret.id, 'sugar::Emails', type);
772         } else {
773             SUGAR.email2.composeLayout.c0_replyForwardEmail(qcd.ieId, qcd.uid, qcd.mbox, type);
774         }
775         //Cean the validate cache to prevent errors on the next call
776         validate['EditView'] = [ ];
777     },
778
779         saveQuickCreateFormAndAddToAddressBook : function(o) {
780            SUGAR.hideMessageBox();
781                 SUGAR.email2.detailView.quickCreateDialog.hide();
782                 SUGAR.email2.complexLayout.findPanel('contactsTab').show();
783                 validate['EditView'] = [ ];
784         },
785
786         handleAssignmentDialogAssignAction : function() {
787
788
789             var assign_user_id = window.document.forms['Distribute'].elements['assigned_user_id'].value;
790
791             var dist = 'direct';
792             var users = false;
793             var rules = false;
794             var get = "";
795             var found_teams = false;
796             var warning_message = mod_strings.LBL_WARN_NO_USERS;
797             if(!found_teams && assign_user_id == '' )
798             {
799                 alert(warning_message);
800                 return;
801             }
802
803             var emailUids = SUGAR.email2.listView.getUidsFromSelection();
804             var uids = "";
805             for(i=0; i<emailUids.length; i++) {
806                 if(uids != '') {
807                     uids += app_strings.LBL_EMAIL_DELIMITER;
808                 }
809                 uids += emailUids[i];
810             }
811
812             var row = SUGAR.email2.grid.getSelectedRows()[0];
813             var data = SUGAR.email2.grid.getRecord(row).getData();
814             var ieid = data.ieId;
815             var mbox = data.mbox;
816             AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentAssign&uids=" + uids + "&ieId=" + ieid + "&folder=" + mbox + "&distribute_method=" + dist + "&users=" +assign_user_id + get);
817             SUGAR.email2.contextMenus.assignToDialogue.hide();
818             SUGAR.showMessageBox('Assignment', app_strings.LBL_EMAIL_ONE_MOMENT);
819
820         },
821
822         handleAssignmentDialogDeleteAction : function() {
823                 // TO pass list of UIDS/emailIds
824                 var uids = SUGAR.email2.listView.getUidsFromSelection();
825                 var row = SUGAR.email2.grid.getSelections()[0];
826                 var ieid = row.data.ieId;
827             var mbox = row.data.mbox;
828         AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentDelete&uids=" + uids + "&ieId=" + ieId + "&folder=" + mbox);
829         SUGAR.email2.contextMenus.assignmentDialog.hide();
830                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
831
832                 // AJAX Call
833
834         },
835
836         showEmailDetailView : function(o) {
837         SUGAR.hideMessageBox();
838         var SED = SUGAR.email2.detailView;
839                 var ret = YAHOO.lang.JSON.parse(o.responseText);
840
841                 if(!SED.quickCreateDialog) {
842                         SED.quickCreateDialog = new YAHOO.widget.Dialog("emailDetailDialog", {
843                                 modal:true,
844                                 visible:true,
845                 //fixedcenter:true,
846                 constraintoviewport: true,
847                 draggable: true,
848                                 autofillheight: "body",
849                                 shadow  : true
850                         });
851                         SED.quickCreateDialog.renderEvent.subscribe(function() {
852                 var viewHeight = YAHOO.util.Dom.getViewportHeight();
853                 var contH = 0;
854                 for (var i in this.body.childNodes) {
855                         if (this.body.childNodes[i].offsetHeight)
856                                 contH += this.body.childNodes[i].offsetHeight;
857                 }
858                         this.body.style.overflow = "auto";
859                         this.body.style.width = "800px";
860                         this.body.style.height = (viewHeight - 75 > contH ? (contH + 10) : (viewHeight - 75)) + "px";
861                         this.center();
862             }, SED.quickCreateDialog);
863                 }
864                 SED.quickCreateDialog.setHeader(app_strings.LBL_EMAIL_RECORD);
865                 SED.quickCreateDialog.setBody(ret.html);
866                 SED.quickCreateDialog.render();
867         SUGAR.util.evalScript(ret.html);
868         SED.quickCreateDialog.show();
869         },
870
871         showAssignmentDialogWithData : function(o) {
872         var SEC = SUGAR.email2.contextMenus;
873                 SUGAR.hideMessageBox();
874         var ret = YAHOO.lang.JSON.parse(o.responseText);
875         if (!SEC.assignmentDialog) {
876                 SEC.assignmentDialog = new YAHOO.widget.Dialog("assignmentDialog", {
877                         visible:false,
878                 fixedcenter:true,
879                 constraintoviewport: true,
880                         modal   : true
881                 });
882                 SEC.assignmentDialog.setBody("");
883                 SEC.assignmentDialog.setHeader(app_strings.LBL_EMAIL_ASSIGNMENT);
884                 SEC.assignmentDialog.renderEvent.subscribe(function() {
885                 var iev = YAHOO.util.Dom.get("Distribute");
886                 if (iev) {
887                         this.body.style.width = "700px";
888                 }
889             },  SEC.assignmentDialog);
890                 SEC.assignmentDialog.render();
891         }
892         SEC.assignmentDialog.setBody(ret);
893         SEC.assignmentDialog.render();
894         validate = [];
895         SEC.assignmentDialog.show();
896         SUGAR.util.evalScript(ret);
897         },
898
899         showImportForm : function(o) {
900                 var SED = SUGAR.email2.detailView;
901                 var ret = YAHOO.lang.JSON.parse(o.responseText);
902         
903         document.getElementById('quickCreateContent').innerHTML = "";
904         SUGAR.hideMessageBox();
905         if (!ret) {
906             return false;
907         }
908
909         if(!SED.importDialog) {
910             SED.importDialog = new YAHOO.widget.Dialog("importDialog", {
911                 modal:true,
912                 visible:false,
913                 fixedcenter:true,
914                 constraintoviewport: true,
915                 buttons : [{
916                         text: app_strings.LBL_EMAIL_ARCHIVE_TO_SUGAR, isDefault: true, handler: function(){
917                                 AjaxObject.detailView.getImportAction(SED.importDialog.ret); }
918                 }]//,
919                 //scroll : true
920             });
921             SED.importDialog.setHeader(app_strings.LBL_EMAIL_IMPORT_SETTINGS);
922             SED.importDialog.setBody("");
923             SED.importDialog.hideEvent.subscribe(function(){
924                 for(var i in QSFieldsArray) {
925                         if (QSFieldsArray[i] != null && typeof(QSFieldsArray[i]) == "object") {
926                                 QSFieldsArray[i].destroy();
927                                 delete QSFieldsArray[i];
928                         }
929                         if (QSProcessedFieldsArray[i]) {
930                                 QSProcessedFieldsArray[i] = false;
931                         } // if
932                                 }
933             });
934             SED.importDialog.renderEvent.subscribe(function() {
935                 var iev = YAHOO.util.Dom.get("ImportEditView");
936                 if (iev) {
937                         //this.body.style.height = (iev.clientHeight + 10) + "px";
938                         this.body.style.width = "600px";
939                 }
940             }, SED.importDialog);
941             SED.importDialog.render();
942         } // end lazy load
943         SED.importDialog.setBody(ret.html);
944         SED.importDialog.ret = ret;
945         SUGAR.util.evalScript(ret.html);
946         SED.importDialog.render();
947         validate = [];
948         SED.importDialog.show();
949         SED.importDialog.focusFirstButton();
950     },
951     getImportAction : function(ret) {
952         if (!check_form('ImportEditView')) return false;
953         if (!SUGAR.collection.prototype.validateTemSet('ImportEditView', 'team_name')) {
954                 alert(mod_strings.LBL_EMAILS_NO_PRIMARY_TEAM_SPECIFIED);
955                 return false;
956         } // if
957                 var get = "";
958         var editView = document.getElementById('ImportEditView');
959         if (editView.assigned_user_id != null) {
960             get = get + "&user_id=" + editView.assigned_user_id.value
961             //var user_id = editView.assigned_user_id.value;
962         }
963         var parent_id = editView.parent_id.value;
964         var parent_type = editView.parent_type.value;
965         var row = SUGAR.email2.grid.getSelectedRows()[0];
966         row = SUGAR.email2.grid.getRecord(row);
967         var data = row.getData();
968         var ieId = data.ieId;
969         var mbox = data.mbox;
970         var serverDelete = editView.serverDelete.checked;
971         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
972         var uids = "";
973         for(i=0; i<emailUids.length; i++) {
974             if(uids != '') {
975                 uids += app_strings.LBL_EMAIL_DELIMITER;
976             }
977             uids += emailUids[i];
978         }
979
980         var action = 'importEmail&uid=';
981         if (ret.move) {
982             action = 'moveEmails';
983             action = action + '&sourceFolder=' + ret['srcFolder'];
984             action = action + '&sourceIeId=' + ret['srcIeId'];
985             action = action + '&destinationFolder=' + ret['dstFolder'];
986             action = action + '&destinationIeId=' + ret['dstIeId'];
987             action = action + '&emailUids=';
988         }
989         if (action.search(/importEmail/) != -1) {
990             SUGAR.showMessageBox(app_strings.LBL_EMAIL_IMPORTING_EMAIL, app_strings.LBL_EMAIL_ONE_MOMENT);
991         } else {
992             SUGAR.showMessageBox("Moving Email(s)", app_strings.LBL_EMAIL_ONE_MOMENT);
993         }
994
995         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=' + action + uids + "&ieId=" + ieId + "&mbox=" + mbox +
996         get + "&parent_id=" + parent_id + "&parent_type=" + parent_type + '&delete=' + serverDelete);
997         SUGAR.email2.detailView.importDialog.hide();
998         document.getElementById('importDialogContent').innerHTML = "";
999
1000     },
1001     showRelateForm : function(o) {
1002         var SED = SUGAR.email2.detailView;
1003         var ret = YAHOO.lang.JSON.parse(o.responseText);
1004         document.getElementById('quickCreateContent').innerHTML = "";
1005         SUGAR.hideMessageBox();
1006         if (!ret) {
1007             return false;
1008         }
1009         dialog_loaded = true;
1010
1011         if(!SED.relateDialog) {
1012             SED.relateDialog = new YAHOO.widget.Dialog('relateDialog', {
1013                                 modal:true,
1014                                 visible:true,
1015                 fixedcenter:true,
1016                 width: '800px',
1017                 constraintoviewport: true,
1018                                 buttons : [{
1019                         text: app_strings.LBL_EMAIL_RELATE_TO, isDefault: true, handler: function(){
1020                                         if (!check_form('RelateEditView')) return false;
1021                                         var get = "";
1022                         var editView = document.getElementById('RelateEditView');
1023                         var parent_id = editView.parent_id.value;
1024                         var parent_type = editView.parent_type.value;
1025                         var row = SUGAR.email2.grid.getSelectedRows()[0];
1026                         row  = SUGAR.email2.grid.getRecord(row);
1027                         var ieId = row.getData().ieId;
1028                         var mbox = row.getData().mbox;
1029                         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
1030                         var uids = "";
1031                         for(i=0; i<emailUids.length; i++) {
1032                             if(uids != '') {
1033                                 uids += app_strings.LBL_EMAIL_DELIMITER;
1034                             }
1035                             uids += emailUids[i];
1036                         }
1037                         SUGAR.showMessageBox(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
1038                         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=relateEmails&uid=' + uids
1039                             + "&ieId=" + ieId + "&mbox=" + mbox + "&parent_id=" + parent_id + "&parent_type=" + parent_type);
1040                         SED.relateDialog.hide();
1041                         document.getElementById('relateDialogContent').innerHTML = "";
1042                         }
1043                 }]
1044                         });
1045
1046             SED.relateDialog.hideEvent.subscribe(function(){
1047                 if (QSFieldsArray['ImportEditView_parent_name'] != null) {
1048                         QSFieldsArray['ImportEditView_parent_name'].destroy();
1049                         delete QSFieldsArray['ImportEditView_parent_name'];
1050                 } // if
1051                                 if (QSProcessedFieldsArray['ImportEditView_parent_name']) {
1052                                         QSProcessedFieldsArray['ImportEditView_parent_name'] = false;
1053                                 } // if
1054             });
1055
1056             SED.relateDialog.renderEvent.subscribe(function() {
1057                 var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
1058                 var contH = 0;
1059                 for (var i in this.body.childNodes) {
1060                         if (this.body.childNodes[i].clientHeight)
1061                                 contH += this.body.childNodes[i].clientHeight;
1062                 }
1063             }, SED.relateDialog);
1064             SED.relateDialog.setHeader(app_strings.LBL_EMAIL_RELATE_EMAIL);
1065                 } // end lazy load
1066
1067         SED.relateDialog.setBody(ret.html);
1068         SED.relateDialog.render();
1069         SUGAR.util.evalScript(ret.html);
1070         SED.relateDialog.show();
1071     }
1072 };
1073 /**
1074  * DetailView callbacks
1075  */
1076 AjaxObject.detailView.callback = {
1077         emailDetail : {
1078                 success : function(o) {
1079                         SUGAR.email2.o = o;
1080                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1081                         SUGAR.email2.detailView.consumeMetaDetail(ret);
1082                 },
1083                 argument: [targetDiv],
1084                 failure : AjaxObject.handleFailure,
1085                 timeout : 0,
1086                 scope   : AjaxObject
1087         },
1088         emailPreview : {
1089                 success : function(o) {
1090                         SUGAR.email2.o = o;
1091                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1092                         SUGAR.email2.detailView.consumeMetaPreview(ret);
1093                 },
1094                 failure : AjaxObject.handleFailure,
1095                 timeout : 0,
1096                 scope   : AjaxObject
1097         },
1098         viewPrint : {
1099                 success : AjaxObject.detailView.displayPrintable,
1100                 failure : AjaxObject.handleFailure,
1101                 timeout : AjaxObject.timeout,
1102                 scope   : AjaxObject
1103         },
1104         viewRaw : {
1105                 success : AjaxObject.detailView.displayView,
1106                 failure : AjaxObject.handleFailure,
1107                 timeout : AjaxObject.timeout,
1108                 scope   : AjaxObject
1109         }
1110 };
1111
1112
1113
1114
1115
1116 AjaxObject.folders = {
1117         /**
1118          * check-mail post actions
1119          */
1120         checkMailCleanup : function(o) {
1121                 SUGAR.hideMessageBox();
1122                 AjaxObject.folders.rebuildFolders(o); // rebuild TreeView
1123
1124                 // refresh focus ListView
1125                 SE.listView.refreshGrid();
1126                 SUGAR.email2.folders.startCheckTimer(); // resets the timer
1127         },
1128
1129         /**
1130          */
1131         rebuildFolders : function(o) {
1132                 SUGAR.hideMessageBox();
1133
1134                 var data = YAHOO.lang.JSON.parse(o.responseText);
1135
1136                 email2treeinit(SUGAR.email2.tree, data.tree_data, 'frameFolders', data.param);
1137                 SUGAR.email2.folders.setSugarFolders();
1138         }
1139 };
1140 AjaxObject.folders.callback = {
1141         checkMail : {
1142                 success : AjaxObject.folders.checkMailCleanup,
1143                 failure : AjaxObject.handleFailure,
1144                 timeout : 600000, // 5 mins
1145                 scope   : AjaxObject
1146         }
1147 }
1148
1149 AjaxObject.rules = {
1150         loadRulesForSettings : function(o) {
1151                 document.getElementById("rulesListCell").innerHTML = o.responseText;
1152                 // assume we have the class we need
1153                 SUGAR.routing.getStrings();
1154                 SUGAR.routing.getDependentDropdowns();
1155         }
1156 };
1157 ////    END PER MODULE CALLBACK OBJECTS
1158 ///////////////////////////////////////////////////////////////////////////
1159
1160
1161 var callback = {
1162         success : AjaxObject.handleSuccess,
1163         failure : AjaxObject.handleFailure,
1164         timeout : AjaxObject.timeout,
1165         scope   : AjaxObject
1166 };
1167 var callbackAccount = {
1168         success : AjaxObject.ieSaveSuccess,
1169         failure : AjaxObject.handleFailure,
1170         timeout : AjaxObject.timeout,
1171         scope   : AjaxObject
1172 };
1173 var callbackAccountDelete = {
1174         success : AjaxObject.ieDeleteSuccess,
1175         failure : AjaxObject.handleFailure,
1176         timeout : AjaxObject.timeout,
1177         scope   : AjaxObject
1178 };
1179 var callbackOutboundTest = {
1180         success : AjaxObject.ieSendSuccess,
1181         failure : AjaxObject.handleFailure,
1182         timeout : AjaxObject.timeout,
1183         scope   : AjaxObject
1184 };
1185
1186
1187
1188 var callbackTeamInfoForSettings = {
1189 success : function (o) {
1190         var data = YAHOO.lang.JSON.parse(o.responseText);
1191         document.getElementById('EditViewGroupFolderTeamTD').innerHTML = data.defaultgroupfolder;
1192 },
1193 failure : AjaxObject.handleFailure,
1194 timeout : AjaxObject.timeout,
1195 scope   : AjaxObject
1196
1197 };
1198
1199 var callbackStatusForImport = {
1200 success : function (o) {
1201         SUGAR.hideMessageBox();
1202         if (o.responseText != "")  {
1203                 var statusString = "";
1204                 var data = YAHOO.lang.JSON.parse(o.responseText);
1205                 for(i=0; i<data.length; i++) {
1206                         statusString = statusString + data[i] + '<br/>';
1207                 }
1208                 SUGAR.showMessageBox(SUGAR.language.get('Emails','LBL_IMPORT_STATUS_TITLE'), statusString, 'alert');
1209         }
1210         SE.listView.refreshGrid();
1211
1212 },
1213 failure : AjaxObject.handleFailure,
1214 timeout : AjaxObject.timeout,
1215 scope   : AjaxObject
1216
1217 };
1218 var callbackComposeCache = {
1219         success : AjaxObject.composeCache,
1220         failure : AjaxObject.handleFailure,
1221         timeout : AjaxObject.timeout,
1222         scope   : AjaxObject
1223 };
1224 var callbackDelete = {
1225         success : AjaxObject.handleDeleteReturn,
1226         failure : AjaxObject.handleFailure,
1227         timeout : AjaxObject.timeout,
1228         scope   : AjaxObject
1229 };
1230 var callbackEmailDetailMultiple = {
1231         success : function(o) {
1232                 SUGAR.hideMessageBox();
1233         var retMulti = YAHOO.lang.JSON.parse(o.responseText);
1234                 var ret = new Object();
1235
1236                 for(var i=0; i<retMulti.length; i++) {
1237                         ret = retMulti[i];
1238
1239                         SUGAR.email2._setDetailCache(ret);
1240                         SUGAR.email2.detailView.populateDetailView(ret.meta.uid, ret.meta.mbox, ret.meta.ieId, true, SUGAR.email2.innerLayout);
1241                 }
1242         },
1243         failure : AjaxObject.handleFailure,
1244         timeout : 0,
1245         scope   : AjaxObject
1246 };
1247 var callbackListViewSortOrderChange = {
1248         success : AjaxObject.saveListViewSortOrderPart2,
1249         failure : AjaxObject.handleFailure,
1250         timeout : AjaxObject.timeout,
1251         scope   : AjaxObject,
1252         argument        : [ieId, ieName, focusFolder]
1253 };
1254 var callbackEmptyTrash = {
1255         success : function(o) {
1256                 SUGAR.hideMessageBox();
1257                 AjaxObject.folderRenameCleanup;
1258         },
1259         failure : AjaxObject.handleFailure,
1260         timeout : AjaxObject.timeout,
1261         scope   : AjaxObject
1262 };
1263 var callbackClearCacheFiles = {
1264         success : function(o) {
1265                 SUGAR.hideMessageBox();
1266         },
1267         failure : AjaxObject.handleFailure,
1268         timeout : AjaxObject.timeout,
1269         scope   : AjaxObject
1270 };
1271 var callbackFolderRename = {
1272         success : function(o) {SUGAR.hideMessageBox();SUGAR.email2.folders.rebuildFolders();},
1273         failure : AjaxObject.handleFailure,
1274         timeout : AjaxObject.timeout,
1275         scope   : AjaxObject
1276 };
1277 var callbackFolderDelete = {
1278         success : function(o) {
1279                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1280                 if (ret.status) {
1281                     if (ret.folder_id) {
1282                         var node = SUGAR.email2.folders.getNodeFromId(ret.folder_id);
1283                         if(node)
1284                                 SUGAR.email2.tree.removeNode(node, true);
1285                     } else if (ret.ieId && ret.mbox) {
1286                         var node = SUGAR.email2.folders.getNodeFromIeIdAndMailbox(ret.ieId, ret.mbox);
1287                         if(node)
1288                                 SUGAR.email2.tree.removeNode(node, true);
1289                     }
1290                         SUGAR.hideMessageBox();
1291                         //SUGAR.email2.folders.loadSettingFolder();
1292                 } else {
1293                         SUGAR.hideMessageBox();
1294                         SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorMessage, 'alert');
1295                 } // else
1296         },
1297         failure : AjaxObject.handleFailure,
1298         timeout : AjaxObject.timeout,
1299         scope   : AjaxObject
1300 };
1301 var callbackFolderSave = {
1302         success : function(o) {
1303                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1304
1305                 switch(ret.action) {
1306                         case 'newFolderSave':
1307                                 SUGAR.email2.folders.rebuildFolders();
1308                         break;
1309                 }
1310         },
1311         failure : AjaxObject.handleFailure,
1312         timeout : AjaxObject.timeout,
1313         scope   : AjaxObject
1314 };
1315 var callbackFolderSubscriptions = {
1316         success : AjaxObject.updateFolderSubscriptions,
1317         failure : AjaxObject.handleFailure,
1318         timeout : AjaxObject.timeout,
1319         scope   : AjaxObject
1320 };
1321 var callbackFolderUpdate = {
1322         success : AjaxObject.updateFrameFolder,
1323         failure : AjaxObject.handleFailure,
1324         timeout : AjaxObject.timeout,
1325         scope   : AjaxObject
1326 };
1327 var callbackFolders = {
1328         success : AjaxObject.folders.rebuildFolders,
1329         //success : void(true),
1330         failure : AjaxObject.handleFailure,
1331         timeout : AjaxObject.timeout,
1332         scope   : AjaxObject
1333 };
1334 var callbackFullSync = {
1335         success : AjaxObject.fullSyncCleanup,
1336         failure : AjaxObject.handleFailure,
1337         timeout : 9999999999999,
1338         scope   : AjaxObject
1339 };
1340 var callbackGeneric = {
1341         success : function() {
1342                 SUGAR.hideMessageBox();
1343         },
1344         failure : AjaxObject.handleFailure,
1345         timeout : AjaxObject.timeout,
1346         scope   : AjaxObject
1347 };
1348 var callbackIeAccountRetrieve = {
1349         success : function(o) {
1350                 // return JSON encoding
1351                 SUGAR.hideMessageBox();
1352                 SUGAR.email2.accounts.fillIeAccount(o.responseText);
1353                 SUGAR.email2.accounts.showEditInboundAccountDialogue(false);
1354         },
1355         failure : AjaxObject.handleFailure,
1356         timeout : AjaxObject.timeout,
1357         scope   : AjaxObject
1358 };
1359 var callbackImportOneEmail = {
1360         success :  AjaxObject.detailView.showImportForm,
1361         failure : AjaxObject.handleFailure,
1362         timeout : AjaxObject.timeout,
1363         scope   : AjaxObject
1364 };
1365 var callbackRelateEmail = {
1366     success : AjaxObject.detailView.showRelateForm,
1367     failure : AjaxObject.handleFailure,
1368     timeout : AjaxObject.timeout,
1369     scope   : AjaxObject
1370 }
1371 var callbackEmailDetailView = {
1372     success : AjaxObject.detailView.showEmailDetailView,
1373     failure : AjaxObject.handleFailure,
1374     timeout : AjaxObject.timeout,
1375     scope   : AjaxObject
1376 }
1377 var callbackAssignmentDialog = {
1378         success :  AjaxObject.detailView.showAssignmentDialogWithData,
1379         failure : AjaxObject.handleFailure,
1380         timeout : AjaxObject.timeout,
1381         scope   : AjaxObject
1382 };
1383 var callbackAssignmentAction = {
1384         success :  function(o) {
1385                 SE.listView.refreshGrid();
1386                 SUGAR.hideMessageBox();
1387                 if(o.responseText != '') {
1388                SUGAR.showMessageBox('Assignment action result', o.responseText, 'alert');
1389             } // if
1390         } ,
1391         failure : AjaxObject.handleFailure,
1392         timeout : AjaxObject.timeout,
1393         scope   : AjaxObject
1394 };
1395 var callbackMoveEmails = {
1396         success :  function(o) {
1397             SE.listView.refreshGrid();
1398                 SUGAR.hideMessageBox();
1399                 if(o.responseText != '') {
1400                SUGAR.showMessageBox(app_strings.LBL_EMAIL_ERROR_DESC, o.responseText, 'alert');
1401             } // if
1402         } ,
1403         failure : AjaxObject.handleFailure,
1404         timeout : AjaxObject.timeout,
1405         scope   : AjaxObject
1406 };
1407 var callbackLoadAttachments = {
1408         success : AjaxObject.loadAttachments,
1409         failure : AjaxObject.handleFailure,
1410         timeout : AjaxObject.timeout,
1411         scope   : AjaxObject
1412 };
1413 var callbackLoadRules = {
1414         success : AjaxObject.rules.loadRulesForSettings,
1415         failure : AjaxObject.handleFailure,
1416         timeout : AjaxObject.timeout,
1417         scope   : AjaxObject
1418 };
1419 var callbackLoadSignature = {
1420         success : AjaxObject.loadSignature,
1421         failure : AjaxObject.handleFailure,
1422         timeout : AjaxObject.timeout,
1423         scope   : AjaxObject
1424 };
1425 var callbackDeleteSignature = {
1426         success : AjaxObject.handleDeleteSignature,
1427         failure : AjaxObject.handleFailure,
1428         timeout : AjaxObject.timeout,
1429         scope   : AjaxObject
1430 };
1431 /*var callbackMoveEmails = {
1432     success : function(o) { SUGAR.email2.listView.moveEmailsCleanup(o) },
1433     failure : AjaxObject.handleFailure,
1434     timeout : AjaxObject.timeout,
1435     scope   : AjaxObject
1436 }*/
1437 var callbackOutboundSave = {
1438         success : AjaxObject.accounts.saveOutboundCleanup,
1439         failure : AjaxObject.handleFailure,
1440         timeout : AjaxObject.timeout,
1441         scope   : AjaxObject
1442 };
1443 var callbackDefaultOutboundSave = {
1444         success : AjaxObject.accounts.saveDefaultOutboundCleanup,
1445         failure : AjaxObject.handleFailure,
1446         timeout : AjaxObject.timeout,
1447         scope   : AjaxObject
1448 };
1449 var callbackQuickCreate = {
1450         success : AjaxObject.detailView.showQuickCreateForm,
1451         failure : AjaxObject.handleFailure,
1452         timeout : AjaxObject.timeout,
1453         scope   : AjaxObject
1454 };
1455 var callbackQuickCreateSave = {
1456         success : AjaxObject.detailView.saveQuickCreateForm,
1457         failure : AjaxObject.handleFailure,
1458         timeout : AjaxObject.timeout,
1459         scope   : AjaxObject
1460 };
1461 var callbackQuickCreateSaveAndAddToAddressBook = {
1462         success : AjaxObject.detailView.saveQuickCreateFormAndAddToAddressBook,
1463         failure : AjaxObject.handleFailure,
1464         timeout : AjaxObject.timeout,
1465         scope   : AjaxObject
1466 };
1467 var callbackQuickCreateSaveAndReply = {
1468     success : AjaxObject.detailView.saveQuickCreateFormAndReply,
1469     failure : AjaxObject.handleFailure,
1470     timeout : AjaxObject.timeout,
1471     scope   : AjaxObject
1472 }
1473 var callbackQuickCreateSaveAndReplyCase = {
1474     success : AjaxObject.detailView.saveQuickCreateFormAndReplyCase,
1475     failure : AjaxObject.handleFailure,
1476     timeout : AjaxObject.timeout,
1477     scope   : AjaxObject
1478 }
1479 var callbackRebuildShowAccountList = {
1480         success : AjaxObject.rebuildShowFolders,
1481         failure : AjaxObject.handleFailure,
1482         timeout : AjaxObject.timeout,
1483         scope   : AjaxObject
1484 };
1485
1486 var callbackRefreshSugarFolders = {
1487         success : function(o) {
1488                 var t = YAHOO.lang.JSON.parse(o.responseText);
1489                 SUGAR.email2.folders.setSugarFoldersEnd(t);
1490         },
1491         failure : AjaxObject.handleFailure,
1492         timeout : AjaxObject.timeout,
1493         scope   : AjaxObject
1494 };
1495 var callbackReplyForward = {
1496         success : AjaxObject.handleReplyForward,
1497         finish : function(a, retryCount,isReOrFwDraft) {
1498                 if (typeof(retryCount) == 'undefined') {
1499                         retryCount = 0;
1500                 } else {
1501                         retryCount++;
1502                 }
1503                 if (typeof(isReOrFwDraft) == 'undefined') {
1504                         isReOrFwDraft = 0;
1505                 }
1506                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
1507                 var t = tinyMCE.getInstanceById('htmleditor' + idx);
1508         try {
1509                         var html = t.getContent();
1510
1511             html = "&nbsp;";
1512             //add hr tag if this is not a reply draft or forward draft
1513             if(!isReOrFwDraft){
1514                 html += "<div><hr></div>";
1515             }
1516             html +=  a.description;
1517
1518                         t.setContent(html);//
1519
1520             if (a.type != 'draft') {
1521                 // Next step, attach signature
1522                 SUGAR.email2.composeLayout.resizeEditorSetSignature(idx,true);
1523             }
1524
1525                 } catch(e) {
1526                         if (retryCount < 5) {
1527                                 setTimeout("callbackReplyForward.finish(globalA, " + retryCount + ");", 500);
1528                                 return;
1529                         }
1530                 }
1531                 var tabArray = SUGAR.email2.innerLayout.get("tabs");
1532                 if (tabArray != null && tabArray.length > 0) {
1533                         for (i = 0 ; i < tabArray.length ; i++) {
1534                                 var tabObject = tabArray[i];
1535                                 if (tabObject.get("id") == ("composeTab" + idx)) {
1536                                         var tabLabel = a.name;
1537                                 if (tabLabel != null && tabLabel.length > 25) {
1538                                         tabLabel = tabLabel.substring(0, 25) + "...";
1539                                 } // if
1540                                         tabObject.get("labelEl").firstChild.data = tabLabel;
1541                                         break;
1542                                 }
1543                         }
1544                 }
1545
1546                 //SUGAR.email2.innerLayout.regions.center.getPanel('composeLayout' + idx).setTitle(a.name);
1547                 if (a.parent_name != null && a.parent_name != "") {
1548                         document.getElementById('data_parent_name' + idx).value = a.parent_name;
1549                 }
1550                 if (a.parent_type != null && a.parent_type != "") {
1551                         document.getElementById('data_parent_type' + idx).value = a.parent_type;
1552                 }
1553                 if (a.parent_id != null && a.parent_id != "") {
1554                         document.getElementById('data_parent_id' + idx).value = a.parent_id;
1555                 }
1556                 if (a.fromAccounts.status) {
1557                         var addressFrom = document.getElementById('addressFrom' + idx);
1558                 SUGAR.email2.util.emptySelectOptions(addressFrom);
1559                 var fromAccountOpts = a.fromAccounts.data;
1560                 for(i=0; i<fromAccountOpts.length; i++) {
1561                       var key = fromAccountOpts[i].value;
1562                       var display = fromAccountOpts[i].text;
1563                       var opt = new Option(display, key);
1564                       if (fromAccountOpts[i].selected) {
1565                         opt.selected = true;
1566                       }
1567                       addressFrom.options.add(opt);
1568                 }
1569                 } // if
1570                 SUGAR.hideMessageBox();
1571
1572         },
1573         failure : AjaxObject.handleFailure,
1574         timeout : AjaxObject.timeout,
1575         scope   : AjaxObject,
1576         argument        : [sendType]
1577 };
1578 var callbackSendEmail = {
1579         success : AjaxObject.sendEmailCleanUp,
1580         failure : AjaxObject.handleFailure,
1581         timeout : AjaxObject.timeout,
1582         scope   : AjaxObject
1583 };
1584 var callbackSettings = {
1585         success : AjaxObject.updateUserPrefs,
1586         failure : AjaxObject.handleFailure,
1587         timeout : AjaxObject.timeout,
1588         scope   : AjaxObject
1589 };
1590 var callbackSettingsFolderRefresh = {
1591         success : AjaxObject.settingsFolderRefresh,
1592         failure : AjaxObject.handleFailure,
1593         timeout : AjaxObject.timeout,
1594         scope   : AjaxObject
1595 };
1596 var callbackLoadSettingFolder = {
1597         success : function(o) {
1598                 AjaxObject.settingsFolderRefresh(o);
1599                 SUGAR.email2.accounts.rebuildFolderList(); // refresh frameFolder
1600         },
1601         failure : AjaxObject.handleFailure,
1602         timeout : AjaxObject.timeout,
1603         scope   : AjaxObject
1604
1605 };
1606 var callbackUploadAttachment = {
1607         success : AjaxObject.uploadAttachmentSuccessful,
1608         upload  : AjaxObject.uploadAttachmentSuccessful,
1609         failure : AjaxObject.handleFailure,
1610         timeout : AjaxObject.timeout,
1611         scope   : AjaxObject
1612 };
1613 var callbackUserPrefs = {
1614         success : function(o) {
1615                 SUGAR.email2.userPrefs = YAHOO.lang.JSON.parse(o.responseText);
1616         },
1617         failure : AjaxObject.handleFailure,
1618         timeout : AjaxObject.timeout,
1619         scope   : AjaxObject
1620 };
1621
1622 var callbackContextmenus = {
1623         markUnread : {
1624                 success : AjaxObject.markEmailCleanup,
1625                 failure : AjaxObject.handleFailure,
1626                 timeout : AjaxObject.timeout,
1627                 scope   : AjaxObject
1628         }
1629 };
1630
1631 var callbackCheckEmail2 = {
1632         success : function(o) {
1633         var ret = YAHOO.lang.JSON.parse(o.responseText);
1634                 SUGAR.showMessageBox(app_strings.LBL_EMAIL_CHECKING_NEW, ret.text);
1635
1636
1637         },
1638         failure : AjaxObject.handleFailure,
1639         timeout : AjaxObject.timeout,
1640         scope   : AjaxObject
1641 }