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