]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit.js
use fieldmapper.AutoIDL inside conify to allow openils.PermaCrud to function properly
[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.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");
38
39 // some handy globals
40 var cgi = new CGI();
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 });
45
46 var current_ou, current_ou_hoo, ou_list_store, hoo_id;
47 var dirtyStore = [];
48 var virgin_ou_id = -1;
49
50 var aou_strings = dojo.i18n.getLocalization('openils.conify', 'conify');
51
52 //var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
53
54 var highlighter = {};
55
56 function status_update (markup) {
57         if (parent !== window && parent.status_update) parent.status_update( markup );
58 }
59
60 function save_org () {
61
62         new_kid_button.disabled = false;
63         save_ou_button.disabled = false;
64         delete_ou_button.disabled = false;
65
66         var modified_ou = new aou().fromStoreItem( current_ou );
67         modified_ou.ischanged( 1 );
68
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' )] ) );
74                 },
75                 oncomplete : function (r) {
76                         var res = r.recv();
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' )] ) );
81                         } else {
82                                 highlighter.editor_pane.red.play();
83                                 status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_DATA, [ou_list_store.getValue( current_ou, 'name' )] ) );
84                         }
85                 },
86     });
87
88 }
89         
90 function hoo_load () {
91         save_hoo_button.disabled = false;
92
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');
99                 }
100         } else {
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' )]);
104                         }
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
120 function addr_load () {
121         // empty result not coming through ...
122
123         save_ill_address.disabled = false;
124         save_holds_address.disabled = false;
125         save_mailing_address.disabled = false;
126         save_billing_address.disabled = false;
127
128         if (ou_list_store.getValue( current_ou, 'billing_address' )) {
129                 pCRUD.request({
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' )]);
134                         },
135                         oncomplete : function (r) {
136                                 current_billing_address = null;
137
138                                 var res = r.recv();
139                                 if (res) {
140                                         if (res.content()) current_billing_address = res.content();
141                                 }
142
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);
146                                 }
147
148                                 set_addr_inputs('billing');
149                                 highlighter.addresses_pane.green.play();
150                         }
151                 }).send();
152         } else {
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');
156         }
157
158         if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
159                 pCRUD.request({
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' )]);
164                         },
165                         oncomplete : function (r) {
166                                 current_mailing_address = null;
167
168                                 var res = r.recv();
169                                 if (res) {
170                                         if (res.content()) current_mailing_address = res.content();
171                                 }
172
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);
176                                 }
177
178                                 set_addr_inputs('mailing');
179                                 highlighter.addresses_pane.green.play();
180                         }
181                 }).send();
182         } else {
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');
186         }
187
188         if (ou_list_store.getValue( current_ou, 'holds_address' )) {
189                 pCRUD.request({
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' )]);
194                         },
195                         oncomplete : function (r) {
196                                 current_holds_address = null;
197
198                                 var res = r.recv();
199                                 if (res) {
200                                         if (res.content()) current_holds_address = res.content();
201                                 }
202
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);
206                                 }
207
208                                 set_addr_inputs('holds');
209                                 highlighter.addresses_pane.green.play();
210                         }
211                 }).send();
212         } else {
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');
216         }
217
218         if (ou_list_store.getValue( current_ou, 'ill_address' )) {
219                 pCRUD.request({
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' )]);
224                         },
225                         oncomplete : function (r) {
226                                 current_ill_address = null;
227
228                                 var res = r.recv();
229                                 if (res) {
230                                         if (res.content()) current_ill_address = res.content();
231                                 }
232
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);
236                                 }
237
238                                 set_addr_inputs('ill');
239                                 highlighter.addresses_pane.green.play();
240                         }
241                 }).send();
242         } else {
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');
246         }
247
248 }
249
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() || '' );
260 }
261