Bug 19672: Move tools templates JavaScript to the footer: More MARC tools
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / marc_modification_templates.tt
1 [% SET footerjs = 1 %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 <style type="text/css">
6     #add_action { display: none; }
7 </style>
8 </head>
9
10 <body id="tools_marc_modification_templates" class="tools">
11 [% INCLUDE 'header.inc' %]
12 [% INCLUDE 'cat-search.inc' %]
13
14 [% IF ( TemplatesLoop ) %]
15     [% FOREACH TemplatesLoo IN TemplatesLoop %]
16         [% IF ( TemplatesLoo.selected ) %]
17             [% SET template_name = TemplatesLoo.name %]
18         [% END %]
19     [% END %]
20 [% END %]
21
22 <div id="breadcrumbs">
23     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
24     <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
25     [% IF ( template_name ) %]
26         <a href="/cgi-bin/koha/tools/marc_modification_templates.pl">MARC modification templates</a>
27         &rsaquo; [% template_name %]
28     [% ELSE %]
29         MARC modification templates
30     [% END %]
31 </div>
32
33 <div id="doc3" class="yui-t2">
34   <div id="bd">
35     <div id="yui-main">
36         <div class="yui-b">
37
38             <div id="toolbar" class="btn-toolbar">
39                 <a href="#" data-toggle="modal" data-template_id="" data-target="#createTemplate" id="new_template" class="btn btn-default btn-sm duplicate_template"><i class="fa fa-plus"></i> New template</a>
40                 [% IF ( template_id != '' ) %]
41                     <a href="#" id="new_action" class="btn btn-default btn-sm"><i class="fa fa-plus"></i> New action</a>
42                 [% END %]
43             </div>
44
45             [% IF error %]
46                 [% IF error == 'no_from_field' %]
47                     <div class="dialog message">Error: no field value specified.</div>
48                 [% END %]
49             [% END %]
50
51             [% IF ( TemplatesLoop ) %]
52
53                 [% IF ( template_id == '' ) %]
54
55                     <h2>MARC modification templates [% template_id %]</h2>
56
57                     <table id="templatest">
58                         <thead>
59                             <tr>
60                                 <th>Template</th>
61                                 <th>Actions</th>
62                             </tr>
63                         </thead>
64                         <tbody>
65                             [% FOREACH TemplatesLoo IN TemplatesLoop %]
66                                 <tr>
67                                     <td>[% TemplatesLoo.name %]</td>
68                                     <td class="actions">
69                                         <a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/marc_modification_templates.pl?template_id=[% TemplatesLoo.template_id %]&amp;op=select_template" ><i class="fa fa-fw fa-pencil"></i> Edit actions</a>
70                                         <a class="btn btn-default btn-xs duplicate_template" href="#" data-toggle="modal" data-template_id="[% TemplatesLoo.template_id %]" data-target="#createTemplate"><i class="fa fa-fw fa-copy"></i> Duplicate</a>
71                                         <a class="btn btn-default btn-xs delete_template" href="/cgi-bin/koha/tools/marc_modification_templates.pl?template_id=[% TemplatesLoo.template_id %]&amp;op=delete_template"><i class="fa fa-fw fa-trash"></i> Delete</a>
72                                     </td>
73                                 </tr>
74                             [% END %]
75                         </tbody>
76                     </table>
77
78                 [% ELSE %]
79
80                     <h2>Actions for <i>[% template_name %]</i></h2>
81
82                     [% IF ( ActionsLoop ) %]
83
84                         <table id="template_actions" class="template_actions">
85                             <thead>
86                                 <tr>
87                                     <th>Change order</th>
88                                     <th>Order</th>
89                                     <th>Action</th>
90                                     <th>Description</th>
91                                     <th>&nbsp;</th>
92                                     <th>&nbsp;</th>
93                                 </tr>
94                             </thead>
95                             <tbody>
96                                 [% FOREACH ActionsLoo IN ActionsLoop %]
97                                     <tr>
98                                         <td class="actions">
99                                             <a title="Move action up" href="marc_modification_templates.pl?op=move_action&amp;where=up&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
100                                                 <i class="fa fa-arrow-up fa-lg order-control"></i>
101                                             </a>
102
103                                             <a title="Move action to top" href="marc_modification_templates.pl?op=move_action&amp;where=top&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
104                                                 <i class="fa fa-arrow-up fa-lg overline order-control"></i>
105                                             </a>
106
107                                             <a title="Move action to bottom" href="marc_modification_templates.pl?op=move_action&amp;where=bottom&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
108                                                 <i class="fa fa-arrow-down fa-lg underline order-control"></i>
109                                             </a>
110
111                                             <a title="Move action down" href="marc_modification_templates.pl?op=move_action&amp;where=down&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
112                                                 <i class="fa fa-arrow-down fa-lg order-control"></i>
113                                             </a>
114                                         </td>
115
116                                         <td>[% ActionsLoo.ordering %]</td>
117                                         <td>
118                                             [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
119                                             [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
120                                             [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
121                                             [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
122                                             [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
123
124                                             [% UNLESS ( ActionsLoo.action_update_field ) %]
125                                                 [% IF ( ActionsLoo.field_number ) %]
126                                                     1st
127                                                 [% END %]
128                                             [% END %]
129
130                                             field
131
132                                             [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
133
134                                             [% IF ( ActionsLoo.field_value ) %]
135                                                 with value <i>[% ActionsLoo.field_value %]</i>
136                                             [% END %]
137
138                                             [% IF ( ActionsLoo.to_field ) %]
139                                                 to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
140
141                                                 [% IF ( ActionsLoo.to_regex_search ) %]
142                                                      using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
143                                                 [% END %]
144                                             [% END %]
145
146                                             [% IF ( ActionsLoo.conditional ) %]
147                                                 [% IF ( ActionsLoo.conditional_if ) %] if [% END %]
148                                                 [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
149
150                                                 [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
151
152                                                 [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
153                                                 [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
154                                                 [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
155                                                 [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
156
157                                                 [% IF ( ActionsLoo.conditional_regex ) %] RegEx m/[% END %]
158                                                 <strong>[% ActionsLoo.conditional_value %]</strong>
159                                                 [% IF ( ActionsLoo.conditional_regex ) %]/[% END %]
160                                             [% END %]
161                                         </td>
162                                         <td>[% ActionsLoo.description %]</td>
163                                         <td>
164                                             <a class="btn btn-default btn-xs" href="#modaction" onclick='editAction(
165                                                             "[% ActionsLoo.mmta_id |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
166                                                             "[% ActionsLoo.ordering |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
167                                                             "[% ActionsLoo.action |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
168                                                             "[% ActionsLoo.field_number |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
169                                                             "[% ActionsLoo.from_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
170                                                             "[% ActionsLoo.from_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
171                                                             "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
172                                                             "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
173                                                             "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
174                                                             "[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
175                                                             "[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
176                                                             "[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
177                                                             "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
178                                                             "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
179                                                             "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
180                                                             "[% ActionsLoo.conditional_comparison |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
181                                                             "[% ActionsLoo.conditional_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
182                                                             "[% ActionsLoo.conditional_regex |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
183                                                             "[% ActionsLoo.description |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
184                                                         );updateAllEvery();'><i class="fa fa-pencil"></i> Edit</a>
185                                         </td>
186                                         <td>
187                                             <a class="btn btn-default btn-xs" href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]" onclick="return confirmDeleteAction();"><i class="fa fa-trash"></i> Delete</a>
188                                         </td>
189                                     </tr>
190                                 [% END # /FOREACH ActionsLoo %]
191                             </tbody>
192                         </table>
193                     [% ELSE %]
194                         <div class="dialog message template_actions"><p>There are no defined actions for this template.</p></div>
195                     [% END # /IF ActionsLoop %]
196
197                     <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
198                         <a name="modaction"></a>
199                         <fieldset>
200                             <legend id="modaction_legend">Add a new action</legend>
201                             <div id="warning_multivalued" style="color:red; display:none;">You have chosen a condition on the same field as the original field. If your records contain multivalued fields it is highly recommended not to do that.</div>
202
203                             <select name="action" id="action" onchange="onActionChange(this);">
204                                 <option value="delete_field">Delete</option>
205                                 <option value="update_field">Add/Update</option>
206                                 <option value="move_field">Move</option>
207                                 <option value="copy_field">Copy</option>
208                                 <option value="copy_and_replace_field">Copy and replace</option>
209                             </select>
210
211                             <span id="field_number_block">
212                                 <select name="field_number" id="field_number">
213                                     <option value="0">All</option>
214                                     <option value="1">1st</option>
215                                 </select>
216                             </span>
217
218                             field(s) <input type="text" name="from_field" id="from_field" size="3" maxlength="3" /> <input type="text" name="from_subfield" id="from_subfield" size="1" maxlength="1" title="let blank for the entire field" />
219
220                             <span name="with_value_block" id="with_value_block" style="display:none;">
221                                 with value <input type="text" name="field_value" id="field_value" />
222                             </span>
223
224                             <span name="to_field_block" id="to_field_block" style="display:none;">
225                                 to field <input type="text" name="to_field" id="to_field" size="3" maxlength="3" /> <input type="text" name="to_subfield" id="to_subfield" size="1" maxlength="1" title="let blank for the entire field" />
226
227                                 <span name="to_field_regex_block" id="to_field_regex_block">
228                                     <sup>
229                                         <label for="to_field_regex">RegEx</label>
230                                         <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
231
232                                         <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
233                                             s/<input type="text" name="to_regex_search" id="to_regex_search" placeholder="regex pattern" />/<input type="text" name="to_regex_replace" id="to_regex_replace" placeholder="regex replacement" />/<input type="text" name="to_regex_modifiers" id="to_regex_modifiers" placeholder="ig" size="3" />
234                                         </span>
235                                     </sup>
236                                 </span>
237                             </span>
238
239                             <p/>
240
241                             <select name="conditional" id="conditional" onchange="onConditionalChange(this);">
242                                 <option value="" selected="selected" />
243                                 <option value="if">if</option>
244                                 <option value="unless">unless</option>
245                             </select>
246
247                             <span name="conditional_block" id="conditional_block" style="display:none;">
248                                 field <input type="text" name="conditional_field" id="conditional_field" size="3" maxlength="3" /> <input type="text" name="conditional_subfield" id="conditional_subfield" size="1" maxlength="1" />
249
250                                 <select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
251                                     <option value="" />
252                                     <option value="exists">exists</option>
253                                     <option value="not_exists">doesn't exist</option>
254                                     <option value="equals">matches</option>
255                                     <option value="not_equals">doesn't match</option>
256                                 </select>
257
258                                 <span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
259
260                                     <span class="match_regex_prefix">m/</span><input type="text" id="conditional_value" name="conditional_value" /><span class="match_regex_suffix">/</span>
261
262                                     <sup>
263                                         <label for="conditional_regex">RegEx</label>
264                                         <input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
265                                     </sup>
266
267                                 </span>
268                             </span>
269
270                             <input type="hidden" name="template_id" value="[% template_id %]" />
271                             <input type="hidden" name="mmta_id" id="mmta_id" />
272                             <input type="hidden" name="op" value="add_action" />
273
274                             <br/><br/>
275                             <label for="description">Description:</label>
276                             <input type="text" name="description" id="description" size="60" />
277
278                             <br/><br/>
279                             <input id="action_submit" type="submit" value="Add action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();">Cancel</a>
280
281                         </fieldset>
282                     </form>
283
284                 [% END %]
285
286             [% ELSE %]
287                 <div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
288             [% END # /IF TemplatesLoop %]
289
290             <!-- Modal to create new template -->
291             <div class="modal" id="createTemplate" tabindex="-1" role="dialog" aria-labelledby="LabelcreateTemplate" aria-hidden="true">
292                 <div class="modal-dialog">
293                 <div class="modal-content">
294                 <div class="modal-header">
295                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
296                     <h3 id="LabelcreateTemplate">Create a new template</h3>
297                 </div>
298                 <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" class="validated">
299                     <div class="modal-body">
300                         <fieldset>
301                             <p>
302                                 <label for="template_name" class="required">Name: </label>
303                                 <input name="template_name" id="template_name" type="text" size="30" required="required" class="required" />
304                                 <span class="required">Required</span>
305                             </p>
306
307                             <input type="hidden" name="op" value="create_template" />
308
309                             <p>
310                                 <label for="duplicate_a_template">Duplicate a template:</label>
311                                 <select name="template_id" id="duplicate_a_template">
312                                     <option value=""> -- None --</option>
313                                     [% FOREACH TemplatesLoo IN TemplatesLoop %]
314                                         <option value="[% TemplatesLoo.template_id %]"> [% TemplatesLoo.name %]</option>
315                                     [% END %]
316                                 </select>
317                                 <input type="hidden" name="duplicate_current_template" id="duplicate_current_template" />
318                             </p>
319                         </fieldset>
320                     </div>
321                     <div class="modal-footer">
322                         <button type="submit" class="btn btn-default">Submit</button>
323                         <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Cancel</button>
324                     </div>
325                 </form>
326                 </div>
327                 </div>
328             </div>
329         </div>
330     </div>
331
332     <div class="yui-b">
333         [% INCLUDE 'tools-menu.inc' %]
334     </div>
335   </div>
336
337 [% MACRO jsinclude BLOCK %]
338     <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
339     <script type="text/javascript">
340         var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty.");
341         var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled.");
342         var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty");
343         var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field.");
344         var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update.");
345         var MSG_MMT_SOURCE_FIELD = _("The source field should be filled.");
346         var MSG_MMT_EVERY = _("Every");
347         var MSG_MMT_ALL = _("All");
348         var MSG_MMT_CONFIRM_DEL_TEMPLATE = _("Are you sure you wish to delete this template?");
349         var MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION = _("Are you sure you wish to delete this template action?");
350         var MSG_MMT_EDIT_ACTION = _("Edit action %s");
351         var MSG_MMT_UPDATE_ACTION = _("Update action");
352     </script>
353     <script type="text/javascript" src="[% interface %]/[% theme %]/js/marc_modification_templates.js"></script>
354 [% END %]
355
356 [% INCLUDE 'intranet-bottom.inc' %]