From: miker Date: Thu, 15 Jul 2010 20:17:20 +0000 (+0000) Subject: complete backporting fun for conify started around 1.6.0.4 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d6764396159b3ca41a5d98f38d0faabee1df8749;p=Evergreen.git complete backporting fun for conify started around 1.6.0.4 git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_0@16944 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 5e4f49be4f..6213c8f67d 100644 --- a/Open-ILS/web/js/dojo/openils/PermaCrud.js +++ b/Open-ILS/web/js/dojo/openils/PermaCrud.js @@ -109,6 +109,9 @@ if(!dojo._hasResource["openils.PermaCrud"]) { var order_by = {}; if (opts.order_by) order_by.order_by = opts.order_by; if (opts.select) order_by.select = opts.select; + if (opts.limit) order_by.limit = opts.limit; + if (opts.offset) order_by.offset = opts.offset; + if (opts.join) order_by.join = opts.join; var method = 'open-ils.pcrud.search.' + fm_class; if(!opts.streaming) method += '.atomic'; @@ -149,12 +152,17 @@ if(!dojo._hasResource["openils.PermaCrud"]) { }, search : function ( fm_class /* Fieldmapper class hint */, search /* Fieldmapper query object */, opts /* Option hash */) { + var return_type = 'search'; if(!opts) opts = {}; var order_by = {}; if (opts.order_by) order_by.order_by = opts.order_by; if (opts.select) order_by.select = opts.select; + if (opts.limit) order_by.limit = opts.limit; + if (opts.offset) order_by.offset = opts.offset; + if (opts.join) order_by.join = opts.join; + if (opts.id_list) return_type = 'id_list'; - var method = 'open-ils.pcrud.search.' + fm_class; + var method = 'open-ils.pcrud.' + return_type + '.' + fm_class; if(!opts.streaming) method += '.atomic'; var req_hash = dojo.mixin( @@ -201,6 +209,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]; @@ -216,32 +225,40 @@ if(!dojo._hasResource["openils.PermaCrud"]) { 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); - _pcrud.disconnect(); - } else { + 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(); 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 { @@ -250,12 +267,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(); @@ -282,26 +305,40 @@ 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 = []; - delete : function ( list, opts ) { - this._CUD( 'delete', list, opts ); + for (var idx = 0; idx < id_list.length; idx++) { + obj_list.push( + this.retrieve( list[idx].classname, id_list[idx] ) + ); + } + + return obj_list; }, /* * 'delete' is a reserved keyword in JavaScript and can't be used * in browsers like IE or Chrome, so we define a safe synonym + * NOTE: delete() is now removed -- use eliminate instead + + delete : function ( list, opts ) { + return this._CUD( 'delete', list, opts ); + }, + */ eliminate: function ( list, opts ) { - this._CUD( 'delete', list, opts ); + return this._CUD( 'delete', list, opts ); }, apply : function ( list, opts ) {