]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/ajax.js
Release 6.2.2
[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-2011 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                                 overlay(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                                 overlay(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                 hideOverlay();
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                 hideOverlay();
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                 overlay('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);", 500);
193         },
194
195         /**
196          */
197         handleSuccess : function(o) {
198                 document.getElementById(this.target).innerHTML = o.responseText;
199                 hideOverlay();
200         },
201
202         /**
203          */
204         ieDeleteSuccess : function(o) {
205                 hideOverlay();
206                 
207                 SUGAR.email2.accounts.refreshInboundAccountTable();
208                 alert(app_strings.LBL_EMAIL_IE_DELETE_SUCCESSFUL);
209                 SUGAR.email2.accounts.rebuildFolderList();
210         },
211
212         /**
213          */
214         ieSaveSuccess : function(o) {
215                 document.getElementById('saveButton').disabled = false;
216                 var a = YAHOO.lang.JSON.parse(o.responseText);
217                 if (a) {
218                         if(a.error) {
219                                 overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_CHECK_IE_SETTINGS, 'alert');
220                                 SUGAR.email2.accounts.ieAccountError(SUGAR.email2.accounts.errorStyle);
221                         } else {
222                                 resp = YAHOO.lang.JSON.parse(o.responseText);
223                                 SUGAR.email2.accounts.refreshInboundAccountTable();
224                                 SUGAR.email2.accounts.refreshOuboundAccountTable();
225                                 SUGAR.email2.folders.startEmailCheckOneAccount(resp.id, true);
226                                 SUGAR.email2.accounts.inboundAccountEditDialog.hide();
227                         }
228                 } else {
229                      hideOverlay();
230                      overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_SAVE_ACCOUNT, 'alert');
231                 }
232
233         },
234
235         /**
236          */
237         loadAttachments : function(o) {
238                 var result = YAHOO.lang.JSON.parse(o.responseText);
239
240                 SUGAR.email2.composeLayout.loadAttachments(result);
241         },
242
243         /**
244          */
245         loadSignature : function(o) {
246                 var ret = YAHOO.lang.JSON.parse(o.responseText);
247                 SUGAR.email2.signatures[ret.id] = ret.signature_html;
248                 SUGAR.email2.composeLayout.setSignature(SUGAR.email2.signatures.targetInstance);
249         },
250
251         /**
252          * Follow up to mark email read|unread|flagged
253          */
254         markEmailCleanup : function(o) {
255                 var ret = YAHOO.lang.JSON.parse(o.responseText);
256                 if (!ret['status']) {
257                 hideOverlay();
258                         overlay(app_strings.LBL_EMAIL_ERROR_DESC, ret['message'], 'alert');
259                 } else {
260                         SUGAR.email2.contextMenus.markEmailCleanup();
261                 } // else
262         },
263
264         /**
265          */
266         rebuildShowFolders : function(o) {
267                 var t = YAHOO.lang.JSON.parse(o.responseText);
268                 var show = document.getElementById('ieAccountListShow');
269
270                 SUGAR.email2.util.emptySelectOptions(show);
271
272                 for(i=0; i<t.length; i++) { // iterate through assoc array
273                         var opt = new Option(t[i].text, t[i].value, t[i].selected);
274                         opt.selected = t[i].selected;
275                         show.options.add(opt);
276                 }
277
278                 SUGAR.email2.accounts.renderTree();
279         },
280         /**
281          */
282         saveListViewSortOrderPart2 : function() {
283                 // create the JSON string the func expects
284                 focusFolderPath = '[ "Home", "' + ieName + '"';
285
286                 var f = new String(focusFolder);
287                 var fEx = f.split('.');
288
289                 for(i=0; i<fEx.length; i++) {
290                         focusFolderPath += ', "' + fEx[i] +'"'
291                 }
292
293                 focusFolderPath += ']';
294
295                 YAHOO.namespace('frameFolders').selectednode = SUGAR.email2.folders.getNodeFromMboxPath(focusFolderPath);
296                 SUGAR.email2.listView.populateListFrame(YAHOO.namespace('frameFolders').selectednode, ieId, 'true');
297         },
298
299         /**
300          *
301          */
302         sendEmailCleanUp : function(o) {
303         var ret;
304                 hideOverlay();
305
306         try {
307             ret = YAHOO.lang.JSON.parse(o.responseText);
308             SUGAR.email2.composeLayout.forceCloseCompose(ret.composeLayoutId);
309             //SUGAR.email2.addressBook.showContactMatches(ret.possibleMatches);
310         } catch(err) {
311             if (o.responseText) {
312                         overlay(mod_strings.LBL_SEND_EMAIL_FAIL_TITLE, o.responseText, 'alert');
313                     }
314             // Else we have an error here.
315         }
316         
317                 if (typeof(SE.grid) != 'undefined')
318                         SE.listView.refreshGrid();
319                 //Disabled while address book is disabled
320
321                 //If this call back was initiated by quick compose from a Detail View page, refresh the
322                 //history subpanel.  If it was initiated by quickcreate from shortcut bar, then
323                 //close the shortcut bar menu
324                 if ( (typeof(action_sugar_grp1) != 'undefined')) {
325                         if(action_sugar_grp1 == 'DetailView') {
326                                 showSubPanel('history',null,true);
327                         } else if(action_sugar_grp1 == 'quickcreate') {
328                                 closeEmailOverlay();
329                         }
330                 }
331
332         },
333
334         ieSendSuccess : function(o) {
335                 hideOverlay();
336                 overlay(app_strings.LBL_EMAIL_TEST_OUTBOUND_SETTINGS_SENT, app_strings.LBL_EMAIL_TEST_NOTIFICATION_SENT, 'plain');
337         },
338
339         /**
340          */
341         settingsFolderRefresh : function(o) {
342                 //SUGAR.email2.accounts.rebuildFolderList(); // refresh frameFolder
343                 var ret = YAHOO.lang.JSON.parse(o.responseText);
344                 var user = document.getElementById('userFolders');
345
346                 SUGAR.email2.util.emptySelectOptions(user);
347
348                 for(i=0; i<ret.userFolders.length; i++) {
349                         var display = ret.userFolders[i].name;
350                         var value = ret.userFolders[i].id;
351                         var selected = (ret.userFolders[i].selected != "") ? true : false;
352                         var opt = new Option(display, value, selected);
353                         opt.selected = selected;
354                         user.options.add(opt);
355                 }
356         },
357
358         /**
359          */
360         startRequest : function(callback, args, forceAbort) {
361                 if(this.currentRequestObject != null) {
362                         if(this.forceAbort == true) {
363                                 YAHOO.util.Connect.abort(this.currentRequestObject, null, false);
364                         }
365                 }
366                 this.currentRequestObject = YAHOO.util.Connect.asyncRequest('POST', "./index.php", callback, args);
367                 this._reset();
368         },
369
370         requestInProgress : function() {
371                 return (YAHOO.util.Connect.isCallInProgress(this.currentRequestObject));
372         },
373
374         /**
375          */
376         updateFolderSubscriptions : function() {
377                 SUGAR.email2.folders.lazyLoadSettings(); // refresh view in Settings overlay
378                 SUGAR.email2.folders.setSugarFolders(1000);// refresh view in TreeView
379                 hideOverlay();
380         },
381
382         /**
383          */
384         updateFrameFolder : function() {
385                 SUGAR.email2.folders.checkEmailAccounts();
386         },
387
388         /**
389          */
390         updateUserPrefs : function(o) {
391                 SUGAR.email2.userPrefs = YAHOO.lang.JSON.parse(o.responseText);
392                 SUGAR.email2.folders.startCheckTimer(); // starts the auto-check interval
393         },
394
395         /**
396          */
397         uploadAttachmentSuccessful : function(o) {
398                 // clear out field
399                 document.getElementById('email_attachment').value = '';
400                 
401                 var ret = YAHOO.lang.JSON.parse(o.responseText);
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                     overlay(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                     hideOverlay();
492                     }
493                     else
494                     {
495                              hideOverlay();
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                    hideOverlay();
517                    overlay(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                        hideOverlay();
552                overlay(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                    hideOverlay();
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         hideOverlay();
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                 overlay(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("quickCreate", {
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].id;
731                   var instId = ret.module + count;
732                   SED.quickCreateEmailsToAdd = ret.emailAddress;
733                   SED.quickCreateEmailCallback = function(instId, tableId) {
734                           var eaw = SUGAR.EmailAddressWidget.instances[instId];
735                           if (typeof(eaw) == "undefined")
736                                   window.setTimeout("SUGAR.email2.detailView.quickCreateEmailCallback('"
737                                                 + instId + "','" + tableId + "');", 100);
738                           eaw.prefillEmailAddresses(tableId, SUGAR.email2.detailView.quickCreateEmailsToAdd);
739                   }
740                   window.setTimeout("SUGAR.email2.detailView.quickCreateEmailCallback('"
741                                         + instId + "','" + tableId + "');", 100);
742                 }
743         },
744
745         saveQuickCreateForm : function(o) {
746             hideOverlay();
747                 SUGAR.email2.detailView.quickCreateDialog.hide();
748                 validate['EditView'] = [ ];
749         },
750
751         saveQuickCreateFormAndReply : function(o) {
752             hideOverlay();
753             var ret = YAHOO.lang.JSON.parse(o.responseText);
754         SUGAR.email2.detailView.quickCreateDialog.hide();
755         var qcd = SUGAR.email2.detailView.quickCreateDialog;
756         var type = (qcd.qcmodule == 'Cases') ? 'replyCase' : 'reply';
757         if (ret) {
758             var emailID = ret.id;
759             SUGAR.email2.composeLayout.c0_replyForwardEmail(null, ret.id, 'sugar::Emails', type);
760         } else {
761             SUGAR.email2.composeLayout.c0_replyForwardEmail(qcd.ieId, qcd.uid, qcd.mbox, type);
762         }
763         //Cean the validate cache to prevent errors on the next call
764         validate['EditView'] = [ ];
765     },
766
767         saveQuickCreateFormAndAddToAddressBook : function(o) {
768            hideOverlay();
769                 SUGAR.email2.detailView.quickCreateDialog.hide();
770                 SUGAR.email2.complexLayout.findPanel('contactsTab').show();
771                 validate['EditView'] = [ ];
772         },
773
774         handleAssignmentDialogAssignAction : function() {
775
776
777             var assign_user_id = window.document.forms['Distribute'].elements['assigned_user_id'].value;
778
779             var dist = 'direct';
780             var users = false;
781             var rules = false;
782             var get = "";
783             var found_teams = false;
784             var warning_message = mod_strings.LBL_WARN_NO_USERS;
785             if(!found_teams && assign_user_id == '' )
786             {
787                 alert(warning_message);
788                 return;
789             }
790
791             var emailUids = SUGAR.email2.listView.getUidsFromSelection();
792             var uids = "";
793             for(i=0; i<emailUids.length; i++) {
794                 if(uids != '') {
795                     uids += app_strings.LBL_EMAIL_DELIMITER;
796                 }
797                 uids += emailUids[i];
798             }
799
800             var row = SUGAR.email2.grid.getSelectedRows()[0];
801             var data = SUGAR.email2.grid.getRecord(row).getData();
802             var ieid = data.ieId;
803             var mbox = data.mbox;
804             AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentAssign&uids=" + uids + "&ieId=" + ieid + "&folder=" + mbox + "&distribute_method=" + dist + "&users=" +assign_user_id + get);
805             SUGAR.email2.contextMenus.assignToDialogue.hide();
806             overlay('Assignment', app_strings.LBL_EMAIL_ONE_MOMENT);
807
808         },
809
810         handleAssignmentDialogDeleteAction : function() {
811                 // TO pass list of UIDS/emailIds
812                 var uids = SUGAR.email2.listView.getUidsFromSelection();
813                 var row = SUGAR.email2.grid.getSelections()[0];
814                 var ieid = row.data.ieId;
815             var mbox = row.data.mbox;
816         AjaxObject.startRequest(callbackAssignmentAction, urlStandard + '&emailUIAction=' + "doAssignmentDelete&uids=" + uids + "&ieId=" + ieId + "&folder=" + mbox);
817         SUGAR.email2.contextMenus.assignmentDialog.hide();
818                 overlay(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
819
820                 // AJAX Call
821
822         },
823
824         showEmailDetailView : function(o) {
825         hideOverlay();
826         var SED = SUGAR.email2.detailView;
827                 var ret = YAHOO.lang.JSON.parse(o.responseText);
828
829                 if(!SED.quickCreateDialog) {
830                         SED.quickCreateDialog = new YAHOO.widget.Dialog("emailDetailDialog", {
831                                 modal:true,
832                                 visible:true,
833                 //fixedcenter:true,
834                 constraintoviewport: true,
835                 draggable: true,
836                                 autofillheight: "body",
837                                 shadow  : true
838                         });
839                         SED.quickCreateDialog.renderEvent.subscribe(function() {
840                 var viewHeight = YAHOO.util.Dom.getViewportHeight();
841                 var contH = 0;
842                 for (var i in this.body.childNodes) {
843                         if (this.body.childNodes[i].offsetHeight)
844                                 contH += this.body.childNodes[i].offsetHeight;
845                 }
846                         this.body.style.overflow = "auto";
847                         this.body.style.width = "800px";
848                         this.body.style.height = (viewHeight - 75 > contH ? (contH + 10) : (viewHeight - 75)) + "px";
849                         this.center();
850             }, SED.quickCreateDialog);
851                 }
852                 SED.quickCreateDialog.setHeader(app_strings.LBL_EMAIL_RECORD);
853                 SED.quickCreateDialog.setBody(ret.html);
854                 SED.quickCreateDialog.render();
855         SUGAR.util.evalScript(ret.html);
856         SED.quickCreateDialog.show();
857         },
858
859         showAssignmentDialogWithData : function(o) {
860         var SEC = SUGAR.email2.contextMenus;
861                 hideOverlay();
862         var ret = YAHOO.lang.JSON.parse(o.responseText);
863         if (!SEC.assignmentDialog) {
864                 SEC.assignmentDialog = new YAHOO.widget.Dialog("assignmentDialog", {
865                         visible:false,
866                 fixedcenter:true,
867                 constraintoviewport: true,
868                         modal   : true
869                 });
870                 SEC.assignmentDialog.setBody("");
871                 SEC.assignmentDialog.setHeader(app_strings.LBL_EMAIL_ASSIGNMENT);
872                 SEC.assignmentDialog.renderEvent.subscribe(function() {
873                 var iev = YAHOO.util.Dom.get("Distribute");
874                 if (iev) {
875                         this.body.style.width = "700px";
876                 }
877             },  SEC.assignmentDialog);
878                 SEC.assignmentDialog.render();
879         }
880         SEC.assignmentDialog.setBody(ret);
881         SEC.assignmentDialog.render();
882         validate = [];
883         SEC.assignmentDialog.show();
884         SUGAR.util.evalScript(ret);
885         },
886
887         showImportForm : function(o) {
888                 var SED = SUGAR.email2.detailView;
889                 var ret = YAHOO.lang.JSON.parse(o.responseText);
890         
891         document.getElementById('quickCreateContent').innerHTML = "";
892         hideOverlay();
893         if (!ret) {
894             return false;
895         }
896
897         if(!SED.importDialog) {
898             SED.importDialog = new YAHOO.widget.Dialog("importDialog", {
899                 modal:true,
900                 visible:false,
901                 fixedcenter:true,
902                 constraintoviewport: true,
903                 buttons : [{
904                         text: app_strings.LBL_EMAIL_ARCHIVE_TO_SUGAR, isDefault: true, handler: function(){
905                                 AjaxObject.detailView.getImportAction(SED.importDialog.ret); }
906                 }]//,
907                 //scroll : true
908             });
909             SED.importDialog.setHeader(app_strings.LBL_EMAIL_IMPORT_SETTINGS);
910             SED.importDialog.setBody("");
911             SED.importDialog.hideEvent.subscribe(function(){
912                 for(var i in QSFieldsArray) {
913                         if (QSFieldsArray[i] != null && typeof(QSFieldsArray[i]) == "object") {
914                                 QSFieldsArray[i].destroy();
915                                 delete QSFieldsArray[i];
916                         }
917                         if (QSProcessedFieldsArray[i]) {
918                                 QSProcessedFieldsArray[i] = false;
919                         } // if
920                                 }
921             });
922             SED.importDialog.renderEvent.subscribe(function() {
923                 var iev = YAHOO.util.Dom.get("ImportEditView");
924                 if (iev) {
925                         //this.body.style.height = (iev.clientHeight + 10) + "px";
926                         this.body.style.width = "600px";
927                 }
928             }, SED.importDialog);
929             SED.importDialog.render();
930         } // end lazy load
931         SED.importDialog.setBody(ret.html);
932         SED.importDialog.ret = ret;
933         SUGAR.util.evalScript(ret.html);
934         SED.importDialog.render();
935         validate = [];
936         SED.importDialog.show();
937         SED.importDialog.focusFirstButton();
938     },
939     getImportAction : function(ret) {
940         if (!check_form('ImportEditView')) return false;
941         if (!SUGAR.collection.prototype.validateTemSet('ImportEditView', 'team_name')) {
942                 alert(mod_strings.LBL_EMAILS_NO_PRIMARY_TEAM_SPECIFIED);
943                 return false;
944         } // if
945                 var get = "";
946         var editView = document.getElementById('ImportEditView');
947         if (editView.assigned_user_id != null) {
948             get = get + "&user_id=" + editView.assigned_user_id.value
949             //var user_id = editView.assigned_user_id.value;
950         }
951         var parent_id = editView.parent_id.value;
952         var parent_type = editView.parent_type.value;
953         var row = SUGAR.email2.grid.getSelectedRows()[0];
954         row = SUGAR.email2.grid.getRecord(row);
955         var data = row.getData();
956         var ieId = data.ieId;
957         var mbox = data.mbox;
958         var serverDelete = editView.serverDelete.checked;
959         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
960         var uids = "";
961         for(i=0; i<emailUids.length; i++) {
962             if(uids != '') {
963                 uids += app_strings.LBL_EMAIL_DELIMITER;
964             }
965             uids += emailUids[i];
966         }
967
968         var action = 'importEmail&uid=';
969         if (ret.move) {
970             action = 'moveEmails';
971             action = action + '&sourceFolder=' + ret['srcFolder'];
972             action = action + '&sourceIeId=' + ret['srcIeId'];
973             action = action + '&destinationFolder=' + ret['dstFolder'];
974             action = action + '&destinationIeId=' + ret['dstIeId'];
975             action = action + '&emailUids=';
976         }
977         if (action.search(/importEmail/) != -1) {
978             overlay(app_strings.LBL_EMAIL_IMPORTING_EMAIL, app_strings.LBL_EMAIL_ONE_MOMENT);
979         } else {
980             overlay("Moving Email(s)", app_strings.LBL_EMAIL_ONE_MOMENT);
981         }
982
983         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=' + action + uids + "&ieId=" + ieId + "&mbox=" + mbox +
984         get + "&parent_id=" + parent_id + "&parent_type=" + parent_type + '&delete=' + serverDelete);
985         SUGAR.email2.detailView.importDialog.hide();
986         document.getElementById('importDialogContent').innerHTML = "";
987
988     },
989     showRelateForm : function(o) {
990         var SED = SUGAR.email2.detailView;
991         var ret = YAHOO.lang.JSON.parse(o.responseText);
992         document.getElementById('quickCreateContent').innerHTML = "";
993         hideOverlay();
994         if (!ret) {
995             return false;
996         }
997         dialog_loaded = true;
998
999         if(!SED.relateDialog) {
1000             SED.relateDialog = new YAHOO.widget.Dialog('relateDialog', {
1001                                 modal:true,
1002                                 visible:true,
1003                 fixedcenter:true,
1004                 width: '800px',
1005                 constraintoviewport: true,
1006                                 buttons : [{
1007                         text: app_strings.LBL_EMAIL_RELATE_TO, isDefault: true, handler: function(){
1008                                         if (!check_form('RelateEditView')) return false;
1009                                         var get = "";
1010                         var editView = document.getElementById('RelateEditView');
1011                         var parent_id = editView.parent_id.value;
1012                         var parent_type = editView.parent_type.value;
1013                         var row = SUGAR.email2.grid.getSelectedRows()[0];
1014                         row  = SUGAR.email2.grid.getRecord(row);
1015                         var ieId = row.getData().ieId;
1016                         var mbox = row.getData().mbox;
1017                         var emailUids = SUGAR.email2.listView.getUidsFromSelection();
1018                         var uids = "";
1019                         for(i=0; i<emailUids.length; i++) {
1020                             if(uids != '') {
1021                                 uids += app_strings.LBL_EMAIL_DELIMITER;
1022                             }
1023                             uids += emailUids[i];
1024                         }
1025                         overlay(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT);
1026                         AjaxObject.startRequest(callbackStatusForImport, urlStandard + '&emailUIAction=relateEmails&uid=' + uids
1027                             + "&ieId=" + ieId + "&mbox=" + mbox + "&parent_id=" + parent_id + "&parent_type=" + parent_type);
1028                         SED.relateDialog.hide();
1029                         document.getElementById('relateDialogContent').innerHTML = "";
1030                         }
1031                 }]
1032                         });
1033
1034             SED.relateDialog.hideEvent.subscribe(function(){
1035                 if (QSFieldsArray['ImportEditView_parent_name'] != null) {
1036                         QSFieldsArray['ImportEditView_parent_name'].destroy();
1037                         delete QSFieldsArray['ImportEditView_parent_name'];
1038                 } // if
1039                                 if (QSProcessedFieldsArray['ImportEditView_parent_name']) {
1040                                         QSProcessedFieldsArray['ImportEditView_parent_name'] = false;
1041                                 } // if
1042             });
1043
1044             SED.relateDialog.renderEvent.subscribe(function() {
1045                 var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
1046                 var contH = 0;
1047                 for (var i in this.body.childNodes) {
1048                         if (this.body.childNodes[i].clientHeight)
1049                                 contH += this.body.childNodes[i].clientHeight;
1050                 }
1051             }, SED.relateDialog);
1052             SED.relateDialog.setHeader(app_strings.LBL_EMAIL_RELATE_EMAIL);
1053                 } // end lazy load
1054
1055         SED.relateDialog.setBody(ret.html);
1056         SED.relateDialog.render();
1057         SUGAR.util.evalScript(ret.html);
1058         SED.relateDialog.show();
1059     }
1060 };
1061 /**
1062  * DetailView callbacks
1063  */
1064 AjaxObject.detailView.callback = {
1065         emailDetail : {
1066                 success : function(o) {
1067                         SUGAR.email2.o = o;
1068                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1069                         SUGAR.email2.detailView.consumeMetaDetail(ret);
1070                 },
1071                 argument: [targetDiv],
1072                 failure : AjaxObject.handleFailure,
1073                 timeout : 0,
1074                 scope   : AjaxObject
1075         },
1076         emailPreview : {
1077                 success : function(o) {
1078                         SUGAR.email2.o = o;
1079                         var ret = YAHOO.lang.JSON.parse(o.responseText);
1080                         SUGAR.email2.detailView.consumeMetaPreview(ret);
1081                 },
1082                 failure : AjaxObject.handleFailure,
1083                 timeout : 0,
1084                 scope   : AjaxObject
1085         },
1086         viewPrint : {
1087                 success : AjaxObject.detailView.displayPrintable,
1088                 failure : AjaxObject.handleFailure,
1089                 timeout : AjaxObject.timeout,
1090                 scope   : AjaxObject
1091         },
1092         viewRaw : {
1093                 success : AjaxObject.detailView.displayView,
1094                 failure : AjaxObject.handleFailure,
1095                 timeout : AjaxObject.timeout,
1096                 scope   : AjaxObject
1097         }
1098 };
1099
1100
1101
1102
1103
1104 AjaxObject.folders = {
1105         /**
1106          * check-mail post actions
1107          */
1108         checkMailCleanup : function(o) {
1109                 hideOverlay();
1110                 AjaxObject.folders.rebuildFolders(o); // rebuild TreeView
1111
1112                 // refresh focus ListView
1113                 SE.listView.refreshGrid();
1114                 SUGAR.email2.folders.startCheckTimer(); // resets the timer
1115         },
1116
1117         /**
1118          */
1119         rebuildFolders : function(o) {
1120                 hideOverlay();
1121
1122                 var data = YAHOO.lang.JSON.parse(o.responseText);
1123
1124                 email2treeinit(SUGAR.email2.tree, data.tree_data, 'frameFolders', data.param);
1125                 SUGAR.email2.folders.setSugarFolders();
1126         }
1127 };
1128 AjaxObject.folders.callback = {
1129         checkMail : {
1130                 success : AjaxObject.folders.checkMailCleanup,
1131                 failure : AjaxObject.handleFailure,
1132                 timeout : 600000, // 5 mins
1133                 scope   : AjaxObject
1134         }
1135 }
1136
1137 AjaxObject.rules = {
1138         loadRulesForSettings : function(o) {
1139                 document.getElementById("rulesListCell").innerHTML = o.responseText;
1140                 // assume we have the class we need
1141                 SUGAR.routing.getStrings();
1142                 SUGAR.routing.getDependentDropdowns();
1143         }
1144 };
1145 ////    END PER MODULE CALLBACK OBJECTS
1146 ///////////////////////////////////////////////////////////////////////////
1147
1148
1149 var callback = {
1150         success : AjaxObject.handleSuccess,
1151         failure : AjaxObject.handleFailure,
1152         timeout : AjaxObject.timeout,
1153         scope   : AjaxObject
1154 };
1155 var callbackAccount = {
1156         success : AjaxObject.ieSaveSuccess,
1157         failure : AjaxObject.handleFailure,
1158         timeout : AjaxObject.timeout,
1159         scope   : AjaxObject
1160 };
1161 var callbackAccountDelete = {
1162         success : AjaxObject.ieDeleteSuccess,
1163         failure : AjaxObject.handleFailure,
1164         timeout : AjaxObject.timeout,
1165         scope   : AjaxObject
1166 };
1167 var callbackOutboundTest = {
1168         success : AjaxObject.ieSendSuccess,
1169         failure : AjaxObject.handleFailure,
1170         timeout : AjaxObject.timeout,
1171         scope   : AjaxObject
1172 };
1173
1174
1175
1176 var callbackTeamInfoForSettings = {
1177 success : function (o) {
1178         var data = YAHOO.lang.JSON.parse(o.responseText);
1179         document.getElementById('EditViewGroupFolderTeamTD').innerHTML = data.defaultgroupfolder;
1180 },
1181 failure : AjaxObject.handleFailure,
1182 timeout : AjaxObject.timeout,
1183 scope   : AjaxObject
1184
1185 };
1186
1187 var callbackStatusForImport = {
1188 success : function (o) {
1189         hideOverlay();
1190         if (o.responseText != "")  {
1191                 var statusString = "";
1192                 var data = YAHOO.lang.JSON.parse(o.responseText);
1193                 for(i=0; i<data.length; i++) {
1194                         statusString = statusString + data[i] + '<br/>';
1195                 }
1196                 overlay(SUGAR.language.get('Emails','LBL_IMPORT_STATUS_TITLE'), statusString, 'alert');
1197         }
1198         SE.listView.refreshGrid();
1199
1200 },
1201 failure : AjaxObject.handleFailure,
1202 timeout : AjaxObject.timeout,
1203 scope   : AjaxObject
1204
1205 };
1206 var callbackComposeCache = {
1207         success : AjaxObject.composeCache,
1208         failure : AjaxObject.handleFailure,
1209         timeout : AjaxObject.timeout,
1210         scope   : AjaxObject
1211 };
1212 var callbackDelete = {
1213         success : AjaxObject.handleDeleteReturn,
1214         failure : AjaxObject.handleFailure,
1215         timeout : AjaxObject.timeout,
1216         scope   : AjaxObject
1217 };
1218 var callbackEmailDetailMultiple = {
1219         success : function(o) {
1220                 hideOverlay();
1221                 var retMulti = YAHOO.lang.JSON.parse(o.responseText);
1222                 var ret = new Object();
1223
1224                 for(var i=0; i<retMulti.length; i++) {
1225                         ret = retMulti[i];
1226
1227                         SUGAR.email2._setDetailCache(ret);
1228                         SUGAR.email2.detailView.populateDetailView(ret.meta.uid, ret.meta.mbox, ret.meta.ieId, true, SUGAR.email2.innerLayout);
1229                 }
1230         },
1231         failure : AjaxObject.handleFailure,
1232         timeout : 0,
1233         scope   : AjaxObject
1234 };
1235 var callbackListViewSortOrderChange = {
1236         success : AjaxObject.saveListViewSortOrderPart2,
1237         failure : AjaxObject.handleFailure,
1238         timeout : AjaxObject.timeout,
1239         scope   : AjaxObject,
1240         argument        : [ieId, ieName, focusFolder]
1241 };
1242 var callbackEmptyTrash = {
1243         success : function(o) {
1244                 hideOverlay();
1245                 AjaxObject.folderRenameCleanup;
1246         },
1247         failure : AjaxObject.handleFailure,
1248         timeout : AjaxObject.timeout,
1249         scope   : AjaxObject
1250 };
1251 var callbackClearCacheFiles = {
1252         success : function(o) {
1253                 hideOverlay();
1254         },
1255         failure : AjaxObject.handleFailure,
1256         timeout : AjaxObject.timeout,
1257         scope   : AjaxObject
1258 };
1259 var callbackFolderRename = {
1260         success : function(o) {hideOverlay();SUGAR.email2.folders.rebuildFolders();},
1261         failure : AjaxObject.handleFailure,
1262         timeout : AjaxObject.timeout,
1263         scope   : AjaxObject
1264 };
1265 var callbackFolderDelete = {
1266         success : function(o) {
1267                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1268                 if (ret.status) {
1269                     if (ret.folder_id) {
1270                         var node = SUGAR.email2.folders.getNodeFromId(ret.folder_id);
1271                         if(node)
1272                                 SUGAR.email2.tree.removeNode(node, true);
1273                     } else if (ret.ieId && ret.mbox) {
1274                         var node = SUGAR.email2.folders.getNodeFromIeIdAndMailbox(ret.ieId, ret.mbox);
1275                         if(node)
1276                                 SUGAR.email2.tree.removeNode(node, true);
1277                     }
1278                         hideOverlay();
1279                         //SUGAR.email2.folders.loadSettingFolder();
1280                 } else {
1281                         hideOverlay();
1282                         overlay(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorMessage, 'alert');
1283                 } // else
1284         },
1285         failure : AjaxObject.handleFailure,
1286         timeout : AjaxObject.timeout,
1287         scope   : AjaxObject
1288 };
1289 var callbackFolderSave = {
1290         success : function(o) {
1291                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1292
1293                 switch(ret.action) {
1294                         case 'newFolderSave':
1295                                 SUGAR.email2.folders.rebuildFolders();
1296                         break;
1297                 }
1298         },
1299         failure : AjaxObject.handleFailure,
1300         timeout : AjaxObject.timeout,
1301         scope   : AjaxObject
1302 };
1303 var callbackFolderSubscriptions = {
1304         success : AjaxObject.updateFolderSubscriptions,
1305         failure : AjaxObject.handleFailure,
1306         timeout : AjaxObject.timeout,
1307         scope   : AjaxObject
1308 };
1309 var callbackFolderUpdate = {
1310         success : AjaxObject.updateFrameFolder,
1311         failure : AjaxObject.handleFailure,
1312         timeout : AjaxObject.timeout,
1313         scope   : AjaxObject
1314 };
1315 var callbackFolders = {
1316         success : AjaxObject.folders.rebuildFolders,
1317         //success : void(true),
1318         failure : AjaxObject.handleFailure,
1319         timeout : AjaxObject.timeout,
1320         scope   : AjaxObject
1321 };
1322 var callbackFullSync = {
1323         success : AjaxObject.fullSyncCleanup,
1324         failure : AjaxObject.handleFailure,
1325         timeout : 9999999999999,
1326         scope   : AjaxObject
1327 };
1328 var callbackGeneric = {
1329         success : function() {
1330                 hideOverlay();
1331         },
1332         failure : AjaxObject.handleFailure,
1333         timeout : AjaxObject.timeout,
1334         scope   : AjaxObject
1335 };
1336 var callbackIeAccountRetrieve = {
1337         success : function(o) {
1338                 // return JSON encoding
1339                 hideOverlay();
1340                 SUGAR.email2.accounts.fillIeAccount(o.responseText);
1341                 SUGAR.email2.accounts.showEditInboundAccountDialogue(false);
1342         },
1343         failure : AjaxObject.handleFailure,
1344         timeout : AjaxObject.timeout,
1345         scope   : AjaxObject
1346 };
1347 var callbackImportOneEmail = {
1348         success :  AjaxObject.detailView.showImportForm,
1349         failure : AjaxObject.handleFailure,
1350         timeout : AjaxObject.timeout,
1351         scope   : AjaxObject
1352 };
1353 var callbackRelateEmail = {
1354     success : AjaxObject.detailView.showRelateForm,
1355     failure : AjaxObject.handleFailure,
1356     timeout : AjaxObject.timeout,
1357     scope   : AjaxObject
1358 }
1359 var callbackEmailDetailView = {
1360     success : AjaxObject.detailView.showEmailDetailView,
1361     failure : AjaxObject.handleFailure,
1362     timeout : AjaxObject.timeout,
1363     scope   : AjaxObject
1364 }
1365 var callbackAssignmentDialog = {
1366         success :  AjaxObject.detailView.showAssignmentDialogWithData,
1367         failure : AjaxObject.handleFailure,
1368         timeout : AjaxObject.timeout,
1369         scope   : AjaxObject
1370 };
1371 var callbackAssignmentAction = {
1372         success :  function(o) {
1373                 SE.listView.refreshGrid();
1374                 hideOverlay();
1375                 if(o.responseText != '') {
1376                overlay('Assignment action result', o.responseText, 'alert');
1377             } // if
1378         } ,
1379         failure : AjaxObject.handleFailure,
1380         timeout : AjaxObject.timeout,
1381         scope   : AjaxObject
1382 };
1383 var callbackMoveEmails = {
1384         success :  function(o) {
1385             SE.listView.refreshGrid();
1386                 hideOverlay();
1387                 if(o.responseText != '') {
1388                overlay(app_strings.LBL_EMAIL_ERROR_DESC, o.responseText, 'alert');
1389             } // if
1390         } ,
1391         failure : AjaxObject.handleFailure,
1392         timeout : AjaxObject.timeout,
1393         scope   : AjaxObject
1394 };
1395 var callbackLoadAttachments = {
1396         success : AjaxObject.loadAttachments,
1397         failure : AjaxObject.handleFailure,
1398         timeout : AjaxObject.timeout,
1399         scope   : AjaxObject
1400 };
1401 var callbackLoadRules = {
1402         success : AjaxObject.rules.loadRulesForSettings,
1403         failure : AjaxObject.handleFailure,
1404         timeout : AjaxObject.timeout,
1405         scope   : AjaxObject
1406 };
1407 var callbackLoadSignature = {
1408         success : AjaxObject.loadSignature,
1409         failure : AjaxObject.handleFailure,
1410         timeout : AjaxObject.timeout,
1411         scope   : AjaxObject
1412 };
1413 var callbackDeleteSignature = {
1414         success : AjaxObject.handleDeleteSignature,
1415         failure : AjaxObject.handleFailure,
1416         timeout : AjaxObject.timeout,
1417         scope   : AjaxObject
1418 };
1419 /*var callbackMoveEmails = {
1420     success : function(o) { SUGAR.email2.listView.moveEmailsCleanup(o) },
1421     failure : AjaxObject.handleFailure,
1422     timeout : AjaxObject.timeout,
1423     scope   : AjaxObject
1424 }*/
1425 var callbackOutboundSave = {
1426         success : AjaxObject.accounts.saveOutboundCleanup,
1427         failure : AjaxObject.handleFailure,
1428         timeout : AjaxObject.timeout,
1429         scope   : AjaxObject
1430 };
1431 var callbackDefaultOutboundSave = {
1432         success : AjaxObject.accounts.saveDefaultOutboundCleanup,
1433         failure : AjaxObject.handleFailure,
1434         timeout : AjaxObject.timeout,
1435         scope   : AjaxObject
1436 };
1437 var callbackQuickCreate = {
1438         success : AjaxObject.detailView.showQuickCreateForm,
1439         failure : AjaxObject.handleFailure,
1440         timeout : AjaxObject.timeout,
1441         scope   : AjaxObject
1442 };
1443 var callbackQuickCreateSave = {
1444         success : AjaxObject.detailView.saveQuickCreateForm,
1445         failure : AjaxObject.handleFailure,
1446         timeout : AjaxObject.timeout,
1447         scope   : AjaxObject
1448 };
1449 var callbackQuickCreateSaveAndAddToAddressBook = {
1450         success : AjaxObject.detailView.saveQuickCreateFormAndAddToAddressBook,
1451         failure : AjaxObject.handleFailure,
1452         timeout : AjaxObject.timeout,
1453         scope   : AjaxObject
1454 };
1455 var callbackQuickCreateSaveAndReply = {
1456     success : AjaxObject.detailView.saveQuickCreateFormAndReply,
1457     failure : AjaxObject.handleFailure,
1458     timeout : AjaxObject.timeout,
1459     scope   : AjaxObject
1460 }
1461 var callbackQuickCreateSaveAndReplyCase = {
1462     success : AjaxObject.detailView.saveQuickCreateFormAndReplyCase,
1463     failure : AjaxObject.handleFailure,
1464     timeout : AjaxObject.timeout,
1465     scope   : AjaxObject
1466 }
1467 var callbackRebuildShowAccountList = {
1468         success : AjaxObject.rebuildShowFolders,
1469         failure : AjaxObject.handleFailure,
1470         timeout : AjaxObject.timeout,
1471         scope   : AjaxObject
1472 };
1473
1474 var callbackRefreshSugarFolders = {
1475         success : function(o) {
1476                 var t = YAHOO.lang.JSON.parse(o.responseText);
1477                 SUGAR.email2.folders.setSugarFoldersEnd(t);
1478         },
1479         failure : AjaxObject.handleFailure,
1480         timeout : AjaxObject.timeout,
1481         scope   : AjaxObject
1482 };
1483 var callbackReplyForward = {
1484         success : AjaxObject.handleReplyForward,
1485         finish : function(a, retryCount) {
1486                 if (typeof(retryCount) == 'undefined') {
1487                         retryCount = 0;
1488                 } else {
1489                         retryCount++;
1490                 }
1491                 var idx = SUGAR.email2.composeLayout.currentInstanceId;
1492                 var t = tinyMCE.getInstanceById('htmleditor' + idx);
1493         try {
1494                         var html = t.getContent();
1495
1496             html = "&nbsp;<div><hr></div>" + a.description;
1497
1498                         t.setContent(html);//
1499
1500             if (a.type != 'draft') {
1501                 // Next step, attach signature
1502                 SUGAR.email2.composeLayout.resizeEditorSetSignature(idx,true);
1503             }
1504
1505                 } catch(e) {
1506                         if (retryCount < 5) {
1507                                 setTimeout("callbackReplyForward.finish(globalA, " + retryCount + ");", 500);
1508                                 return;
1509                         }
1510                 }
1511                 var tabArray = SUGAR.email2.innerLayout.get("tabs");
1512                 if (tabArray != null && tabArray.length > 0) {
1513                         for (i = 0 ; i < tabArray.length ; i++) {
1514                                 var tabObject = tabArray[i];
1515                                 if (tabObject.get("id") == ("composeTab" + idx)) {
1516                                         var tabLabel = a.name;
1517                                 if (tabLabel != null && tabLabel.length > 25) {
1518                                         tabLabel = tabLabel.substring(0, 25) + "...";
1519                                 } // if
1520                                         tabObject.get("labelEl").firstChild.data = tabLabel;
1521                                         break;
1522                                 }
1523                         }
1524                 }
1525
1526                 //SUGAR.email2.innerLayout.regions.center.getPanel('composeLayout' + idx).setTitle(a.name);
1527                 if (a.parent_name != null && a.parent_name != "") {
1528                         document.getElementById('data_parent_name' + idx).value = a.parent_name;
1529                 }
1530                 if (a.parent_type != null && a.parent_type != "") {
1531                         document.getElementById('data_parent_type' + idx).value = a.parent_type;
1532                 }
1533                 if (a.parent_id != null && a.parent_id != "") {
1534                         document.getElementById('data_parent_id' + idx).value = a.parent_id;
1535                 }
1536                 if (a.fromAccounts.status) {
1537                         var addressFrom = document.getElementById('addressFrom' + idx);
1538                 SUGAR.email2.util.emptySelectOptions(addressFrom);
1539                 var fromAccountOpts = a.fromAccounts.data;
1540                 for(i=0; i<fromAccountOpts.length; i++) {
1541                       var key = fromAccountOpts[i].value;
1542                       var display = fromAccountOpts[i].text;
1543                       var opt = new Option(display, key);
1544                       if (fromAccountOpts[i].selected) {
1545                         opt.selected = true;
1546                       }
1547                       addressFrom.options.add(opt);
1548                 }
1549                 } // if
1550                 hideOverlay();
1551
1552         },
1553         failure : AjaxObject.handleFailure,
1554         timeout : AjaxObject.timeout,
1555         scope   : AjaxObject,
1556         argument        : [sendType]
1557 };
1558 var callbackSendEmail = {
1559         success : AjaxObject.sendEmailCleanUp,
1560         failure : AjaxObject.handleFailure,
1561         timeout : AjaxObject.timeout,
1562         scope   : AjaxObject
1563 };
1564 var callbackSettings = {
1565         success : AjaxObject.updateUserPrefs,
1566         failure : AjaxObject.handleFailure,
1567         timeout : AjaxObject.timeout,
1568         scope   : AjaxObject
1569 };
1570 var callbackSettingsFolderRefresh = {
1571         success : AjaxObject.settingsFolderRefresh,
1572         failure : AjaxObject.handleFailure,
1573         timeout : AjaxObject.timeout,
1574         scope   : AjaxObject
1575 };
1576 var callbackLoadSettingFolder = {
1577         success : function(o) {
1578                 AjaxObject.settingsFolderRefresh(o);
1579                 SUGAR.email2.accounts.rebuildFolderList(); // refresh frameFolder
1580         },
1581         failure : AjaxObject.handleFailure,
1582         timeout : AjaxObject.timeout,
1583         scope   : AjaxObject
1584
1585 };
1586 var callbackUploadAttachment = {
1587         success : AjaxObject.uploadAttachmentSuccessful,
1588         upload  : AjaxObject.uploadAttachmentSuccessful,
1589         failure : AjaxObject.handleFailure,
1590         timeout : AjaxObject.timeout,
1591         scope   : AjaxObject
1592 };
1593 var callbackUserPrefs = {
1594         success : function(o) {
1595                 SUGAR.email2.userPrefs = YAHOO.lang.JSON.parse(o.responseText);
1596         },
1597         failure : AjaxObject.handleFailure,
1598         timeout : AjaxObject.timeout,
1599         scope   : AjaxObject
1600 };
1601
1602 var callbackContextmenus = {
1603         markUnread : {
1604                 success : AjaxObject.markEmailCleanup,
1605                 failure : AjaxObject.handleFailure,
1606                 timeout : AjaxObject.timeout,
1607                 scope   : AjaxObject
1608         }
1609 };
1610
1611 var callbackCheckEmail2 = {
1612         success : function(o) {
1613                 var ret = YAHOO.lang.JSON.parse(o.responseText);
1614                 overlay(app_strings.LBL_EMAIL_CHECKING_NEW, ret.text);
1615
1616
1617         },
1618         failure : AjaxObject.handleFailure,
1619         timeout : AjaxObject.timeout,
1620         scope   : AjaxObject
1621 }