]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/do_not_auto_attempt_print_setting.js
e1eaea094027d78219d0f7a68a0ab8e1381786d8
[Evergreen.git] / Open-ILS / xul / staff_client / server / admin / do_not_auto_attempt_print_setting.js
1 var error;
2 var network;
3 var data;
4 var coust_obj;
5
6 function my_init() {
7     try {
8         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
9         if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
10         JSAN.errorLevel = "die"; // none, warn, or die
11         JSAN.addRepository('/xul/server/');
12         JSAN.use('util.error'); error = new util.error();
13         error.sdump('D_TRACE','my_init() for main_test.xul');
14         JSAN.use('util.network'); network = new util.network();
15         JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
16
17         dojo.require('openils.PermaCrud');
18         coust_obj = new openils.PermaCrud({authtoken:ses()}).search('coust',{'name':'circ.staff_client.do_not_auto_attempt_print'})[0];
19         document.getElementById('caption').setAttribute('label',coust_obj.label());
20         document.getElementById('caption').setAttribute('tooltiptext',coust_obj.name());
21         append_to_vbox('desc',coust_obj.description());
22
23         render_current_setting();
24
25         document.getElementById('apply').addEventListener(
26             'command',
27             apply_setting,
28             false
29         );
30
31         render_lib_menu();
32
33     } catch(E) {
34         try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
35     }
36 }
37
38 function append_to_vbox(id,node) {
39     if (typeof node == 'string') { var text = document.createTextNode(node); node = document.createElement('description'); node.appendChild(text); }
40     document.getElementById(id).appendChild(node);
41 }
42
43 function admin_string(s,p) {
44     var mc = document.getElementById('adminStrings');
45     if (p) {
46         return mc.getFormattedString(s,p);
47     } else {
48         return mc.getString(s);
49     }
50 }
51
52 function apply_setting(ev) {
53     var values = [];
54     if (document.getElementById('checkout').checked) { values.push('Checkout'); }
55     if (document.getElementById('bill_pay').checked) { values.push('Bill Pay'); }
56     if (document.getElementById('hold_slip').checked) { values.push('Hold Slip'); }
57     if (document.getElementById('transit_slip').checked) { values.push('Transit Slip'); }
58     if (document.getElementById('hold_transit_slip').checked) { values.push('Hold/Transit Slip'); }
59     var org = document.getElementById('lib_menulist').value;
60     var result = network.simple_request('FM_AOUS_UPDATE',[ ses(), org, { 'circ.staff_client.do_not_auto_attempt_print' : values } ]);
61     if (result == 1) {
62         alert(admin_string('staff.admin.staff.do_not_auto_attempt_print_setting.update_success'));
63         render_current_setting();
64     } else {
65         error.standard_unexpected_error_alert(admin_string('staff.admin.staff.do_not_auto_attempt_print_setting.update_failure'),result);
66     }
67 }
68
69 function render_current_setting() {
70     JSAN.use('util.widgets');
71
72     util.widgets.remove_children('current');
73
74     /* FIXME: would be good to have an .authoritative version of FM_AOUS_SPECIFIC_RETRIEVE */
75     var aous_req = network.simple_request('FM_AOUS_SPECIFIC_RETRIEVE',[ ses('ws_ou'), 'circ.staff_client.do_not_auto_attempt_print', ses() ]);
76     if (aous_req) {
77         append_to_vbox(
78             'current',
79             admin_string(
80                 'staff.admin.staff.do_not_auto_attempt_print_setting.current_setting_preamble',
81                 [ ses('ws_ou_shortname'), data.hash.aou[ aous_req.org ].shortname() ]
82             )
83         );
84
85         for (var i in aous_req.value) {
86             var label = document.createElement('label');
87             label.setAttribute('value', '   ' + aous_req.value[i]);
88             append_to_vbox('current',label);
89         }
90
91         /* update data.hash.aous while we have fresh data */
92
93         data.hash.aous['circ.staff_client.do_not_auto_attempt_print'] = aous_req.value;
94         data.stash('hash');
95
96     } else {
97         append_to_vbox(
98             'current',
99             admin_string(
100                 'staff.admin.staff.do_not_auto_attempt_print_setting.current_setting_nonexistent',
101                 [ ses('ws_ou_shortname') ]
102             )
103         );
104     }
105 }
106
107
108 function render_lib_menu() {
109     try {
110         JSAN.use('util.functional'); JSAN.use('util.fm_utils'); JSAN.use('util.widgets');
111
112         var work_ous = network.simple_request(
113             'PERM_RETRIEVE_WORK_OU',
114             [ ses(), 'ADMIN_ORG_UNIT_SETTING_TYPE']
115         );
116         if (work_ous.length == 0) {
117             return;
118         } else {
119             document.getElementById('apply').disabled = false;
120         }
121
122         var my_libs = [];
123         for (var i = 0; i < work_ous.length; i++ ) {
124             var perm_depth = data.hash.aout[ data.hash.aou[ work_ous[i] ].ou_type() ].depth();
125
126             var my_libs_tree = network.simple_request(
127                 'FM_AOU_DESCENDANTS_RETRIEVE',
128                 [ work_ous[i], perm_depth ]
129             );
130             if (!instanceOf(my_libs_tree,aou)) { /* FIXME - workaround for weird descendants call result */
131                 my_libs_tree = my_libs_tree[0];
132             }
133             my_libs = my_libs.concat( util.fm_utils.flatten_ou_branch( my_libs_tree ) );
134         }
135
136         var x = document.getElementById('menu');
137         util.widgets.remove_children( x );
138
139         var default_lib = my_libs[0].id();
140
141         var ml = util.widgets.make_menulist(
142             util.functional.map_list(
143                 my_libs,
144                 function(obj) {
145                     return [
146                         obj.shortname(),
147                         obj.id(),
148                         false,
149                         ( data.hash.aout[ obj.ou_type() ].depth() )
150                     ];
151                 }
152             ),
153             default_lib
154         );
155         ml.setAttribute('id','lib_menulist');
156
157         x.appendChild( ml );
158     } catch(E) {
159         alert('Error in do_not_auto_attempt_print_setting.js, render_lib_menu(): ' + E);
160     }
161 }