diff options
author | hikalkan <hi_kalkan@yahoo.com> | 2014-03-05 21:00:35 +0200 |
---|---|---|
committer | hikalkan <hi_kalkan@yahoo.com> | 2014-03-05 21:00:35 +0200 |
commit | bc47eca00f84edb1294526e7b468ab1064677a42 (patch) | |
tree | 5ff7f6a230a82733d0203b3092fac15152edd7af /dev/jquery.jtable.deletion.js | |
parent | ac038f4e00ec133d2dd9898cd0a4200aa24de103 (diff) | |
download | jtable-bc47eca00f84edb1294526e7b468ab1064677a42.zip jtable-bc47eca00f84edb1294526e7b468ab1064677a42.tar.gz jtable-bc47eca00f84edb1294526e7b468ab1064677a42.tar.bz2 |
Functions as actions support
Can define functions as actions instead of URL strings.
Define a function that returns a deffered or the result.
Diffstat (limited to 'dev/jquery.jtable.deletion.js')
-rw-r--r-- | dev/jquery.jtable.deletion.js | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/dev/jquery.jtable.deletion.js b/dev/jquery.jtable.deletion.js index fdc3f10..217532c 100644 --- a/dev/jquery.jtable.deletion.js +++ b/dev/jquery.jtable.deletion.js @@ -56,7 +56,7 @@ *************************************************************************/ _createDeleteDialogDiv: function () { var self = this; - + //Check if deleteAction is supplied if (!self.options.actions.deleteAction) { return; @@ -331,11 +331,28 @@ }, /* Performs an ajax call to server to delete record - * and removesd row of record from table if ajax call success. + * and removes row of the record from table if ajax call success. *************************************************************************/ _deleteRecordFromServer: function ($row, success, error, url) { var self = this; + var completeDelete = function(data) { + if (data.Result != 'OK') { + $row.data('deleting', false); + if (error) { + error(data.Message); + } + + return; + } + + self._trigger("recordDeleted", null, { record: $row.data('record'), row: $row, serverResponse: data }); + + if (success) { + success(data); + } + }; + //Check if it is already being deleted right now if ($row.data('deleting') == true) { return; @@ -345,34 +362,45 @@ var postData = {}; postData[self._keyField] = self._getKeyValueOfRecord($row.data('record')); - - this._ajax({ - url: (url || self.options.actions.deleteAction), - data: postData, - success: function (data) { - - if (data.Result != 'OK') { + + //deleteAction may be a function, check if it is + if (!url && $.isFunction(self.options.actions.deleteAction)) { + + //Execute the function + var funcResult = self.options.actions.deleteAction(postData); + + //Check if result is a jQuery Deferred object + if (self._isDeferredObject(funcResult)) { + //Wait promise + funcResult.done(function (data) { + completeDelete(data); + }).fail(function () { $row.data('deleting', false); if (error) { - error(data.Message); + error(self.options.messages.serverCommunicationError); } + }); + } else { //assume it returned the deletion result + completeDelete(funcResult); + } - return; + } else { //Assume it's a URL string + //Make ajax call to delete the record from server + this._ajax({ + url: (url || self.options.actions.deleteAction), + data: postData, + success: function (data) { + completeDelete(data); + }, + error: function () { + $row.data('deleting', false); + if (error) { + error(self.options.messages.serverCommunicationError); + } } + }); - self._trigger("recordDeleted", null, { record: $row.data('record'), row: $row, serverResponse: data }); - - if (success) { - success(data); - } - }, - error: function () { - $row.data('deleting', false); - if (error) { - error(self.options.messages.serverCommunicationError); - } - } - }); + } }, /* Removes a row from table after a 'deleting' animation. |