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.widget.TranslatorPopup');
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');
35 dojo.requireLocalization("openils.conify", "conify");
39 var cookieManager = new HTTP.Cookies();
40 var ses = cookieManager.read('ses') || cgi.param('ses');
41 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
43 var current_ou, current_ou_hoo;
44 var virgin_ou_id = -1;
46 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
48 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
52 function status_update (markup) {
53 if (parent !== window && parent.status_update) parent.status_update( markup );
56 function save_org () {
57 var modified_ou = new aou().fromStoreItem( current_ou );
58 modified_ou.ischanged( 1 );
60 new_kid_button.disabled = false;
61 save_ou_button.disabled = false;
62 delete_ou_button.disabled = false;
65 method : 'open-ils.permacrud.update.aou',
67 params : [ ses, modified_ou ],
68 onerror : function (r) {
69 highlighter.editor_pane.red.play();
70 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
72 oncomplete : function (r) {
74 if ( res && res.content() ) {
75 ou_list_store.setValue( current_ou, 'ischanged', 0 );
76 highlighter.editor_pane.green.play();
77 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
79 highlighter.editor_pane.red.play();
80 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
86 function hoo_load () {
87 // empty result not coming through ...
88 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
89 current_ou_hoo.isnew(1);
92 method : 'open-ils.permacrud.retrieve.aouhoo',
93 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
94 onerror : function (r) {
95 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS, [ou_list_store.getValue( current_ou, 'name' )]);
97 oncomplete : function (r) {
98 current_ou_hoo = null;
102 if (res.content()) current_ou_hoo = res.content();
105 if (!current_ou_hoo) {
106 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
107 current_ou_hoo.isnew(1);
108 for (var i = 0; i < 7; i++) {
109 current_ou_hoo['dow_' + i + '_open']('09:00:00');
110 current_ou_hoo['dow_' + i + '_close']('17:00:00');
114 for (var i = 0; i < 7; i++) {
115 window['dow_' + i + '_open'].setValue(
116 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
118 window['dow_' + i + '_close'].setValue(
119 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
123 highlighter.hoo_pane.green.play();
129 function addr_load () {
130 // empty result not coming through ...
132 save_ill_address.disabled = false;
133 save_holds_address.disabled = false;
134 save_mailing_address.disabled = false;
135 save_billing_address.disabled = false;
137 if (ou_list_store.getValue( current_ou, 'billing_address' )) {
139 method : 'open-ils.permacrud.retrieve.aoa',
140 params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
141 onerror : function (r) {
142 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]);
144 oncomplete : function (r) {
145 current_billing_address = null;
149 if (res.content()) current_billing_address = res.content();
152 if (!current_billing_address) {
153 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
154 current_billing_address.isnew(1);
157 set_addr_inputs('billing');
158 highlighter.addresses_pane.green.play();
162 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
163 current_billing_address.isnew(1);
164 set_addr_inputs('billing');
167 if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
169 method : 'open-ils.permacrud.retrieve.aoa',
170 params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
171 onerror : function (r) {
172 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [ou_list_store.getValue( current_ou, 'name' )]);
174 oncomplete : function (r) {
175 current_mailing_address = null;
179 if (res.content()) current_mailing_address = res.content();
182 if (!current_mailing_address) {
183 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
184 current_mailing_address.isnew(1);
187 set_addr_inputs('mailing');
188 highlighter.addresses_pane.green.play();
192 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
193 current_mailing_address.isnew(1);
194 set_addr_inputs('mailing');
197 if (ou_list_store.getValue( current_ou, 'holds_address' )) {
199 method : 'open-ils.permacrud.retrieve.aoa',
200 params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
201 onerror : function (r) {
202 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]);
204 oncomplete : function (r) {
205 current_holds_address = null;
209 if (res.content()) current_holds_address = res.content();
212 if (!current_holds_address) {
213 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
214 current_holds_address.isnew(1);
217 set_addr_inputs('holds');
218 highlighter.addresses_pane.green.play();
222 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
223 current_holds_address.isnew(1);
224 set_addr_inputs('holds');
227 if (ou_list_store.getValue( current_ou, 'ill_address' )) {
229 method : 'open-ils.permacrud.retrieve.aoa',
230 params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
231 onerror : function (r) {
232 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]);
234 oncomplete : function (r) {
235 current_ill_address = null;
239 if (res.content()) current_ill_address = res.content();
242 if (!current_ill_address) {
243 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
244 current_ill_address.isnew(1);
247 set_addr_inputs('ill');
248 highlighter.addresses_pane.green.play();
252 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
253 current_ill_address.isnew(1);
254 set_addr_inputs('ill');
259 function set_addr_inputs (type) {
260 window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
261 window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
262 window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
263 window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
264 window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
265 window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
266 window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
267 window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
268 window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );