From: Michael M Slusarz Date: Wed, 4 Nov 2009 21:39:15 +0000 (-0700) Subject: Rework DimpCore.doAction() API X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0de2667618078473188cbcc3254a33c8ac904a92;p=horde.git Rework DimpCore.doAction() API In compose screen, must do synchronous request when closing window or else javascript errors are thrown. --- diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index 1aaadf97b..c05c0086e 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -275,7 +275,7 @@ var DimpBase = { this.highlightSidebar('appportal'); this._addHistory(loc); DimpCore.setTitle(DIMP.text.portal); - DimpCore.doAction('ShowPortal', {}, null, this._portalCallback.bind(this)); + DimpCore.doAction('ShowPortal', {}, { callback: this._portalCallback.bind(this) }); break; case 'options': @@ -679,7 +679,7 @@ var DimpBase = { case 'ctx_folder_empty': tmp = baseelt.up('LI'); if (window.confirm(DIMP.text.empty_folder.replace(/%s/, tmp.readAttribute('title')))) { - DimpCore.doAction('EmptyFolder', { view: tmp.retrieve('mbox') }, null, this._emptyFolderCallback.bind(this)); + DimpCore.doAction('EmptyFolder', { view: tmp.retrieve('mbox') }, { callback: this._emptyFolderCallback.bind(this) }); } break; @@ -687,7 +687,7 @@ var DimpBase = { case 'ctx_vfolder_delete': tmp = baseelt.up('LI'); if (window.confirm(DIMP.text.delete_folder.replace(/%s/, tmp.readAttribute('title')))) { - DimpCore.doAction('DeleteFolder', { view: tmp.retrieve('mbox') }, null, this._folderCallback.bind(this)); + DimpCore.doAction('DeleteFolder', { view: tmp.retrieve('mbox') }, { callback: this._folderCallback.bind(this) }); } break; @@ -1054,7 +1054,7 @@ var DimpBase = { this.loadingImg('msg', true); - DimpCore.doAction('ShowPreview', params || {}, this.viewport.createSelection('dataob', this.pp), this._loadPreviewCallback.bind(this)); + DimpCore.doAction('ShowPreview', params || {}, { uids: this.viewport.createSelection('dataob', this.pp), callback: this._loadPreviewCallback.bind(this) }); }, _loadPreviewCallback: function(resp) @@ -1319,7 +1319,7 @@ var DimpBase = { args = this.viewport.addRequestParams({}); } $('checkmaillink').down('A').update('[' + DIMP.text.check + ']'); - DimpCore.doAction('Poll', args, null, this._pollCallback.bind(this)); + DimpCore.doAction('Poll', args, { callback: this._pollCallback.bind(this) }); }, _pollCallback: function(r) @@ -1456,7 +1456,7 @@ var DimpBase = { dropbase = (drop == $('dropbase')); if (dropbase || (ftype != 'special' && !this.isSubfolder(drag, drop))) { - DimpCore.doAction('RenameFolder', { old_name: drag.retrieve('mbox'), new_parent: dropbase ? '' : foldername, new_name: drag.retrieve('l') }, null, this._folderCallback.bind(this)); + DimpCore.doAction('RenameFolder', { old_name: drag.retrieve('mbox'), new_parent: dropbase ? '' : foldername, new_name: drag.retrieve('l') }, { callback: this._folderCallback.bind(this) }); } } else if (ftype != 'container') { sel = this.viewport.getSelected(); @@ -1471,11 +1471,11 @@ var DimpBase = { if (uids.size()) { if (e.ctrlKey) { - DimpCore.doAction('CopyMessage', this.viewport.addRequestParams({ tofld: foldername }), uids, this._pollCallback.bind(this)); + DimpCore.doAction('CopyMessage', this.viewport.addRequestParams({ tofld: foldername }), { uids: uids, callback: this._pollCallback.bind(this) }); } else if (this.folder != foldername) { // Don't allow drag/drop to the current folder. this.updateFlag(uids, '\\deleted', true); - DimpCore.doAction('MoveMessage', this.viewport.addRequestParams({ tofld: foldername }), uids, this._deleteCallback.bind(this)); + DimpCore.doAction('MoveMessage', this.viewport.addRequestParams({ tofld: foldername }), { uids: uids, callback: this._deleteCallback.bind(this) }); } } } @@ -1931,7 +1931,7 @@ var DimpBase = { } if (action) { - DimpCore.doAction(action, params, null, this._folderCallback.bind(this)); + DimpCore.doAction(action, params, { callback: this._folderCallback.bind(this) }); } } }, @@ -2317,7 +2317,7 @@ var DimpBase = { this.deleteFolderElt(elt.readAttribute('id'), true); }, this); - DimpCore.doAction('ListFolders', { unsub: Number(this.showunsub) }, null, this._folderLoadCallback.bind(this)); + DimpCore.doAction('ListFolders', { unsub: Number(this.showunsub) }, { callback: this._folderLoadCallback.bind(this) }); }, subscribeFolder: function(f, sub) @@ -2363,7 +2363,7 @@ var DimpBase = { // This needs to be synchronous Ajax if we are calling from a // popup window because Mozilla will not correctly call the // callback function if the calling window has been closed. - DimpCore.doAction(type, this.viewport.addRequestParams(args), vs, this._deleteCallback.bind(this), { asynchronous: !(opts.uid && opts.mailbox) }); + DimpCore.doAction(type, this.viewport.addRequestParams(args), { uids: vs, callback: this._deleteCallback.bind(this), ajaxopts: { asynchronous: !(opts.uid && opts.mailbox) } }); return vs; } @@ -2445,7 +2445,7 @@ var DimpBase = { this.updateFlag(vs, flag, set); if (!opts.noserver) { - DimpCore.doAction('FlagMessage', { flags: flags.toJSON(), view: this.folder }, vs); + DimpCore.doAction('FlagMessage', { flags: flags.toJSON(), view: this.folder }, { uids: vs }); } }, @@ -2453,7 +2453,7 @@ var DimpBase = { // mbox = (string) The mailbox to flag flagAll: function(type, set, mbox) { - DimpCore.doAction('FlagAll', { flags: [ type ].toJSON(), set: Number(set), view: mbox }, null, this._flagAllCallback.bind(this)); + DimpCore.doAction('FlagAll', { flags: [ type ].toJSON(), set: Number(set), view: mbox }, { callback: this._flagAllCallback.bind(this) }); }, hasFlag: function(f, r) @@ -2504,12 +2504,12 @@ var DimpBase = { /* Miscellaneous folder actions. */ purgeDeleted: function() { - DimpCore.doAction('PurgeDeleted', this.viewport.addRequestParams({}), null, this._deleteCallback.bind(this)); + DimpCore.doAction('PurgeDeleted', this.viewport.addRequestParams({}), { callback: this._deleteCallback.bind(this) }); }, modifyPoll: function(folder, add) { - DimpCore.doAction('ModifyPoll', { view: folder, add: Number(add) }, null, this._modifyPollCallback.bind(this)); + DimpCore.doAction('ModifyPoll', { view: folder, add: Number(add) }, { callback: this._modifyPollCallback.bind(this) }); }, _modifyPollCallback: function(r) @@ -2585,7 +2585,7 @@ var DimpBase = { /* Create the folder list. Any pending notifications will be caught * via the return from this call. */ - DimpCore.doAction('ListFolders', {}, null, this._folderLoadCallback.bind(this)); + DimpCore.doAction('ListFolders', {}, { callback: this._folderLoadCallback.bind(this) }); /* Init quicksearch. These needs to occur before loading the message * list since it may be disabled if we are in a search mailbox. */ diff --git a/imp/js/DimpCore.js b/imp/js/DimpCore.js index 90e87e6bf..c611f7033 100644 --- a/imp/js/DimpCore.js +++ b/imp/js/DimpCore.js @@ -108,38 +108,42 @@ var DimpCore = { }, /* 'action' -> if action begins with a '*', the exact string will be used - * instead of sending the action to the IMP handler. */ - doAction: function(action, params, uids, callback, opts) + * instead of sending the action to the IMP handler. + * 'opts' -> ajaxopts, callback, uids */ + doAction: function(action, params, opts) { - var b, tmp = {}; - - opts = Object.extend(this.doActionOpts, opts || {}); - params = $H(params); action = action.startsWith('*') ? action.substring(1) : DIMP.conf.URI_AJAX + '/' + action; + params = $H(params); + opts = opts || {}; - if (uids) { - if (uids.viewport_selection) { - b = uids.getBuffer(); + var b, + ajaxopts = Object.extend(this.doActionOpts, opts.ajaxopts || {}), + tmp = {}; + + if (opts.uids) { + if (opts.uids.viewport_selection) { + b = opts.uids.getBuffer(); if (b.getMetaData('search')) { - uids.get('dataob').each(function(r) { + opts.uids.get('dataob').each(function(r) { if (!tmp[r.view]) { tmp[r.view] = []; } tmp[r.view].push(r.imapuid); }); } else { - tmp[b.getView()] = uids.get('uid'); + tmp[b.getView()] = opts.uids.get('uid'); } - uids = tmp; + opts.uids = tmp; } - params.set('uid', this.toRangeString(uids)); + params.set('uid', this.toRangeString(opts.uids)); } - opts.parameters = this.addRequestParams(params); - opts.onComplete = function(t, o) { this.doActionComplete(t, callback); }.bind(this); - new Ajax.Request(action, opts); + ajaxopts.parameters = this.addRequestParams(params); + ajaxopts.onComplete = function(t, o) { this.doActionComplete(t, opts.callback); }.bind(this); + + new Ajax.Request(action, ajaxopts); }, // params - (Hash) @@ -435,7 +439,7 @@ var DimpCore = { break; case 'ctx_contacts_add': - this.doAction('AddContact', { name: baseelt.retrieve('personal'), email: baseelt.retrieve('email') }, null, true); + this.doAction('AddContact', { name: baseelt.retrieve('personal'), email: baseelt.retrieve('email') }, {}, true); break; } }, diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 4b7ebb01e..be704a39b 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -18,7 +18,7 @@ var DimpCompose = { confirmCancel: function() { if (window.confirm(DIMP.text_compose.cancel)) { - DimpCore.doAction(DIMP.conf_compose.auto_save_interval_val ? 'DeleteDraft' : 'CancelCompose', { imp_compose: $F('composeCache') }); + DimpCore.doAction(DIMP.conf_compose.auto_save_interval_val ? 'DeleteDraft' : 'CancelCompose', { imp_compose: $F('composeCache') }, { ajaxopts: { asynchronous: DIMP.conf_compose.qreply } }); this.updateDraftsMailbox(); return this.closeCompose(); } @@ -220,7 +220,7 @@ var DimpCompose = { // Use an AJAX submit here so that we can do javascript-y stuff // before having to close the window on success. - DimpCore.doAction('*' + DIMP.conf.URI_COMPOSE, c.serialize(true), null, this.uniqueSubmitCallback.bind(this)); + DimpCore.doAction('*' + DIMP.conf.URI_COMPOSE, c.serialize(true), { callback: this.uniqueSubmitCallback.bind(this) }); } }, @@ -345,11 +345,11 @@ var DimpCompose = { $('composeMessageParent').childElements().invoke('hide'); $('composeMessage').show().setStyle({ visibility: null }).focus(); - DimpCore.doAction('Html2Text', { text: text }, null, this.setMessageText.bind(this), { asynchronous: false }); + DimpCore.doAction('Html2Text', { text: text }, { callback: this.setMessageText.bind(this), ajaxopts: { asynchronous: false } }); } else { this.editor_on = true; if (!noupdate) { - DimpCore.doAction('Text2Html', { text: $F('composeMessage') }, null, this.setMessageText.bind(this), { asynchronous: false }); + DimpCore.doAction('Text2Html', { text: $F('composeMessage') }, { callback: this.setMessageText.bind(this), ajaxopts: { asynchronous: false } }); } // Try to reuse the old fckeditor instance. diff --git a/imp/js/fullmessage-dimp.js b/imp/js/fullmessage-dimp.js index 2299a7650..bb3d41823 100644 --- a/imp/js/fullmessage-dimp.js +++ b/imp/js/fullmessage-dimp.js @@ -31,8 +31,8 @@ var DimpFullmessage = { DimpCore.doAction(func, { imp_compose: $F('composeCache'), type: type }, - ob, - this.msgTextCallback.bind(this)); + { uids: ob, + callback: this.msgTextCallback.bind(this) }); }, msgTextCallback: function(result)