moving toward the openils.PermaCrud module
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 21 Dec 2008 05:26:16 +0000 (05:26 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 21 Dec 2008 05:26:16 +0000 (05:26 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11643 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/conify/global/actor/org_unit.html
Open-ILS/web/conify/global/actor/org_unit.js

index b5648ce..4924f52 100644 (file)
                        <div dojoType="dijit.layout.ContentPane" sizeShare="100">
                                <script type="dojo/method">
 <![CDATA[
-                                       var ou_list_data = { label : 'shortname', identifier : 'id' };
-                                       window.dirtyStore = [];
-               
-                                       pCRUD.request({
-                                               method : 'open-ils.pcrud.search.aou.atomic',
-                                               timeout : 15,
-                                               params : [ ses, { id : { "!=" : null } }, { order_by : { aou : 'shortname' } } ],
-                                               onerror : function (r) { throw aou_strings.ERROR_FETCHING_ORGS; },
-                                               oncomplete : function (r) {
-                                                       window._ou_list = r.recv().content();
-                                                       window._ou_data = aou.toStoreData( window._ou_list );
-                                                       window.ou_list_store = new dojo.data.ItemFileWriteStore({ data : window._ou_data });
-
-                                                       window.ou_list_store.onSet = function (item, attr, o, n) {
-                                                               if (attr == 'ischanged') return;
-                                                               if (n == o) return;
-                                                               this.setValue( item, 'ischanged', 1);
-                                                       };
-
-                                                       dojo.addOnUnload( function (event) {
-
-                                                               ou_list_store.fetch({
-                                                                       query : { ischanged : 1 },
-                                                                       queryOptions : { deep : true },
-                                                                       onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
-                                                                       scope : ou_list_store
-                                                               });
-
-                                                               if (dirtyStore.length > 0) {
-                                                                       var confirmation = confirm(aou_strings.CONFIRM_EXIT_AOU);
-
-                                                                       if (confirmation) {
-                                                                               for (var i in window.dirtyStore) {
-                                                                                       window.current_ou = window.dirtyStore[i];
-                                                                                       save_org(true);
-                                                                               }
-                                                                       }
-                                                               }
 
-                                                       });
-                                               }
-                                       }).send();
+                    pcrud.retrieveAll( 'aou', {
+                        timeout : 10, order_by : { aou : 'shortname' },
+                        onerror : function (r) { status_update(aou_strings.ERROR_FETCHING_ORGS); },
+                        oncomplete : function (r) {
+                            var _ou_list = r.recv().content();
+                            var _ou_data = aou.toStoreData( _ou_list );
+                            ou_list_store = new dojo.data.ItemFileWriteStore({ data : _ou_data });
+
+                            ou_list_store.onSet = function (item, attr, o, n) {
+                                if (attr == 'ischanged') return;
+                                if (n == o) return;
+                                this.setValue( item, 'ischanged', 1);
+                            };
+
+                            dojo.addOnUnload( function (event) {
+
+                                ou_list_store.fetch({
+                                    query : { ischanged : 1 },
+                                    queryOptions : { deep : true },
+                                    onItem : function (item, req) {
+                                        try {
+                                            if (this.isItem( item )) window.dirtyStore.push( item );
+                                        } catch (e) {}
+                                    },
+                                    scope : window.ou_list_store
+                                });
+
+                                if (window.dirtyStore.length > 0) {
+                                    var confirmation = confirm(aou_strings.CONFIRM_EXIT_AOU);
+
+                                    if (confirmation) {
+                                        for (var i in dirtyStore) {
+                                            window.current_ou = window.dirtyStore[i];
+                                            save_org(true);
+                                        }
+                                    }
+                                }
+                            });
+                        }
+                    });
 
-                    pCRUD.request({
-                        method : 'open-ils.pcrud.search.aout.atomic',
-                        timeout : 10,
-                        params : [ ses, { id : { "!=" : null } }, { order_by : { aout : 'depth' } } ],
-                        onerror : function (r) { status_update(aou_strings.ERROR_FETCHING_TYPES_AOUT) },
+                    pcrud.retrieveAll( 'aout', {
+                        timeout : 10, order_by : { aout : 'depth' },
+                        onerror : function (r) { status_update(aou_strings.ERROR_FETCHING_TYPES_AOUT); },
                         oncomplete : function (r) {
                             window._ou_type_list = r.recv().content();
                             window._ou_type_data = aout.toStoreData( window._ou_type_list );
                             window.ou_type_store = new dojo.data.ItemFileReadStore({ data : window._ou_type_data });
-                        }
-                    }).send();
+                       }
+                    });
 
                                        highlighter.ou_tree = {};
                                        highlighter.editor_pane = {};
index 0cd98ad..b139e1c 100644 (file)
@@ -17,6 +17,7 @@
 
 dojo.require('fieldmapper.dojoData');
 dojo.require('openils.widget.TranslatorPopup');
+dojo.require('openils.PermaCrud');
 dojo.require('dojo.parser');
 dojo.require('dojo.data.ItemFileWriteStore');
 dojo.require('dojo.date.stamp');
@@ -39,8 +40,10 @@ var cgi = new CGI();
 var cookieManager = new HTTP.Cookies();
 var ses = cookieManager.read('ses') || cgi.param('ses');
 var pCRUD = new OpenSRF.ClientSession('open-ils.pcrud');
+var pcrud = new openils.PermaCrud({ authtoken : ses });
 
-var current_ou, current_ou_hoo;
+var current_ou, current_ou_hoo, ou_list_store
+var dirtyStore = [];
 var virgin_ou_id = -1;
 
 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
@@ -54,91 +57,33 @@ function status_update (markup) {
 }
 
 function save_org () {
-       var modified_ou = new aou().fromStoreItem( current_ou );
-       modified_ou.ischanged( 1 );
 
        new_kid_button.disabled = false;
        save_ou_button.disabled = false;
        delete_ou_button.disabled = false;
 
-    if (!pCRUD.connect()) {
-               highlighter.editor_pane.red.play();
-               status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-        return null;
-    }
-    
-       var commit = pCRUD.request({
-               method : 'open-ils.pcrud.transaction.commit',
-               timeout : 10,
-               params : [ ses, modified_ou ],
+       var modified_ou = new aou().fromStoreItem( current_ou );
+       modified_ou.ischanged( 1 );
+
+    pcrud.apply( modified_ou, {
+        timeout : 10, // makes it synchronous
                onerror : function (r) {
                        highlighter.editor_pane.red.play();
                        status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-            pCRUD.disconnect();
-            throw 'commit error';
                },
                oncomplete : function (r) {
                        var res = r.recv();
-                       if ( res ) {
+                       if ( res && res.content() ) {
                                ou_list_store.setValue( current_ou, 'ischanged', 0 );
                                highlighter.editor_pane.green.play();
                                status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
                        } else {
                                highlighter.editor_pane.red.play();
                                status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-                throw 'commit error';
-                       }
-            pCRUD.disconnect();
-               },
-       });
-
-       var update = pCRUD.request({
-               method : 'open-ils.pcrud.update.aou',
-               timeout : 10,
-               params : [ ses, modified_ou ],
-               onerror : function (r) {
-                       highlighter.editor_pane.red.play();
-                       status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-            pCRUD.disconnect();
-            throw 'update error';
-               },
-               oncomplete : function (r) {
-                       var res = r.recv();
-                       if ( res && res.content() ) {
-                commit.send();
-                       } else {
-                               highlighter.editor_pane.red.play();
-                               status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-                pCRUD.disconnect();
-                throw 'update error';
-                       }
-               },
-       });
-
-       var begin = pCRUD.request({
-               method : 'open-ils.pcrud.transaction.begin',
-               timeout : 10,
-               params : [ ses, modified_ou ],
-               onerror : function (r) {
-                       highlighter.editor_pane.red.play();
-                       status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-            pCRUD.disconnect();
-            throw 'begin error';
-               },
-               oncomplete : function (r) {
-                       var res = r.recv();
-                       if ( res && res.content() ) {
-                update.send();
-                       } else {
-                               highlighter.editor_pane.red.play();
-                               status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
-                pCRUD.disconnect();
-                throw 'begin error';
                        }
                },
-       });
+    });
 
-    begin.send();
 }
        
 function hoo_load () {