Bug 18316: Fix field weight validation/deletion bug
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / searchengine / elasticsearch / mappings.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% INCLUDE 'doc-head-open.inc' %]
4 <title>Koha &rsaquo; Administration &rsaquo; Search engine configuration</title>
5 [% INCLUDE 'doc-head-close.inc' %]
6 [% Asset.js("lib/jquery/plugins/jquery.tablednd.js") | $raw %]
7 <script>
8     function clean_line( line ) {
9         $(line).find('input[type="text"]').val("");
10         $(line).find('select').find('option:first').attr("selected", "selected");
11     }
12
13     function clone_line( line ) {
14         var new_line = $(line).clone();
15         $(new_line).removeClass("nodrag nodrop");
16         $(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html(_("Delete"));
17         $(new_line).find('[data-id]').each( function() {
18             $(this).attr({ name: $(this).attr('data-id') }).removeAttr('data-id');
19         } );
20         $(new_line).find("select").each( function() {
21             var attr = $(this).attr('name');
22             var val = $(line).find('[data-id="' + attr + '"]').val();
23             $(this).find('option[value="' + val + '"]').attr("selected", "selected");
24         } );
25         return new_line;
26     }
27
28     $(document).ready(function() {
29         $("#tabs").tabs();
30         $('.delete').click(function() {
31             $(this).parents('tr').remove();
32         });
33
34         $("table.mappings").tableDnD( {
35             onDragClass: "dragClass",
36         } );
37         $('.add').click(function() {
38             var table = $(this).closest('table');
39             var index_name   = $(table).attr('data-index_name');
40             var line = $(this).closest("tr");
41             var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val();
42             if ( marc_field.length > 0 ) {
43                 var new_line = clone_line( line );
44                 new_line.appendTo($('table[data-index_name="'+index_name+'"]>tbody'));
45                 $('.delete').click(function() {
46                     $(this).parents('tr').remove();
47                 });
48                 clean_line(line);
49
50                 $(table).tableDnD( {
51                     onDragClass: "dragClass",
52                 } );
53             }
54         });
55     });
56 </script>
57 <style>
58 a.add, a.delete {
59     cursor: pointer;
60 }
61 </style>
62 </head>
63 <body id="admin_searchengine_mappings" class="admin">
64 [% INCLUDE 'header.inc' %]
65 [% INCLUDE 'prefs-admin-search.inc' %]
66
67 <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</div>
68
69 <div class="main container-fluid">
70     <div class="row">
71         <div class="col-sm-10 col-sm-push-2">
72             <main>
73
74     [% FOR m IN messages %]
75       <div class="dialog [% m.type | html %]">
76         [% SWITCH m.code %]
77         [% CASE 'error_on_update' %]
78           An error occurred when updating mappings ([% m.message | html %]).
79         [% CASE 'error_on_delete' %]
80           An error occurred when deleting the existing mappings. Nothing has been changed!
81           (search field [% m.values.field_name | html %] with mapping [% m.values.marc_field | html %].)
82         [% CASE 'invalid_field_weight' %]
83           Invalid field weight "[% m.weight | html %]", must be a positive decimal number.
84         [% CASE 'success_on_update' %]
85           Mappings updated successfully.
86         [% CASE 'success_on_reset' %]
87           Mappings have been reset successfully.
88         [% CASE %]
89           [% m.code | html %]
90         [% END %]
91       </div>
92     [% END %]
93
94     <h1>Search engine configuration</h1>
95     <div class="dialog message">
96         Warning: Any changes to the configuration will only take effect after a full reindex. Until then searching may not work correctly.
97
98         <p>Weight: define weight as a positive number. Higher numbers indicate increased relevancy.
99         <strong>Note that fields weighting works only for simple search.</strong></p>
100         <ol>
101           <li>only search fields mapped with biblios can be weighted</li>
102           <li>search will boost/increase weighted field(s) relevancy</li>
103         </ol>
104     </div>
105     [% IF errors %]
106         <div class="dialog alert">
107         Changes have not been applied. Please check the following values:
108           <ul>
109             [% FOREACH e IN errors %]
110                 <li>
111                     [% IF ( e.type == "malformed_mapping" ) %]
112                         The value "[% e.value | html %]" is not supported for mappings
113                     [% ELSIF ( e.type == "no_mapping" ) %]
114                         There is no mapping for the index [% e.value | html %]
115                     [% END %]
116                 </li>
117             [% END %]
118           </ul>
119         </div>
120     [% END %]
121
122     [% IF reset_confirm %]
123         <div class="dialog alert">
124             <h3>The current mappings you see on the screen will be erased and replaced by the mappings in the mappings.yaml file.</h3>
125             <form method="post">
126                 <input type="hidden" name="op" value="reset_confirmed" />
127                 <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, reset mappings</button>
128             </form>
129             <br>
130             <form method="post">
131                 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not reset mappings</button>
132             </form>
133         </div>
134     [% END %]
135     <form method="post">
136         <div id="tabs" class="toptabs" style="clear:both">
137             <ul>
138                 <li><a href="#search_fields">Search fields</a></li>
139                 [% FOREACH index IN indexes %]
140                     [% SWITCH index.index_name %]
141                         [% CASE 'biblios' %]<li><a href="#mapping_biblios">Bibliographic records</a></li>
142                         [% CASE 'authorities' %]<li><a href="#mapping_authorities">Authorities</a></li>
143                     [% END %]
144                 [% END %]
145             </ul>
146             <div id="search_fields">
147               <table class="search_fields">
148                 <thead>
149                   <tr>
150                     <th>Name</th>
151                     <th>Label</th>
152                     <th>Type</th>
153                     <th>Weight</th>
154                   </tr>
155                 </thead>
156                 <tbody>
157                   [% FOREACH search_field IN all_search_fields %]
158                     <tr>
159                       <td>
160                         <input type="text" name="search_field_name" value="[% search_field.name | html %]" />
161                       </td>
162                       <td><input type="text" name="search_field_label" value="[% search_field.label | html %]" />
163                       <td>
164                         <select name="search_field_type">
165                           <option value=""></option>
166                           [% IF search_field.type == "string" %]
167                             <option value="string" selected="selected">String</option>
168                           [% ELSE %]
169                             <option value="string">String</option>
170                           [% END %]
171                           [% IF search_field.type == "date" %]
172                             <option value="date" selected="selected">Date</option>
173                           [% ELSE %]
174                             <option value="date">Date</option>
175                           [% END %]
176                           [% IF search_field.type == "number" %]
177                             <option value="number" selected="selected">Number</option>
178                           [% ELSE %]
179                             <option value="number">Number</option>
180                           [% END %]
181                           [% IF search_field.type == "boolean" %]
182                             <option value="boolean" selected="selected">Boolean</option>
183                           [% ELSE %]
184                             <option value="boolean">Boolean</option>
185                           [% END %]
186                           [% IF search_field.type == "sum" %]
187                             <option value="sum" selected="selected">Sum</option>
188                           [% ELSE %]
189                             <option value="sum">Sum</option>
190                           [% END %]
191                           [% IF search_field.type == "isbn" %]
192                             <option value="isbn" selected="selected">ISBN</option>
193                           [% ELSE %]
194                             <option value="isbn">ISBN</option>
195                           [% END %]
196                           [% IF search_field.type == "stdno" %]
197                             <option value="stdno" selected="selected">Std. Number</option>
198                           [% ELSE %]
199                             <option value="stdno">Std. Number</option>
200                           [% END %]
201                         </select>
202                       </td>
203                       <td>
204                       [% IF search_field.mapped_biblios %]
205                         <input type="number" step="0.01" min="0.01" max="999.99" name="search_field_weight" value="[% search_field.weight %]" />
206                       [% ELSE %]
207                         <input type="hidden" name="search_field_weight" value="">
208                       [% END %]
209                       </td>
210                     </tr>
211                   [% END %]
212                 </tbody>
213               </table>
214             </div>
215             [% FOREACH index IN indexes %]
216                 <div id="mapping_[% index.index_name | html %]">
217                     <table class="mappings" data-index_name="[% index.index_name | html %]">
218                       <thead>
219                         <tr class="nodrag nodrop">
220                           <th>Search field</th>
221                           <th>Sortable</th>
222                           <th>Facetable</th>
223                           <th>Suggestible</th>
224                           <th>Mapping</th>
225                           <th></th>
226                         </tr>
227                       </thead>
228                       <tbody>
229                         [% FOREACH mapping IN index.mappings %]
230                           <tr>
231                             <td>
232                               <input type="hidden" name="mapping_index_name" value="[% index.index_name | html %]" />
233                               <input type="hidden" name="mapping_search_field_name" value="[% mapping.search_field_name | html %]">
234                               [% mapping.search_field_label | html %]
235                             </td>
236                             <td>
237                               <select name="mapping_sort">
238                                 [% IF mapping.sort == 'undef' %]
239                                   <option value="undef" selected="selected">Undef</option>
240                                 [% ELSE %]
241                                   <option value="undef">Undef</option>
242                                 [% END %]
243                                 [% IF mapping.sort == 0 %]
244                                   <option value="0" selected="selected">0</option>
245                                 [% ELSE %]
246                                   <option value="0">0</option>
247                                 [% END %]
248                                 [% IF  mapping.sort == 1 %]
249                                   <option value="1" selected="selected">1</option>
250                                 [% ELSE %]
251                                   <option value="1">1</option>
252                                 [% END %]
253                               </select>
254                             </td>
255                             <td>
256                               <select name="mapping_facet">
257                                 [% IF mapping.facet %]
258                                   <option value="0">No</option>
259                                   <option value="1" selected="selected">Yes</option>
260                                 [% ELSE %]
261                                   <option value="0" selected="selected">No</option>
262                                   <option value="1">Yes</option>
263                                 [% END %]
264                               </select>
265                             </td>
266                             <td>
267                               <select name="mapping_suggestible">
268                                 [% IF mapping.suggestible %]
269                                   <option value="0">No</option>
270                                   <option value="1" selected="selected">Yes</option>
271                                 [% ELSE %]
272                                   <option value="0" selected="selected">No</option>
273                                   <option value="1">Yes</option>
274                                 [% END %]
275                               </select>
276                             </td>
277                             <td>
278                                 <input name="mapping_marc_field" type="text" value="[% mapping.marc_field | html %]" />
279                             </td>
280                             <td><a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a></td>
281                           </tr>
282                         [% END %]
283                       </tbody>
284                       <tfoot>
285                         <tr class="nodrag nodrop">
286                           <td>
287                             <input data-id="mapping_index_name" type="hidden" value="[% index.index_name | html %]" />
288                             <select data-id="mapping_search_field_name">
289                              [% FOREACH f IN all_search_fields %]
290                                <option value="[% f.name | html %]">[% f.name | html %]</option>
291                              [% END %]
292                             </select>
293                           </td>
294                           <td>
295                             <select data-id="mapping_sort">
296                               <option value="undef">Undef</option>
297                               <option value="0">0</option>
298                               <option value="1">1</option>
299                             </select>
300                           </td>
301                           <td>
302                             <select data-id="mapping_facet">
303                               [% IF mapping.facet %]
304                                 <option value="0">No</option>
305                                 <option value="1" selected="selected">Yes</option>
306                               [% ELSE %]
307                                 <option value="0" selected="selected">No</option>
308                                 <option value="1">Yes</option>
309                               [% END %]
310                             </select>
311                           </td>
312                           <td>
313                             <select data-id="mapping_suggestible">
314                               [% IF mapping.suggestible %]
315                                 <option value="0">No</option>
316                                 <option value="1" selected="selected">Yes</option>
317                               [% ELSE %]
318                                 <option value="0" selected="selected">No</option>
319                                 <option value="1">Yes</option>
320                               [% END %]
321                             </select>
322                           </td>
323                           <td><input data-id="mapping_marc_field" type="text" /></td>
324                           <td><a class="btn btn-default btn-xs add"><i class="fa fa-plus"></i> Add</a></td>
325                         </tr>
326                       </tfoot>
327                     </table>
328                 </div>
329             [% END %]
330         </div>
331         <p>
332             <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
333             <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
334         </p>
335     </form>
336
337             </main>
338         </div> <!-- /.col-sm-10.col-sm-push-2 -->
339
340         <div class="col-sm-2 col-sm-pull-10">
341             <aside>
342                 [% INCLUDE 'admin-menu.inc' %]
343             </aside>
344         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
345      </div> <!-- /.row -->
346
347 [% INCLUDE 'intranet-bottom.inc' %]