2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008 Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
18 dojo.require('fieldmapper.dojoData');
19 dojo.require('dojo.parser');
20 dojo.require('dojo.data.ItemFileWriteStore');
21 dojo.require('dojo.date.stamp');
22 dojo.require('dijit.form.TextBox');
23 dojo.require('dijit.form.TimeTextBox');
24 dojo.require('dijit.form.ValidationTextBox');
25 dojo.require('dijit.form.CheckBox');
26 dojo.require('dijit.form.FilteringSelect');
27 dojo.require('dijit.Tree');
28 dojo.require('dijit.layout.ContentPane');
29 dojo.require('dijit.layout.TabContainer');
30 dojo.require('dijit.layout.LayoutContainer');
31 dojo.require('dijit.layout.SplitContainer');
32 dojo.require('dojox.widget.Toaster');
33 dojo.require('dojox.fx');
37 var cookieManager = new HTTP.Cookies();
38 var ses = cookieManager.read('ses') || cgi.param('ses');
39 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
41 var current_ou, current_ou_hoo;
42 var virgin_ou_id = -1;
44 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
48 function status_update (markup) {
49 if (parent !== window && parent.status_update) parent.status_update( markup );
52 function save_org () {
53 var modified_ou = new aou().fromStoreItem( current_ou );
54 modified_ou.ischanged( 1 );
56 new_kid_button.disabled = false;
57 save_ou_button.disabled = false;
58 delete_ou_button.disabled = false;
61 method : 'open-ils.permacrud.update.aou',
63 params : [ ses, modified_ou ],
64 onerror : function (r) {
65 highlighter.editor_pane.red.play();
66 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
68 oncomplete : function (r) {
70 if ( res && res.content() ) {
71 ou_list_store.setValue( current_ou, 'ischanged', 0 );
72 highlighter.editor_pane.green.play();
73 status_update( 'Saved changes to ' + ou_list_store.getValue( current_ou, 'name' ) );
75 highlighter.editor_pane.red.play();
76 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
82 function hoo_load () {
83 // empty result not coming through ...
84 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
85 current_ou_hoo.isnew(1);
88 method : 'open-ils.permacrud.retrieve.aouhoo',
89 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
90 onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
91 oncomplete : function (r) {
92 current_ou_hoo = null;
96 if (res.content()) current_ou_hoo = res.content();
99 if (!current_ou_hoo) {
100 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
101 current_ou_hoo.isnew(1);
102 for (var i = 0; i < 7; i++) {
103 current_ou_hoo['dow_' + i + '_open']('09:00:00');
104 current_ou_hoo['dow_' + i + '_close']('17:00:00');
108 for (var i = 0; i < 7; i++) {
109 window['dow_' + i + '_open'].setValue(
110 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
112 window['dow_' + i + '_close'].setValue(
113 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
117 highlighter.hoo_pane.green.play();
123 function addr_load () {
124 // empty result not coming through ...
126 save_ill_address.disabled = false;
127 save_holds_address.disabled = false;
128 save_mailing_address.disabled = false;
129 save_billing_address.disabled = false;
131 if (ou_list_store.getValue( current_ou, 'billing_address' )) {
133 method : 'open-ils.permacrud.retrieve.aoa',
134 params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
135 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
136 oncomplete : function (r) {
137 current_billing_address = null;
141 if (res.content()) current_billing_address = res.content();
144 if (!current_billing_address) {
145 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
146 current_billing_address.isnew(1);
149 set_addr_inputs('billing');
150 highlighter.addresses_pane.green.play();
154 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
155 current_billing_address.isnew(1);
156 set_addr_inputs('billing');
159 if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
161 method : 'open-ils.permacrud.retrieve.aoa',
162 params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
163 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
164 oncomplete : function (r) {
165 current_mailing_address = null;
169 if (res.content()) current_mailing_address = res.content();
172 if (!current_mailing_address) {
173 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
174 current_mailing_address.isnew(1);
177 set_addr_inputs('mailing');
178 highlighter.addresses_pane.green.play();
182 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
183 current_mailing_address.isnew(1);
184 set_addr_inputs('mailing');
187 if (ou_list_store.getValue( current_ou, 'holds_address' )) {
189 method : 'open-ils.permacrud.retrieve.aoa',
190 params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
191 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
192 oncomplete : function (r) {
193 current_holds_address = null;
197 if (res.content()) current_holds_address = res.content();
200 if (!current_holds_address) {
201 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
202 current_holds_address.isnew(1);
205 set_addr_inputs('holds');
206 highlighter.addresses_pane.green.play();
210 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
211 current_holds_address.isnew(1);
212 set_addr_inputs('holds');
215 if (ou_list_store.getValue( current_ou, 'ill_address' )) {
217 method : 'open-ils.permacrud.retrieve.aoa',
218 params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
219 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
220 oncomplete : function (r) {
221 current_ill_address = null;
225 if (res.content()) current_ill_address = res.content();
228 if (!current_ill_address) {
229 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
230 current_ill_address.isnew(1);
233 set_addr_inputs('ill');
234 highlighter.addresses_pane.green.play();
238 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
239 current_ill_address.isnew(1);
240 set_addr_inputs('ill');
245 function set_addr_inputs (type) {
246 window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
247 window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
248 window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
249 window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
250 window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
251 window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
252 window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
253 window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
254 window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );