]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/new_standing_penalty.js
Add granular settings for requiring staff initials for notes
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / new_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 new_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.staff.require_initials.patron_standing_penalty'] ) == 'true';
28         if (show_initials) {
29             document.getElementById('initials_box').hidden = false;
30         }
31
32         /* set widget behavior */
33         window.new_standing_penalty_event_listeners = new EventListenerList();
34         window.new_standing_penalty_event_listeners.add(document.getElementById('csp_menulist'), 
35             'command',
36             function() {
37                 document.getElementById('note_btn').checked = false;
38                 document.getElementById('alert_btn').checked = false;
39                 document.getElementById('block_btn').checked = false;
40             },
41             false
42         );
43         window.new_standing_penalty_event_listeners.add(document.getElementById('note_btn'), 
44             'command', 
45             function() { 
46                 document.getElementById('csp_menulist').setAttribute('label',''); 
47                 document.getElementById('csp_menupopup').setAttribute('value','21'); // SILENT_NOTE
48             }, 
49             false
50         );
51         window.new_standing_penalty_event_listeners.add(document.getElementById('alert_btn'), 
52             'command', 
53             function() { 
54                 document.getElementById('csp_menulist').setAttribute('label',''); 
55                 document.getElementById('csp_menupopup').setAttribute('value','20'); // ALERT_NOTE
56             }, 
57             false
58         );
59         window.new_standing_penalty_event_listeners.add(document.getElementById('block_btn'), 
60             'command', 
61             function() { 
62                 document.getElementById('csp_menulist').setAttribute('label',''); 
63                 document.getElementById('csp_menupopup').setAttribute('value','25'); // STAFF_CHR
64             }, 
65             false
66         );
67         window.new_standing_penalty_event_listeners.add(document.getElementById('cancel_btn'), 
68             'command', function() { window.close(); }, false
69         );
70         window.new_standing_penalty_event_listeners.add(document.getElementById('apply_btn'), 
71             'command', 
72             function() {
73                 var note = document.getElementById('note_tb').value;
74                 if (!document.getElementById('initials_box').hidden) {
75                     var initials_tb = document.getElementById('initials_tb');
76                     if (initials_tb.value == '') {
77                         initials_tb.focus(); return;
78                     } else {
79                         JSAN.use('util.date');
80                         note = note + commonStrings.getFormattedString('staff.initials.format',[initials_tb.value,util.date.formatted_date(new Date(),'%F'), ses('ws_ou_shortname')]);
81                     }
82                 }
83                 xulG.id = document.getElementById('csp_menupopup').getAttribute('value');
84                 xulG.note = note;
85                 xulG.modify = 1;
86                 window.close();
87             }, 
88             false
89         );
90
91         default_focus();
92
93     } catch(E) {
94         var err_prefix = 'standing_penalties.js -> penalty_init() : ';
95         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
96     }
97
98 }
99
100 function new_penalty_cleanup() {
101     try {
102         window.new_standing_penalty_event_listeners.removeAll();
103     } catch(E) {
104         var err_prefix = 'standing_penalties.js -> penalty_cleanup() : ';
105         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
106     }
107
108 }
109
110 function build_penalty_menu() {
111     try {
112
113         var csp_menupopup = document.getElementById('csp_menupopup');
114         util.widgets.remove_children(csp_menupopup);
115         for (var i = 0; i < data.list.csp.length; i++) {
116             if (data.list.csp[i].id() > 100) {
117                 var menuitem = document.createElement('menuitem'); csp_menupopup.appendChild(menuitem);
118                 menuitem.setAttribute('label',data.list.csp[i].label());
119                 menuitem.setAttribute('value',data.list.csp[i].id());
120                 menuitem.setAttribute('id','csp_'+data.list.csp[i].id());
121                 menuitem.setAttribute('oncommand',"var p = this.parentNode; p.parentNode.setAttribute('label',this.getAttribute('label')); p.setAttribute('value'," + data.list.csp[i].id() + ")");
122             }
123         }
124
125     } catch(E) {
126         var err_prefix = 'new_standing_penalty.js -> build_penalty_menu() : ';
127         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
128     }
129 }
130