[open-ils-commits] r16944 - branches/rel_1_6_0/Open-ILS/web/js/dojo/openils (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jul 15 16:17:25 EDT 2010
Author: miker
Date: 2010-07-15 16:17:20 -0400 (Thu, 15 Jul 2010)
New Revision: 16944
Modified:
branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/PermaCrud.js
Log:
complete backporting fun for conify started around 1.6.0.4
Modified: branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/PermaCrud.js
===================================================================
--- branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/PermaCrud.js 2010-07-15 20:10:10 UTC (rev 16943)
+++ branches/rel_1_6_0/Open-ILS/web/js/dojo/openils/PermaCrud.js 2010-07-15 20:17:20 UTC (rev 16944)
@@ -109,6 +109,9 @@
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 @@
},
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 (!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 (++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 {
@@ -250,12 +267,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();
@@ -282,26 +305,40 @@
}
},
}).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 ) {
More information about the open-ils-commits
mailing list