Bug 19482: (follow-up) Don't set readonly as a variable, use conditionals
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / searchengine / elasticsearch / mappings.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha &rsaquo; Administration &rsaquo; Search engine configuration (Elasticsearch)</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 [% Asset.js("lib/jquery/plugins/jquery.tablednd.js") | $raw %]
8 <script>
9     function clean_line( line ) {
10         $(line).find('input[type="text"]').val("");
11         $(line).find('select').find('option:first').attr("selected", "selected");
12     }
13
14     function clone_line( line ) {
15         var new_line = $(line).clone();
16         $(new_line).removeClass("nodrag nodrop");
17         $(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html(_("Delete"));
18         $(new_line).find('[data-id]').each( function() {
19             $(this).attr({ name: $(this).attr('data-id') }).removeAttr('data-id');
20         } );
21         $(new_line).find("select").each( function() {
22             var attr = $(this).attr('name');
23             var val = $(line).find('[data-id="' + attr + '"]').val();
24             $(this).find('option[value="' + val + '"]').attr("selected", "selected");
25         } );
26         return new_line;
27     }
28
29     $(document).ready(function() {
30         $("#tabs").tabs();
31         $('.delete').click(function() {
32             if( $(this).hasClass('mandatory') && $(".mandatory[data-field_name="+$(this).attr('data-field_name')+"]").length < 2 ){
33                 alert("This field is mandatory and must have at least one mapping");
34                 return;
35             } else {
36                 $(this).parents('tr').remove();
37             }
38         });
39
40         $("table.mappings").tableDnD( {
41             onDragClass: "dragClass",
42         } );
43         $('.add').click(function() {
44             var table = $(this).closest('table');
45             var index_name   = $(table).attr('data-index_name');
46             var line = $(this).closest("tr");
47             var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val();
48             if ( marc_field.length > 0 ) {
49                 var new_line = clone_line( line );
50                 new_line.appendTo($('table[data-index_name="'+index_name+'"]>tbody'));
51                 $('.delete').click(function() {
52                     $(this).parents('tr').remove();
53                 });
54                 clean_line(line);
55
56                 $(table).tableDnD( {
57                     onDragClass: "dragClass",
58                 } );
59             }
60         });
61         $("#facet_biblios > table").tableDnD( {
62             onDragClass: "dragClass",
63         } );
64     });
65 </script>
66 <style>
67 a.add, a.delete {
68     cursor: pointer;
69 }
70 </style>
71 </head>
72 <body id="admin_searchengine_mappings" class="admin">
73 [% INCLUDE 'header.inc' %]
74 [% INCLUDE 'prefs-admin-search.inc' %]
75
76 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Search engine configuration (Elasticsearch)</div>
77
78 [% INCLUDE 'blocking_errors.inc' %]
79
80 <div class="main container-fluid">
81     <div class="row">
82         <div class="col-sm-10 col-sm-push-2">
83             <main>
84
85     [% FOR m IN messages %]
86       <div class="dialog [% m.type | html %]">
87         [% SWITCH m.code %]
88         [% CASE 'error_on_update' %]
89           [% tx("An error occurred when updating mappings: {message}.", { message = m.message }) | html %]
90         [% CASE 'error_on_delete' %]
91           [% t("An error occurred when deleting the existing mappings. Nothing has been changed!") | $raw %]
92           [% tx("(search field {field_name} with mapping {marc_field}.)", { field_name = m.values.field_name, marc_field = m.values.marc_field }) | html %]
93         [% CASE 'invalid_field_weight' %]
94           [% tx("Invalid field weight '{weight}', must be a positive decimal number.", { weight = m.weight }) | html %]
95         [% CASE 'missing_mandatory_fields' %]
96           [% t("You attempted to delete all mappings for a required index, you must leave at least one mapping") | $raw %]
97         [% CASE 'error_on_update_es_mappings' %]
98           [% tx("An error occurred when updating Elasticsearch index mappings: {message}.", { message = m.message }) | html %]
99         [% CASE 'reindex_required' %]
100           [% tx("Index '{index}' needs to be reindexed.", { index = m.index }) | html %]
101         [% CASE 'recreate_required' %]
102           [% tx("Index '{index}' needs to be recreated.", { index = m.index }) | html %]
103         [% CASE 'success_on_update' %]
104           [% t("Mappings updated successfully.") | $raw %]
105         [% CASE 'success_on_reset' %]
106           [% t("Mappings have been reset successfully.") | $raw %]
107         [% CASE 'elasticsearch_disabled' %]
108           [% t("Elasticsearch is currently disabled.") | $raw %]
109         [% CASE %]
110           [% m.code | html %]
111         [% END %]
112       </div>
113     [% END %]
114
115     <h1>Search engine configuration (Elasticsearch)</h1>
116     <div class="dialog message">
117         Warning: Any changes to the configuration will only take effect after a full reindex. Until then searching may not work correctly.
118
119         <p>Weight: define weight as a positive number. Higher numbers indicate increased relevancy.
120         <strong>Note that fields weighting works only for simple search.</strong></p>
121         <ol>
122           <li>only search fields mapped with biblios can be weighted</li>
123           <li>search will boost/increase weighted field(s) relevancy</li>
124         </ol>
125     </div>
126     [% IF errors %]
127         <div class="dialog alert">
128         Changes have not been applied. Please check the following values:
129           <ul>
130             [% FOREACH e IN errors %]
131                 <li>
132                     [% IF ( e.type == "malformed_mapping" ) %]
133                         <span>The value "[% e.value | html %]" is not supported for mappings</span>
134                     [% ELSIF ( e.type == "no_mapping" ) %]
135                         <span>There is no mapping for the index [% e.value | html %]</span>
136                     [% END %]
137                 </li>
138             [% END %]
139           </ul>
140         </div>
141     [% END %]
142
143     [% IF reset_confirm %]
144         <div class="dialog alert">
145             <h3>The current mappings you see on the screen will be erased and replaced by the mappings in the mappings.yaml file.</h3>
146             <form method="post">
147                 <input type="hidden" name="op" value="reset_confirmed" />
148                 <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, reset mappings</button>
149             </form>
150             <br>
151             <form method="post">
152                 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not reset mappings</button>
153             </form>
154         </div>
155     [% END %]
156     <form method="post">
157         <div id="tabs" class="toptabs" style="clear:both">
158             <ul>
159                 <li><a href="#search_fields">Search fields</a></li>
160                 [% FOREACH index IN indexes %]
161                     [% SWITCH index.index_name %]
162                         [% CASE 'biblios' %]<li><a href="#mapping_biblios">Bibliographic records</a></li>
163                         [% CASE 'authorities' %]<li><a href="#mapping_authorities">Authorities</a></li>
164                     [% END %]
165                 [% END %]
166             </ul>
167             <div id="search_fields">
168               <table class="search_fields">
169                 <thead>
170                   <tr>
171                     <th>Name</th>
172                     <th>Label</th>
173                     <th>Type</th>
174                     <th colspan="2">Searchable</th>
175                     <th>Weight</th>
176                   </tr>
177                   <tr>
178                     <th colspan=3>&nbsp;</th>
179                     <th>Staff interface</th>
180                     <th>OPAC</th>
181                     <th>&nbsp;</th>
182                   </tr>
183                 </thead>
184                 <tbody>
185                   [% FOREACH search_field IN all_search_fields %]
186                     <tr>
187                       <td>
188                         [% IF search_field.mandatory %]
189                             <input type="text" name="search_field_name" value="[% search_field.name | html %]" readonly />
190                         [% ELSE %]
191                             <input type="text" name="search_field_name" value="[% search_field.name | html %]" />
192                         [% END %]
193                       </td>
194                       <td>
195                         [% IF search_field.mandatory %]
196                             <input type="text" name="search_field_label" value="[% search_field.label | html %]" readonly />
197                         [% ELSE %]
198                             <input type="text" name="search_field_label" value="[% search_field.label | html %]" />
199                         [% END %]
200
201                       <td>
202                         [% IF search_field.mandatory %]
203                             <input type="hidden" name="search_field_type" value="[% search_field.type | html %]" />
204                             <select name="search_field_type" disabled>
205                         [% ELSE %]
206                             <select name="search_field_type">
207                         [% END %]
208                               <option value=""></option>
209                               [% IF search_field.type == "string" %]
210                                 <option value="string" selected="selected">String</option>
211                               [% ELSE %]
212                                 <option value="string">String</option>
213                               [% END %]
214                               [% IF search_field.type == "date" %]
215                                 <option value="date" selected="selected">Date</option>
216                               [% ELSE %]
217                                 <option value="date">Date</option>
218                               [% END %]
219                               [% IF search_field.type == "year" %]
220                                 <option value="year" selected="selected">Year</option>
221                               [% ELSE %]
222                                 <option value="year">Year</option>
223                               [% END %]
224                               [% IF search_field.type == "number" %]
225                                 <option value="number" selected="selected">Number</option>
226                               [% ELSE %]
227                                 <option value="number">Number</option>
228                               [% END %]
229                               [% IF search_field.type == "boolean" %]
230                                 <option value="boolean" selected="selected">Boolean</option>
231                               [% ELSE %]
232                                 <option value="boolean">Boolean</option>
233                               [% END %]
234                               [% IF search_field.type == "sum" %]
235                                 <option value="sum" selected="selected">Sum</option>
236                               [% ELSE %]
237                                 <option value="sum">Sum</option>
238                               [% END %]
239                               [% IF search_field.type == "isbn" %]
240                                 <option value="isbn" selected="selected">ISBN</option>
241                               [% ELSE %]
242                                 <option value="isbn">ISBN</option>
243                               [% END %]
244                               [% IF search_field.type == "stdno" %]
245                                 <option value="stdno" selected="selected">Std. Number</option>
246                               [% ELSE %]
247                                 <option value="stdno">Std. Number</option>
248                               [% END %]
249                             </select>
250                       </td>
251                       <td>
252                         <select name="search_field_staff_client">
253                           [% IF search_field.staff_client %]
254                             <option value="1" selected="selected">Yes</option>
255                             <option value="0">No</option>
256                           [% ELSE %]
257                             <option value="1">Yes</option>
258                             <option value="0" selected="selected">No</option>
259                           [% END %]
260                         </select>
261                       </td>
262                       <td>
263                         <select name="search_field_opac">
264                           [% IF search_field.opac %]
265                             <option value="1" selected="selected">Yes</option>
266                             <option value="0">No</option>
267                           [% ELSE %]
268                             <option value="1">Yes</option>
269                             <option value="0" selected="selected">No</option>
270                           [% END %]
271                         </select>
272                       </td>
273                       <td>
274                         [% IF search_field.mapped_biblios %]
275                             <input type="number" step="0.01" min="0.01" max="999.99" name="search_field_weight" value="[% search_field.weight | html %]" />
276                         [% ELSE %]
277                             <input type="hidden" name="search_field_weight" value="">
278                         [% END %]
279                       </td>
280                     </tr>
281                   [% END %]
282                 </tbody>
283               </table>
284             </div>
285             [% FOREACH index IN indexes %]
286                 <div id="mapping_[% index.index_name | html %]">
287                     <table class="mappings" data-index_name="[% index.index_name | html %]">
288                       <thead>
289                         <tr class="nodrag nodrop">
290                           <th>Search field</th>
291                           <th>Sortable</th>
292                           <th>Facetable</th>
293                           <th>Suggestible</th>
294                           <th>Searchable</th>
295                           <th>Mapping</th>
296                           <th></th>
297                         </tr>
298                       </thead>
299                       <tbody>
300                         [% FOREACH mapping IN index.mappings %]
301                             [% IF mapping.search_field_mandatory && mapping.search_field_label != loop.next.search_field_label && mapping.search_field_label != loop.prev.search_field_label %]
302                               <tr>
303                                 <td>
304                                   <input type="hidden" name="mapping_index_name" value="[% index.index_name | html %]" />
305                                   <input type="hidden" name="mapping_search_field_name" value="[% mapping.search_field_name | html %]">
306                                   [% mapping.search_field_label | html %]
307                                 </td>
308                                 <td>
309                                   <input type="hidden" name="mapping_sort" value="[% mapping.sort | html %]" readonly />[% IF mapping.sort == 'undef' %]Undef[% ELSE %][% mapping.sort | html %][% END %]
310                                 </td>
311                                 <td>
312                                   <input type="hidden" name="mapping_facet" value="[% mapping.facet | html %]" readonly />[% IF mapping.facet == 1 %]Yes[% ELSE %]No[% END %]
313                                 </td>
314                                 <td>
315                                   <input type="hidden" name="mapping_suggestible" value="[% mapping.suggestible | html %]" readonly />[% IF mapping.suggestible == 1 %]Yes[% ELSE %]No[% END %]
316                                 </td>
317                                 <td>
318                                   <input type="hidden" name="mapping_search" value="[% mapping.search | html %]" readonly />[% IF mapping.search == 1 %]Yes[% ELSE %]No[% END %]
319                                 </td>
320                                 <td>
321                                     <input name="mapping_marc_field" type="text" value="[% mapping.marc_field | html %]" />
322                                 </td>
323                               </tr>
324                             [% ELSE %]
325                               <tr>
326                                 <td>
327                                   <input type="hidden" name="mapping_index_name" value="[% index.index_name | html %]" />
328                                   <input type="hidden" name="mapping_search_field_name" value="[% mapping.search_field_name | html %]">
329                                   [% mapping.search_field_label | html %]
330                                 </td>
331                                 <td>
332                                   <select name="mapping_sort">
333                                     [% IF mapping.sort == 'undef' %]
334                                       <option value="undef" selected="selected">Undef</option>
335                                     [% ELSE %]
336                                       <option value="undef">Undef</option>
337                                     [% END %]
338                                     [% IF mapping.sort == 0 %]
339                                       <option value="0" selected="selected">0</option>
340                                     [% ELSE %]
341                                       <option value="0">0</option>
342                                     [% END %]
343                                     [% IF  mapping.sort == 1 %]
344                                       <option value="1" selected="selected">1</option>
345                                     [% ELSE %]
346                                       <option value="1">1</option>
347                                     [% END %]
348                                   </select>
349                                 </td>
350                                 <td>
351                                   [% IF mapping.is_facetable %]
352                                     <select name="mapping_facet">
353                                       [% IF mapping.facet %]
354                                         <option value="0">No</option>
355                                         <option value="1" selected="selected">Yes</option>
356                                       [% ELSE %]
357                                         <option value="0" selected="selected">No</option>
358                                         <option value="1">Yes</option>
359                                       [% END %]
360                                     </select>
361                                   [% ELSE %]
362                                     <input type="hidden" name="mapping_facet" value="0" />
363                                     No
364                                   [% END %]
365                                 </td>
366                                 <td>
367                                   <select name="mapping_suggestible">
368                                     [% IF mapping.suggestible %]
369                                       <option value="0">No</option>
370                                       <option value="1" selected="selected">Yes</option>
371                                     [% ELSE %]
372                                       <option value="0" selected="selected">No</option>
373                                       <option value="1">Yes</option>
374                                     [% END %]
375                                   </select>
376                                 </td>
377                                 <td>
378                                   <select name="mapping_search">
379                                     [% IF mapping.search %]
380                                       <option value="0">No</option>
381                                       <option value="1" selected="selected">Yes</option>
382                                     [% ELSE %]
383                                       <option value="0" selected="selected">No</option>
384                                       <option value="1">Yes</option>
385                                     [% END %]
386                                   </select>
387                                 </td>
388                                 <td>
389                                     <input name="mapping_marc_field" type="text" value="[% mapping.marc_field | html %]" />
390                                 </td>
391                                 [% IF mapping.search_field_mandatory %]
392                                     <td><a class="btn btn-default btn-xs delete mandatory" data-field_name="[% mapping.search_field_name | html %]" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a></td>
393                                 [% ELSE %]
394                                     <td><a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a></td>
395                                 [% END %]
396                               </tr>
397                             [% END %]
398                         [% END %]
399                       </tbody>
400                       <tfoot>
401                         <tr class="nodrag nodrop">
402                           <td>
403                             <input data-id="mapping_index_name" type="hidden" value="[% index.index_name | html %]" />
404                             <select data-id="mapping_search_field_name">
405                              [% FOREACH f IN all_search_fields %]
406                                <option value="[% f.name | html %]">[% f.name | html %]</option>
407                              [% END %]
408                             </select>
409                           </td>
410                           <td>
411                             <select data-id="mapping_sort">
412                               <option value="undef">Undef</option>
413                               <option value="0">0</option>
414                               <option value="1">1</option>
415                             </select>
416                           </td>
417                           <td>
418                             <select data-id="mapping_facet">
419                               [% IF mapping.facet %]
420                                 <option value="0">No</option>
421                                 <option value="1" selected="selected">Yes</option>
422                               [% ELSE %]
423                                 <option value="0" selected="selected">No</option>
424                                 <option value="1">Yes</option>
425                               [% END %]
426                             </select>
427                           </td>
428                           <td>
429                             <select data-id="mapping_suggestible">
430                               [% IF mapping.suggestible %]
431                                 <option value="0">No</option>
432                                 <option value="1" selected="selected">Yes</option>
433                               [% ELSE %]
434                                 <option value="0" selected="selected">No</option>
435                                 <option value="1">Yes</option>
436                               [% END %]
437                             </select>
438                           </td>
439                           <td>
440                             <select data-id="mapping_search">
441                               [% IF mapping.search %]
442                                 <option value="0">No</option>
443                                 <option value="1" selected="selected">Yes</option>
444                               [% ELSE %]
445                                 <option value="0" selected="selected">No</option>
446                                 <option value="1">Yes</option>
447                               [% END %]
448                             </select>
449                           </td>
450                           <td><input data-id="mapping_marc_field" type="text" /></td>
451                           <td><a class="btn btn-default btn-xs add"><i class="fa fa-plus"></i> Add</a></td>
452                         </tr>
453                       </tfoot>
454                     </table>
455
456                     [% IF index.index_name == 'biblios' %]
457                         <h3>Facet order</h3>
458                         <div id="facet_[% index.index_name | html %]">
459                             <table>
460                                 <thead>
461                                     <tr>
462                                         <th>Search field</th>
463                                         <th>Label</th>
464                                         <th>Display</th>
465                                     </tr>
466                                 </thead>
467                                 <tbody>
468                                     [% FOREACH f IN facetable_fields %]
469                                         <tr>
470                                             <td>
471                                                 [% f.name | html %]
472                                             </td>
473                                             <td>
474                                                 [% SWITCH f.name %]
475                                                 [% CASE 'author' %]Authors
476                                                 [% CASE 'itype' %]Item Types
477                                                 [% CASE 'location' %]Locations
478                                                 [% CASE 'su-geo' %]Places
479                                                 [% CASE 'title-series' %]Series
480                                                 [% CASE 'subject' %]Topics
481                                                 [% CASE 'ccode' %]Collections
482                                                 [% CASE 'holdingbranch' %]Holding libraries
483                                                 [% CASE 'homebranch' %]Home libraries
484                                                 [% CASE 'ln' %]Language
485                                                 [% CASE %][% f | html %]
486                                                 [% END %]
487                                             </td>
488                                             <td>
489                                                 [% IF f.facet_order %]
490                                                     <input type="checkbox" name="display_facet" value="[% f.name | html %]" checked="checked" />
491                                                 [% ELSE %]
492                                                     <input type="checkbox" name="display_facet" value="[% f.name | html %]" />
493                                                 [% END %]
494                                             </td>
495                                         </tr>
496                                     [% END %]
497                                 </tbody>
498                             </table>
499                         </div>
500                     [% END %]
501                 </div>
502             [% END %]
503         </div>
504         <p>
505             <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
506             <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
507         </p>
508     </form>
509
510             </main>
511         </div> <!-- /.col-sm-10.col-sm-push-2 -->
512
513         <div class="col-sm-2 col-sm-pull-10">
514             <aside>
515                 [% INCLUDE 'admin-menu.inc' %]
516             </aside>
517         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
518      </div> <!-- /.row -->
519
520 [% INCLUDE 'intranet-bottom.inc' %]