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