teach open-ils.PermaCrud to return objects created by .create, updated by .update...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Nov 2009 20:19:29 +0000 (20:19 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Nov 2009 20:19:29 +0000 (20:19 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15028 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/PermaCrud.js

index 0d5ab77..fb07bf6 100644 (file)
@@ -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 ) {