1 function penalty_init() {
3 commonStrings = document.getElementById('commonStrings');
4 patronStrings = document.getElementById('patronStrings');
6 if (typeof JSAN == 'undefined') {
8 commonStrings.getString('common.jsan.missing')
12 JSAN.errorLevel = "die"; // none, warn, or die
13 JSAN.addRepository('..');
15 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
16 XML_HTTP_SERVER = data.server_unadorned;
18 JSAN.use('util.error'); var error = new util.error();
19 JSAN.use('util.network'); var net = new util.network();
20 JSAN.use('patron.util'); JSAN.use('util.list'); JSAN.use('util.functional');
22 var list = new util.list( 'csp_list' );
25 'columns' : patron.util.csp_columns({}),
26 'map_row_to_columns' : patron.util.std_map_row_to_columns(),
27 'retrieve_row' : function(params) {
28 params.row_node.setAttribute('retrieve_id',params.row.my.csp.id());
29 if (params.row.my.ausp) { params.row_node.setAttribute('retrieve_ausp_id',params.row.my.ausp.id()); }
30 params.on_retrieve(params.row);
33 'on_select' : function(ev) {
34 var sel = list.retrieve_selection();
35 var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } );
36 var ausp_ids = util.functional.filter_list(
37 util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_ausp_id') || 'null' ); } ),
38 function(o) { return o != null; }
41 document.getElementById('cmd_apply_penalty').setAttribute('disabled','false');
43 document.getElementById('cmd_apply_penalty').setAttribute('disabled','true');
45 if (ausp_ids.length > 0) {
46 document.getElementById('cmd_remove_penalty').setAttribute('disabled','false');
48 document.getElementById('cmd_remove_penalty').setAttribute('disabled','true');
54 for (var i = 0; i < data.list.csp.length; i++) {
55 if (data.list.csp[i].id() > 100 ) {
61 'csp' : data.list.csp[i],
63 'ausp' : util.functional.find_list( xulG.patron.standing_penalties(), function(o) { return o.standing_penalty().id() == data.list.csp[i].id(); } )
71 document.getElementById('cmd_apply_penalty').addEventListener(
74 var sel = list.retrieve_selection();
75 var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } );
78 var note = window.prompt(patronStrings.getString('staff.patron.standing_penalty.note_prompt'),'',patronStrings.getString('staff.patron.standing_penalty.note_title'));
80 function gen_func(id) {
82 var penalty = new ausp();
83 penalty.usr( xulG.patron.id() );
85 penalty.standing_penalty( id );
86 penalty.org_unit( ses('ws_ou') );
88 var req = net.simple_request( 'FM_AUSP_APPLY', [ ses(), penalty ] );
89 if (typeof req.ilsevent != 'undefined' || String(req) != '1') {
90 error.standard_unexpected_error_alert(patronStrings.getFormattedString('staff.patron.standing_penalty.apply_error',[data.hash.csp[id].name()]),req);
96 for (var i = 0; i < ids.length; i++) {
97 funcs.push( gen_func(ids[i]) );
101 if (xulG && typeof xulG.refresh == 'function') {
104 document.getElementById('progress').hidden = true;
107 document.getElementById('progress').hidden = false;
108 JSAN.use('util.exec'); var exec = new util.exec();
115 document.getElementById('cmd_remove_penalty').addEventListener(
118 var sel = list.retrieve_selection();
119 var ids = util.functional.filter_list(
120 util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_ausp_id') || 'null' ); } ),
121 function(o) { return o != null; }
123 if (ids.length > 0) {
124 function gen_func(id) {
126 var penalty = util.functional.find_list( xulG.patron.standing_penalties(), function(o) { return o.id() == id; } );
127 penalty.isdeleted(1);
129 var req = net.simple_request( 'FM_AUSP_REMOVE', [ ses(), penalty ] );
130 if (typeof req.ilsevent != 'undefined' || String(req) != '1') {
131 error.standard_unexpected_error_alert(patronStrings.getFormattedString('staff.patron.standing_penalty.remove_error',[data.hash.csp[id].name()]),req);
137 for (var i = 0; i < ids.length; i++) {
138 funcs.push( gen_func(ids[i]) );
142 if (xulG && typeof xulG.refresh == 'function') {
145 document.getElementById('progress').hidden = true;
148 document.getElementById('progress').hidden = false;
149 JSAN.use('util.exec'); var exec = new util.exec();