[open-ils-commits] r15438 - branches/rel_1_6/Open-ILS/web/js/dojo/openils (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Feb 3 10:20:48 EST 2010


Author: miker
Date: 2010-02-03 10:20:46 -0500 (Wed, 03 Feb 2010)
New Revision: 15438

Modified:
   branches/rel_1_6/Open-ILS/web/js/dojo/openils/PermaCrud.js
Log:
backporting changes to allow C/U/D to return results to the user-supplied oncomplete handler via a second parameter

Modified: branches/rel_1_6/Open-ILS/web/js/dojo/openils/PermaCrud.js
===================================================================
--- branches/rel_1_6/Open-ILS/web/js/dojo/openils/PermaCrud.js	2010-02-02 21:56:21 UTC (rev 15437)
+++ branches/rel_1_6/Open-ILS/web/js/dojo/openils/PermaCrud.js	2010-02-03 15:20:46 UTC (rev 15438)
@@ -205,6 +205,7 @@
             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];
@@ -220,32 +221,40 @@
 
                 if (++pos == obj_list.length) {
                     req.oncomplete = function (r) {
+                        var res = r.recv();
 
-                        _pcrud.session.request({
-                            method : 'open-ils.pcrud.transaction.commit',
-                            timeout : 10,
-                            params : [ _pcrud.auth() ],
-                            onerror : function (r) {
-                                _pcrud.disconnect();
-                                throw 'Transaction commit error';
-                            },      
-                            oncomplete : function (r) {
-                                var res = r.recv();
-                                if ( res && res.content() ) {
-                                    if(req._final_complete)
-                                        req._final_complete(req);
+                        if ( res && res.content() ) {
+                            _return_list.push( res.content() );
+                            _pcrud.session.request({
+                                method : 'open-ils.pcrud.transaction.commit',
+                                timeout : 10,
+                                params : [ _pcrud.auth() ],
+                                onerror : function (r) {
                                     _pcrud.disconnect();
-                                } else {
-                                    _pcrud.disconnect();
                                     throw 'Transaction commit error';
-                                }
-                            },
-                        }).send();
+                                },      
+                                oncomplete : function (r) {
+                                    var res = r.recv();
+                                    if ( res && res.content() ) {
+                                        if(req._final_complete)
+                                            req._final_complete(req, _return_list);
+                                        _pcrud.disconnect();
+                                    } else {
+                                        _pcrud.disconnect();
+                                        throw 'Transaction commit error';
+                                    }
+                                },
+                            }).send();
+                        } 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);
                     };
 
                 } else {
@@ -254,12 +263,18 @@
                     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 +301,30 @@
                     }
                 },
             }).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 +332,7 @@
 	 * 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 ) {



More information about the open-ils-commits mailing list