From a4a94bb0fd0836b239ddc68abf89ebefe8128e85 Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 5 Jan 2009 06:48:06 +0000 Subject: [PATCH] remove standing penalties git-svn-id: svn://svn.open-ils.org/ILS/trunk@11736 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Actor.pm | 15 +++++ .../chrome/content/main/constants.js | 1 + .../server/locale/en-US/patron.properties | 1 + .../xul/staff_client/server/patron/display.js | 1 + .../server/patron/standing_penalties.js | 60 ++++++++++++++++++- .../xul/staff_client/server/patron/summary.js | 46 ++++++++++++-- 6 files changed, 116 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index e58eec7700..a9614faaf6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -2754,6 +2754,21 @@ sub apply_penalty { return 1; } +__PACKAGE__->register_method( + method => "remove_penalty", + api_name => "open-ils.actor.user.penalty.remove"); + +sub remove_penalty { + my($self, $conn, $auth, $penalty) = @_; + my $e = new_editor(authtoken=>$auth, xact => 1); + return $e->die_event unless $e->checkauth; + my $user = $e->retrieve_actor_user($penalty->usr) or return $e->die_event; + return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou); + + $e->delete_actor_user_standing_penalty($penalty) or return $e->die_event; + $e->commit; + return 1; +} __PACKAGE__->register_method( method => "ranged_penalty_thresholds", diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 1fe5fe35e7..1eb445253f 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -133,6 +133,7 @@ const api = { 'FM_AUS_RETRIEVE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.patron.settings.retrieve' }, 'FM_AUS_UPDATE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.patron.settings.update' }, 'FM_AUSP_APPLY' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.penalty.apply' }, + 'FM_AUSP_REMOVE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.penalty.remove' }, 'FM_BRE_RETRIEVE_VIA_ID' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.biblio.record.metadata.retrieve', 'secure' : false }, 'FM_BRE_RETRIEVE_VIA_ID.authoritative' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.biblio.record.metadata.retrieve.authoritative', 'secure' : false }, 'FM_BRE_ID_SEARCH_VIA_BARCODE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.biblio.find_by_barcode', 'secure' : false }, diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties index 29ce617d00..c14d8dbe16 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties @@ -245,6 +245,7 @@ staff.patron.summary.standing_penalty.remove=Remove staff.patron.standing_penalty.note_prompt=Enter note to go with penalties: staff.patron.standing_penalty.note_title=Apply Penalty staff.patron.standing_penalty.apply_error=Error applying %1$s block/standing penalty. +staff.patron.standing_penalty.remove_error=Error removing %1$s block/standing penalty. staff.patron.ue.uEditInit.session_no_defined=User session is not defined staff.patron.ue.uEditSaveuser.error_creating_note=Error creating patron guardian or parent note staff.patron.ue.uEditShowSearch.search=Search would be:\n%1$s diff --git a/Open-ILS/xul/staff_client/server/patron/display.js b/Open-ILS/xul/staff_client/server/patron/display.js index a8066f83e3..1b47830add 100644 --- a/Open-ILS/xul/staff_client/server/patron/display.js +++ b/Open-ILS/xul/staff_client/server/patron/display.js @@ -410,6 +410,7 @@ patron.display.prototype = { { 'barcode' : obj.barcode, 'id' : obj.id, + 'refresh' : function() { obj.refresh_all(); }, 'on_finished' : function(patron) { obj.patron = patron; obj.controller.render(); diff --git a/Open-ILS/xul/staff_client/server/patron/standing_penalties.js b/Open-ILS/xul/staff_client/server/patron/standing_penalties.js index 35db818a4e..33ee046a19 100644 --- a/Open-ILS/xul/staff_client/server/patron/standing_penalties.js +++ b/Open-ILS/xul/staff_client/server/patron/standing_penalties.js @@ -24,15 +24,27 @@ function penalty_init() { { 'columns' : patron.util.csp_columns({}), 'map_row_to_columns' : patron.util.std_map_row_to_columns(), - 'retrieve_row' : function(params) { params.row_node.setAttribute('retrieve_id',params.row.my.csp.id()); params.on_retrieve(params.row); return params.row; }, + 'retrieve_row' : function(params) { + params.row_node.setAttribute('retrieve_id',params.row.my.csp.id()); + if (params.row.my.ausp) { params.row_node.setAttribute('retrieve_ausp_id',params.row.my.ausp.id()); } + params.on_retrieve(params.row); + return params.row; + }, 'on_select' : function(ev) { var sel = list.retrieve_selection(); var ids = util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_id') ); } ); + var ausp_ids = util.functional.filter_list( + util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_ausp_id') || 'null' ); } ), + function(o) { return o != null; } + ); if (ids.length > 0) { document.getElementById('cmd_apply_penalty').setAttribute('disabled','false'); - document.getElementById('cmd_remove_penalty').setAttribute('disabled','false'); } else { document.getElementById('cmd_apply_penalty').setAttribute('disabled','true'); + } + if (ausp_ids.length > 0) { + document.getElementById('cmd_remove_penalty').setAttribute('disabled','false'); + } else { document.getElementById('cmd_remove_penalty').setAttribute('disabled','true'); } } @@ -48,7 +60,7 @@ function penalty_init() { 'my' : { 'csp' : data.list.csp[i], 'au' : xulG.patron, - 'ausp' : util.functional.find_list( xulG.patron.standing_penalties(), function(o) { dump(js2JSON(o) + '\n'); return o.standing_penalty().id() == data.list.csp[i].id(); } ) + 'ausp' : util.functional.find_list( xulG.patron.standing_penalties(), function(o) { return o.standing_penalty().id() == data.list.csp[i].id(); } ) } } } @@ -100,6 +112,48 @@ function penalty_init() { false ); + document.getElementById('cmd_remove_penalty').addEventListener( + 'command', + function() { + var sel = list.retrieve_selection(); + var ids = util.functional.filter_list( + util.functional.map_list( sel, function(o) { return JSON2js( o.getAttribute('retrieve_ausp_id') || 'null' ); } ), + function(o) { return o != null; } + ); + if (ids.length > 0) { + function gen_func(id) { + return function() { + var penalty = util.functional.find_list( xulG.patron.standing_penalties(), function(o) { return o.id() == id; } ); + penalty.isdeleted(1); + + var req = net.simple_request( 'FM_AUSP_REMOVE', [ ses(), penalty ] ); + if (typeof req.ilsevent != 'undefined' || String(req) != '1') { + error.standard_unexpected_error_alert(patronStrings.getFormattedString('staff.patron.standing_penalty.remove_error',[data.hash.csp[id].name()]),req); + } + }; + } + + var funcs = []; + for (var i = 0; i < ids.length; i++) { + funcs.push( gen_func(ids[i]) ); + } + funcs.push( + function() { + if (xulG && typeof xulG.refresh == 'function') { + xulG.refresh(); + } + document.getElementById('progress').hidden = true; + } + ); + document.getElementById('progress').hidden = false; + JSAN.use('util.exec'); var exec = new util.exec(); + exec.chain(funcs); + } + }, + false + ); + + } catch(E) { alert(E); } diff --git a/Open-ILS/xul/staff_client/server/patron/summary.js b/Open-ILS/xul/staff_client/server/patron/summary.js index e5ba811c95..3f1be5d53e 100644 --- a/Open-ILS/xul/staff_client/server/patron/summary.js +++ b/Open-ILS/xul/staff_client/server/patron/summary.js @@ -1,6 +1,7 @@ dump('entering patron.summary.js\n'); function $(id) { return document.getElementById(id); } +var patronStrings = $('patronStrings'); if (typeof patron == 'undefined') patron = {}; patron.summary = function (params) { @@ -79,7 +80,7 @@ patron.summary.prototype = { function(e) { return function() { e.setAttribute('value', - $("patronStrings").getString('staff.patron.summary.patron_net_access') + + patronStrings.getString('staff.patron.summary.patron_net_access') + ' ' + obj.OpenILS.data.hash.cnal[ obj.patron.net_access_level() ].name() @@ -104,14 +105,49 @@ patron.summary.prototype = { row.appendChild(label); var button = document.createElement('button'); - button.setAttribute('label', $("patronStrings").getString('staff.patron.summary.standing_penalty.remove')); + button.setAttribute('label', patronStrings.getString('staff.patron.summary.standing_penalty.remove')); button.setAttribute('image','/xul/server/skin/media/images/icon_delete.gif'); button.setAttribute('disabled','true'); + button.setAttribute('hidden','true'); + button.setAttribute('retrieve_ausp_id',penalties[i].id()); row.appendChild(button); // XXX check a permission here? How to fire the remove action ??? XXX if (penalties[i].standing_penalty().id() > 100) { button.setAttribute('disabled','false'); + button.setAttribute('hidden','false'); + button.addEventListener( + 'command', + function(ev) { + try { + JSAN.use('util.functional'); + var id = ev.target.getAttribute('retrieve_ausp_id'); + var penalty = util.functional.find_list( obj.patron.standing_penalties(), function(o) { return o.id() == id; } ); + penalty.isdeleted(1); + + var req = obj.network.simple_request( 'FM_AUSP_REMOVE', [ ses(), penalty ] ); + if (typeof req.ilsevent != 'undefined' || String(req) != '1') { + obj.error.standard_unexpected_error_alert( + patronStrings.getFormattedString( + 'staff.patron.standing_penalty.remove_error', + [obj.data.hash.csp[id].name()] + ), + req + ); + } + if (typeof xulG.refresh == 'function') { xulG.refresh(); } + } catch(F) { + obj.error.standard_unexpected_error_alert( + patronStrings.getFormattedString( + 'staff.patron.standing_penalty.remove_error', + [ev.target.getAttribute('retrieve_ausp_id')] + ), + F + ); + } + }, + false + ); } if (penalties[i].standing_penalty().block_list()) { @@ -151,7 +187,7 @@ patron.summary.prototype = { function(req) { JSAN.use('util.money'); var robj = req.getResultObject(); - e.setAttribute('value', $("patronStrings").getFormattedString('staff.patron.summary.patron_bill.money', [util.money.sanitize( robj.balance_owed() )])); + e.setAttribute('value', patronStrings.getFormattedString('staff.patron.summary.patron_bill.money', [util.money.sanitize( robj.balance_owed() )])); } ); /* @@ -319,7 +355,7 @@ patron.summary.prototype = { function(e) { return function() { e.setAttribute('value', - $("patronStrings").getString('staff.patron.summary.expires_on') + ' ' + ( + patronStrings.getString('staff.patron.summary.expires_on') + ' ' + ( obj.patron.expire_date() ? obj.patron.expire_date().substr(0,10) : '' @@ -609,7 +645,7 @@ patron.summary.prototype = { [ ses(), obj.id ] ); } else { - throw($("patronStrings").getString('staff.patron.summary.retrieve.no_barcode')); + throw(patronStrings.getString('staff.patron.summary.retrieve.no_barcode')); } if (robj) { -- 2.43.2