Bug 13618: Add html filters to all the variables
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / subscription-frequencies.tt
1 [% SET footerjs = 1 %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Serials &rsaquo; Frequencies</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 </head>
6
7 <body id="ser_subscription_frequencies" class="ser">
8 [% INCLUDE 'header.inc' %]
9 [% INCLUDE 'serials-search.inc' %]
10
11 [% BLOCK translate_frequnit %]
12 [%  SWITCH frequnit %]
13 [%   CASE 'day'     %] day
14 [%   CASE 'week'    %] week
15 [%   CASE 'month'   %] month
16 [%   CASE 'year'    %] year
17 [%  END %]
18 [% END %]
19
20 <div id="breadcrumbs">
21     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
22     <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
23     <a href="/cgi-bin/koha/serials/subscription-frequencies.pl">Frequencies</a>
24 </div>
25
26 <div id="doc3" class="yui-t2">
27
28 <div id="bd">
29   <div id="yui-main">
30     <div class="yui-b">
31       [% IF (new or modify) %]
32         [% IF (new) %]
33           <h1>New frequency</h1>
34         [% ELSE %]
35           <h1>Edit frequency: [% description | html %]</h1>
36         [% END %]
37         <form action="/cgi-bin/koha/serials/subscription-frequencies.pl" id="add_frequency_form" method="post">
38           [% IF (modify) %]
39             <input type="hidden" name="id" value="[% id | html %]" />
40             <input type="hidden" name="op" value="savemod" />
41           [% ELSE %]
42             <input type="hidden" name="op" value="savenew" />
43           [% END %]
44           <fieldset class="rows">
45             <ol>
46               <li>
47                 <label class="required" for="description">Description: </label>
48                 <input type="text" id="description" name="description" value="[% description | html %]" class="required" required="required" /> <span class="required">Required</span>
49               </li>
50               <li>
51                 <label for="unit">Unit: </label>
52                 <select id="unit" name="unit">
53                   <option value="">None</option>
54                   [% FOREACH unit IN units_loop %]
55                     [% IF (unit.selected) %]
56                       <option selected="selected" value="[% unit.val | html %]">
57                     [% ELSE %]
58                       <option value="[% unit.val | html %]">
59                     [% END %]
60                       [% PROCESS translate_frequnit frequnit=unit.val %]
61                     </option>
62                   [% END %]
63                 </select>
64               </li>
65               <li><span class="hint">Note: one of the two following fields must be equal to 1</span></li>
66               <li>
67                 <label for="issuesperunit">Issues per unit: </label>
68                 [% IF (new) %]
69                   <input type="text" id="issuesperunit" name="issuesperunit" value="1" size="3" />
70                 [% ELSE %]
71                   <input type="text" id="issuesperunit" name="issuesperunit" value="[% issuesperunit | html %]" size="3" />
72                 [% END %]
73               </li>
74               <li>
75                 <label for="unitsperissue">Units per issue: </label>
76                 [% IF (new) %]
77                   <input type="text" id="unitsperissue" name="unitsperissue" value="1" size="3" />
78                 [% ELSE %]
79                   <input type="text" id="unitsperissue" name="unitsperissue" value="[% unitsperissue | html %]" size="3" />
80                 [% END %]
81               </li>
82               <li>
83                 <label for="displayorder">Display order: </label>
84                 <input type="text" id="displayorder" name="displayorder" value="[% displayorder | html %]" size="3" />
85               </li>
86             </ol>
87           </fieldset>
88           <fieldset class="action">
89             <input type="submit" value="Save" />
90             <a href="/cgi-bin/koha/serials/subscription-frequencies.pl" class="cancel">Cancel</a>
91           </fieldset>
92         </form>
93       [% ELSE %]
94
95         <div id="toolbar" class="btn-toolbar">
96             <a class="btn btn-default btn-sm" id="newfrequency" href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=new"><i class="fa fa-plus"></i> New frequency</a>
97         </div>
98
99         <h1>Frequencies</h1>
100         [% IF still_used %]
101             <div class="dialog alert">
102                 <p>
103                     This frequency is still used by [% subscriptions.size | html %]
104                     subscription(s). Do you still want to delete it?
105                 </p>
106                 <p><a href="#" id="show_blocking_subs">Show subscriptions</a></p>
107                 <ul id="blocking_subs" style="display:none">
108                     [% FOREACH sub IN subscriptions %]
109                         <li style="list-style-type:none">
110                             <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% sub.subscriptionid | html %]">[% sub.title | html %]</a>
111                         </li>
112                     [% END %]
113                 </ul>
114
115                 <form action="/cgi-bin/koha/serials/subscription-frequencies.pl" method="get">
116                     <input type="hidden" name="op" value="del" />
117                     <input type="hidden" name="confirm" value="1" />
118                     <input type="hidden" name="frequencyid" value="[% frequencyid | html %]" />
119                     <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
120                 </form>
121                 <form action="/cgi-bin/koha/serials/subscription-frequencies.pl" method="get">
122                     <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
123                 </form>
124             </div>
125         [% END %]
126
127         [% IF (frequencies_loop.size) %]
128           <table id="frequenciest">
129             <thead>
130               <tr>
131                 <th>Description</th>
132                 <th>Unit</th>
133                 <th>Issues per unit</th>
134                 <th>Units per issue</th>
135                 <th>Display order</th>
136                 <th>Actions</th>
137               </tr>
138             </thead>
139             <tbody>
140               [% FOREACH frequency IN frequencies_loop %]
141                 <tr>
142                   <td>[% frequency.description | html %]</td>
143                   <td>[% PROCESS translate_frequnit frequnit=frequency.unit %]</td>
144                   <td>[% frequency.issuesperunit | html %]</td>
145                   <td>[% frequency.unitsperissue | html %]</td>
146                   <td>[% frequency.displayorder | html %]</td>
147                   <td class="actions">
148                     <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=modify&frequencyid=[% frequency.id | html %]"><i class="fa fa-pencil"></i> Edit</a>
149                     <a class="delete_frequency btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=del&frequencyid=[% frequency.id | html %]"><i class="fa fa-trash"></i> Delete</a>
150                   </td>
151                 </tr>
152               [% END %]
153             </tbody>
154           </table>
155         [% ELSE %]
156           <p>There is no defined frequency.</p>
157         [% END %]
158       [% END %]
159
160     </div>
161   </div>
162   <div class="yui-b">
163     [% INCLUDE 'serials-menu.inc' %]
164   </div>
165 </div>
166
167 [% MACRO jsinclude BLOCK %]
168     <script type="text/javascript">
169         function confirmDelete() {
170             return confirm(_("Are you sure you want to delete this subscription frequency?"));
171         }
172
173         function check_form() {
174             var description = $("#description").val();
175             var unit = $("#unit").val();
176             var issuesperunit = $("#issuesperunit").val();
177             var unitsperissue = $("#unitsperissue").val();
178             var alert_msg = _("Some fields are not valid:") + "\n";
179             var errors = 0;
180
181             if(description.length == 0) {
182                 alert_msg += "\t - " + _("Description is required");
183                 errors ++;
184             }
185             if(unit.length > 0) {
186                 if(isNaN(issuesperunit) || issuesperunit == 0) {
187                     alert_msg += "\n\t - " + _("Issues per unit is required")
188                         + " " + _("(must be a number greater than 0)");
189                     errors ++;
190                 }
191                 if(isNaN(unitsperissue) || unitsperissue == 0) {
192                     alert_msg += "\n\t - " + _("Units per issue is required")
193                         + " " + _("(must be a number greater than 0)");
194                     errors ++;
195                 }
196                 if(issuesperunit > 1 && unitsperissue > 1) {
197                     alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
198                     errors ++;
199                 }
200             }
201
202             if(errors == 0) {
203                 return true;
204             }
205
206             alert(alert_msg);
207             return false;
208         }
209
210         $(document).ready(function() {
211             $("#issuesperunit").change(function() {
212                 var value = $(this).val();
213                 if(!isNaN(value) && value > 1) {
214                     $("#unitsperissue").val(1);
215                 }
216             });
217             $("#unitsperissue").change(function() {
218                 var value = $(this).val();
219                 if(!isNaN(value) && value > 1) {
220                     $("#issuesperunit").val(1);
221                 }
222             });
223             $(".delete_frequency").on("click",function(){
224                 return confirmDelete();
225             });
226             $("#add_frequency_form").on("submit",function(){
227                 return check_form();
228             });
229             $("#show_blocking_subs").on("click",function(e){
230                 e.preventDefault();
231                 $("#blocking_subs").show();
232             });
233         });
234     </script>
235 [% END %]
236
237 [% INCLUDE 'intranet-bottom.inc' %]