View | Details | Raw Unified | Return to bug 11676
Collapse All | Expand All

(-)a/acqui/neworderempty.pl (-1 / +10 lines)
Lines 346-351 if ( defined $subscriptionid ) { Link Here
346
# Find the items.barcode subfield for barcode validations
346
# Find the items.barcode subfield for barcode validations
347
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
347
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
348
348
349
#Find the Marc Subfields for changing the shelving location based on the item's homebranch.
350
#These are needed to target the right <select> element to receive shelving location AJAX-updates when the homebranch is changed.
351
my ($shelvingLocationMarcTag, $shelvingLocationMarcSubfield) = C4::Biblio::GetMarcFromKohaField( "items.location", $params->{'frameworkcode'} );
352
my ($homebranchMarcTag, $homebranchMarcSubfield) = C4::Biblio::GetMarcFromKohaField( "items.homebranch", $params->{'frameworkcode'} );
353
349
# fill template
354
# fill template
350
$template->param(
355
$template->param(
351
    close        => $close,
356
    close        => $close,
Lines 415-421 $template->param( Link Here
415
    import_batch_id  => $import_batch_id,
420
    import_batch_id  => $import_batch_id,
416
    subscriptionid   => $subscriptionid,
421
    subscriptionid   => $subscriptionid,
417
    acqcreate        => C4::Context->preference("AcqCreateItem") eq "ordering" ? 1 : "",
422
    acqcreate        => C4::Context->preference("AcqCreateItem") eq "ordering" ? 1 : "",
418
    (uc(C4::Context->preference("marcflavour"))) => 1
423
    (uc(C4::Context->preference("marcflavour"))) => 1,
424
	shelvingLocationMarcTag => $shelvingLocationMarcTag,
425
	shelvingLocationMarcSubfield => $shelvingLocationMarcSubfield,
426
	homebranchMarcTag => $homebranchMarcTag,
427
	homebranchMarcSubfield => $homebranchMarcSubfield,
419
);
428
);
420
429
421
$template->param ( notes => $data->{'notes'} ) if ( $ordernumber );
430
$template->param ( notes => $data->{'notes'} ) if ( $ordernumber );
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js (+10 lines)
Lines 161-166 function cloneItemBlock(index, unique_item_fields) { Link Here
161
            });
161
            });
162
162
163
            $("#outeritemblock").append(clone);
163
            $("#outeritemblock").append(clone);
164
            
165
            //Add a onChange handler to "Permanent Location"-<select> to update shelving locations based on the items homebranch.
166
            var homebranchSelector = $(clone).find("div[id=subfield"+homebranchMarcSubfield+"]").find("select[name=field_value]");
167
            var shelvingLocationSelector = $(clone).find("div[id=subfield"+shelvingLocationMarcSubfield+"]").find("select[name=field_value]");
168
            
169
            //Reload shelving location with AJAX if the "Permanent location" (homebranch) changes.
170
            //Function is bound from koha-to-marc-mapping-api.js
171
            $(homebranchSelector).change(function() {
172
                reloadShelvingLocations(this.value, '', shelvingLocationSelector);
173
            });
164
        }
174
        }
165
    });
175
    });
166
}
176
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/koha-to-marc-mapping-api.js (+33 lines)
Line 0 Link Here
1
//Fetch the Shelving locations using AJAX
2
//Build the replacement HTML for the shelving location options
3
//Then replace the existing HTML with this.
4
function reloadShelvingLocations(branch, framework, selectorElement) {
5
6
    if (typeof framework == "undefined" && typeof shelvingLocationMarcField == "undefined") {
7
        framework = "0"; //Get the default framework
8
    }
9
10
    $.ajax({
11
        url: "/cgi-bin/koha/svc/getShelvingLocations.pl",
12
        type: "POST",
13
        dataType: 'json',
14
        data: { 'branch' : branch, 'framework' : framework },
15
        success: function(data, textStatus, jqXHR) {
16
17
            var locations = data.locations;
18
            if ( selectorElement ) {
19
                var html_replacement = '<option value="" selected="selected"></option>\n';
20
                for (var k in locations) {
21
                    html_replacement += '<option value="'+ k +'">'+ locations[k] +'</option>\n';
22
                }
23
                $(selectorElement).html( html_replacement );
24
            }
25
            else {
26
                alert("ERROR in koha-to-marc-mapping-api.js: No element given to place new shelving locations into!");
27
            }            
28
        },
29
        error: function(data, textStatus, jqXHR) {
30
            alert("ERROR in koha-to-marc-mapping-api.js: Couldn't make a decent AJAX-call!");
31
        }
32
    });
33
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +7 lines)
Lines 8-16 Link Here
8
<script type="text/javascript" src="[% themelang %]/js/additem.js"></script>
8
<script type="text/javascript" src="[% themelang %]/js/additem.js"></script>
9
<script type="text/javascript" src="[% themelang %]/js/cataloging.js"></script>
9
<script type="text/javascript" src="[% themelang %]/js/cataloging.js"></script>
10
<script type="text/javascript" src="[% themelang %]/js/prevent_submit.js"></script>
10
<script type="text/javascript" src="[% themelang %]/js/prevent_submit.js"></script>
11
<script type="text/javascript" src="[% themelang %]/js/koha-to-marc-mapping-api.js"></script>
11
<script type="text/javascript">
12
<script type="text/javascript">
12
//<![CDATA[
13
//<![CDATA[
13
actTotal = "";
14
actTotal = "";
15
//Set javascript globals to find the shelving location and homebranch elements from the HTML mess.
16
var shelvingLocationMarcTag = "[% shelvingLocationMarcTag %]";
17
var shelvingLocationMarcSubfield = "[% shelvingLocationMarcSubfield %]";
18
var homebranchMarcTag = "[% homebranchMarcTag %]";
19
var homebranchMarcSubfield = "[% homebranchMarcSubfield %]";
14
20
15
function Check(ff) {
21
function Check(ff) {
16
    [% IF (AcqCreateItemOrdering) %]
22
    [% IF (AcqCreateItemOrdering) %]
Lines 141-147 $(document).ready(function() Link Here
141
                $('#budget_id .b_inactive').remove();
147
                $('#budget_id .b_inactive').remove();
142
            }
148
            }
143
        });
149
        });
144
    });
150
});
145
//]]>
151
//]]>
146
</script>
152
</script>
147
</head>
153
</head>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-25 / +8 lines)
Lines 9-46 Link Here
9
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
9
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
10
<![endif]-->
10
<![endif]-->
11
<script type="text/javascript" src="[% interface %]/js/browser.js"></script>
11
<script type="text/javascript" src="[% interface %]/js/browser.js"></script>
12
<script type="text/javascript" src="[% themelang %]/js/koha-to-marc-mapping-api.js"></script>
12
<script type="text/javascript">
13
<script type="text/javascript">
13
//<![CDATA[
14
//<![CDATA[
14
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
15
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
15
    browser.show();
16
    browser.show();
16
17
17
//Fetch the Shelving locations using AJAX
18
//Build the replacement HTML for the shelving location options
19
//Then replace the existing HTML with this.
20
function reloadShelvingLocations(homebranch) {
21
22
    $.ajax({
23
        url: "/cgi-bin/koha/svc/getAuthorisedValues.pl",
24
        type: "POST",
25
        dataType: 'json',
26
        data: { 'category' : 'LOC', 'branch_limit' : homebranch },
27
        success: function(data, textStatus, jqXHR) {
28
29
            var html_replacement = '<option value="" selected="selected"></option>\n';
30
            for (var i in data) {
31
                html_replacement += '<option value="'+data[i].authorised_value+'">'+data[i].lib+'</option>\n';
32
            }
33
            $("select[id*='tag_[% shelvingLocationMarcTag %]_subfield_[% shelvingLocationMarcSubfield %]']").html(html_replacement);
34
        }
35
    });
36
}
37
38
18
39
$(document).ready(function(){
19
$(document).ready(function(){
40
41
    //Reload shelving location with AJAX if the "Permanent location" (homebranch) changes.
20
    //Reload shelving location with AJAX if the "Permanent location" (homebranch) changes.
42
    $("select[id*='tag_[% homebranchMarcTag %]_subfield_[% homebranchMarcSubfield %]']").change(function() {
21
    //Function is bound from koha-to-marc-mapping-api.js
43
        reloadShelvingLocations(this.value);
22
    $("select[id^='tag_[% homebranchMarcTag %]_subfield_[% homebranchMarcSubfield %]']").change(function() {
23
        var shelvingLocationSelector = $(this).closest("ol") //Get the shelving location <select>-element of this specific Item. On this same page there can be many items.
24
                                           .find("select[id^='tag_[% shelvingLocationMarcTag %]_subfield_[% shelvingLocationMarcSubfield %]']");
25
        reloadShelvingLocations(this.value, [% frameworkcode || 0 %], shelvingLocationSelector);
44
    });
26
    });
45
27
46
28
Lines 296-299 $(document).ready(function() { Link Here
296
278
297
</div>
279
</div>
298
</div>
280
</div>
299
[% INCLUDE 'intranet-bottom.inc' %]
281
282
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/svc/getAuthorisedValues.pl (-69 lines)
Lines 1-69 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright Anonymous
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head SYNOPSIS
21
22
This file is a AJAX-callable wrapper for C4::Koha::GetAuthorisedValues()
23
24
Valid parameters:
25
26
category
27
selected
28
opac
29
branch_limit
30
31
See C4::Koha::GetAuthorisedValues() for detailed documentation.
32
33
=cut
34
use Modern::Perl;
35
36
use CGI;
37
use C4::Auth qw/check_cookie_auth/;
38
use JSON qw/to_json/;
39
use C4::Koha qw/GetAuthorisedValues/;
40
41
my $input = new CGI;
42
43
my ( $auth_status, $sessionID ) =
44
        check_cookie_auth(
45
            $input->cookie('CGISESSID'),
46
            { 'catalogue' => '*' } );
47
48
if ( $auth_status ne "ok" ) {
49
    exit 0;
50
}
51
52
## Getting the input parameters ##
53
54
my $category = $input->param('category');
55
my $selected = $input->param('selected');
56
my $opac = $input->param('opac');
57
my $branch_limit = $input->param('branch_limit');
58
59
60
my $avs = C4::Koha::GetAuthorisedValues($category, $selected, $opac, $branch_limit);
61
62
63
binmode STDOUT, ":encoding(UTF-8)";
64
print $input->header(
65
    -type => 'application/json',
66
    -charset => 'UTF-8'
67
);
68
69
print to_json( $avs);
(-)a/svc/getShelvingLocations.pl (-1 / +81 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright Anonymous
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head SYNOPSIS
21
22
Gets the shelving locations and the Koha-to-MARC-mapping on demand.
23
Returns a JSON hash.
24
25
Valid parameters:
26
27
branch - The branchcode, eg CPL, FFL, JNS
28
framework - The Framework code or don't define. Returns the field and subfield for the shelving location defined in the given framework code
29
          eg. ACQ, BKS.
30
          Reverts to the default framework if defined as 0 (zero).
31
32
=cut
33
use Modern::Perl;
34
35
use CGI;
36
#use C4::Auth qw/check_cookie_auth/;
37
use JSON qw/to_json/;
38
use C4::Koha qw/GetAuthorisedValues/;
39
use C4::Biblio qw(GetMarcFromKohaField);
40
41
my $input = new CGI;
42
43
#No need to authenticate since shelving locations are quite public.
44
#my ( $auth_status, $sessionID ) =
45
#        check_cookie_auth(
46
#            $input->cookie('CGISESSID'),
47
#            { 'catalogue' => '*' } );
48
#
49
#if ( $auth_status ne "ok" ) {
50
#    exit 0;
51
#}
52
53
## Getting the input parameters ##
54
55
my $branch = $input->param('branch');
56
my $framework = $input->param('framework'); #The MARC framework
57
58
#shloc as shelving location, not to be mixed with http://www.schlockmercenary.com/
59
my $shlocs = C4::Koha::GetAuthorisedValues('LOC', undef, undef, $branch);
60
my ( $shloc_field, $shloc_subfield );
61
62
my $ret = {}; #Prepare the return value.
63
64
if (defined $framework) {
65
    ( $ret->{field}, $ret->{subfield} ) = C4::Biblio::GetMarcFromKohaField( "items.location", $framework );
66
}
67
68
#Build a sane return value, don't bash around huge JSON blobs needlessly!
69
my $ret_locations = $ret->{locations} = {}; #Create a reference point so locations-hash need not be dereferenced for each iteration of @$shloc
70
foreach my $av (@$shlocs) {
71
    $ret_locations->{ $av->{authorised_value} } = $av->{lib};
72
}
73
74
binmode STDOUT, ":encoding(UTF-8)";
75
76
print $input->header(
77
    -type => 'application/json',
78
    -charset => 'UTF-8'
79
);
80
81
print to_json( $ret);

Return to bug 11676