Bugzilla – Attachment 26965 Details for
Bug 11676
Loading shelving locations based on the item's homebranch instead of the user's logged-in branch.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11676 - Loading shelving locations based on stuff. For acquisitions. Found out that there is another way of adding items, which has a different mechanism (datatables yay) of addition, so this feature enables shelving location updating in the newordere
Bug-11676---Loading-shelving-locations-based-on-st.patch (text/plain), 14.19 KB, created by
Olli-Antti Kivilahti
on 2014-04-10 08:05:39 UTC
(
hide
)
Description:
Bug 11676 - Loading shelving locations based on stuff. For acquisitions. Found out that there is another way of adding items, which has a different mechanism (datatables yay) of addition, so this feature enables shelving location updating in the newordere
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2014-04-10 08:05:39 UTC
Size:
14.19 KB
patch
obsolete
>From 2b1d4612112b4b6928fefb18ebccd7ee68012cd9 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Thu, 3 Apr 2014 17:40:33 +0300 >Subject: [PATCH] Bug 11676 - Loading shelving locations based on stuff. For > acquisitions. Found out that there is another way of adding items, which has > a different mechanism (datatables yay) of addition, so this feature enables > shelving location updating in the neworderempty.pl. > >Centralized the shelving location fetching code (to koha-to-marc-mapping-api.js) >to have a central place to share related features. > >------------- >- TEST PLAN - >------------- >Same as in the first patch, but this time use the neworderempty.pl-script. >--- > acqui/neworderempty.pl | 11 ++- > koha-tmpl/intranet-tmpl/prog/en/js/additem.js | 10 +++ > .../prog/en/js/koha-to-marc-mapping-api.js | 33 +++++++++ > .../prog/en/modules/acqui/neworderempty.tt | 8 ++- > .../prog/en/modules/cataloguing/additem.tt | 33 +++------ > svc/getAuthorisedValues.pl | 69 ------------------ > svc/getShelvingLocations.pl | 81 ++++++++++++++++++++++ > 7 files changed, 149 insertions(+), 96 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/koha-to-marc-mapping-api.js > delete mode 100755 svc/getAuthorisedValues.pl > create mode 100755 svc/getShelvingLocations.pl > >diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl >index 9fdf032..aad2195 100755 >--- a/acqui/neworderempty.pl >+++ b/acqui/neworderempty.pl >@@ -346,6 +346,11 @@ if ( defined $subscriptionid ) { > # Find the items.barcode subfield for barcode validations > my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); > >+#Find the Marc Subfields for changing the shelving location based on the item's homebranch. >+#These are needed to target the right <select> element to receive shelving location AJAX-updates when the homebranch is changed. >+my ($shelvingLocationMarcTag, $shelvingLocationMarcSubfield) = C4::Biblio::GetMarcFromKohaField( "items.location", $params->{'frameworkcode'} ); >+my ($homebranchMarcTag, $homebranchMarcSubfield) = C4::Biblio::GetMarcFromKohaField( "items.homebranch", $params->{'frameworkcode'} ); >+ > # fill template > $template->param( > close => $close, >@@ -415,7 +420,11 @@ $template->param( > import_batch_id => $import_batch_id, > subscriptionid => $subscriptionid, > acqcreate => C4::Context->preference("AcqCreateItem") eq "ordering" ? 1 : "", >- (uc(C4::Context->preference("marcflavour"))) => 1 >+ (uc(C4::Context->preference("marcflavour"))) => 1, >+ shelvingLocationMarcTag => $shelvingLocationMarcTag, >+ shelvingLocationMarcSubfield => $shelvingLocationMarcSubfield, >+ homebranchMarcTag => $homebranchMarcTag, >+ homebranchMarcSubfield => $homebranchMarcSubfield, > ); > > $template->param ( notes => $data->{'notes'} ) if ( $ordernumber ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js >index aa19155..6d771d9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js >+++ b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js >@@ -161,6 +161,16 @@ function cloneItemBlock(index, unique_item_fields) { > }); > > $("#outeritemblock").append(clone); >+ >+ //Add a onChange handler to "Permanent Location"-<select> to update shelving locations based on the items homebranch. >+ var homebranchSelector = $(clone).find("div[id=subfield"+homebranchMarcSubfield+"]").find("select[name=field_value]"); >+ var shelvingLocationSelector = $(clone).find("div[id=subfield"+shelvingLocationMarcSubfield+"]").find("select[name=field_value]"); >+ >+ //Reload shelving location with AJAX if the "Permanent location" (homebranch) changes. >+ //Function is bound from koha-to-marc-mapping-api.js >+ $(homebranchSelector).change(function() { >+ reloadShelvingLocations(this.value, '', shelvingLocationSelector); >+ }); > } > }); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/koha-to-marc-mapping-api.js b/koha-tmpl/intranet-tmpl/prog/en/js/koha-to-marc-mapping-api.js >new file mode 100644 >index 0000000..c339abb >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/js/koha-to-marc-mapping-api.js >@@ -0,0 +1,33 @@ >+//Fetch the Shelving locations using AJAX >+//Build the replacement HTML for the shelving location options >+//Then replace the existing HTML with this. >+function reloadShelvingLocations(branch, framework, selectorElement) { >+ >+ if (typeof framework == "undefined" && typeof shelvingLocationMarcField == "undefined") { >+ framework = "0"; //Get the default framework >+ } >+ >+ $.ajax({ >+ url: "/cgi-bin/koha/svc/getShelvingLocations.pl", >+ type: "POST", >+ dataType: 'json', >+ data: { 'branch' : branch, 'framework' : framework }, >+ success: function(data, textStatus, jqXHR) { >+ >+ var locations = data.locations; >+ if ( selectorElement ) { >+ var html_replacement = '<option value="" selected="selected"></option>\n'; >+ for (var k in locations) { >+ html_replacement += '<option value="'+ k +'">'+ locations[k] +'</option>\n'; >+ } >+ $(selectorElement).html( html_replacement ); >+ } >+ else { >+ alert("ERROR in koha-to-marc-mapping-api.js: No element given to place new shelving locations into!"); >+ } >+ }, >+ error: function(data, textStatus, jqXHR) { >+ alert("ERROR in koha-to-marc-mapping-api.js: Couldn't make a decent AJAX-call!"); >+ } >+ }); >+} >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >index 596aa07..d5cabaa 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >@@ -8,9 +8,15 @@ > <script type="text/javascript" src="[% themelang %]/js/additem.js"></script> > <script type="text/javascript" src="[% themelang %]/js/cataloging.js"></script> > <script type="text/javascript" src="[% themelang %]/js/prevent_submit.js"></script> >+<script type="text/javascript" src="[% themelang %]/js/koha-to-marc-mapping-api.js"></script> > <script type="text/javascript"> > //<![CDATA[ > actTotal = ""; >+//Set javascript globals to find the shelving location and homebranch elements from the HTML mess. >+var shelvingLocationMarcTag = "[% shelvingLocationMarcTag %]"; >+var shelvingLocationMarcSubfield = "[% shelvingLocationMarcSubfield %]"; >+var homebranchMarcTag = "[% homebranchMarcTag %]"; >+var homebranchMarcSubfield = "[% homebranchMarcSubfield %]"; > > function Check(ff) { > [% IF (AcqCreateItemOrdering) %] >@@ -141,7 +147,7 @@ $(document).ready(function() > $('#budget_id .b_inactive').remove(); > } > }); >- }); >+}); > //]]> > </script> > </head> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >index b45bbc0..062e309 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -9,38 +9,20 @@ > <script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script> > <![endif]--> > <script type="text/javascript" src="[% interface %]/js/browser.js"></script> >+<script type="text/javascript" src="[% themelang %]/js/koha-to-marc-mapping-api.js"></script> > <script type="text/javascript"> > //<![CDATA[ > var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10)); > browser.show(); > >-//Fetch the Shelving locations using AJAX >-//Build the replacement HTML for the shelving location options >-//Then replace the existing HTML with this. >-function reloadShelvingLocations(homebranch) { >- >- $.ajax({ >- url: "/cgi-bin/koha/svc/getAuthorisedValues.pl", >- type: "POST", >- dataType: 'json', >- data: { 'category' : 'LOC', 'branch_limit' : homebranch }, >- success: function(data, textStatus, jqXHR) { >- >- var html_replacement = '<option value="" selected="selected"></option>\n'; >- for (var i in data) { >- html_replacement += '<option value="'+data[i].authorised_value+'">'+data[i].lib+'</option>\n'; >- } >- $("select[id*='tag_[% shelvingLocationMarcTag %]_subfield_[% shelvingLocationMarcSubfield %]']").html(html_replacement); >- } >- }); >-} >- > > $(document).ready(function(){ >- > //Reload shelving location with AJAX if the "Permanent location" (homebranch) changes. >- $("select[id*='tag_[% homebranchMarcTag %]_subfield_[% homebranchMarcSubfield %]']").change(function() { >- reloadShelvingLocations(this.value); >+ //Function is bound from koha-to-marc-mapping-api.js >+ $("select[id^='tag_[% homebranchMarcTag %]_subfield_[% homebranchMarcSubfield %]']").change(function() { >+ var shelvingLocationSelector = $(this).closest("ol") //Get the shelving location <select>-element of this specific Item. On this same page there can be many items. >+ .find("select[id^='tag_[% shelvingLocationMarcTag %]_subfield_[% shelvingLocationMarcSubfield %]']"); >+ reloadShelvingLocations(this.value, [% frameworkcode || 0 %], shelvingLocationSelector); > }); > > >@@ -296,4 +278,5 @@ $(document).ready(function() { > > </div> > </div> >-[% INCLUDE 'intranet-bottom.inc' %] >+ >+[% INCLUDE 'intranet-bottom.inc' %] >\ No newline at end of file >diff --git a/svc/getAuthorisedValues.pl b/svc/getAuthorisedValues.pl >deleted file mode 100755 >index 3db1399..0000000 >--- a/svc/getAuthorisedValues.pl >+++ /dev/null >@@ -1,69 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Copyright Anonymous >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-=head SYNOPSIS >- >-This file is a AJAX-callable wrapper for C4::Koha::GetAuthorisedValues() >- >-Valid parameters: >- >-category >-selected >-opac >-branch_limit >- >-See C4::Koha::GetAuthorisedValues() for detailed documentation. >- >-=cut >-use Modern::Perl; >- >-use CGI; >-use C4::Auth qw/check_cookie_auth/; >-use JSON qw/to_json/; >-use C4::Koha qw/GetAuthorisedValues/; >- >-my $input = new CGI; >- >-my ( $auth_status, $sessionID ) = >- check_cookie_auth( >- $input->cookie('CGISESSID'), >- { 'catalogue' => '*' } ); >- >-if ( $auth_status ne "ok" ) { >- exit 0; >-} >- >-## Getting the input parameters ## >- >-my $category = $input->param('category'); >-my $selected = $input->param('selected'); >-my $opac = $input->param('opac'); >-my $branch_limit = $input->param('branch_limit'); >- >- >-my $avs = C4::Koha::GetAuthorisedValues($category, $selected, $opac, $branch_limit); >- >- >-binmode STDOUT, ":encoding(UTF-8)"; >-print $input->header( >- -type => 'application/json', >- -charset => 'UTF-8' >-); >- >-print to_json( $avs); >\ No newline at end of file >diff --git a/svc/getShelvingLocations.pl b/svc/getShelvingLocations.pl >new file mode 100755 >index 0000000..b9c1dd4 >--- /dev/null >+++ b/svc/getShelvingLocations.pl >@@ -0,0 +1,81 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright Anonymous >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head SYNOPSIS >+ >+Gets the shelving locations and the Koha-to-MARC-mapping on demand. >+Returns a JSON hash. >+ >+Valid parameters: >+ >+branch - The branchcode, eg CPL, FFL, JNS >+framework - The Framework code or don't define. Returns the field and subfield for the shelving location defined in the given framework code >+ eg. ACQ, BKS. >+ Reverts to the default framework if defined as 0 (zero). >+ >+=cut >+use Modern::Perl; >+ >+use CGI; >+#use C4::Auth qw/check_cookie_auth/; >+use JSON qw/to_json/; >+use C4::Koha qw/GetAuthorisedValues/; >+use C4::Biblio qw(GetMarcFromKohaField); >+ >+my $input = new CGI; >+ >+#No need to authenticate since shelving locations are quite public. >+#my ( $auth_status, $sessionID ) = >+# check_cookie_auth( >+# $input->cookie('CGISESSID'), >+# { 'catalogue' => '*' } ); >+# >+#if ( $auth_status ne "ok" ) { >+# exit 0; >+#} >+ >+## Getting the input parameters ## >+ >+my $branch = $input->param('branch'); >+my $framework = $input->param('framework'); #The MARC framework >+ >+#shloc as shelving location, not to be mixed with http://www.schlockmercenary.com/ >+my $shlocs = C4::Koha::GetAuthorisedValues('LOC', undef, undef, $branch); >+my ( $shloc_field, $shloc_subfield ); >+ >+my $ret = {}; #Prepare the return value. >+ >+if (defined $framework) { >+ ( $ret->{field}, $ret->{subfield} ) = C4::Biblio::GetMarcFromKohaField( "items.location", $framework ); >+} >+ >+#Build a sane return value, don't bash around huge JSON blobs needlessly! >+my $ret_locations = $ret->{locations} = {}; #Create a reference point so locations-hash need not be dereferenced for each iteration of @$shloc >+foreach my $av (@$shlocs) { >+ $ret_locations->{ $av->{authorised_value} } = $av->{lib}; >+} >+ >+binmode STDOUT, ":encoding(UTF-8)"; >+ >+print $input->header( >+ -type => 'application/json', >+ -charset => 'UTF-8' >+); >+ >+print to_json( $ret); >\ No newline at end of file >-- >1.8.1.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11676
:
25034
|
25035
|
25036
|
25060
|
25061
|
25062
|
25064
|
25065
|
26796
| 26965