]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/admin/do_not_auto_attempt_print_setting.js
liberate this perm-cognizant lib menu generator
[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         var ml = util.widgets.render_perm_org_menu('ADMIN_ORG_UNIT_SETTING_TYPE');
32         if (ml) {
33             document.getElementById('apply').disabled = false;
34             ml.setAttribute('id','lib_menulist');
35             var x = document.getElementById('menu');
36             util.widgets.remove_children(x);
37             x.appendChild(ml);
38         }
39
40     } catch(E) {
41         try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
42     }
43 }
44
45 function append_to_vbox(id,node) {
46     if (typeof node == 'string') { var text = document.createTextNode(node); node = document.createElement('description'); node.appendChild(text); }
47     document.getElementById(id).appendChild(node);
48 }
49
50 function admin_string(s,p) {
51     var mc = document.getElementById('adminStrings');
52     if (p) {
53         return mc.getFormattedString(s,p);
54     } else {
55         return mc.getString(s);
56     }
57 }
58
59 function apply_setting(ev) {
60     var values = [];
61     if (document.getElementById('checkout').checked) { values.push('Checkout'); }
62     if (document.getElementById('bill_pay').checked) { values.push('Bill Pay'); }
63     if (document.getElementById('hold_slip').checked) { values.push('Hold Slip'); }
64     if (document.getElementById('transit_slip').checked) { values.push('Transit Slip'); }
65     if (document.getElementById('hold_transit_slip').checked) { values.push('Hold/Transit Slip'); }
66     var org = document.getElementById('lib_menulist').value;
67     var result = network.simple_request('FM_AOUS_UPDATE',[ ses(), org, { 'circ.staff_client.do_not_auto_attempt_print' : values } ]);
68     if (result == 1) {
69         alert(admin_string('staff.admin.staff.do_not_auto_attempt_print_setting.update_success'));
70         render_current_setting();
71     } else {
72         error.standard_unexpected_error_alert(admin_string('staff.admin.staff.do_not_auto_attempt_print_setting.update_failure'),result);
73     }
74 }
75
76 function render_current_setting() {
77     JSAN.use('util.widgets');
78
79     util.widgets.remove_children('current');
80
81     /* FIXME: would be good to have an .authoritative version of FM_AOUS_SPECIFIC_RETRIEVE */
82     var aous_req = network.simple_request('FM_AOUS_SPECIFIC_RETRIEVE',[ ses('ws_ou'), 'circ.staff_client.do_not_auto_attempt_print', ses() ]);
83     if (aous_req) {
84         append_to_vbox(
85             'current',
86             admin_string(
87                 'staff.admin.staff.do_not_auto_attempt_print_setting.current_setting_preamble',
88                 [ ses('ws_ou_shortname'), data.hash.aou[ aous_req.org ].shortname() ]
89             )
90         );
91
92         for (var i in aous_req.value) {
93             var label = document.createElement('label');
94             label.setAttribute('value', '   ' + aous_req.value[i]);
95             append_to_vbox('current',label);
96         }
97
98         /* update data.hash.aous while we have fresh data */
99
100         data.hash.aous['circ.staff_client.do_not_auto_attempt_print'] = aous_req.value;
101         data.stash('hash');
102
103     } else {
104         append_to_vbox(
105             'current',
106             admin_string(
107                 'staff.admin.staff.do_not_auto_attempt_print_setting.current_setting_nonexistent',
108                 [ ses('ws_ou_shortname') ]
109             )
110         );
111     }
112 }
113
114
115