]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
merging admin interface from the dojo-admin branch
[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('dojo.parser');
20 dojo.require('dojo.data.ItemFileWriteStore');
21 dojo.require('dojo.date.stamp');
22 dojo.require('dijit.form.TextBox');
23 dojo.require('dijit.form.TimeTextBox');
24 dojo.require('dijit.form.ValidationTextBox');
25 dojo.require('dijit.form.CheckBox');
26 dojo.require('dijit.form.FilteringSelect');
27 dojo.require('dijit.Tree');
28 dojo.require('dijit.layout.ContentPane');
29 dojo.require('dijit.layout.TabContainer');
30 dojo.require('dijit.layout.LayoutContainer');
31 dojo.require('dijit.layout.SplitContainer');
32 dojo.require('dojox.widget.Toaster');
33 dojo.require('dojox.fx');
34
35 // some handy globals
36 var cgi = new CGI();
37 var cookieManager = new HTTP.Cookies();
38 var ses = cookieManager.read('ses') || cgi.param('ses');
39 var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
40
41 var current_ou, current_ou_hoo;
42 var virgin_ou_id = -1;
43
44 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
45
46 var highlighter = {};
47
48 function status_update (markup) {
49         if (parent !== window && parent.status_update) parent.status_update( markup );
50 }
51
52 function save_org () {
53         var modified_ou = new aou().fromStoreItem( current_ou );
54         modified_ou.ischanged( 1 );
55
56         new_kid_button.disabled = false;
57         save_ou_button.disabled = false;
58         delete_ou_button.disabled = false;
59
60         pCRUD.request({
61                 method : 'open-ils.permacrud.update.aou',
62                 timeout : 10,
63                 params : [ ses, modified_ou ],
64                 onerror : function (r) {
65                         highlighter.editor_pane.red.play();
66                         status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
67                 },
68                 oncomplete : function (r) {
69                         var res = r.recv();
70                         if ( res && res.content() ) {
71                                 ou_list_store.setValue( current_ou, 'ischanged', 0 );
72                                 highlighter.editor_pane.green.play();
73                                 status_update( 'Saved changes to ' + ou_list_store.getValue( current_ou, 'name' ) );
74                         } else {
75                                 highlighter.editor_pane.red.play();
76                                 status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
77                         }
78                 },
79         }).send();
80 }
81         
82 function hoo_load () {
83         // empty result not coming through ...
84         current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
85         current_ou_hoo.isnew(1);
86
87         pCRUD.request({
88                 method : 'open-ils.permacrud.retrieve.aouhoo',
89                 params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
90                 onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
91                 oncomplete : function (r) {
92                         current_ou_hoo = null;
93
94                         var res = r.recv();
95                         if (res) {
96                                 if (res.content()) current_ou_hoo = res.content();
97                         }
98
99                         if (!current_ou_hoo) {
100                                 current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
101                                 current_ou_hoo.isnew(1);
102                                 for (var i = 0; i < 7; i++) {
103                                         current_ou_hoo['dow_' + i + '_open']('09:00:00');
104                                         current_ou_hoo['dow_' + i + '_close']('17:00:00');
105                                 }
106                         }
107
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']() )
111                                 );
112                                 window['dow_' + i + '_close'].setValue(
113                                         dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
114                                 );
115                         }
116
117                         highlighter.hoo_pane.green.play();
118                 }
119         }).send();
120
121 }
122
123 function addr_load () {
124         // empty result not coming through ...
125
126         save_ill_address.disabled = false;
127         save_holds_address.disabled = false;
128         save_mailing_address.disabled = false;
129         save_billing_address.disabled = false;
130
131         if (ou_list_store.getValue( current_ou, 'billing_address' )) {
132                 pCRUD.request({
133                         method : 'open-ils.permacrud.retrieve.aoa',
134                         params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
135                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
136                         oncomplete : function (r) {
137                                 current_billing_address = null;
138
139                                 var res = r.recv();
140                                 if (res) {
141                                         if (res.content()) current_billing_address = res.content();
142                                 }
143
144                                 if (!current_billing_address) {
145                                         current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
146                                         current_billing_address.isnew(1);
147                                 }
148
149                                 set_addr_inputs('billing');
150                                 highlighter.addresses_pane.green.play();
151                         }
152                 }).send();
153         } else {
154                 current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
155                 current_billing_address.isnew(1);
156                 set_addr_inputs('billing');
157         }
158
159         if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
160                 pCRUD.request({
161                         method : 'open-ils.permacrud.retrieve.aoa',
162                         params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
163                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
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.permacrud.retrieve.aoa',
190                         params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
191                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
192                         oncomplete : function (r) {
193                                 current_holds_address = null;
194
195                                 var res = r.recv();
196                                 if (res) {
197                                         if (res.content()) current_holds_address = res.content();
198                                 }
199
200                                 if (!current_holds_address) {
201                                         current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
202                                         current_holds_address.isnew(1);
203                                 }
204
205                                 set_addr_inputs('holds');
206                                 highlighter.addresses_pane.green.play();
207                         }
208                 }).send();
209         } else {
210                 current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
211                 current_holds_address.isnew(1);
212                 set_addr_inputs('holds');
213         }
214
215         if (ou_list_store.getValue( current_ou, 'ill_address' )) {
216                 pCRUD.request({
217                         method : 'open-ils.permacrud.retrieve.aoa',
218                         params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
219                         onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
220                         oncomplete : function (r) {
221                                 current_ill_address = null;
222
223                                 var res = r.recv();
224                                 if (res) {
225                                         if (res.content()) current_ill_address = res.content();
226                                 }
227
228                                 if (!current_ill_address) {
229                                         current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
230                                         current_ill_address.isnew(1);
231                                 }
232
233                                 set_addr_inputs('ill');
234                                 highlighter.addresses_pane.green.play();
235                         }
236                 }).send();
237         } else {
238                 current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
239                 current_ill_address.isnew(1);
240                 set_addr_inputs('ill');
241         }
242
243 }
244
245 function set_addr_inputs (type) {
246         window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
247         window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
248         window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
249         window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
250         window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
251         window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
252         window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
253         window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
254         window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
255 }
256