Re-commit miker's PermaCrud changes, just a tad more nicer ;-)
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 24 Sep 2010 00:15:31 +0000 (00:15 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 24 Sep 2010 00:15:31 +0000 (00:15 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17941 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 834c6cd..5bc6d39 100644 (file)
@@ -66,7 +66,41 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                 return false;
             }
         },
-        
+
+        _session_request : function ( args /* hash */, commitOnComplete /* set to true, else no */ ) {
+
+            var me = this;
+            var endstyle = 'rollback';
+            var aopts = dojo.mixin({}, args);
+            args = aopts;
+            if (commitOnComplete) endstyle = 'commit';
+
+            if (me.authoritative) {
+                if (!me.connected) me.connect();
+                if (args.timeout && !args.oncomplete && !args.onresponse) { // pure sync call
+                    args.oncomplete = function (r) {
+                        me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth());
+                        me.session.disconnect();
+                        me.disconnect();
+                    };
+                } else if (args.oncomplete) { // there's an oncomplete, fire that, and then end the transaction
+                    var orig_oncomplete = args.oncomplete;
+                    args.oncomplete = function (r) {
+                        var ret;
+                        try {
+                            ret = orig_oncomplete(r);
+                        } finally {
+                            me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth());
+                            me.session.disconnect();
+                            me.disconnect();
+                        }
+                        return ret;
+                    };
+                }
+                me.session.request('open-ils.pcrud.transaction.begin', me.auth());
+            }
+            return me.session.request( args );
+        },
 
         retrieve : function ( fm_class /* Fieldmapper class hint */, id /* Fieldmapper object primary key value */,  opts /* Option hash */) {
             if(!opts) opts = {};