Bug 12365: (follow-up) Adding maxlength attribute and popover
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / currency.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% USE ColumnsSettings %]
5 [% USE HtmlTags %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; Administration &rsaquo; Currencies &amp; Exchange rates &rsaquo;
9 [% IF op == 'add_form' %][% IF currency %]Modify currency '[% currency.currency | html %]'[% ELSE %]New currency[% END %][% END %]
10 [% IF op == 'delete_confirm' %]Confirm deletion of currency '[% currency.currency | html %]'[% END %]
11 [% IF op == 'list' %]Currencies[% END %]</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 [% Asset.css("css/datatables.css") | $raw %]
14 </head>
15
16 <body id="admin_currency" class="admin">
17 [% INCLUDE 'header.inc' %]
18 [% INCLUDE 'currencies-admin-search.inc' %]
19
20 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;  <a href="/cgi-bin/koha/admin/currency.pl">Currencies &amp; Exchange rates</a> &rsaquo; [% IF op == 'add_form' %][% IF currency %]Modify currency '[% currency.currency | html %]'[% ELSE %]New currency[% END %][% END %]
21 [% IF op == 'delete_confirm' %]Confirm deletion of currency [% currency.currency | $HtmlTags tag='span' attributes=>'class="ex"' %]
22 [% ELSIF op == 'list' %]Currencies
23 [% END %]
24 </div>
25
26 <div class="main container-fluid">
27     <div class="row">
28         <div class="col-sm-10 col-sm-push-2">
29             <main>
30
31 [% IF op == 'list' %]
32 <div id="toolbar" class="btn-toolbar">
33     <a class="btn btn-default btn-sm" id="newcurrency" href="/cgi-bin/koha/admin/currency.pl?op=add_form"><i class="fa fa-plus"></i> New currency</a>
34 </div>
35 [% END %]
36
37 [% FOR m IN messages %]
38     <div class="dialog [% m.type | html %]">
39         [% SWITCH m.code %]
40         [% CASE 'error_on_update' %]
41             An error occurred when updating this currency. Perhaps it already exists.
42         [% CASE 'error_on_insert' %]
43             An error occurred when adding this currency. The currency code might already exist.
44         [% CASE 'error_on_delete' %]
45             An error occurred when deleting this currency. Check the logs.
46         [% CASE 'success_on_update' %]
47             Currency updated successfully.
48         [% CASE 'success_on_insert' %]
49             Currency added successfully.
50         [% CASE 'success_on_delete' %]
51             Currency deleted successfully.
52         [% CASE %]
53             [% m.code | html %]
54         [% END %]
55     </div>
56 [% END %]
57
58
59
60 [% IF op == 'add_form' %]
61
62 <form action="/cgi-bin/koha/admin/currency.pl" name="Aform" method="post" class="validated">
63     <input type="hidden" name="op" value="add_validate" />
64     <fieldset class="rows">
65         <legend>
66             [% IF currency %]
67                 Modify currency
68             [% ELSE %]
69                 New currency
70             [% END %]
71         </legend>
72         <ol>
73             <li>
74                 [% IF currency %]
75                     <span class="label">Currency: </span>
76                     <input type="hidden" name="is_a_modif" value="1" />
77                     <input type="hidden" name="currency_code" id="currency" value="[% currency.currency | html %]" />[% currency.currency | html %]
78                 [% ELSE %]
79                     <label for="currency_code" class="required">Currency: </label>
80                     <input type="text" name="currency_code" id="currency_code" size="50" maxlength="50" required="required" class="required" /> <span class="required">Required</span>
81                 [% END %]
82             </li>
83             <li>
84                 <label for="rate" class="required">Rate: </label>
85                 <input type="text" name="rate" id="rate" size="10" maxlength="10" value="[% currency.rate | html %]" required="required" class="required" /> <span class="required">Required</span>
86             </li>
87             <li>
88                 <label for="symbol" class="required">Symbol: </label>
89                 <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% currency.symbol | html %]" required="required" class="required" /> <span class="required">Required</span>
90             </li>
91             <li>
92                 <label for="isocode">ISO code: </label>
93                 <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% currency.isocode | html %]" />
94             </li>
95             <li>
96                 <span class="label">Last updated: </span>[% currency.timestamp | $KohaDates %]
97             </li>
98             <li>
99                 <label for="p_sep_by_space">Space separation between symbol and value: </label>
100                 [% IF currency.p_sep_by_space %]
101                     <input type="checkbox" id="p_sep_by_space" name="p_sep_by_space" value="1" checked="checked" />
102                 [% ELSE %]
103                     <input type="checkbox" id="p_sep_by_space" name="p_sep_by_space" value="1" />
104                 [% END %]
105             </li>
106             <li>
107                 <label for="active">Active: </label>
108                 [% IF currency.active %]
109                 <input type="checkbox" id="active" name="active" value="1" checked="checked" />
110                 [% ELSE %]
111                 <input type="checkbox" id="active" name="active" value="1" />
112                 [% END %]
113                 <span id="hint" class="hint"></span>
114             </li>
115         </ol>
116     </fieldset>
117
118     <fieldset class="action">
119         <input type="submit" value="Submit" />
120         <a href="/cgi-bin/koha/admin/currency.pl" class="cancel">Cancel</a>
121     </fieldset>
122     </form>
123
124 [% END %]
125
126 [% IF op =='delete_confirm' %]
127     [% IF nb_of_orders or nb_of_vendors %]
128     <div class="dialog alert">
129         <h3>Cannot delete currency [% currency.currency | $HtmlTags tag='span' attributes=>'class="ex"' %]</h3>
130         <p>
131             [% IF nb_of_orders %]
132                 This currency is used by [% nb_of_orders | html %] orders.
133             [% ELSIF nb_of_vendors %]
134                 This currency is used by [% nb_of_vendors | html %] vendors.
135             [% END %]
136             Deletion not possible
137         </p>
138         <form action="/cgi-bin/koha/admin/currency.pl" method="post">
139             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
140         </form>
141     </div>
142     [% ELSE %]
143     <div class="dialog alert">
144         <h3>Confirm deletion of currency [% currency.currency | $HtmlTags tag='span' attributes=>'class="ex"' %]</h3>
145         <table>
146             <tr><th>Currency</th>
147                 <td>[% currency.currency | html %]</td>
148             </tr>
149             <tr><th>Rate</th>
150                 <td>[% currency.rate | html %]</td>
151             </tr>
152         </table>
153         <form action="/cgi-bin/koha/admin/currency.pl" method="post">
154             <input type="hidden" name="op" value="delete_confirmed" />
155             <input type="hidden" name="currency_code" value="[% currency.currency | html %]" />
156             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this currency</button>
157         </form>
158         <form action="/cgi-bin/koha/admin/currency.pl" method="post">
159             <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
160         </form>
161     </div>
162     [% END %]
163 [% END %]
164
165 [% IF op == 'list' %]
166
167 <h2>Currencies and exchange rates</h2>
168
169     [% IF currencies and no_active_currency %]
170         <div class="dialog alert"><h3>No active currency is defined</h3><p>Please edit one currency and mark it as active.</p></div>
171     [% END %]
172
173     [% IF searchfield %]
174         You searched for [% searchfield | html %]</span>
175     [% END %]
176
177     <table id='currencies-table'>
178       <thead>
179         <tr>
180             <th>Currency</th>
181             <th>Rate</th>
182             <th>Symbol</th>
183             <th>ISO code</th>
184             <th class="title-string">Last updated</th>
185             <th>Active</th>
186             <th>Archived</th>
187             <th>Actions</th>
188         </tr>
189       </thead>
190       <tbody>
191         [% FOREACH currency IN currencies %]
192           <tr>
193             <td>[% currency.currency | html %]</td>
194             <td>[% currency.rate | html %]</td>
195             <td>[% currency.symbol | html %]</td>
196             <td>[% currency.isocode | html %]</td>
197             <td><span title="[% currency.timestamp | html %]">[% currency.timestamp | $KohaDates %]</span></td>
198             <td style="color:green;">[% IF currency.active %]✓[% END %]</td>
199             <td>[% IF currency.archived %]Yes[% END %]</td>
200             <td class="actions">
201               <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/currency.pl?op=add_form&amp;currency_code=[% currency.currency | html %]"><i class="fa fa-pencil"></i> Edit</a>
202               <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/currency.pl?op=delete_confirm&amp;currency_code=[% currency.currency | html %]"><i class="fa fa-trash"></i> Delete</a>
203             </td>
204           </tr>
205         [% END %]
206       </tbody>
207     </table>
208
209     <br />
210     <div class="hint">
211         <p>
212             When importing MARC files via the staging tools, the tool will attempt to find and use the price of the currently active currency.
213         </p>
214         <p>
215             Some examples of compatible price fields include "$9.99", "9.99 USD", "$9.99 USD", "9.99 USD (10.00 CAN)", "$9.99 USD (paperback)".
216             These examples assume USD is the active currency.
217         </p>
218     </div>
219
220 [% END %]
221
222             </main>
223         </div> <!-- /.col-sm-10.col-sm-push-2 -->
224
225         <div class="col-sm-2 col-sm-pull-10">
226             <aside>
227                 [% INCLUDE 'admin-menu.inc' %]
228             </aside>
229         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
230      </div> <!-- /.row -->
231
232 [% MACRO jsinclude BLOCK %]
233     [% Asset.js("js/admin-menu.js") | $raw %]
234     [% INCLUDE 'datatables.inc' %]
235     [% INCLUDE 'columns_settings.inc' %]
236     <script>
237
238         function check_currency(val) {
239             if ( val == 1.0 ) {
240                 $("#active").prop('disabled', false);
241                 $("#hint").html("");
242             } else {
243                 $("#active").prop('checked', false);
244                 $("#active").prop('disabled', true);
245                 $("#hint").html(_("The active currency must have a rate of 1.0"));
246             }
247         }
248
249         $(document).ready(function() {
250             columns_settings = [% ColumnsSettings.GetColumns( 'admin', 'currency', 'currencies-table', 'json' ) | $raw %]
251             var issuest = KohaTable("currencies-table", {
252                 dom: 'B<"clearfix">t',
253                 "columnDefs": [
254                     { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
255                     { "sType": "title-string", "aTargets" : [ "title-string" ] }
256                     ],
257             }, columns_settings );
258
259             // prevents users to check active with a currency != 1
260             $("#rate").keyup(function() {
261                 check_currency( $(this).val() );
262             });
263             check_currency( $("#rate").val() );
264             $("#currency_code").on("blur",function(){
265                 toUC(this);
266             });
267         });
268
269     </script>
270 [% END %]
271 [% INCLUDE 'intranet-bottom.inc' %]