Bug 17702: Add UI to manage account credit types
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / credit_types.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% PROCESS i18n.inc %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Administration &rsaquo;
8     [% IF op =='add_form' %]
9        [% t('Credit types') %] &rsaquo;
10        [% IF credit_type.code %]
11            [% t('Modify credit type') %]
12        [% ELSE %]
13            [% t('New credit type') %]
14        [% END %]
15     [% ELSE %]
16        [% t('Credit types') %]
17     [% END %]
18 </title>
19 [% INCLUDE 'doc-head-close.inc' %]
20 </head>
21
22 <body id="admin_credit_types" class="admin">
23 [% INCLUDE 'header.inc' %]
24 [% INCLUDE 'prefs-admin-search.inc' %]
25
26 <div id="breadcrumbs">
27     <a href="/cgi-bin/koha/mainpage.pl">[% t('Home') %]</a>
28 &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">[% t('Administration') %]</a>
29 &rsaquo; <a href="/cgi-bin/koha/admin/credit_types.pl">[% t('Credit types') %]</a>
30 [% IF op == 'add_form' %]
31 &rsaquo; [% IF credit_type.code %][% t('Modify credit type') %][% ELSE %][% t('New credit type') %][% END %]
32 [% END %]
33 </div>
34
35 <div class="main container-fluid">
36     <div class="row">
37         <div class="col-sm-10 col-sm-push-2">
38             <main>
39
40                 [% FOREACH m IN messages %]
41                 <div class="dialog [% m.type | html %]">
42                     [% SWITCH m.code %]
43                     [% CASE 'success_on_saving' %]
44                         [% t('Credit type saved successfully.') %]
45                     [% CASE 'error_on_saving' %]
46                         [% t('An error occurred when saving this credit type.') %]
47                     [% CASE 'success_on_archive' %]
48                         [% t('Credit type archived successfully.') %]
49                     [% CASE 'success_on_restore' %]
50                         [% t('Credit type restored successfully.') %]
51                     [% CASE %]
52                         [% m.code | html %]
53                     [% END %]
54                 </div>
55                 [% END %]
56
57                 [% IF op == 'add_form' %]
58                     [% IF credit_type %]
59                         <h3>[% t('Modify a credit type') %]</h3>
60                     [% ELSE %]
61                         <h3>[% t('New credit type') %]</h3>
62                     [% END %]
63
64                     <form action="/cgi-bin/koha/admin/credit_types.pl" name="Aform" method="post" class="validated">
65                         <input type="hidden" name="op" value="add_validate" />
66                         <fieldset class="rows">
67                             <ol>
68                                 <li>
69                                     <label for="code" class="required">[% t('Credit type code:') %] </label>
70                                     [% IF credit_type %]
71                                         <strong>[% credit_type.code | html %]</strong>
72                                         <input type="hidden" name="code" value="[% code | html %]" />
73                                     [% ELSE %]
74                                     <input type="text" name="code" id="code" size="80" maxlength="64" class="required" required="required"><span class="required">[% t('Required. Maximum length is 64 letters') %]</span>
75                                     [% END %]
76                                 </li>
77                                 <li>
78                                     <label for="description" class="required">[% t('Description:') %] </label>
79                                     <input type="text" name="description" id="description" required="required" class="required" size="80" maxlength="100" value="[% credit_type.description | html %]" /> <span class="required">[% t('Required') %]</span>
80                                 </li>
81                                 <li>
82                                     <label for="can_be_added_manually">[% t('Can be manually added ?') %] </label>
83                                     [% IF credit_type.can_be_added_manually %]
84                                         <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" checked="checked" value="1" />
85                                     [% ELSE %]
86                                         <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" value="1" />
87                                     [% END %]
88                                 </li>
89                                 <li>
90                                     <label for="branches">[% t('Libraries limitation:') %] </label>
91                                     <select id="branches" name="branches" multiple size="10">
92                                         <option value="">[% t('All libraries') %]</option>
93                                         [% FOREACH branch IN branches_loop %]
94                                         [% IF ( branch.selected ) %]
95                                         <option selected="selected" value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
96                                         [% ELSE %]
97                                         <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
98                                         [% END %]
99                                         [% END %]
100                                     </select>
101                                     <span>[% t("Select 'All libraries' if this credit type should be available at all libraries. Otherwise select libraries you want to associate credit type with.") %]</span>
102                                 </li>
103                             </ol>
104                         </fieldset>
105
106                         <fieldset class="action">
107                             <button id="save_credit_type" class="btn btn-default"><i class="fa fa-save"></i> [% t('Save') %]</button>
108                             <a class="cancel btn-link" href="/cgi-bin/koha/admin/credit_types.pl"><i class="fa fa-times"></i> [% t('Cancel') %]</a>
109                         </fieldset>
110                     </form>
111                 [% END %]
112
113                 [% IF op == 'list' %]
114                     <div id="toolbar" class="btn-toolbar">
115                         <a class="btn btn-default" id="newcredittype" href="/cgi-bin/koha/admin/credit_types.pl?op=add_form"><i class="fa fa-plus"></i> [% t('New credit type') %]</a>
116                     </div>
117
118                     <h3>[% t('Account credit types') %]</h3>
119                     [% IF credit_types.count %]
120                         <table id="table_credit_types">
121                             <thead>
122                                 <th>[% t('Archived') %]</th>
123                                 <th>[% t('System') %]</th>
124                                 <th>[% t('Code') %]</th>
125                                 <th>[% t('Description') %]</th>
126                                 <th>[% t('Available for') %]</th>
127                                 <th>[% t('Library limitations') %]</th>
128                                 <th>[% t('Actions') %]</th>
129                             </thead>
130                             <tbody>
131                                 [% FOREACH credit_type IN credit_types %]
132                                 <tr>
133                                     <td>[% credit_type.archived | html %]</td>
134                                     <td>[% credit_type.is_system | html %]</td>
135                                     <td>[% credit_type.code | html %]</td>
136                                     <td>[% credit_type.description | html %]</td>
137                                     <td>[% IF credit_type.can_be_added_manually %][% t('Manual credit') %][% END %]</td>
138                                     <td>
139                                         [% IF credit_type.library_limits.count > 0 %]
140                                             [% library_limits_str = "" %]
141                                             [% FOREACH library IN credit_type.library_limits %]
142                                                 [%- IF loop.first -%]
143                                                 [% library_limits_str = library.branchname _ " (" _ library.branchcode _ ")" %]
144                                                 [% ELSE %]
145                                                 [% library_limits_str = library_limits_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %]
146                                                 [% END %]
147                                             [% END %]
148                                             <span class="library_limitation" title="[% library_limits_str | html %]">
149                                                 [% limits_count = credit_type.library_limits.count %]
150                                                 [% tnx('{count} library limitation', '{count} library limitations', limits_count, { count => limits_count }) %]
151                                         [% ELSE %]
152                                             [% t('No limitation') %]
153                                         [% END %]
154                                     </td>
155                                     <td class="actions">
156                                         [% IF !credit_type.is_system && !credit_type.archived %]
157                                         <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=add_form&amp;code=[% credit_type.code | uri %]&type=credit"><i class="fa fa-pencil"></i> [% t('Edit') %]</a>
158                                         <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=archive&amp;code=[% credit_type.code | uri %]"><i class="fa fa-archive"></i> [% t('Archive') %]</a>
159                                         [% ELSIF credit_type.archived %]
160                                         <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/credit_types.pl?op=unarchive&amp;code=[% credit_type.code | uri %]"><i class="fa fa-undo"></i> [% t('Restore') %]</a>
161                                         [% END %]
162                                     </td>
163                                 </tr>
164                                 [% END %]
165                             </tbody>
166                         </table>
167                     [% ELSE %]
168                         <div class="dialog message">
169                             [% t('There are no account credit types defined.') %]
170                             <a href="/cgi-bin/koha/admin/credit_types.pl?op=add_form">[% t('Create new credit type') %]</a>
171                         </div>
172                     [% END %]
173                 [% END %]
174             </main>
175         </div> <!-- /.col-sm-10.col-sm-push-2 -->
176
177         <div class="col-sm-2 col-sm-pull-10">
178             <aside>
179                 [% INCLUDE 'admin-menu.inc' %]
180             </aside>
181         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
182     </div> <!-- /.row -->
183
184 [% MACRO jsinclude BLOCK %]
185     [% Asset.js("js/admin-menu.js") | $raw %]
186     [% INCLUDE 'datatables.inc' %]
187
188     <script>
189         $(document).ready(function() {
190             var txtActivefilter = _("Filter system credit types");
191             var txtInactivefilter = _("Show all credit types");
192             var table_credit_types = $("#table_credit_types").dataTable($.extend(true, {}, dataTablesDefaults, {
193                 "aoColumnDefs": [
194                     { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
195                     { "aTargets": [ 0, 1 ], "bSortable": false, "bVisible": false },
196                 ],
197                 "aaSorting": [[ 0, "asc" ],[ 2, "asc" ]],
198                 "sDom": 'C<"top pager"ilpfB><"#filter_s">tr<"bottom pager"ip>',
199                 "iDisplayLength": 20,
200                 "sPaginationType": "full_numbers"
201             }));
202             $("#filter_s").html('<p><a href="#" id="filter_system"><i class="fa fa-filter"></i> '+txtActivefilter+'</a>');
203             $('#filter_system').click(function(e) {
204                 e.preventDefault();
205                 if ($(this).hasClass('filtered')) {
206                     var filteredValue = '';
207                     $(this).html('<i class="fa fa-filter"></i> '+txtActivefilter);
208                 } else { //Not filtered. Let's do it!
209                     var filteredValue = '0';
210                     $(this).html('<i class="fa fa-filter"></i> '+txtInactivefilter);
211                 }
212                 table_credit_types.fnFilter(filteredValue, 1, false, false);
213                 $(this).toggleClass('filtered');
214             });
215
216             //Start filtered
217             $('#filter_system').click();
218         });
219     </script>
220 [% END %]
221
222 [% INCLUDE 'intranet-bottom.inc' %]