]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/edit_standing_penalty.js
fix some indentation from the great tab to space conversion
[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('note_tb').value = xul_param('note',{'modal_xulG':true});
34         document.getElementById('csp_menupopup').setAttribute('value',xul_param('id',{'modal_xulG':true}));
35         if (xul_param('id',{'modal_xulG':true})==21) { // SILENT_NOTE
36             document.getElementById('note_btn').checked = true;
37         } else if (xul_param('id',{'modal_xulG':true})==20) { // ALERT_NOTE
38             document.getElementById('alert_btn').checked = true;
39         } else if (xul_param('id',{'modal_xulG':true})==25) { // STAFF_CHR
40             document.getElementById('block_btn').checked = true;
41         } else {
42             var nl = document.getElementById('csp_menupopup').getElementsByAttribute('value',xul_param('id',{'modal_xulG':true}));
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         document.getElementById('csp_menulist').addEventListener(
52             'command',
53             function() {
54                 document.getElementById('note_btn').checked = false;
55                 document.getElementById('alert_btn').checked = false;
56                 document.getElementById('block_btn').checked = false;
57             },
58             false
59         );
60         document.getElementById('note_btn').addEventListener(
61             'command', 
62             function() { 
63                 document.getElementById('csp_menulist').setAttribute('label',''); 
64                 document.getElementById('csp_menupopup').setAttribute('value','21'); // SILENT_NOTE
65             }, 
66             false
67         );
68         document.getElementById('alert_btn').addEventListener(
69             'command', 
70             function() { 
71                 document.getElementById('csp_menulist').setAttribute('label',''); 
72                 document.getElementById('csp_menupopup').setAttribute('value','20'); // ALERT_NOTE
73             }, 
74             false
75         );
76         document.getElementById('block_btn').addEventListener(
77             'command', 
78             function() { 
79                 document.getElementById('csp_menulist').setAttribute('label',''); 
80                 document.getElementById('csp_menupopup').setAttribute('value','25'); // STAFF_CHR
81             }, 
82             false
83         );
84         document.getElementById('cancel_btn').addEventListener(
85             'command', function() { window.close(); }, false
86         );
87         document.getElementById('apply_btn').addEventListener(
88             'command', 
89             function() {
90                 var note = document.getElementById('note_tb').value;
91                 if (!document.getElementById('initials_box').hidden) {
92                     var initials_tb = document.getElementById('initials_tb');
93                     if (initials_tb.value == '') {
94                         initials_tb.focus(); return;
95                     } else {
96                         note = note + ' - ' + initials_tb.value;
97                     }
98                 }
99                 update_modal_xulG(
100                     {
101                         'id' : document.getElementById('csp_menupopup').getAttribute('value'),
102                         'note' : note,
103                         'modify' : 1
104                     }
105                 )
106                 window.close();
107             }, 
108             false
109         );
110         default_focus();
111
112     } catch(E) {
113         var err_prefix = 'standing_penalties.js -> penalty_init() : ';
114         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
115     }
116
117 }
118
119 function build_penalty_menu() {
120     try {
121
122         var csp_menupopup = document.getElementById('csp_menupopup');
123         util.widgets.remove_children(csp_menupopup);
124         for (var i = 0; i < data.list.csp.length; i++) {
125             if (data.list.csp[i].id() > 100) {
126                 var menuitem = document.createElement('menuitem'); csp_menupopup.appendChild(menuitem);
127                 menuitem.setAttribute('label',data.list.csp[i].label());
128                 menuitem.setAttribute('value',data.list.csp[i].id());
129                 menuitem.setAttribute('id','csp_'+data.list.csp[i].id());
130                 menuitem.setAttribute('oncommand',"var p = this.parentNode; p.parentNode.setAttribute('label',this.getAttribute('label')); p.setAttribute('value'," + data.list.csp[i].id() + ")");
131             }
132         }
133
134     } catch(E) {
135         var err_prefix = 'edit_standing_penalty.js -> build_penalty_menu() : ';
136         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
137     }
138 }
139