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.ausp_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.ausp.id());
29 params.on_retrieve(params.row);
32 'on_select' : function(ev) {
33 var sel = list.retrieve_selection();
34 var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } );
36 document.getElementById('cmd_remove_penalty').setAttribute('disabled','false');
38 document.getElementById('cmd_remove_penalty').setAttribute('disabled','true');
45 for (var i = 0; i < xulG.patron.standing_penalties().length; i++) {
49 'ausp' : xulG.patron.standing_penalties()[i],
50 'csp' : xulG.patron.standing_penalties()[i].standing_penalty(),
55 rows[ xulG.patron.standing_penalties()[i].id() ] = list.append( row_params );
58 document.getElementById('cmd_apply_penalty').addEventListener(
61 var sel = list.retrieve_selection();
62 var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } );
65 var note = window.prompt(patronStrings.getString('staff.patron.standing_penalty.note_prompt'),'',patronStrings.getString('staff.patron.standing_penalty.note_title'));
67 function gen_func(id) {
69 var penalty = new ausp();
70 penalty.usr( xulG.patron.id() );
72 penalty.standing_penalty( id );
73 penalty.org_unit( ses('ws_ou') );
75 var req = net.simple_request( 'FM_AUSP_APPLY', [ ses(), penalty ] );
76 if (typeof req.ilsevent != 'undefined') {
77 error.standard_unexpected_error_alert(patronStrings.getFormattedString('staff.patron.standing_penalty.apply_error',[data.hash.csp[id].name()]),req);
83 for (var i = 0; i < ids.length; i++) {
84 funcs.push( gen_func(ids[i]) );
88 if (xulG && typeof xulG.refresh == 'function') {
91 document.getElementById('progress').hidden = true;
94 document.getElementById('progress').hidden = false;
95 JSAN.use('util.exec'); var exec = new util.exec();
102 document.getElementById('cmd_remove_penalty').addEventListener(
105 var sel = list.retrieve_selection();
106 var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } );
107 if (ids.length > 0) {
108 function gen_func(id) {
111 var penalty = util.functional.find_list( xulG.patron.standing_penalties(), function(o) { return o.id() == id; } );
112 penalty.isdeleted(1);
114 var req = net.simple_request( 'FM_AUSP_REMOVE', [ ses(), penalty ] );
115 if (typeof req.ilsevent != 'undefined' || String(req) != '1') {
116 error.standard_unexpected_error_alert(patronStrings.getFormattedString('staff.patron.standing_penalty.remove_error',[id]),req);
118 var node = rows[ id ].my_node;
119 var parentNode = node.parentNode;
120 parentNode.removeChild( node );
130 for (var i = 0; i < ids.length; i++) {
131 funcs.push( gen_func(ids[i]) );
135 if (xulG && typeof xulG.refresh == 'function') {
138 document.getElementById('progress').hidden = true;
141 document.getElementById('progress').hidden = false;
142 JSAN.use('util.exec'); var exec = new util.exec();