From f5e686873bea9392c0cafa5ca7aeb7414d89dab3 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 23 Oct 2009 17:21:03 +0000 Subject: [PATCH] Patch from Warren Layton which fixes the behavior of the new Org Unit configuration interfaces. Moving from raw open-ils.pcrud service calls to the handy openils.PermaCrud dojo module. Applied with minor editorialization to remove some duplicated code. git-svn-id: svn://svn.open-ils.org/ILS/trunk@14579 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/conify/global/actor/org_unit.html | 321 +++++++++++++------------ Open-ILS/web/conify/global/actor/org_unit.js | 264 +++++++------------- 2 files changed, 247 insertions(+), 338 deletions(-) diff --git a/Open-ILS/web/conify/global/actor/org_unit.html b/Open-ILS/web/conify/global/actor/org_unit.html index 647cb89e87..b66b7d3f32 100644 --- a/Open-ILS/web/conify/global/actor/org_unit.html +++ b/Open-ILS/web/conify/global/actor/org_unit.html @@ -81,7 +81,7 @@ ou_list_store.onSet = function (item, attr, o, n) { if (attr == 'ischanged') return; - if (n == o) return; + if ((n == o) || ((o == null) && (n == ''))) return; this.setValue( item, 'ischanged', 1); }; @@ -103,7 +103,7 @@ if (confirmation) { for (var i in dirtyStore) { - window.current_ou = window.dirtyStore[i]; + current_ou = window.dirtyStore[i]; save_org(true); } } @@ -349,26 +349,39 @@ if (confirm(dojo.string.substitute(aou_strings.CONFIRM_DELETE, [current_ou.name]))) { ou_list_store.setValue( current_ou, 'isdeleted', 1 ); - + var modified_ou = new aou().fromStoreItem( current_ou ); modified_ou.isdeleted( 1 ); - - pcrud.eliminate( modified_ou, { + + var objs = []; + objs.push(modified_ou); + if (!current_billing_address.isnew()) { + current_billing_address.isdeleted( 1 ); + objs.push(current_billing_address); + } + if (!current_mailing_address.isnew()) { + current_mailing_address.isdeleted( 1 ); + objs.push(current_mailing_address); + } + if (!current_holds_address.isnew()) { + current_holds_address.isdeleted( 1 ); + objs.push(current_holds_address); + } + if (!current_ill_address.isnew()) { + current_ill_address.isdeleted( 1 ); + objs.push(current_ill_address); + } + if (!current_ou_hoo.isnew()) { + current_ou_hoo.isdeleted( 1 ); + objs.push(current_ou_hoo); + } + pcrud.apply(objs, { timeout : 10, onerror : function (r) { highlighter.editor_pane.red.play(); status_update(dojo.string.substitute(aou_strings.ERROR_DELETING, [old_name])); }, oncomplete : function (r) { - ou_list_store.fetch({ - query : { id : ou_list_store.getValue( current_ou, 'id' ) }, - queryOptions : { deep : true }, - onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } }, - scope : ou_list_store - }); - - current_ou = null; - new_kid_button.disabled = true; save_ou_button.disabled = true; delete_ou_button.disabled = true; @@ -380,6 +393,20 @@ window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value } + ou_list_store.fetch({ + query : { id : ou_list_store.getValue( current_ou, 'id' ) }, + queryOptions : { deep : true }, + onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { } }, + scope : ou_list_store + }); + + current_billing_address = null; + current_mailing_address = null; + current_holds_address = null; + current_ill_address = null; + current_ou_hoo = null; + current_ou = null; + highlighter.editor_pane.green.play(); status_update(dojo.string.substitute(aou_strings.STATUS_DELETED, [old_name])); } @@ -399,15 +426,13 @@ @@ -521,10 +536,10 @@
@@ -567,33 +582,31 @@ @@ -636,33 +649,31 @@ @@ -704,33 +715,31 @@ @@ -772,33 +781,31 @@ diff --git a/Open-ILS/web/conify/global/actor/org_unit.js b/Open-ILS/web/conify/global/actor/org_unit.js index 73c8b7fa26..7f73391a6b 100644 --- a/Open-ILS/web/conify/global/actor/org_unit.js +++ b/Open-ILS/web/conify/global/actor/org_unit.js @@ -40,10 +40,9 @@ dojo.requireLocalization("openils.conify", "conify"); 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, ou_list_store, hoo_id; +var current_ou, current_ou_hoo, ou_list_store; var dirtyStore = []; var virgin_ou_id = -1; @@ -54,208 +53,111 @@ var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify'); var highlighter = {}; function status_update (markup) { - if (parent !== window && parent.status_update) parent.status_update( markup ); + if (parent !== window && parent.status_update) parent.status_update( markup ); } function save_org () { - new_kid_button.disabled = false; - save_ou_button.disabled = false; - delete_ou_button.disabled = false; + new_kid_button.disabled = false; + save_ou_button.disabled = false; + delete_ou_button.disabled = false; - var modified_ou = new aou().fromStoreItem( current_ou ); - modified_ou.ischanged( 1 ); + var modified_ou = new aou().fromStoreItem( current_ou ); + modified_ou.ischanged ( 1 ); - pcrud.update( modified_ou, { + 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' )] ) ); - }, - oncomplete : function (r) { - var res = r.recv(); - 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' )] ) ); - } - }, + 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' )] ) ); + }, + oncomplete : function (r) { + var res = r.recv(); + 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' )] ) ); + } + }, }); } - + function hoo_load () { - save_hoo_button.disabled = false; - - hoo_id = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )}); - if (hoo_id.length == 0) { - current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )}); - for (var i = 0; i < 7; i++) { - current_ou_hoo['dow_' + i + '_open']('09:00:00'); - current_ou_hoo['dow_' + i + '_close']('17:00:00'); - } - } else { - current_ou_hoo = pcrud.retrieve( 'aouhoo', ou_list_store.getValue( current_ou, 'id' ), { - onerror : function (r) { - throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS,[ou_list_store.getValue( current_ou, 'name' )]); - } - }); - } - - for (var i = 0; i < 7; i++) { - window['dow_' + i + '_open'].setValue( - dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() ) - ); - window['dow_' + i + '_close'].setValue( - dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() ) - ); - } - - highlighter.hoo_pane.green.play(); + save_hoo_button.disabled = false; + + var hours_list = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )}); + + if (hours_list.length) { + current_ou_hoo = hours_list[0]; + current_ou_hoo.ischanged(1); // XXX why? + } else { + current_ou_hoo = new aouhoo().fromHash({ + isnew : 1, + id : ou_list_store.getValue( current_ou, 'id' ) + }); + for (var i = 0; i < 7; i++) { + current_ou_hoo['dow_' + i + '_open']('09:00:00'); + current_ou_hoo['dow_' + i + '_close']('17:00:00'); + } + } + + for (var i = 0; i < 7; i++) { + window['dow_' + i + '_open'].setValue( + dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() ) + ); + window['dow_' + i + '_close'].setValue( + dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() ) + ); + } + + highlighter.hoo_pane.green.play(); } -function addr_load () { - // empty result not coming through ... - - save_ill_address.disabled = false; - save_holds_address.disabled = false; - save_mailing_address.disabled = false; - save_billing_address.disabled = false; - - if (ou_list_store.getValue( current_ou, 'billing_address' )) { - pCRUD.request({ - method : 'open-ils.pcrud.retrieve.aoa', - params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ], - onerror : function (r) { - throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]); - }, - oncomplete : function (r) { - current_billing_address = null; - - var res = r.recv(); - if (res) { - if (res.content()) current_billing_address = res.content(); - } - - if (!current_billing_address) { - current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_billing_address.isnew(1); - } - set_addr_inputs('billing'); - highlighter.addresses_pane.green.play(); - } - }).send(); - } else { - current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_billing_address.isnew(1); - set_addr_inputs('billing'); - } - - if (ou_list_store.getValue( current_ou, 'mailing_address' )) { - pCRUD.request({ - method : 'open-ils.pcrud.retrieve.aoa', - params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ], - onerror : function (r) { - throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [ou_list_store.getValue( current_ou, 'name' )]); - }, - oncomplete : function (r) { - current_mailing_address = null; - - var res = r.recv(); - if (res) { - if (res.content()) current_mailing_address = res.content(); - } - - if (!current_mailing_address) { - current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_mailing_address.isnew(1); - } - - set_addr_inputs('mailing'); - highlighter.addresses_pane.green.play(); - } - }).send(); - } else { - current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_mailing_address.isnew(1); - set_addr_inputs('mailing'); - } - - if (ou_list_store.getValue( current_ou, 'holds_address' )) { - pCRUD.request({ - method : 'open-ils.pcrud.retrieve.aoa', - params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ], - onerror : function (r) { - throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]); - }, - oncomplete : function (r) { - current_holds_address = null; - - var res = r.recv(); - if (res) { - if (res.content()) current_holds_address = res.content(); - } +function addr_load () { - if (!current_holds_address) { - current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_holds_address.isnew(1); - } + save_ill_address.disabled = false; + save_holds_address.disabled = false; + save_mailing_address.disabled = false; + save_billing_address.disabled = false; - set_addr_inputs('holds'); - highlighter.addresses_pane.green.play(); - } - }).send(); - } else { - current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_holds_address.isnew(1); - set_addr_inputs('holds'); - } + atype_list = ['billing','mailing','holds','ill']; + for (var addr_idx in atype_list) { - if (ou_list_store.getValue( current_ou, 'ill_address' )) { - pCRUD.request({ - method : 'open-ils.pcrud.retrieve.aoa', - params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ], - onerror : function (r) { - throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]); - }, - oncomplete : function (r) { - current_ill_address = null; + var atype = atype_list[addr_idx]; + var cur_var_name = 'current_' + atype + '_address'; - var res = r.recv(); - if (res) { - if (res.content()) current_ill_address = res.content(); - } + var this_addr = pcrud.search( 'aoa',{id:ou_list_store.getValue( current_ou, atype + '_address')}); - if (!current_ill_address) { - current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_ill_address.isnew(1); - } + if (this_addr.length) { + window[cur_var_name] = this_addr[0]; + window[cur_var_name].ischanged( 1 ); // XXX why? + } else { + window[cur_var_name] = new aoa().fromHash({ + isnew : 1, + org_unit : ou_list_store.getValue( current_ou, 'id' ) + }); + } + set_addr_inputs(atype); + } - set_addr_inputs('ill'); - highlighter.addresses_pane.green.play(); - } - }).send(); - } else { - current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )}); - current_ill_address.isnew(1); - set_addr_inputs('ill'); - } + highlighter.addresses_pane.green.play(); } function set_addr_inputs (type) { - window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false ); - window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' ); - window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' ); - window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' ); - window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' ); - window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' ); - window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' ); - window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' ); - window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' ); + window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false ); + window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' ); + window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' ); + window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' ); + window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' ); + window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' ); + window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' ); + window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' ); + window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' ); } -- 2.11.0