From d248d735716a0b9ea053cf558ae6d690b727422e Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 3 Feb 2006 20:03:39 +0000 Subject: [PATCH] user stat cats in the user editor git-svn-id: svn://svn.open-ils.org/ILS/trunk@2964 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Actor.pm | 15 +-- .../OpenILS/Application/Circ/StatCat.pm | 33 ++++++ .../Application/Storage/Publisher/actor.pm | 43 ++++++- .../staff_client/server/patron/user_edit.js | 109 +++++++++++++++++- .../staff_client/server/patron/user_edit.xml | 31 ++++- 5 files changed, 217 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 7d5dc2490a..31ac9d1170 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -622,14 +622,15 @@ sub _create_stat_maps { for my $map (@$maps) { - next unless($map->isnew() || $map->ischanged()); - my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update"; - if($map->isnew()) { + if ($map->isdeleted()) { + $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.delete"; + } elsif ($map->isnew()) { $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.create"; $map->clear_id; } + $map->target_usr($new_patron->id); #warn "Updating stat entry with method $method and session $user_session and map $map\n"; @@ -637,10 +638,10 @@ sub _create_stat_maps { my $req = $session->request($method, $map); my $status = $req->gather(1); - if( $map->isnew() and !$status) { - throw OpenSRF::EX::ERROR - ("Error creating permission map with method $method"); - } + #if(!$map->ischanged && !$status) { + # throw OpenSRF::EX::ERROR + # ("Error handling stat_cat map with method $method"); + #} } return $new_patron; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm index a14bd6fdd7..f7e912154b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm @@ -24,6 +24,39 @@ my $apputils = "OpenILS::Application::AppUtils"; +__PACKAGE__->register_method( + method => "retrieve_stat_cat_list", + argc => 1, + api_name => "open-ils.circ.stat_cat.actor.retrieve.batch"); + +__PACKAGE__->register_method( + method => "retrieve_stat_cat_list", + argc => 1, + api_name => "open-ils.circ.stat_cat.asset.retrieve.batch"); + +# retrieves all of the stat cats for a given org unit +# if no orgid, user_session->home_ou is used + +sub retrieve_stat_cat_list { + my( $self, $client, $user_session, @sc ) = @_; + + if (ref($sc[0])) { + @sc = @{$sc[0]}; + } + + my $method = "open-ils.storage.fleshed.actor.stat_cat.retrieve.batch.atomic"; + if( $self->api_name =~ /asset/ ) { + $method = "open-ils.storage.fleshed.asset.stat_cat.retrieve.batch.atomic"; + } + + my $user_obj = $apputils->check_user_session($user_session); + + my $cats = $apputils->simple_scalar_request( + "open-ils.storage", $method, @sc); + + return [ sort { $a->name cmp $b->name } @$cats ]; +} + __PACKAGE__->register_method( method => "retrieve_stat_cats", api_name => "open-ils.circ.stat_cat.actor.retrieve.all"); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm index 40e94b766f..7c22a91e2d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -350,8 +350,43 @@ __PACKAGE__->register_method( stream => 1, ); +sub fleshed_actor_stat_cat { + my $self = shift; + my $client = shift; + my @list = @_; + + @list = ($list[0]) unless ($self->api_name =~ /batch$/o); + + for my $sc (@list) { + my $cat = actor::stat_cat->retrieve($sc); + next unless ($cat); + + my $sc_fm = $cat->to_fieldmapper; + $sc_fm->entries( [ map { $_->to_fieldmapper } $cat->entries ] ); + + $client->respond( $sc_fm ); + + } + + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.fleshed.actor.stat_cat.retrieve', + api_level => 1, + argc => 1, + method => 'fleshed_actor_stat_cat', +); + +__PACKAGE__->register_method( + api_name => 'open-ils.storage.fleshed.actor.stat_cat.retrieve.batch', + api_level => 1, + argc => 1, + stream => 1, + method => 'fleshed_actor_stat_cat', +); + #XXX Fix stored proc calls -sub ranged_actor_stat_cat { +sub ranged_actor_stat_cat_all { my $self = shift; my $client = shift; my $ou = ''.shift(); @@ -385,15 +420,17 @@ sub ranged_actor_stat_cat { __PACKAGE__->register_method( api_name => 'open-ils.storage.ranged.fleshed.actor.stat_cat.all', api_level => 1, + argc => 1, stream => 1, - method => 'ranged_actor_stat_cat', + method => 'ranged_actor_stat_cat_all', ); __PACKAGE__->register_method( api_name => 'open-ils.storage.ranged.actor.stat_cat.all', api_level => 1, + argc => 1, stream => 1, - method => 'ranged_actor_stat_cat', + method => 'ranged_actor_stat_cat_all', ); #XXX Fix stored proc calls diff --git a/Open-ILS/xul/staff_client/server/patron/user_edit.js b/Open-ILS/xul/staff_client/server/patron/user_edit.js index 78ed5709e6..5bbb477bcc 100644 --- a/Open-ILS/xul/staff_client/server/patron/user_edit.js +++ b/Open-ILS/xul/staff_client/server/patron/user_edit.js @@ -84,7 +84,7 @@ function clear_alert_message () { function save_user () { user.ischanged(1); - //alert( js2JSON(user)); + alert( js2JSON(user.stat_cat_entries()) ); //return false; try { @@ -165,6 +165,8 @@ function save_user () { alert( js2JSON( e )) }; + + return false; } @@ -473,9 +475,114 @@ function init_editor (u) { for (var i in perm_list) display_perm(f,perm_list[i],staff_perms); + + req = new RemoteRequest( 'open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all', ses_id, user.home_ou() ); + req.send(true); + var sc_list = req.getResultObject(); + + var missing_scs = []; + for (var i in user.stat_cat_entries()) { + var found = 0; + for (var j in sc_list) { + if (sc_list[j].id() == user.stat_cat_entries()[i].stat_cat()) { + found = 1; + break; + } + } + if (!found) + missing_scs.push(user.stat_cat_entries()[i].stat_cat()); + } + + req = new RemoteRequest( 'open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.batch', ses_id, missing_scs ); + req.send(true); + var foreign_sc_list = req.getResultObject(); + + f = document.getElementById('statcats'); + while (f.firstChild) f.removeChild(f.lastChild); + + for (var i in sc_list) + display_sc(f,sc_list[i],user.stat_cat_entries()); + + for (var i in foreign_sc_list) + display_sc(f,foreign_sc_list[i],user.stat_cat_entries(), true); + return true; } +function set_sc_value (node) { + var id = parseInt(node.getAttribute('scid')); + var value = node.value; + + + var sc; + for (var i in user.stat_cat_entries()) { + if (user.stat_cat_entries()[i].stat_cat() == id) { + user.stat_cat_entries()[i].stat_cat_entry(value); + if (value == '') { + user.stat_cat_entries()[i].isdeleted(1); + } else { + user.stat_cat_entries()[i].isdeleted(0); + user.stat_cat_entries()[i].ischanged(1); + } + sc = user.stat_cat_entries()[i]; + break; + } + } + + if (!sc) { + sc = new actscecm(); + sc.isnew(1); + sc.stat_cat_entry(value); + sc.stat_cat(id); + sc.target_usr(user.id()); + + user.stat_cat_entries().push(sc); + } +} + +function display_sc (root,sc_def, user_scs, foreign) { + + var sc; + for (var i in user_scs) { + if (sc_def.id() == user_scs[i].stat_cat()) { + sc = user_scs[i]; + break; + } + } + + var sc_row = findNodeByName(document.getElementById('statcat-tmpl'), 'scrow').cloneNode(true); + root.appendChild(sc_row); + + findNodeByName(sc_row,'sc.name').appendChild(text(sc_def.name())); + + var text_box = findNodeByName(sc_row,'sce.value'); + text_box.setAttribute('scid', sc_def.id()); + if (sc) text_box.value = sc.stat_cat_entry(); + + if (!foreign) { + if (sc_def.entries().length > 0) { + var selector = findNodeByName(sc_row,'sce_select'); + selector.id = 'scid-' + sc_def.id(); + + removeCSSClass(selector.parentNode, 'hideme'); + + selectBuilder( + 'scid-' + sc_def.id(), + sc_def.entries(), + (sc ? sc.stat_cat_entry() : ''), + { label_field : 'value', + value_field : 'value', + empty_label : '-- Select One --', + empty_value : '', + clear : true } + ); + } + } else { + text_box.disabled = true; + text_box.parentNode.appendChild(text('(Foreign Stat Cat)')); + } +} + function display_perm (root,perm_def,staff_perms) { var prow = findNodeByName(document.getElementById('permission-tmpl'), 'prow').cloneNode(true); diff --git a/Open-ILS/xul/staff_client/server/patron/user_edit.xml b/Open-ILS/xul/staff_client/server/patron/user_edit.xml index 38ba57e507..73b2a5cd8b 100644 --- a/Open-ILS/xul/staff_client/server/patron/user_edit.xml +++ b/Open-ILS/xul/staff_client/server/patron/user_edit.xml @@ -59,7 +59,7 @@
- +
@@ -224,8 +224,7 @@ - - + + + + +
User Identifcation
User Specific Permissions: + @@ -241,6 +240,12 @@ + + + + + + @@ -296,6 +301,26 @@
Local Statistical Catagories
Required Surveys
+ +
+
+ + + +
+
-- 2.43.2