Bug 27846: admin folder
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / transport-cost-matrix.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Administration &rsaquo; Transport cost matrix</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 <style>
9 .disabled-transfer {
10     background-color: #FF8888;
11 }
12 </style>
13 </head>
14
15 <body id="admin_transport_cost_matrix" class="admin">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'prefs-admin-search.inc' %]
18
19 <nav aria-label="Breadcrumb" class="breadcrumb">
20     <ol>
21         <li>
22             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
23         </li>
24         <li>
25             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
26         </li>
27         <li>
28             <a href="#" aria-current="page">
29                 Transport cost matrix
30             </a>
31         </li>
32     </ol>
33 </nav>
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     <h1 class="parameters">
41             Defining transport costs between libraries
42     </h1>
43 [% IF ( WARNING_transport_cost_matrix_off ) %]
44 <div class="dialog message">Because the "UseTransportCostMatrix" system preference is currently not enabled, the transport cost matrix is not being used.  <br/>Go to the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=UseTransportCostMatrix">UseTransportCostMatrix</a> system preference if you wish to enable this feature.</div>
45 [% END %]
46
47     [% IF ( errors ) %]<div class="dialog alert">
48         <h4>There were problems with your submission</h4>
49         <ul>
50             [% FOR e IN errors %]
51                 <li>Invalid value for [% e | html %]</li>
52             [% END %]
53         </ul>
54     </div>[% END %]
55
56         <form method="post" action="/cgi-bin/koha/admin/transport-cost-matrix.pl" id="cost_matrix_form">
57             <input type="hidden" name="op" value="set-cost-matrix" />
58             <fieldset id="transport-cost-matrix">
59                 <div class="help">
60                     <p>Costs are decimal values between some arbitrary maximum value (e.g. 1 or 100) and 0 which is the minimum (no) cost.</p>
61                     <p>Red cells signify no transfer allowed.</p>
62                     <p>Click on individual cells to edit.</p>
63                 </div>
64
65                 <table>
66                     <tr>
67                         <th>From \ To</th>
68                         [% FOR b IN Branches.all() %]
69                         <th>[% b.branchname | html %]</th>
70                         [% END %]
71                     </tr>
72                 [% FOR bf IN branchfromloop %]
73                     <tr>
74                         <th>[% bf.name | html %]</th>
75                     [% FOR bt IN bf.branchtoloop %]
76                         <td>
77                         [% IF bt.skip %]
78                             &nbsp;
79                         [% ELSE %]
80                             [% IF bt.disabled %]
81                             <div id="celldiv_[% bt.id | html %]" class="disabled-transfer">
82                             [% ELSE %]
83                             <div id="celldiv_[% bt.id | html %]">
84                             [% END %]
85                             <div class="enable_cost_input" data-cost-id="[% bt.id | html %]">[% IF bt.disabled %]&nbsp;[% ELSE %][% bt.value | html %][% END %]</div>
86                             <input type="hidden" name="cost_[% bt.id | html %]" value="[% bt.value | html %]" />
87                             [% IF bt.disabled %]
88                             <input type="hidden" name="disable_[% bt.id | html %]" value="1" />
89                             [% END %]
90                             </div>
91                         [% END %]
92                         </td>
93                     [% END %]
94                     </tr>
95                 [% END %]
96                 </table>
97             </fieldset>
98             <fieldset class="action">
99                 <input type="submit" value="Save" class="submit" /> <a href="/cgi-bin/koha/admin/transport-cost-matrix.pl" class="cancel">Cancel</a>
100             </fieldset>
101         </form>
102
103             </main>
104         </div> <!-- /.col-sm-10.col-sm-push-2 -->
105
106         <div class="col-sm-2 col-sm-pull-10">
107             <aside>
108                 [% INCLUDE 'admin-menu.inc' %]
109             </aside>
110         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
111      </div> <!-- /.row -->
112
113 [% MACRO jsinclude BLOCK %]
114     [% Asset.js("js/admin-menu.js") | $raw %]
115     <script>
116         function check_transport_cost(e) {
117             var val = e.value;
118             if (val && val != '' && !isNaN(parseFloat(val)) && val >= 0.0) {
119                 return;
120             }
121             alert(_("Cost must be expressed as a decimal number >= 0"));
122         }
123         function disable_transport_cost_chg(e) {
124             var input_name = e.name;
125             var cost_id = input_name.replace(/disable_/,''); // Parse the code_id out of the input name
126             disable_transport_cost(cost_id, e.checked);
127         }
128         function disable_transport_cost(cost_id, disable) {
129             if (disable) {
130                 $('#celldiv_'+cost_id).find('input[type=text]').prop('disabled', true).addClass('disabled-transfer');
131             } else {
132                 $('#celldiv_'+cost_id).find('input:disabled').prop('disabled', false).removeClass('disabled-transfer');
133             }
134         }
135         function enable_cost_input(cost_id) {
136             var cell = $('#celldiv_'+cost_id);
137             var cost = $(cell).text();
138             var disabled = $(cell).hasClass('disabled-transfer');
139             $(cell).removeClass('disabled-transfer');
140
141             $('#celldiv_'+cost_id).html(
142                 '<input type="text" name="cost_'+cost_id+'" class="cost_input" size="4" value="'+$.trim(cost)+'" />'+
143                 '<br/>' + _("Disable ") + '<input name="disable_'+cost_id+'" value="1" class="disable_transport_cost" type="checkbox" '+(disabled ? 'checked' : '')+' />'
144             );
145             disable_transport_cost(cost_id, disabled);
146         }
147
148         function form_submit (f) {
149             $(f).find('input:disabled').prop('disabled', false);
150             return true;
151         }
152         $(document).ready(function(){
153             $(".enable_cost_input").on("click",function(){
154                 var cost_id = $(this).data("cost-id");
155                 enable_cost_input( cost_id );
156             });
157             $("body").on("blur",".cost_input",function(){
158                 check_transport_cost(this);
159             });
160             $("body").on("change",".disable_transport_cost",function(){
161                 disable_transport_cost_chg(this);
162             });
163             $("#cost_matrix_form").on("submit",function(){
164                 return form_submit(this);
165             });
166         });
167     </script>
168 [% END %]
169 [% INCLUDE 'intranet-bottom.inc' %]