From: miker Date: Wed, 25 Nov 2009 20:19:29 +0000 (+0000) Subject: teach open-ils.PermaCrud to return objects created by .create, updated by .update... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5d4a58b440e4a1bff2b1c8d7121453e988307f14;p=evergreen%2Fpines.git teach open-ils.PermaCrud to return objects created by .create, updated by .update, and the list of ids deleted by .delete/.eliminate git-svn-id: svn://svn.open-ils.org/ILS/trunk@15028 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/PermaCrud.js b/Open-ILS/web/js/dojo/openils/PermaCrud.js index 0d5ab77b48..fb07bf6c78 100644 --- a/Open-ILS/web/js/dojo/openils/PermaCrud.js +++ b/Open-ILS/web/js/dojo/openils/PermaCrud.js @@ -205,6 +205,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) { if (!this.connected) this.connect(); var _pcrud = this; + var _return_list = []; function _CUD_recursive ( obj_list, pos, final_complete, final_error ) { var obj = obj_list[pos]; @@ -254,12 +255,18 @@ if(!dojo._hasResource["openils.PermaCrud"]) { req.oncomplete = function (r) { var res = r.recv(); if ( res && res.content() ) { + _return_list.push( res.content() ); _CUD_recursive( r._obj_list, r._pos, r._final_complete ); } else { _pcrud.disconnect(); throw '_CUD: Error creating, deleting or updating ' + js2JSON(obj); } }; + req.onerror = function (r) { + if (r._final_error) r._final_error(r); + _pcrud.disconnect(); + throw '_CUD: Error creating, deleting or updating ' + js2JSON(obj); + }; } req.send(); @@ -286,18 +293,30 @@ if(!dojo._hasResource["openils.PermaCrud"]) { } }, }).send(); + + return _return_list; + }, create : function ( list, opts ) { - this._CUD( 'create', list, opts ); + return this._CUD( 'create', list, opts ); }, update : function ( list, opts ) { - this._CUD( 'update', list, opts ); + var id_list = this._CUD( 'update', list, opts ); + var obj_list = []; + + for (var idx = 0; idx < id_list.length; idx++) { + obj_list.push( + this.retrieve( list[idx].classname, id_list[idx] ) + ); + } + + return obj_list; }, delete : function ( list, opts ) { - this._CUD( 'delete', list, opts ); + return this._CUD( 'delete', list, opts ); }, /* @@ -305,7 +324,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) { * in browsers like IE or Chrome, so we define a safe synonym */ eliminate: function ( list, opts ) { - this._CUD( 'delete', list, opts ); + return this._CUD( 'delete', list, opts ); }, apply : function ( list, opts ) {