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