Bug 18426: Make sure the logged in user can edit the subscriptions
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / subscription-numberpatterns.tt
1 [% USE Asset %]
2 [% SET footerjs = 1 %]
3 [% INCLUDE 'doc-head-open.inc' %]
4 <title>Koha &rsaquo; Serials &rsaquo; Numbering patterns</title>
5 [% INCLUDE 'doc-head-close.inc' %]
6 [% Asset.css("css/datatables.css") %]
7 </head>
8
9 <body id="ser_subscription_numberpatterns" class="ser">
10 [% INCLUDE 'header.inc' %]
11 [% INCLUDE 'serials-search.inc' %]
12
13 <div id="breadcrumbs">
14     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
15     <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
16     <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">Numbering patterns</a>
17     [% IF ( new ) %]
18         &rsaquo; New numbering pattern
19     [% ELSIF ( modify ) %]
20         &rsaquo; Modifying numbering pattern '[% label %]'
21     [% END %]
22 </div>
23
24 <div id="doc3" class="yui-t2">
25
26 <div id="bd">
27   <div id="yui-main">
28     <div class="yui-b">
29       [% IF (new or modify) %]
30         <div class="yui-g">
31           [% IF (new) %]
32             <h1>New numbering pattern</h1>
33             [% IF (error_existing_numberpattern) %]
34               <div class="dialog alert">
35                 <p>A pattern with this name already exists.</p>
36               </div>
37             [% END %]
38           [% ELSE %]
39             <h1>Modify pattern: [% label %]</h1>
40             [% IF (error_existing_numberpattern) %]
41               <div class="dialog alert">
42                 <p>Another pattern with this name already exists.</p>
43               </div>
44             [% END %]
45           [% END %]
46         </div>
47         <div class="yui-g">
48           <form action="/cgi-bin/koha/serials/subscription-numberpatterns.pl" method="post">
49             [% IF (new) %]
50               <input type="hidden" name="op" value="savenew" />
51             [% ELSE %]
52               <input type="hidden" name="op" value="savemod" />
53               <input type="hidden" name="id" value="[% id %]" />
54             [% END %]
55             <fieldset class="rows">
56               <ol>
57                 <li>
58                   <label for="label">Name:</label>
59                   <input type="text" id="label" name="label" value="[% label %]" />
60                 </li>
61                 <li>
62                   <label for="description">Description:</label>
63                   <input type="text" id="description" name="description" value="[% description %]" />
64                 </li>
65                 <li>
66                   <label for="numberingmethod">Numbering formula:</label>
67                   <input type="text" id="numberingmethod" name="numberingmethod" value="[% numberingmethod %]" />
68                 </li>
69                 <li>
70                   <label for="displayorder">Display order:</label>
71                   <input type="text" id="displayorder" name="displayorder" value="[% displayorder %]" />
72                 </li>
73               </ol>
74               <table>
75                 <thead>
76                   <tr>
77                     <th>&nbsp;</th>
78                     <th>X</th>
79                     <th>Y</th>
80                     <th>Z</th>
81                   </tr>
82                 </thead>
83                 <tbody>
84                   <tr>
85                     <td>Label</td>
86                     <td><input type="text" id="label1" name="label1" value="[% label1 %]" /></td>
87                     <td><input type="text" id="label2" name="label2" value="[% label2 %]" /></td>
88                     <td><input type="text" id="label3" name="label3" value="[% label3 %]" /></td>
89                   </tr>
90                   <tr>
91                     <td>Add</td>
92                     <td><input type="text" id="add1" name="add1" value="[% add1 %]" /></td>
93                     <td><input type="text" id="add2" name="add2" value="[% add2 %]" /></td>
94                     <td><input type="text" id="add3" name="add3" value="[% add3 %]" /></td>
95                   </tr>
96                   <tr>
97                     <td>Every</td>
98                     <td><input type="text" id="every1" name="every1" value="[% every1 %]" /></td>
99                     <td><input type="text" id="every2" name="every2" value="[% every2 %]" /></td>
100                     <td><input type="text" id="every3" name="every3" value="[% every3 %]" /></td>
101                   </tr>
102                   <tr>
103                     <td>Set back to</td>
104                     <td><input type="text" id="setto1" name="setto1" value="[% setto1 %]" /></td>
105                     <td><input type="text" id="setto2" name="setto2" value="[% setto2 %]" /></td>
106                     <td><input type="text" id="setto3" name="setto3" value="[% setto3 %]" /></td>
107                   </tr>
108                   <tr>
109                     <td>When more than</td>
110                     <td><input type="text" id="whenmorethan1" name="whenmorethan1" value="[% whenmorethan1 %]" /></td>
111                     <td><input type="text" id="whenmorethan2" name="whenmorethan2" value="[% whenmorethan2 %]" /></td>
112                     <td><input type="text" id="whenmorethan3" name="whenmorethan3" value="[% whenmorethan3 %]" /></td>
113                   </tr>
114                   <tr>
115                     [% BLOCK numbering_select %]
116                       <select id="[% name %]" name="[% name %]">
117                         <option value=""></option>
118                         [% IF (value == "dayname") %]
119                             <option selected="selected" value="dayname">Name of day</option>
120                         [% ELSE %]
121                             <option value="dayname">Name of day</option>
122                         [% END %]
123                         [% IF (value == "dayabrv") %]
124                             <option selected="selected" value="dayabrv">Name of day (abbreviated)</option>
125                         [% ELSE %]
126                             <option value="dayabrv">Name of day (abbreviated)</option>
127                         [% END %]
128                         [% IF (value == "monthname") %]
129                             <option selected="selected" value="monthname">Name of month</option>
130                         [% ELSE %]
131                             <option value="monthname">Name of month</option>
132                         [% END %]
133                         [% IF (value == "monthabrv") %]
134                             <option selected="selected" value="monthabrv">Name of month (abbreviated)</option>
135                         [% ELSE %]
136                             <option value="monthabrv">Name of month (abbreviated)</option>
137                         [% END %]
138                         [% IF (value == "season") %]
139                             <option selected="selected" value="season">Name of season</option>
140                         [% ELSE %]
141                             <option value="season">Name of season</option>
142                         [% END %]
143                         [% IF (value == "seasonabrv") %]
144                             <option selected="selected" value="seasonabrv">Name of season (abbreviated)</option>
145                         [% ELSE %]
146                             <option value="seasonabrv">Name of season (abbreviated)</option>
147                         [% END %]
148                       </select>
149                     [% END %]
150                     <td>Formatting</td>
151                     <td>[% PROCESS numbering_select name="numbering1" value=numbering1 %]</td>
152                     <td>[% PROCESS numbering_select name="numbering2" value=numbering2 %]</td>
153                     <td>[% PROCESS numbering_select name="numbering3" value=numbering3 %]</td>
154                   </tr>
155                 </tbody>
156               </table>
157             </fieldset>
158             <fieldset class="action">
159               <button type="submit" class="btn btn-default btn-sm">Save</button>
160               <button type="reset" class="btn btn-default btn-sm">Reset</button>
161               <a class="cancel" href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">Cancel</a>
162             </fieldset>
163           </form>
164         </div>
165         <div class="yui-g">
166           <form>
167             <fieldset class="rows">
168               <legend>Test prediction pattern</legend>
169               <ol>
170                 <li>
171                   <label for="frequency">Frequency: </label>
172                   <select id="frequency">
173                     [% FOREACH frequency IN frequencies_loop %]
174                       <option value="[% frequency.id %]">[% frequency.description %]</option>
175                     [% END %]
176                   </select>
177                 </li>
178                 <li>
179                   <label for="firstacquidate">First issue publication date: </label>
180                   <input type="text" id="firstacquidate" class="datepicker" size="10" />
181                 </li>
182                 <li>
183                   <label for="sublength">Subscription length:</label>
184                   <select id="subtype">
185                     [% FOREACH subtype IN subtypes_loop %]
186                       <option value="[% subtype.value %]">[% subtype.value %]</option>
187                     [% END %]
188                   </select>
189                   <input type="text" id="sublength" size="3" />
190                 </li>
191                 <li>
192                   <label for="locale">Locale: </label>
193                   <select id="locale" name="locale">
194                       <option value=""></option>
195                       [% FOREACH locale IN locales %]
196                         <option value="[% locale.language %]">[% locale.description %]</option>
197                       [% END %]
198                     </select>
199                   <span class="hint">If empty, English is used</span>
200                 </li>
201               </ol>
202               <table>
203                 <thead>
204                   <tr>
205                     <th>&nbsp;</th>
206                     <th>X</th>
207                     <th>Y</th>
208                     <th>Z</th>
209                   </tr>
210                 </thead>
211                 <tbody>
212                   <tr>
213                     <td>Begins with</td>
214                     <td><input type="text" id="lastvalue1" name="lastvalue1" value="[% lastvalue1 %]" /></td>
215                     <td><input type="text" id="lastvalue2" name="lastvalue2" value="[% lastvalue2 %]" /></td>
216                     <td><input type="text" id="lastvalue3" name="lastvalue3" value="[% lastvalue3 %]" /></td>
217                   </tr>
218                   <tr>
219                     <td>Inner counter</td>
220                     <td><input type="text" id="innerloop1" name="innerloop1" value="[% innerloop1 %]" /></td>
221                     <td><input type="text" id="innerloop2" name="innerloop2" value="[% innerloop2 %]" /></td>
222                     <td><input type="text" id="innerloop3" name="innerloop3" value="[% innerloop3 %]" /></td>
223                   </tr>
224                 </tbody>
225               </table>
226               <fieldset class="action">
227                   <button type="button" id="test_pattern" class="btn btn-default btn-sm">Test pattern</button>
228               </fieldset>
229               <div id="predictionpattern"></div>
230             </fieldset>
231           </form>
232         </div>
233       [% ELSE %]
234         <h1>Numbering patterns</h1>
235         [% IF still_used %]
236             <div class="dialog alert">
237                 <p>
238                     This pattern is still used by [% subscriptions.size %]
239                     subscription(s). Do you still want to delete it?
240                 </p>
241                 <p><a href="#" id="show_blocking_subs">Show subscriptions</a></p>
242                 <ul id="blocking_subs" style="display:none">
243                     [% FOREACH sub IN subscriptions %]
244                         <li style="list-style-type:none">
245                             <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% sub.subscriptionid %]">[% sub.title %]</a>
246                         </li>
247                     [% END %]
248                 </ul>
249
250                 <form action="/cgi-bin/koha/serials/subscription-numberpatterns.pl" method="get">
251                     <input type="hidden" name="op" value="del" />
252                     <input type="hidden" name="confirm" value="1" />
253                     <input type="hidden" name="id" value="[% id %]" />
254                     <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
255                 </form>
256                 <form action="/cgi-bin/koha/serials/subscription-numberpatterns.pl" method="get">
257                     <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
258                 </form>
259             </div>
260         [% END %]
261
262         <div id="toolbar" class="btn-toolbar">
263             <a class="btn btn-default btn-sm" id="newnumberpattern" href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=new"><i class="fa fa-plus"></i> New numbering pattern</a>
264         </div>
265
266         [% IF (numberpatterns_loop.size) %]
267           <table id="numberpatternst">
268             <thead>
269               <tr>
270                 <th>Name</th>
271                 <th>Description</th>
272                 <th>Numbering formula</th>
273                 <th>Display order</th>
274                 <th>Actions</th>
275               </tr>
276             </thead>
277             <tbody>
278               [% FOREACH numberpattern IN numberpatterns_loop %]
279                 <tr>
280                   <td>[% numberpattern.label %]</td>
281                   <td>[% numberpattern.description %]</td>
282                   <td>[% numberpattern.numberingmethod %]</td>
283                   <td>[% numberpattern.displayorder %]</td>
284                   <td class="actions">
285                     <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=modify&id=[% numberpattern.id %]"><i class="fa fa-pencil"></i> Edit</a>
286                     <a class="delete_pattern btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=del&id=[% numberpattern.id %]"><i class="fa fa-trash"></i> Delete</a>
287                   </td>
288                 </tr>
289               [% END %]
290             </tbody>
291           </table>
292         [% ELSE %]
293           <p>There are no existing numbering patterns.</p>
294         [% END %]
295       [% END %]
296     </div>
297   </div>
298   <div class="yui-b">
299     [% INCLUDE 'serials-menu.inc' %]
300   </div>
301 </div>
302
303 [% MACRO jsinclude BLOCK %]
304     [% IF (daily_options) %]
305         [% Asset.js("js/showpredictionpattern.js") %]
306     [% END %]
307     [% INCLUDE 'calendar.inc' %]
308     [% INCLUDE 'datatables.inc' %]
309     <script type="text/javascript">
310         function confirmDelete() {
311             return confirm(_("Are you sure you want to delete this numbering pattern?"));
312         }
313
314         [% IF (new or modify) %]
315             function testPattern() {
316                 var frequencyid = $("#frequency").val();
317                 var firstacquidate = $("#firstacquidate").val();
318                 var error = 0;
319                 var error_msg = "";
320                 if(frequencyid == undefined || frequencyid == "") {
321                     error_msg += _("- Frequency is not defined") + "\n";
322                     error ++;
323                 }
324                 if(firstacquidate == undefined || firstacquidate == "") {
325                     error_msg += _("- First publication date is not defined") + "\n";
326                     error ++;
327                 }
328
329                 if(error){
330                     alert(_("Cannot test prediction pattern for the following reason(s):") + "\n\n"
331                         + error_msg);
332                     return false;
333                 }
334
335                 var ajaxData = {
336                     'custompattern': true,
337                 };
338                 var ajaxParams = [
339                     'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
340                     'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
341                     'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
342                     'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
343                     'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
344                 ];
345                 for(i in ajaxParams) {
346                     var param = ajaxParams[i];
347                     var value = $("#"+param).val();
348                     if(value.length > 0)
349                         ajaxData[param] = value;
350                 }
351
352                 $.ajax({
353                     url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
354                     data: ajaxData,
355                     async: false,
356                     dataType: "text",
357                     success: function(data) {
358                         $("#predictionpattern").html(data);
359                     }
360                 });
361             }
362         [% END %]
363
364         function show_blocking_subs() {
365             $("#blocking_subs").show();
366         }
367         $(document).ready(function(){
368
369             $("#numberpatternst").dataTable($.extend(true, {}, dataTablesDefaults, {
370                 "aoColumnDefs": [
371                     { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
372                 ],
373                 "sPaginationType": "four_button"
374             }));
375
376             $(".delete_pattern").on("click",function(){
377                 return confirmDelete();
378             });
379             $("#show_blocking_subs").on("click",function(e){
380                 e.preventDefault();
381                 $("#blocking_subs").show();
382             });
383             $("#test_pattern").on("click",function(){
384                  testPattern();
385             });
386         });
387     </script>
388 [% END %]
389
390 [% INCLUDE 'intranet-bottom.inc' %]