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('openils.I18N');
20 dojo.require('dojo.parser');
21 dojo.require('dojo.data.ItemFileWriteStore');
22 dojo.require('dojo.date.stamp');
23 dojo.require('dijit.form.TextBox');
24 dojo.require('dijit.form.TimeTextBox');
25 dojo.require('dijit.form.ValidationTextBox');
26 dojo.require('dijit.form.CheckBox');
27 dojo.require('dijit.form.FilteringSelect');
28 dojo.require('dijit.Tree');
29 dojo.require('dijit.layout.ContentPane');
30 dojo.require('dijit.layout.TabContainer');
31 dojo.require('dijit.layout.LayoutContainer');
32 dojo.require('dijit.layout.SplitContainer');
33 dojo.require('dojox.widget.Toaster');
34 dojo.require('dojox.fx');
38 var cookieManager = new HTTP.Cookies();
39 var ses = cookieManager.read('ses') || cgi.param('ses');
40 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
42 var current_ou, current_ou_hoo;
43 var virgin_ou_id = -1;
45 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
49 function status_update (markup) {
50 if (parent !== window && parent.status_update) parent.status_update( markup );
53 function save_org () {
54 var modified_ou = new aou().fromStoreItem( current_ou );
55 modified_ou.ischanged( 1 );
57 new_kid_button.disabled = false;
58 save_ou_button.disabled = false;
59 delete_ou_button.disabled = false;
62 method : 'open-ils.permacrud.update.aou',
64 params : [ ses, modified_ou ],
65 onerror : function (r) {
66 highlighter.editor_pane.red.play();
67 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
69 oncomplete : function (r) {
71 if ( res && res.content() ) {
72 ou_list_store.setValue( current_ou, 'ischanged', 0 );
73 highlighter.editor_pane.green.play();
74 status_update( 'Saved changes to ' + ou_list_store.getValue( current_ou, 'name' ) );
76 highlighter.editor_pane.red.play();
77 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
83 function hoo_load () {
84 // empty result not coming through ...
85 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
86 current_ou_hoo.isnew(1);
89 method : 'open-ils.permacrud.retrieve.aouhoo',
90 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
91 onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
92 oncomplete : function (r) {
93 current_ou_hoo = null;
97 if (res.content()) current_ou_hoo = res.content();
100 if (!current_ou_hoo) {
101 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
102 current_ou_hoo.isnew(1);
103 for (var i = 0; i < 7; i++) {
104 current_ou_hoo['dow_' + i + '_open']('09:00:00');
105 current_ou_hoo['dow_' + i + '_close']('17:00:00');
109 for (var i = 0; i < 7; i++) {
110 window['dow_' + i + '_open'].setValue(
111 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
113 window['dow_' + i + '_close'].setValue(
114 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
118 highlighter.hoo_pane.green.play();
124 function addr_load () {
125 // empty result not coming through ...
127 save_ill_address.disabled = false;
128 save_holds_address.disabled = false;
129 save_mailing_address.disabled = false;
130 save_billing_address.disabled = false;
132 if (ou_list_store.getValue( current_ou, 'billing_address' )) {
134 method : 'open-ils.permacrud.retrieve.aoa',
135 params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
136 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
137 oncomplete : function (r) {
138 current_billing_address = null;
142 if (res.content()) current_billing_address = res.content();
145 if (!current_billing_address) {
146 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
147 current_billing_address.isnew(1);
150 set_addr_inputs('billing');
151 highlighter.addresses_pane.green.play();
155 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
156 current_billing_address.isnew(1);
157 set_addr_inputs('billing');
160 if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
162 method : 'open-ils.permacrud.retrieve.aoa',
163 params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
164 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
165 oncomplete : function (r) {
166 current_mailing_address = null;
170 if (res.content()) current_mailing_address = res.content();
173 if (!current_mailing_address) {
174 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
175 current_mailing_address.isnew(1);
178 set_addr_inputs('mailing');
179 highlighter.addresses_pane.green.play();
183 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
184 current_mailing_address.isnew(1);
185 set_addr_inputs('mailing');
188 if (ou_list_store.getValue( current_ou, 'holds_address' )) {
190 method : 'open-ils.permacrud.retrieve.aoa',
191 params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
192 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
193 oncomplete : function (r) {
194 current_holds_address = null;
198 if (res.content()) current_holds_address = res.content();
201 if (!current_holds_address) {
202 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
203 current_holds_address.isnew(1);
206 set_addr_inputs('holds');
207 highlighter.addresses_pane.green.play();
211 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
212 current_holds_address.isnew(1);
213 set_addr_inputs('holds');
216 if (ou_list_store.getValue( current_ou, 'ill_address' )) {
218 method : 'open-ils.permacrud.retrieve.aoa',
219 params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
220 onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
221 oncomplete : function (r) {
222 current_ill_address = null;
226 if (res.content()) current_ill_address = res.content();
229 if (!current_ill_address) {
230 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
231 current_ill_address.isnew(1);
234 set_addr_inputs('ill');
235 highlighter.addresses_pane.green.play();
239 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
240 current_ill_address.isnew(1);
241 set_addr_inputs('ill');
246 function set_addr_inputs (type) {
247 window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
248 window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
249 window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
250 window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
251 window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
252 window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
253 window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
254 window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
255 window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );