diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2015-08-28 13:58:57 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2015-11-27 15:50:56 +0100 |
commit | 148083f26a51110860f58b1610ae032f74e6465c (patch) | |
tree | 8229e019fdfde1382e8a7379db7c1218250c4432 /install/ui/src/freeipa/rpc.js | |
parent | 7978c214731edfa4e05d64ffd2079d327e7b34d4 (diff) | |
download | freeipa-148083f26a51110860f58b1610ae032f74e6465c.tar.gz freeipa-148083f26a51110860f58b1610ae032f74e6465c.tar.xz freeipa-148083f26a51110860f58b1610ae032f74e6465c.zip |
webui: add Deferred/Promise API to rpc.command
so that commands could be easily chained
prerequisite for: https://fedorahosted.org/freeipa/ticket/4286
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
Diffstat (limited to 'install/ui/src/freeipa/rpc.js')
-rw-r--r-- | install/ui/src/freeipa/rpc.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/install/ui/src/freeipa/rpc.js b/install/ui/src/freeipa/rpc.js index 784f7555b..9e684a7da 100644 --- a/install/ui/src/freeipa/rpc.js +++ b/install/ui/src/freeipa/rpc.js @@ -24,13 +24,14 @@ define([ 'dojo/_base/lang', + 'dojo/Deferred', './auth', './ipa', './text', './util', 'exports' ], - function(lang, auth, IPA, text, util, rpc /*exports*/) { + function(lang, Deferred, auth, IPA, text, util, rpc /*exports*/) { /** * Call an IPA command over JSON-RPC. @@ -204,6 +205,8 @@ rpc.command = function(spec) { */ that.execute = function() { + var deferred = new Deferred(); + function dialog_open(xhr, text_status, error_thrown) { var ajax = this; @@ -320,6 +323,14 @@ rpc.command = function(spec) { //custom error handling, maintaining AJAX call's context that.on_error.call(this, xhr, text_status, error_thrown); } + + deferred.reject({ + command: that, + context: this, + xhr: xhr, + text_status: text_status, + error_thrown: error_thrown + }); } function success_handler(data, text_status, xhr) { @@ -378,6 +389,13 @@ rpc.command = function(spec) { if (that.on_success) that.on_success.call(this, data, text_status, xhr); } that.process_warnings(data.result); + deferred.resolve({ + command: that, + context: this, + data: data, + text_status: text_status, + xhr: xhr + }); } } @@ -397,6 +415,7 @@ rpc.command = function(spec) { IPA.display_activity_icon(); $.ajax(that.request); + return deferred.promise; }; /** |