[open-ils-commits] r11643 - trunk/Open-ILS/web/conify/global/actor

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Dec 21 00:26:19 EST 2008


Author: miker
Date: 2008-12-21 00:26:16 -0500 (Sun, 21 Dec 2008)
New Revision: 11643

Modified:
   trunk/Open-ILS/web/conify/global/actor/org_unit.html
   trunk/Open-ILS/web/conify/global/actor/org_unit.js
Log:
moving toward the openils.PermaCrud module

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit.html
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit.html	2008-12-21 05:25:45 UTC (rev 11642)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit.html	2008-12-21 05:26:16 UTC (rev 11643)
@@ -69,60 +69,57 @@
 			<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);
-							};
+                    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 });
 
-							dojo.addOnUnload( function (event) {
+                            ou_list_store.onSet = function (item, attr, o, n) {
+                                if (attr == 'ischanged') return;
+                                if (n == o) return;
+                                this.setValue( item, 'ischanged', 1);
+                            };
 
-								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
-								});
+                            dojo.addOnUnload( function (event) {
 
-								if (dirtyStore.length > 0) {
-									var confirmation = confirm(aou_strings.CONFIRM_EXIT_AOU);
+                                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 (confirmation) {
-										for (var i in window.dirtyStore) {
-											window.current_ou = window.dirtyStore[i];
-											save_org(true);
-										}
-									}
-								}
+                                if (window.dirtyStore.length > 0) {
+                                    var confirmation = confirm(aou_strings.CONFIRM_EXIT_AOU);
 
-							});
-						}
-					}).send();
+                                    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 = {};

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit.js
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit.js	2008-12-21 05:25:45 UTC (rev 11642)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit.js	2008-12-21 05:26:16 UTC (rev 11643)
@@ -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 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 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 () {



More information about the open-ils-commits mailing list