]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
Patch from Warren Layton at Laurentian university which addresses some issues
[working/Evergreen.git] / Open-ILS / web / conify / global / actor / org_unit.js
1 /*
2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
5
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.
10
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 # ---------------------------------------------------------------------------
16 */
17
18 dojo.require('fieldmapper.dojoData');
19 dojo.require('openils.widget.TranslatorPopup');
20 dojo.require('openils.PermaCrud');
21 dojo.require('dojo.parser');
22 dojo.require('dojo.data.ItemFileWriteStore');
23 dojo.require('dojo.date.stamp');
24 dojo.require('dijit.form.TextBox');
25 dojo.require('dijit.form.TimeTextBox');
26 dojo.require('dijit.form.ValidationTextBox');
27 dojo.require('dijit.form.CheckBox');
28 dojo.require('dijit.form.FilteringSelect');
29 dojo.require('dijit.Tree');
30 dojo.require('dijit.layout.ContentPane');
31 dojo.require('dijit.layout.TabContainer');
32 dojo.require('dijit.layout.LayoutContainer');
33 dojo.require('dijit.layout.SplitContainer');
34 dojo.require('dojox.widget.Toaster');
35 dojo.require('dojox.fx');
36 dojo.requireLocalization("openils.conify", "conify");
37
38 // some handy globals
39 var cgi = new CGI();
40 var cookieManager = new HTTP.Cookies();
41 var ses = cookieManager.read('ses') || cgi.param('ses');
42 var pCRUD = new OpenSRF.ClientSession('open-ils.pcrud');
43 var pcrud = new openils.PermaCrud({ authtoken : ses });
44
45 var current_ou, current_ou_hoo, ou_list_store, hoo_id;
46 var dirtyStore = [];
47 var virgin_ou_id = -1;
48
49 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
50
51 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
52
53 var highlighter = {};
54
55 function status_update (markup) {
56         if (parent !== window && parent.status_update) parent.status_update( markup );
57 }
58
59 function save_org () {
60
61         new_kid_button.disabled = false;
62         save_ou_button.disabled = false;
63         delete_ou_button.disabled = false;
64
65         var modified_ou = new aou().fromStoreItem( current_ou );
66         modified_ou.ischanged( 1 );
67
68         pcrud.update( modified_ou, {
69         timeout : 10, // makes it synchronous
70                 onerror : function (r) {
71                         highlighter.editor_pane.red.play();
72                         status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
73                 },
74                 oncomplete : function (r) {
75                         var res = r.recv();
76                         if ( res && res.content() ) {
77                                 ou_list_store.setValue( current_ou, 'ischanged', 0 );
78                                 highlighter.editor_pane.green.play();
79                                 status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVE, [ou_list_store.getValue( current_ou, 'name' )] ) );
80                         } else {
81                                 highlighter.editor_pane.red.play();
82                                 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
83                         }
84                 },
85     });
86
87 }
88         
89 function hoo_load () {
90         save_hoo_button.disabled = false;
91
92         hoo_id = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )});
93         if (hoo_id.length == 0) {
94                 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
95                 for (var i = 0; i < 7; i++) {
96                         current_ou_hoo['dow_' + i + '_open']('09:00:00');
97                         current_ou_hoo['dow_' + i + '_close']('17:00:00');
98                 }
99         } else {
100                 current_ou_hoo = pcrud.retrieve( 'aouhoo', ou_list_store.getValue( current_ou, 'id' ), {
101                         onerror : function (r) {
102                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS,[ou_list_store.getValue( current_ou, 'name' )]);
103                         }
104                 });
105         }
106
107         for (var i = 0; i < 7; i++) {
108                 window['dow_' + i + '_open'].setValue(
109                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
110                 );
111                 window['dow_' + i + '_close'].setValue(
112                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
113                 );
114         }
115
116         highlighter.hoo_pane.green.play();
117 }
118
119 function addr_load () {
120         // empty result not coming through ...
121
122         save_ill_address.disabled = false;
123         save_holds_address.disabled = false;
124         save_mailing_address.disabled = false;
125         save_billing_address.disabled = false;
126
127         if (ou_list_store.getValue( current_ou, 'billing_address' )) {
128                 pCRUD.request({
129                         method : 'open-ils.pcrud.retrieve.aoa',
130                         params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
131                         onerror : function (r) {
132                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_PHYSICAL, [ou_list_store.getValue( current_ou, 'name' )]);
133                         },
134                         oncomplete : function (r) {
135                                 current_billing_address = null;
136
137                                 var res = r.recv();
138                                 if (res) {
139                                         if (res.content()) current_billing_address = res.content();
140                                 }
141
142                                 if (!current_billing_address) {
143                                         current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
144                                         current_billing_address.isnew(1);
145                                 }
146
147                                 set_addr_inputs('billing');
148                                 highlighter.addresses_pane.green.play();
149                         }
150                 }).send();
151         } else {
152                 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
153                 current_billing_address.isnew(1);
154                 set_addr_inputs('billing');
155         }
156
157         if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
158                 pCRUD.request({
159                         method : 'open-ils.pcrud.retrieve.aoa',
160                         params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
161                         onerror : function (r) {
162                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_MAILING, [ou_list_store.getValue( current_ou, 'name' )]);
163                         },
164                         oncomplete : function (r) {
165                                 current_mailing_address = null;
166
167                                 var res = r.recv();
168                                 if (res) {
169                                         if (res.content()) current_mailing_address = res.content();
170                                 }
171
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);
175                                 }
176
177                                 set_addr_inputs('mailing');
178                                 highlighter.addresses_pane.green.play();
179                         }
180                 }).send();
181         } else {
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');
185         }
186
187         if (ou_list_store.getValue( current_ou, 'holds_address' )) {
188                 pCRUD.request({
189                         method : 'open-ils.pcrud.retrieve.aoa',
190                         params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
191                         onerror : function (r) {
192                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOLDS, [ou_list_store.getValue( current_ou, 'name' )]);
193                         },
194                         oncomplete : function (r) {
195                                 current_holds_address = null;
196
197                                 var res = r.recv();
198                                 if (res) {
199                                         if (res.content()) current_holds_address = res.content();
200                                 }
201
202                                 if (!current_holds_address) {
203                                         current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
204                                         current_holds_address.isnew(1);
205                                 }
206
207                                 set_addr_inputs('holds');
208                                 highlighter.addresses_pane.green.play();
209                         }
210                 }).send();
211         } else {
212                 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
213                 current_holds_address.isnew(1);
214                 set_addr_inputs('holds');
215         }
216
217         if (ou_list_store.getValue( current_ou, 'ill_address' )) {
218                 pCRUD.request({
219                         method : 'open-ils.pcrud.retrieve.aoa',
220                         params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
221                         onerror : function (r) {
222                                 throw dojo.string.substitute(aou_strings.ERROR_FETCHING_ILL, [ou_list_store.getValue( current_ou, 'name' )]);
223                         },
224                         oncomplete : function (r) {
225                                 current_ill_address = null;
226
227                                 var res = r.recv();
228                                 if (res) {
229                                         if (res.content()) current_ill_address = res.content();
230                                 }
231
232                                 if (!current_ill_address) {
233                                         current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
234                                         current_ill_address.isnew(1);
235                                 }
236
237                                 set_addr_inputs('ill');
238                                 highlighter.addresses_pane.green.play();
239                         }
240                 }).send();
241         } else {
242                 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
243                 current_ill_address.isnew(1);
244                 set_addr_inputs('ill');
245         }
246
247 }
248
249 function set_addr_inputs (type) {
250         window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
251         window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
252         window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
253         window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
254         window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
255         window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
256         window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
257         window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
258         window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
259 }
260