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

(-)a/admin/search_filters.pl (+60 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
# Copyright 2013 BibLibre
3
#
4
# This file is part of Koha
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use CGI;
21
22
use C4::Auth qw( get_template_and_user );
23
use C4::Output qw( output_html_with_http_headers );
24
25
use Koha::SearchFilters;
26
27
use Try::Tiny qw( catch try);
28
29
my $cgi = CGI->new;
30
31
my ($template, $borrowernumber, $cookie) = get_template_and_user({
32
    template_name => 'admin/search_filters.tt',
33
    query => $cgi,
34
    type => 'intranet',
35
    flagsrequired   => { parameters => 'manage_search_filters' },
36
});
37
38
my $op = $cgi->param('op') || '';
39
40
if ($op eq 'del') {
41
    my $id = $cgi->param('id');
42
    my $sf = Koha::SearchFilters->find($id);
43
    $template->param(filter_not_found => 1) unless $sf;
44
    if ($sf) {
45
        try{
46
            $sf->delete();
47
            $template->param( filter_deleted => $sf->name );
48
        } catch {
49
            $template->param( error => $_ );
50
        };
51
    }
52
}
53
54
my $filters = Koha::SearchFilters->search();
55
56
$template->param(
57
    filters_count => $filters->count,
58
);
59
60
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/catalogue/search.pl (-27 / +47 lines)
Lines 176-182 my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); Link Here
176
my %is_nolimit = map { $_ => 1 } @nolimits;
176
my %is_nolimit = map { $_ => 1 } @nolimits;
177
@limits = grep { not $is_nolimit{$_} } @limits;
177
@limits = grep { not $is_nolimit{$_} } @limits;
178
if  (
178
if  (
179
        !$cgi->param('edit_search') &&
179
        !$cgi->param('edit_search') && !$cgi->param('edit_filter') &&
180
        ( (@limits>=1) || (defined $cgi->param("q") && $cgi->param("q") ne "" ) || ($cgi->param('limit-yr')) )
180
        ( (@limits>=1) || (defined $cgi->param("q") && $cgi->param("q") ne "" ) || ($cgi->param('limit-yr')) )
181
    ) {
181
    ) {
182
    $template_name = 'catalogue/results.tt';
182
    $template_name = 'catalogue/results.tt';
Lines 257-288 $template->param( searchid => scalar $cgi->param('searchid'), ); Link Here
257
# The following should only be loaded if we're bringing up the advanced search template
257
# The following should only be loaded if we're bringing up the advanced search template
258
if ( $template_type eq 'advsearch' ) {
258
if ( $template_type eq 'advsearch' ) {
259
259
260
    my @operands;
261
    my @operators;
262
    my @indexes;
260
    my $expanded = $cgi->param('expanded_options');
263
    my $expanded = $cgi->param('expanded_options');
261
    if( $cgi->param('edit_search') ){
264
    if( $cgi->param('edit_search') ){
262
        my @operators = $cgi->multi_param('op');
265
        @operands = $cgi->multi_param('q');
263
        my @indexes   = $cgi->multi_param('idx');
266
        @operators = $cgi->multi_param('op');
264
        my %limit_hash;
267
        @indexes   = $cgi->multi_param('idx');
265
        foreach my $limit (@limits){
266
            if ( $limit eq 'available' ){
267
                $template->param( limit_available => 1 );
268
            } else {
269
                my ($index,$value) = split(':',$limit);
270
                $value =~ s/"//g;
271
                if ( $index =~ /mc-/ ){
272
                    $limit_hash{$index . "_" . $value} = 1;
273
                } else {
274
                    push @{$limit_hash{$index}}, $value;
275
                }
276
            }
277
        };
278
        $expanded = 1 if scalar @operators || scalar @limits;
279
        $template->param( operators => \@operators );
280
        $template->param( limits => \%limit_hash );
281
        $template->param(
268
        $template->param(
282
           indexes   => \@indexes,
283
           sort      => $cgi->param('sort_by'),
269
           sort      => $cgi->param('sort_by'),
284
        );
270
        );
271
        # determine what to display next to the search boxes
272
    } elsif ( $cgi->param('edit_filter') ){
273
        my $search_filter = Koha::SearchFilters->find( $cgi->param('edit_filter') );
274
        if( $search_filter ){
275
            my $query = decode_json( $search_filter->query );
276
            my $limits = decode_json( $search_filter->limits );
277
            @operands  = @{ $query->{operands} };
278
            @indexes   = @{ $query->{indexes} };
279
            @operators = @{ $query->{operators} };
280
            @limits    = @{ $limits->{limits} };
281
            $template->param( edit_filter => $search_filter );
282
        } else {
283
            $template->param( unknown_filter => 1 );
284
        }
285
    }
286
287
    while( scalar @operands < 3 ){
288
        push @operands, "";
285
    }
289
    }
290
    $template->param( operands  => \@operands );
291
    $template->param( operators => \@operators );
292
    $template->param( indexes   => \@indexes );
293
294
    my %limit_hash;
295
    foreach my $limit (@limits){
296
        if ( $limit eq 'available' ){
297
            $template->param( limit_available => 1 );
298
        } else {
299
            my ($index,$value) = split(':',$limit);
300
            $value =~ s/"//g;
301
            if ( $index =~ /mc-/ ){
302
                $limit_hash{$index . "_" . $value} = 1;
303
            } else {
304
                push @{$limit_hash{$index}}, $value;
305
            }
306
        }
307
    };
308
    $template->param( limits => \%limit_hash );
309
310
    $expanded = 1 if scalar @operators || scalar @limits;
311
286
    # load the servers (used for searching -- to do federated searching, etc.)
312
    # load the servers (used for searching -- to do federated searching, etc.)
287
    my $primary_servers_loop;# = displayPrimaryServers();
313
    my $primary_servers_loop;# = displayPrimaryServers();
288
    $template->param(outer_servers_loop =>  $primary_servers_loop,);
314
    $template->param(outer_servers_loop =>  $primary_servers_loop,);
Lines 299-315 if ( $template_type eq 'advsearch' ) { Link Here
299
        $template->param( sort_by => $default_sort_by  );
325
        $template->param( sort_by => $default_sort_by  );
300
    }
326
    }
301
327
302
    # determine what to display next to the search boxes
303
    my @queries = $cgi->multi_param('q');
304
    while( scalar @queries < 3 ){
305
        push @queries, "";
306
    }
307
    $template->param(uc(C4::Context->preference("marcflavour")) =>1 );
328
    $template->param(uc(C4::Context->preference("marcflavour")) =>1 );
308
329
309
    # load the language limits (for search)
330
    # load the language limits (for search)
310
    my $languages_limit_loop = getLanguages($lang, 1);
331
    my $languages_limit_loop = getLanguages($lang, 1);
311
    $template->param(search_languages_loop => $languages_limit_loop,);
332
    $template->param(search_languages_loop => $languages_limit_loop,);
312
    $template->param(       queries   => \@queries );
313
333
314
    # Expanded search options in advanced search:
334
    # Expanded search options in advanced search:
315
    # use the global setting by default, but let the user override it
335
    # use the global setting by default, but let the user override it
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+3 lines)
Lines 97-102 Link Here
97
            [% IF ( CAN_user_parameters_manage_item_search_fields ) %]
97
            [% IF ( CAN_user_parameters_manage_item_search_fields ) %]
98
                <li><a href="/cgi-bin/koha/admin/items_search_fields.pl">Item search fields</a></li>
98
                <li><a href="/cgi-bin/koha/admin/items_search_fields.pl">Item search fields</a></li>
99
            [% END %]
99
            [% END %]
100
            [% IF ( Koha.Preference('SavedSearchFilters') && CAN_user_parameters_manage_search_filters ) %]
101
                <li><a href="/cgi-bin/koha/admin/search_filters.pl">Search filters</a></li>
102
            [% END %]
100
            [% IF ( CAN_user_parameters_manage_search_engine_config ) %]
103
            [% IF ( CAN_user_parameters_manage_search_engine_config ) %]
101
                <li><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></li>
104
                <li><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></li>
102
            [% END %]
105
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+4 lines)
Lines 192-197 Link Here
192
                        <dt><a href="/cgi-bin/koha/admin/items_search_fields.pl">Item search fields</a></dt>
192
                        <dt><a href="/cgi-bin/koha/admin/items_search_fields.pl">Item search fields</a></dt>
193
                        <dd>Manage custom fields for item search</dd>
193
                        <dd>Manage custom fields for item search</dd>
194
                    [% END %]
194
                    [% END %]
195
                    [% IF Koha.Preference('SavedSearchFilters') && ( CAN_user_parameters_manage_search_filters ) %]
196
                        <dt><a href="/cgi-bin/koha/admin/search_filters.pl">Search filters</a></dt>
197
                        <dd>Manage custom search filters</dd>
198
                    [% END %]
195
                    [% IF ( CAN_user_parameters_manage_search_engine_config ) %]
199
                    [% IF ( CAN_user_parameters_manage_search_engine_config ) %]
196
                        <dt><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></dt>
200
                        <dt><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></dt>
197
                        <dd>Manage indexes, facets, and their mappings to MARC fields and subfields</dd>
201
                        <dd>Manage indexes, facets, and their mappings to MARC fields and subfields</dd>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt (+226 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% USE AuthorisedValues %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
  <title>Search filters &rsaquo; Administration &rsaquo; Koha</title>
7
  [% INCLUDE 'doc-head-close.inc' %]
8
</head>
9
10
<body id="admin_searchfilters" class="admin">
11
  [% INCLUDE 'header.inc' %]
12
  [% INCLUDE 'prefs-admin-search.inc' %]
13
14
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
15
    <ol>
16
        <li>
17
            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
18
        </li>
19
        <li>
20
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
21
        </li>
22
        <li>
23
            <a href="#" aria-current="page">
24
                Search filters
25
            </a>
26
        </li>
27
    </ol>
28
</nav>
29
30
<div class="main container-fluid">
31
    <div class="row">
32
        <div class="col-sm-10 col-sm-push-2">
33
            <main>
34
35
        [% IF filters_count %]
36
            <div id="search_filters_list">
37
                <h2>Search filters</h2>
38
39
                <table id="search_filters_table">
40
                    <thead>
41
                        <tr>
42
                            <th>Id</th>
43
                            <th>Name</th>
44
                            <th>Query</th>
45
                            <th>Limits</th>
46
                            <th>OPAC</th>
47
                            <th>Staff client</th>
48
                            <th>&nbsp;</th>
49
                        </tr>
50
                    </thead>
51
                </table>
52
            </div>
53
        [% ELSE %]
54
            <div class="dialog message">
55
                There are no search filters defined.
56
            </div>
57
        [% END %]
58
59
            </main>
60
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
61
62
        <div class="col-sm-2 col-sm-pull-10">
63
            <aside>
64
                [% INCLUDE 'admin-menu.inc' %]
65
            </aside>
66
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
67
     </div> <!-- /.row -->
68
69
    <div id="edit_search_filter_modal" class="modal" role="dialog" aria-hidden="true">
70
        <div class="modal-dialog">
71
        <div class="modal-content">
72
            <div class="modal-header">
73
                <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
74
                <h3 id="search_filters_label">Edit filter: <span id="filter_edit_modal_name"></span</h3>
75
            </div>
76
            <div class="modal-body">
77
                <input type="hidden" id="filter_edit_id" name="filter_edit_id">
78
                <label for="filter_edit_name">Name:</label>
79
                <input id="filter_edit_name" name="filter_edit_name" type="text">
80
                <hr>
81
                <h6>Visibility:<h6>
82
                <label for="filter_edit_opac">Show in OPAC?</label>
83
                <input type="checkbox" id="filter_edit_opac" name="filter_edit_opac">
84
                <label for="filter_edit_staff_client">Show in Staff client?</label>
85
                <input type="checkbox" id="filter_edit_staff_client" name="filter_edit_staff_client">
86
                <hr>
87
                <a id="replace_existing_filter" class="btn btn-default btn-xs" href="#">Update</a>
88
            </div>
89
            <div class="modal-footer">
90
                <a href="#" data-dismiss="modal" aria-hidden="true" class="cancel">Cancel</a>
91
            </div>
92
        </div>
93
        </div>
94
    </div>
95
96
[% MACRO jsinclude BLOCK %]
97
    [% Asset.js("js/admin-menu.js") | $raw %]
98
    [% Asset.css("css/humanmsg.css") | $raw %]
99
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
100
    [% INCLUDE 'datatables.inc' %]
101
102
    <script>
103
        let filters_table;
104
        $(document).ready(function(){
105
            filters_table = $("#search_filters_table").kohaTable({
106
                "ajax": {
107
                    "url": "/api/v1/search_filters"
108
                },
109
                "columns": [
110
                    {
111
                        "data": "search_filter_id",
112
                        "searchable": true,
113
                        "orderable": true
114
                    },
115
                    {
116
                        "data": "name",
117
                        "searchable": true,
118
                        "orderable": true
119
                    },
120
                    {
121
                        "data": "filter_query",
122
                        "searchable": true,
123
                        "orderable": true
124
                    },
125
                    {
126
                        "data": "filter_limits",
127
                        "searchable": true,
128
                        "orderable": true
129
                    },
130
                    {
131
                        "data": "opac",
132
                        "searchable": true,
133
                        "orderable": true
134
                    },
135
                    {
136
                        "data": "staff_client",
137
                        "searchable": true,
138
                        "orderable": true
139
                    },
140
                    {
141
                        "data": function( row, meta, val, type ) {
142
                            let filter = row;
143
                            let filter_buttons = '<a class="btn btn-default btn-xs edit_filter" onclick="edit_filter(this)"';
144
                            filter_buttons += ' data-filter_id="'+ filter.search_filter_id;
145
                            filter_buttons += '" data-filter_name="'+ filter.name;
146
                            filter_buttons += '" data-filter_opac="'+ filter.opac;
147
                            filter_buttons += '" data-filter_staff_client="'+ filter.staff_client;
148
                            filter_buttons += '" ><i class="fa fa-pencil"></i> Edit filter</a>';
149
                            filter_buttons += '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/catalogue/search.pl?edit_filter='+filter.search_filter_id+'"><i class="fa fa-search"></i> Edit search</a>';
150
                            filter_buttons += '<a class="btn btn-default btn-xs delete_filter" onclick="delete_filter(this)"';
151
                            filter_buttons += ' data-filter_id="'+ filter.search_filter_id;
152
                            filter_buttons += '"><i class="fa fa-trash"></i> Delete</a>';
153
                            return filter_buttons;
154
                        },
155
                        "searchable": false,
156
                        "orderable": false
157
                    }
158
                ]
159
            });
160
        });
161
162
        $("#replace_existing_filter").click(function(){
163
            let name = $("#filter_edit_name").val();
164
            let id = $("#filter_edit_id").val();
165
            let opac = $("#filter_edit_opac").prop('checked');
166
            let staff_client = $("#filter_edit_staff_client").prop('checked');
167
            save_search_filter(name,id,opac,staff_client);
168
        });
169
170
        function edit_filter(element){
171
            let filter_id = $(element).data('filter_id');
172
            let filter_name = $(element).data('filter_name');
173
            let filter_opac = $(element).data('filter_opac');
174
            let filter_staff_client = $(element).data('filter_staff_client');
175
            $("#filter_edit_name").val(filter_name);
176
            $("#filter_edit_id").val(filter_id);
177
            $("#filter_edit_opac").prop('checked',filter_opac);
178
            $("#filter_edit_staff_client").prop('checked',filter_staff_client);
179
            $("#edit_search_filter_modal").modal('show');
180
        };
181
182
        function delete_filter(element){
183
            let filter_id = $(element).data('filter_id');
184
            let options = {
185
                url: '/api/v1/search_filters/' + filter_id,
186
                method: "DELETE",
187
                contentType: "application/json",
188
            };
189
            $.ajax(options)
190
                .then(function(result) {
191
                    humanMsg.displayAlert( _("Filter successfully deleted."), { className: 'human Success' } );
192
                    filters_table.DataTable().ajax.reload();
193
                })
194
                .fail(function(err) {
195
                    humanMsg.displayAlert( _("There was an error during saving:") + err.responseText, { className: 'humanError' } );
196
                });
197
        }
198
199
200
        function save_search_filter(name,id,opac,staff){
201
            let options = {
202
                url: '/api/v1/search_filters/' + id,
203
                method: "PUT",
204
                contentType: "application/json",
205
                data: JSON.stringify({
206
                    name: name,
207
                    opac: opac,
208
                    staff_client: staff,
209
                })
210
            };
211
            $.ajax(options)
212
                .then(function(result) {
213
                    $("#edit_search_filter_modal").modal('hide');
214
                    humanMsg.displayAlert( _("Saved filter: ") + name  , { className: 'human Success' } );
215
                    filters_table.DataTable().ajax.reload();
216
                })
217
                .fail(function(err) {
218
                    humanMsg.displayAlert( _("There was an error during saving:") + err.responseText, { className: 'humanError' } );
219
                });
220
        }
221
222
223
    </script>
224
[% END %]
225
226
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (-2 / +87 lines)
Lines 48-53 Link Here
48
48
49
<form action="search.pl" method="get">
49
<form action="search.pl" method="get">
50
<div id="advanced-search">
50
<div id="advanced-search">
51
[% IF edit_filter %]
52
<div id="toolbar" class="btn-toolbar">
53
    <fieldset class="action" id="submit1">
54
        <legend>Editing filter: [% edit_filter.name | html %]</legend>
55
        <div class="btn-group">
56
            <label for="filter_edit_opac">Show in OPAC?</label>
57
            [% IF edit_filter.opac %]
58
                <input type="checkbox" id="show_filter_opac" name="show_filter_opac" checked="checked">
59
            [% ELSE %]
60
                <input type="checkbox" id="show_filter_opac" name="show_filter_opac">
61
            [% END %]
62
            <label for="filter_edit_staff_client">Show in Staff client?</label>
63
            [% IF edit_filter.staff_client %]
64
                <input type="checkbox" id="filter_edit_staff_client" name="filter_edit_staff_client" checked="checked">
65
            [% ELSE %]
66
                <input type="checkbox" id="filter_edit_staff_client" name="filter_edit_staff_client">
67
            [% END %]
68
        </div>
69
        <hr>
70
        <div class="btn-group">
71
            <button id="save_filter" class="btn btn-default"><i class="fa fa-save"></i> Save filter</button>
72
            <button class="btn btn-default" type="submit" accesskey="s"><i class="fa fa-search"></i> Search using filter</button>
73
        </div>
74
        <div class="btn-group">
75
            <a href="/cgi-bin/koha/catalogue/search.pl?do=Clear&expanded_options=[% expanded_options | uri %]" class="btn btn-link"><i class="fa fa-trash"></i> Cancel</a>
76
        </div>
77
    </fieldset>
78
</div>
79
[% ELSE %]
51
<input type="hidden" name="advsearch" value="1"/>
80
<input type="hidden" name="advsearch" value="1"/>
52
<h1>Advanced search</h1>
81
<h1>Advanced search</h1>
53
<p>
82
<p>
Lines 77-83 Link Here
77
    </fieldset>
106
    </fieldset>
78
</div>
107
</div>
79
<!-- /SEARCH BUTTONS -->
108
<!-- /SEARCH BUTTONS -->
80
109
[% END %]
81
110
82
[% IF ( outer_servers_loop ) %]
111
[% IF ( outer_servers_loop ) %]
83
<!-- DATABASES -->
112
<!-- DATABASES -->
Lines 105-111 Link Here
105
<!-- BOOLEAN SEARCH OPTIONS -->
134
<!-- BOOLEAN SEARCH OPTIONS -->
106
    <fieldset id="searchterms">
135
    <fieldset id="searchterms">
107
    <legend>Search for </legend>
136
    <legend>Search for </legend>
108
    [% FOREACH query IN queries %]
137
    [% FOREACH query IN operands %]
109
        [% IF ( expanded_options ) %]
138
        [% IF ( expanded_options ) %]
110
        [% IF loop.first %]
139
        [% IF loop.first %]
111
        <div class="search-term-row" style="text-indent: 4.25em;">
140
        <div class="search-term-row" style="text-indent: 4.25em;">
Lines 328-333 Link Here
328
[% END %]
357
[% END %]
329
<!-- /OTHER LIMITS (facets, etc.) -->
358
<!-- /OTHER LIMITS (facets, etc.) -->
330
359
360
[% UNLESS edit_filter %]
331
<!-- RANK LIMITS -->
361
<!-- RANK LIMITS -->
332
<fieldset id="sortby"><legend>Sorting</legend>
362
<fieldset id="sortby"><legend>Sorting</legend>
333
    <p>
363
    <p>
Lines 336-341 Link Here
336
    </select>
366
    </select>
337
        </p>
367
        </p>
338
</fieldset>
368
</fieldset>
369
[% END %]
339
</div>
370
</div>
340
<!-- /RANK LIMITS -->
371
<!-- /RANK LIMITS -->
341
</form>
372
</form>
Lines 345-350 Link Here
345
[% MACRO jsinclude BLOCK %]
376
[% MACRO jsinclude BLOCK %]
346
    [% Asset.js("lib/hc-sticky.js") | $raw %]
377
    [% Asset.js("lib/hc-sticky.js") | $raw %]
347
    [% Asset.js("js/browser.js") | $raw %]
378
    [% Asset.js("js/browser.js") | $raw %]
379
    [% Asset.css("css/humanmsg.css") | $raw %]
380
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
348
    <script>
381
    <script>
349
        /**
382
        /**
350
         *  Function add_field();
383
         *  Function add_field();
Lines 398-403 Link Here
398
                browser.show_back_link();
431
                browser.show_back_link();
399
            [% END %]
432
            [% END %]
400
433
434
            [% IF edit_filter %]
435
            $("#save_filter").click(function(e){
436
                e.preventDefault();
437
                let operators = [];
438
                let indexes = [];
439
                let operands = [];
440
                let limits =[];
441
                let opac = $("#show_filter_opac").prop('checked');
442
                let staff_client = $("#show_filter_staff_client").prop('checked');
443
                $("select[name='op']").each(function(){
444
                    operators.push( $(this).val() );
445
                });
446
                $("select[name='idx']").each(function(){
447
                    indexes.push( $(this).val() );
448
                });
449
                $("input[name='q']").each(function(){
450
                    operands.push( $(this).val() );
451
                });
452
                $("select[name='limit'],input[name='limit']:checked").each(function(){
453
                    if( $(this).val() != ""){
454
                        limits.push( $(this).val() );
455
                    }
456
                });
457
                let year_limit = $("#limit-yr").val();
458
                if( year_limit ){
459
                    limits.push( "yr,st-numeric:"+year_limit );
460
                }
461
                let options = {
462
                    url: '/api/v1/search_filters/'+ [% edit_filter.id | html %],
463
                    method: "PUT",
464
                    contentType: "application/json",
465
                    data: JSON.stringify({
466
                        name: "[% edit_filter.name | html %]",
467
                        filter_query: JSON.stringify({ operands: operands, indexes: indexes, operators:operators }),
468
                        filter_limits: JSON.stringify({ limits: limits }),
469
                        opac: opac,
470
                        staff_client: staff_client,
471
                    })
472
                };
473
                $.ajax(options)
474
                    .then(function(result) {
475
                        humanMsg.displayAlert( _("Saved filter: ") + result.name  , { className: 'human Success' } );
476
                    })
477
                    .fail( function(err){
478
                        humanMsg.displayAlert( _("There was an error during saving:") + err.responseText, { className: 'humanError' } );
479
                    });
480
481
482
            });
483
            [% END %]
484
485
401
        });
486
        });
402
    </script>
487
    </script>
403
[% END %]
488
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt (-3 lines)
Lines 832-838 Link Here
832
            $("#replace_existing_filter").click(function(){
832
            $("#replace_existing_filter").click(function(){
833
                let id = $("#existing_filters").val();
833
                let id = $("#existing_filters").val();
834
                let name = $("#existing_filters option[value="+id+"]").text();
834
                let name = $("#existing_filters option[value="+id+"]").text();
835
                console.log(id,name);
836
                save_search_filter(name,id);
835
                save_search_filter(name,id);
837
            });
836
            });
838
            function save_search_filter(name,id,opac,staff){
837
            function save_search_filter(name,id,opac,staff){
Lines 860-866 Link Here
860
                        getFilters();
859
                        getFilters();
861
                    })
860
                    })
862
                    .fail(function(err) {
861
                    .fail(function(err) {
863
                        console.log(err);
864
                        humanMsg.displayAlert( _("There was an error during saving:") + err.responseText, { className: 'humanError' } );
862
                        humanMsg.displayAlert( _("There was an error during saving:") + err.responseText, { className: 'humanError' } );
865
                    });
863
                    });
866
            }
864
            }
867
- 

Return to bug 17170