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