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.AutoIDL');
19 dojo.require('fieldmapper.dojoData');
20 dojo.require('openils.widget.TranslatorPopup');
21 dojo.require('openils.PermaCrud');
22 dojo.require('dojo.parser');
23 dojo.require('dojo.data.ItemFileWriteStore');
24 dojo.require('dojo.date.stamp');
25 dojo.require('dijit.form.TextBox');
26 dojo.require('dijit.form.TimeTextBox');
27 dojo.require('dijit.form.ValidationTextBox');
28 dojo.require('dijit.form.CheckBox');
29 dojo.require('dijit.form.FilteringSelect');
30 dojo.require('dijit.Tree');
31 dojo.require('dijit.layout.ContentPane');
32 dojo.require('dijit.layout.TabContainer');
33 dojo.require('dijit.layout.LayoutContainer');
34 dojo.require('dijit.layout.SplitContainer');
35 dojo.require('dojox.widget.Toaster');
36 dojo.require('dojox.fx');
37 dojo.requireLocalization("openils.conify", "conify");
41 var cookieManager = new HTTP.Cookies();
42 var ses = cookieManager.read('ses') || cgi.param('ses');
43 var pCRUD = new OpenSRF.ClientSession('open-ils.pcrud');
44 var pcrud = new openils.PermaCrud({ authtoken : ses });
46 var current_ou, current_ou_hoo, ou_list_store, hoo_id;
48 var virgin_ou_id = -1;
50 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
52 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
56 function status_update (markup) {
57 if (parent !== window && parent.status_update) parent.status_update( markup );
60 function save_org () {
62 new_kid_button.disabled = false;
63 save_ou_button.disabled = false;
64 delete_ou_button.disabled = false;
66 var modified_ou = new aou().fromStoreItem( current_ou );
67 modified_ou.ischanged( 1 );
69 pcrud.update( modified_ou, {
70 timeout : 10, // makes it synchronous
71 onerror : function (r) {
72 highlighter.editor_pane.red.play();
73 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
75 oncomplete : function (r) {
77 if ( res && res.content() ) {
78 ou_list_store.setValue( current_ou, 'ischanged', 0 );
79 highlighter.editor_pane.green.play();
80 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
82 highlighter.editor_pane.red.play();
83 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
90 function hoo_load () {
91 save_hoo_button.disabled = false;
93 hoo_id = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )});
94 if (hoo_id.length == 0) {
95 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
96 for (var i = 0; i < 7; i++) {
97 current_ou_hoo['dow_' + i + '_open']('09:00:00');
98 current_ou_hoo['dow_' + i + '_close']('17:00:00');
101 current_ou_hoo = pcrud.retrieve( 'aouhoo', ou_list_store.getValue( current_ou, 'id' ), {
102 onerror : function (r) {
103 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS,[ou_list_store.getValue( current_ou, 'name' )]);
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();
120 function addr_load () {
121 // empty result not coming through ...
123 save_ill_address.disabled = false;
124 save_holds_address.disabled = false;
125 save_mailing_address.disabled = false;
126 save_billing_address.disabled = false;
128 if (ou_list_store.getValue( current_ou, 'billing_address' )) {
130 method : 'open-ils.pcrud.retrieve.aoa',
131 params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
132 onerror : function (r) {
133 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]);
135 oncomplete : function (r) {
136 current_billing_address = null;
140 if (res.content()) current_billing_address = res.content();
143 if (!current_billing_address) {
144 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
145 current_billing_address.isnew(1);
148 set_addr_inputs('billing');
149 highlighter.addresses_pane.green.play();
153 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
154 current_billing_address.isnew(1);
155 set_addr_inputs('billing');
158 if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
160 method : 'open-ils.pcrud.retrieve.aoa',
161 params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
162 onerror : function (r) {
163 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [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.pcrud.retrieve.aoa',
191 params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
192 onerror : function (r) {
193 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]);
195 oncomplete : function (r) {
196 current_holds_address = null;
200 if (res.content()) current_holds_address = res.content();
203 if (!current_holds_address) {
204 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
205 current_holds_address.isnew(1);
208 set_addr_inputs('holds');
209 highlighter.addresses_pane.green.play();
213 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
214 current_holds_address.isnew(1);
215 set_addr_inputs('holds');
218 if (ou_list_store.getValue( current_ou, 'ill_address' )) {
220 method : 'open-ils.pcrud.retrieve.aoa',
221 params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
222 onerror : function (r) {
223 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]);
225 oncomplete : function (r) {
226 current_ill_address = null;
230 if (res.content()) current_ill_address = res.content();
233 if (!current_ill_address) {
234 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
235 current_ill_address.isnew(1);
238 set_addr_inputs('ill');
239 highlighter.addresses_pane.green.play();
243 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
244 current_ill_address.isnew(1);
245 set_addr_inputs('ill');
250 function set_addr_inputs (type) {
251 window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
252 window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
253 window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
254 window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
255 window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
256 window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
257 window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
258 window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
259 window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );