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.pcrud');
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;
64 if (!pCRUD.connect()) {
65 highlighter.editor_pane.red.play();
66 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
70 var commit = pCRUD.request({
71 method : 'open-ils.pcrud.transaction.commit',
73 params : [ ses, modified_ou ],
74 onerror : function (r) {
75 highlighter.editor_pane.red.play();
76 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
80 oncomplete : function (r) {
83 ou_list_store.setValue( current_ou, 'ischanged', 0 );
84 highlighter.editor_pane.green.play();
85 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
87 highlighter.editor_pane.red.play();
88 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
95 var update = pCRUD.request({
96 method : 'open-ils.pcrud.update.aou',
98 params : [ ses, modified_ou ],
99 onerror : function (r) {
100 highlighter.editor_pane.red.play();
101 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
103 throw 'update error';
105 oncomplete : function (r) {
107 if ( res && res.content() ) {
110 highlighter.editor_pane.red.play();
111 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
113 throw 'update error';
118 var begin = pCRUD.request({
119 method : 'open-ils.pcrud.transaction.begin',
121 params : [ ses, modified_ou ],
122 onerror : function (r) {
123 highlighter.editor_pane.red.play();
124 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
128 oncomplete : function (r) {
130 if ( res && res.content() ) {
133 highlighter.editor_pane.red.play();
134 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
144 function hoo_load () {
145 // empty result not coming through ...
146 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
147 current_ou_hoo.isnew(1);
150 method : 'open-ils.pcrud.retrieve.aouhoo',
151 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
152 onerror : function (r) {
153 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS, [ou_list_store.getValue( current_ou, 'name' )]);
155 oncomplete : function (r) {
156 current_ou_hoo = null;
160 if (res.content()) current_ou_hoo = res.content();
163 if (!current_ou_hoo) {
164 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
165 current_ou_hoo.isnew(1);
166 for (var i = 0; i < 7; i++) {
167 current_ou_hoo['dow_' + i + '_open']('09:00:00');
168 current_ou_hoo['dow_' + i + '_close']('17:00:00');
172 for (var i = 0; i < 7; i++) {
173 window['dow_' + i + '_open'].setValue(
174 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
176 window['dow_' + i + '_close'].setValue(
177 dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
181 highlighter.hoo_pane.green.play();
187 function addr_load () {
188 // empty result not coming through ...
190 save_ill_address.disabled = false;
191 save_holds_address.disabled = false;
192 save_mailing_address.disabled = false;
193 save_billing_address.disabled = false;
195 if (ou_list_store.getValue( current_ou, 'billing_address' )) {
197 method : 'open-ils.pcrud.retrieve.aoa',
198 params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
199 onerror : function (r) {
200 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]);
202 oncomplete : function (r) {
203 current_billing_address = null;
207 if (res.content()) current_billing_address = res.content();
210 if (!current_billing_address) {
211 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
212 current_billing_address.isnew(1);
215 set_addr_inputs('billing');
216 highlighter.addresses_pane.green.play();
220 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
221 current_billing_address.isnew(1);
222 set_addr_inputs('billing');
225 if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
227 method : 'open-ils.pcrud.retrieve.aoa',
228 params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
229 onerror : function (r) {
230 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [ou_list_store.getValue( current_ou, 'name' )]);
232 oncomplete : function (r) {
233 current_mailing_address = null;
237 if (res.content()) current_mailing_address = res.content();
240 if (!current_mailing_address) {
241 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
242 current_mailing_address.isnew(1);
245 set_addr_inputs('mailing');
246 highlighter.addresses_pane.green.play();
250 current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
251 current_mailing_address.isnew(1);
252 set_addr_inputs('mailing');
255 if (ou_list_store.getValue( current_ou, 'holds_address' )) {
257 method : 'open-ils.pcrud.retrieve.aoa',
258 params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
259 onerror : function (r) {
260 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]);
262 oncomplete : function (r) {
263 current_holds_address = null;
267 if (res.content()) current_holds_address = res.content();
270 if (!current_holds_address) {
271 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
272 current_holds_address.isnew(1);
275 set_addr_inputs('holds');
276 highlighter.addresses_pane.green.play();
280 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
281 current_holds_address.isnew(1);
282 set_addr_inputs('holds');
285 if (ou_list_store.getValue( current_ou, 'ill_address' )) {
287 method : 'open-ils.pcrud.retrieve.aoa',
288 params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
289 onerror : function (r) {
290 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]);
292 oncomplete : function (r) {
293 current_ill_address = null;
297 if (res.content()) current_ill_address = res.content();
300 if (!current_ill_address) {
301 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
302 current_ill_address.isnew(1);
305 set_addr_inputs('ill');
306 highlighter.addresses_pane.green.play();
310 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
311 current_ill_address.isnew(1);
312 set_addr_inputs('ill');
317 function set_addr_inputs (type) {
318 window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
319 window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
320 window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
321 window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
322 window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
323 window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
324 window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
325 window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
326 window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );