]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/edit_standing_penalty.js
Staff initials for standing penalties. Looks for org setting ui.circ.standing_penalt...
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / edit_standing_penalty.js
1 var data; var error; 
2
3 function default_focus() { document.getElementById('note_tb').focus(); } // parent interfaces often call this
4
5 function edit_penalty_init() {
6     try {
7
8         commonStrings = document.getElementById('commonStrings');
9         patronStrings = document.getElementById('patronStrings');
10
11         if (typeof JSAN == 'undefined') {
12             throw(
13                 commonStrings.getString('common.jsan.missing')
14             );
15         }
16
17         JSAN.errorLevel = "die"; // none, warn, or die
18         JSAN.addRepository('..');
19
20                 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
21
22         JSAN.use('util.error'); error = new util.error();
23         JSAN.use('util.widgets');
24
25         build_penalty_menu();
26
27         var show_initials = String( data.hash.aous['ui.circ.standing_penalty.require_initials'] ) == 'true';
28         if (show_initials) {
29             document.getElementById('initials_box').hidden = false;
30         }
31
32         /* set widget values */
33         document.getElementById('csp_menupopup').setAttribute('value',xul_param('id',{'modal_xulG':true}));
34         if (xul_param('id',{'modal_xulG':true})==21) { // SILENT_NOTE
35             document.getElementById('note_btn').checked = true;
36         } else if (xul_param('id',{'modal_xulG':true})==20) { // ALERT_NOTE
37             document.getElementById('alert_btn').checked = true;
38         } else if (xul_param('id',{'modal_xulG':true})==25) { // STAFF_CHR
39             document.getElementById('block_btn').checked = true;
40         } else {
41             var nl = document.getElementById('csp_menupopup').getElementsByAttribute('value',xul_param('id',{'modal_xulG':true}));
42             if (nl.length > 0) {
43                 document.getElementById('csp_menulist').setAttribute('label', nl[0].getAttribute('label'));
44             } else {
45                 document.getElementById('csp_menulist').setAttribute('label', '???');
46             }
47         }
48
49         /* set widget behavior */
50         document.getElementById('csp_menulist').addEventListener(
51             'command',
52             function() {
53                 document.getElementById('note_btn').checked = false;
54                 document.getElementById('alert_btn').checked = false;
55                 document.getElementById('block_btn').checked = false;
56             },
57             false
58         );
59         document.getElementById('note_btn').addEventListener(
60             'command', 
61             function() { 
62                 document.getElementById('csp_menulist').setAttribute('label',''); 
63                 document.getElementById('csp_menupopup').setAttribute('value','21'); // SILENT_NOTE
64             }, 
65             false
66         );
67         document.getElementById('alert_btn').addEventListener(
68             'command', 
69             function() { 
70                 document.getElementById('csp_menulist').setAttribute('label',''); 
71                 document.getElementById('csp_menupopup').setAttribute('value','20'); // ALERT_NOTE
72             }, 
73             false
74         );
75         document.getElementById('block_btn').addEventListener(
76             'command', 
77             function() { 
78                 document.getElementById('csp_menulist').setAttribute('label',''); 
79                 document.getElementById('csp_menupopup').setAttribute('value','25'); // STAFF_CHR
80             }, 
81             false
82         );
83         document.getElementById('cancel_btn').addEventListener(
84             'command', function() { window.close(); }, false
85         );
86         document.getElementById('apply_btn').addEventListener(
87             'command', 
88             function() {
89                 var note = document.getElementById('note_tb').value;
90                 if (!document.getElementById('initials_box').hidden) {
91                     var initials_tb = document.getElementById('initials_tb');
92                     if (initials_tb.value == '') {
93                         initials_tb.focus(); return;
94                     } else {
95                         note = note + ' - ' + initials_tb.value;
96                     }
97                 }
98                 update_modal_xulG(
99                     {
100                         'id' : document.getElementById('csp_menupopup').getAttribute('value'),
101                         'note' : note,
102                         'modify' : 1
103                     }
104                 )
105                 window.close();
106             }, 
107             false
108         );
109         default_focus();
110
111     } catch(E) {
112         var err_prefix = 'standing_penalties.js -> penalty_init() : ';
113         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
114     }
115
116 }
117
118 function build_penalty_menu() {
119     try {
120
121         var csp_menupopup = document.getElementById('csp_menupopup');
122         util.widgets.remove_children(csp_menupopup);
123         for (var i = 0; i < data.list.csp.length; i++) {
124             if (data.list.csp[i].id() > 100) {
125                 var menuitem = document.createElement('menuitem'); csp_menupopup.appendChild(menuitem);
126                 menuitem.setAttribute('label',data.list.csp[i].label());
127                 menuitem.setAttribute('value',data.list.csp[i].id());
128                 menuitem.setAttribute('id','csp_'+data.list.csp[i].id());
129                 menuitem.setAttribute('oncommand',"var p = this.parentNode; p.parentNode.setAttribute('label',this.getAttribute('label')); p.setAttribute('value'," + data.list.csp[i].id() + ")");
130             }
131         }
132
133     } catch(E) {
134         var err_prefix = 'edit_standing_penalty.js -> build_penalty_menu() : ';
135         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
136     }
137 }
138