Bug 21526: uri escape TT variables when used in 'a href'
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / aqbudgets.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AuthorisedValues %]
4 [% USE Branches %]
5 [% USE Price %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; Administration &rsaquo; Funds[% IF op == 'add_form' %] &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name | html %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
9 [% Asset.css("css/datatables.css") | $raw %]
10 [% Asset.css("lib/jquery/plugins/treetable/stylesheets/jquery.treetable.css") | $raw %]
11 [% INCLUDE 'doc-head-close.inc' %]
12 </head>
13
14 <body id="admin_aqbudgets" class="admin">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'budgets-admin-search.inc' %]
17
18 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
19     <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> &rsaquo; [% IF op == 'list' %][% IF budget_period_id %]Funds for '[% budget_period_description | html %]'[% ELSE %]All funds[% END %][% END %]
20     [% IF op == 'add_form' %]
21       <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id | uri %]">Funds</a> &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name | html %]'[% END %][% ELSE %]Add fund[% END %]
22     [% END %]
23     [% IF op == 'delete_confirm' %]
24       <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> &rsaquo; Delete fund?
25     [% END %]
26 </div>
27
28 <div class="main container-fluid">
29     <div class="row">
30         <div class="col-sm-10 col-sm-push-2">
31             <main>
32
33 [% UNLESS op == 'delete_confirm' %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
34
35 [% IF (error_not_authorised_to_modify) %]
36     <div class="error">
37         <p>You are not authorized to modify this fund</p>
38     </div>
39 [% END %]
40
41 [% IF op == 'list' %]
42
43 <h1>
44   [% IF budget_period_id %]
45     Funds for '[% budget_period_description | html %]'
46   [% ELSE %]
47     All funds
48   [% END %]
49 </h1>
50
51 [% INCLUDE 'budgets-active-currency.inc' %]
52
53 [% IF budgets %]
54
55 <table id="budgeth" class="group">
56     [% UNLESS budget_period_id %]
57       <caption>
58         <span class="actions"><a href="#" id="expand_all">Expand all</a>
59         | <a href="#" id="collapse_all">Collapse all</a>
60         | <a href="#" id="hide_inactive">Hide inactive budgets</a>
61         | <a href="#" id="show_inactive">Show inactive budgets</a></span>
62       </caption>
63     [% END %]
64     <thead>
65         <tr>
66             <th>Active</th>
67             <th>Budget period description</th>
68             <th>Fund code</th>
69             <th>Fund name</th>
70             <th>Base-level allocated</th>
71             <th>Base-level ordered</th>
72             <th>Total ordered</th>
73             <th>Base-level spent</th>
74             <th>Total spent</th>
75             <th>Base-level available</th>
76             <th>Total available</th>
77             <th>Actions</th>
78         </tr>
79     </thead>
80     <tfoot>
81     <tr>
82     <th></th>
83     <th></th>
84     <th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF budget_period_total %][% budget_period_total | $Price %][% END %]  </th>
85     <th nowrap="nowrap" class="data"> [% period_alloc_total | $Price %]</th>
86     <th></th>
87     <th class="data">[% ordered_total | $Price %]</th>
88     <th></th>
89     <th class="data">[% spent_total | $Price %]</th>
90     <th></th>
91     <th class="data">[% available_total | $Price %]</th>
92     <th></th>
93     </tr>
94     </tfoot>
95     <tbody>
96     [% FOREACH budget IN budgets %]
97     [% IF budget.budget_parent_id %]
98       <tr data-tt-id="[% budget.budget_id | html %]" data-tt-parent-id="[% budget.budget_parent_id | html %]">
99     [% ELSE %]
100       <tr data-tt-id="[% budget.budget_id | html %]">
101     [% END %]
102     <td>[% budget.budget_period_active | html %]</td>
103     <td>Budget [% budget.budget_period_description | html %] [id=[% budget.budget_period_id | html %]][% UNLESS budget.budget_period_active %] (inactive)[% END %]</td>
104     <td>[% budget.budget_code | html %]</td>
105     <td>[% budget.budget_name | html %]</td>
106     <td class="data">
107       [% IF budget.budget_parent_id %]
108         <span class="child_fund_amount">[% budget.budget_amount | $Price %]</span>
109       [% ELSE %]
110         <span class="total_amount">[% budget.budget_amount | $Price %]</span>
111       [% END %]
112     </td>
113     <td class="data">
114       [% IF budget.budget_parent_id %]
115         <span class="child_fund_amount">[% budget.budget_ordered | $Price %]</span>
116       [% ELSE %]
117         <span class="total_amount">[% budget.budget_ordered | $Price %]</span>
118       [% END %]
119     </td>
120     <td class="data">
121       [% IF budget.budget_parent_id %]
122         <span class="child_fund_amount">[% budget.total_ordered | $Price %]</span>
123       [% ELSE %]
124         <span class="total_amount">[% budget.total_ordered | $Price %]</span>
125       [% END %]
126     </td>
127     <td class="data">
128       [% IF budget.budget_parent_id %]
129         <span class="child_fund_amount">[% budget.budget_spent | $Price %]</span>
130       [% ELSE %]
131         <span class="total_amount">[% budget.budget_spent | $Price %]</span>
132       [% END %]
133     </td>
134     <td class="data">
135       [% IF budget.budget_parent_id %]
136         <span class="child_fund_amount">[% budget.total_spent | $Price %]</span>
137       [% ELSE %]
138         <span class="total_amount">[% budget.total_spent | $Price %]</span>
139       [% END %]
140     </td>
141
142
143     [% BLOCK colorcellvalue %]
144         [% IF parent %]
145             [% IF (value > 0) %]
146                 <span class="child_fund_amount" style="color: green;">
147             [% ELSIF (value < 0) %]
148                 <span class="child_fund_amount" style="color: red;">
149             [% ELSE %]
150                 <span class="child_fund_amount">
151             [% END %]
152          [% ELSE %]
153             [% IF (value > 0) %]
154                 <span class="total_amount" style="color: green;">
155             [% ELSIF (value < 0) %]
156                 <span class="total_amount" style="color: red;">
157             [% ELSE %]
158                 <span class="totalamount">
159             [% END %]
160         [% END %]
161             [% value | $Price %]
162         </span>
163     [% END %]
164     <td class="data">
165         [% INCLUDE colorcellvalue value=budget.budget_remaining parent=budget.budget_parent_id %]
166     </td>
167     <td class="data">
168         [% INCLUDE colorcellvalue value=budget.total_remaining parent=budget.budget_parent_id %]
169     </td>
170     [% IF ( budget.budget_lock ) %]
171         <td> <span></span> </td>
172     [% ELSE %]
173         <td>
174             <div class="dropdown dropup">
175                 <a class="btn btn-default btn-xs dropdown-toggle" id="budgetactions[% budget.budget_id | html %]_[% budget.budget_period_id | html %]" role="button" data-toggle="dropdown" href="#">
176                    Actions <b class="caret"></b>
177                 </a>
178                 <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="budgetactions[% budget.budget_id | html %]_[% budget.budget_period_id | html %]">
179                     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa fa-pencil"></i> Edit</a></li>
180                     [% IF budget.budget_has_children %]
181                         <li class="disabled"><a href="#" class="deletefund-disabled" data-toggle="tooltip" data-placement="left" title="This fund has children"><i class="fa fa-trash"></i> Delete</a></li>
182                     [% ELSE %]
183                         <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&amp;budget_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa fa-trash"></i> Delete</a></li>
184                     [% END %]
185                     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_parent_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa fa-plus"></i> Add child fund</a></li>
186                 </ul>
187             </div>
188         </td>
189     [% END %]
190     </tr>
191     [% END %]
192     </tbody>
193 </table>
194
195 [% ELSE %]
196     <p>No fund found</p>
197 [% END %]
198
199 [% END %] <!-- list -->
200
201 <!-- ********************************************************************************************** -->
202 <!-- create add/mod entry form -->
203 [% IF op == 'add_form' && !error_not_authorised_to_modify %]
204 <form action="/cgi-bin/koha/admin/aqbudgets.pl" id="edit_fund" name="Aform" method="post">
205     <fieldset class="rows">
206     <legend>[% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund
207     [% IF ( budget_period_description ) %]
208         [% budget_name | html %] for Budget '[% budget_period_description | html %]'
209     [% END %]
210     </legend>
211
212     <input type="hidden" name="op" value="add_validate" />
213     <input type="hidden" name="checked" value="0" />
214     <ol>
215     [% IF ( budget_parent_id ) %]
216     <li>
217         <span class="label">Fund parent: </span>
218         [% budget_parent_name | html %]
219         [% budget_parent_id | html %] - [% budget_parent_name | html %]
220         <input type="hidden" name="budget_parent_id" value="[% budget_parent_id | html %]" />
221     </li>
222     [% END %]
223     <li>
224     <label class="required"  for="budget_code">Fund code: </label>
225     <input type="text" name="budget_code" id="budget_code" value="[% budget_code | html %]" size="30" />
226     </li>
227
228     <li>
229     <label class="required" for="budget_name">Fund name: </label>
230     <input type="text" name="budget_name" id="budget_name" value="[% budget_name | html %]" size="60" />
231     </li>
232
233     <li>
234     <label style="white-space: nowrap;" for="budget_amount" class="required">Amount: </label>
235     <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount | $Price on_editing => 1 | html %]" size="8" />
236     </li>
237
238     <li>
239       <label for="budget_encumb">Warning at (%): </label>
240       <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb | html %]" size="10" />
241       <span class="hint">0 to disable</span>
242     </li>
243
244     <li>
245       <label for="budget_expend">Warning at (amount): </label>
246       <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend | $Price on_editing => 1 | html %]" size="10" />
247       <span class="hint">0 to disable</span>
248     </li>
249
250     <li>
251         <span class="label">Owner: </span>
252         [% IF  budget_owner %]
253             <span  id="budget_owner_name">
254                 <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budget_owner.borrowernumber | uri %]">
255                     [% budget_owner.firstname | html %] [% budget_owner.surname | html %]
256                 </a> |
257             </span>
258         [% ELSE %]
259             <span  id="budget_owner_name"></span>
260         [% END %]
261         <a id="edit_owner" class="new_window" href="#"><i class="fa fa-search"></i> Select owner</a>
262         <a id="remove_owner" href="#"><i class="fa fa-trash"></i> Remove owner</a>
263         <input type="hidden" name="budget_owner_id" id="budget_owner_id"
264             value="[% budget_owner.borrowernumber | html %]" />
265     </li>
266
267
268     [% IF budget_has_children %]
269         <li class="radio">
270             <label>
271                 <input type="checkbox" id="set_owner_to_children" name="set_owner_to_children" value="1" />
272                 Update all child funds with this owner
273             </label>
274             <span class="hint">Selecting this option will overwrite existing fund owners, if any</span>
275         </li>
276     [% END %]
277
278     <li>
279         <span class="label">Users:</span>
280         <ul style="float:left;" id="budget_users">
281             [% FOREACH user IN budget_users %]
282                 <li id="user_[% user.borrowernumber | html %]">
283                     <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% user.borrowernumber | uri %]">
284                         [% user.firstname | html %] [% user.surname | html %]
285                     </a>
286                     &bull; <a href="#" class="del_user" data-borrowernumber="[% user.borrowernumber | html %]"><i class="fa fa-trash"></i> Remove</a>
287                 </li>
288             [% END %]
289             <li><a href="#" id="add_user_button"><i class="fa fa-plus"></i> Add users</a></li>
290         </ul>
291         <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids | html %]" />
292     </li>
293     <li>
294     <label for="budget_branchcode">Library: </label>
295     <select name="budget_branchcode" id="budget_branchcode">
296         <option value=""></option>
297         [% PROCESS options_for_libraries libraries => Branches.all( selected => budget_branchcode, unfiltered => 1 ) %]
298     </select>
299     </li>
300
301     <li>
302     <label for="budget_permission">Restrict access to: </label>
303     <select name="budget_permission" id="budget_permission">
304         [% IF ( budget_perm_0 ) %]
305             <option value="0" selected="selected">
306         [% ELSE %]
307             <option value="0">
308         [% END %]
309             None
310         </option>
311
312         [% IF ( budget_perm_1 ) %]
313             <option value="1" selected="selected">
314         [% ELSE %]
315             <option value="1">
316         [% END %]
317             Owner
318         </option>
319
320         [% IF ( budget_perm_3) %]
321             <option value="3" selected="selected">
322         [% ELSE %]
323             <option value="3">
324         [% END %]
325             Owner and users
326         </option>
327
328         [% IF ( budget_perm_2 ) %]
329             <option value="2" selected="selected">
330         [% ELSE %]
331             <option value="2">
332         [% END %]
333             Owner, users and library
334         </option>
335     </select>
336     </li>
337
338     <li>
339     <label for="budget_notes">Notes: </label>
340     <textarea name="budget_notes" id="budget_notes"  cols="80" rows="6">[% budget_notes | html %]</textarea>
341     </li>
342
343     <li>
344     <label  style="white-space: nowrap;" for="authorised_value_category1">Statistic 1 done on: </label>
345         <select name="sort1_authcat" id="authorised_value_category1">
346             <option value=""></option>
347             [% PROCESS options_for_authorised_value_categories authorised_value_categories => AuthorisedValues.GetCategories( selected => sort1_authcat ) %]
348         </select>
349     </li>
350     <li>
351     <label  style="white-space: nowrap;" for="authorised_value_category2">Statistic 2 done on: </label>
352         <select name="sort2_authcat" id="authorised_value_category2">
353             <option value=""></option>
354             [% PROCESS options_for_authorised_value_categories authorised_value_categories => AuthorisedValues.GetCategories( selected => sort2_authcat ) %]
355         </select>
356     </li>
357     </ol>
358
359     [% IF ( budget_id ) %]
360         <input type="hidden" name="budget_id" value="[% budget_id | html %]" />
361     [% END %]
362     </fieldset>
363
364     <fieldset class="action">
365         <input type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/aqbudgets.pl">Cancel</a>
366         <input type="hidden" name="budget_period_id" value="[% budget_period_id | html %]" />
367     </fieldset>
368 </form>
369
370 [% END %] <!-- add_form -->
371
372 [% IF op == 'delete_confirm' %]
373     <div class="dialog alert">
374         <h3>Delete fund [% budget_name | html %]?</h3>
375         If you delete this fund, all orders linked to this fund will be deleted!
376         <table>
377             <tr>
378             <th scope="row">Fund amount:</th>
379             <td>[% budget_amount | $Price %]</td>
380             </tr>
381         </table>
382
383         <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="post">
384             <input type="hidden" name="op" value="delete_confirmed" />
385             <input type="hidden" name="budget_id" value="[% budget_id | html %]" />
386             <input type="hidden" name="budget_period_id" value="[% budget_period_id | html %]" />
387             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this fund</button>
388         </form>
389         <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
390             <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
391         </form>
392     </div>
393 [% END %]
394
395             </main>
396         </div> <!-- /.col-sm-10.col-sm-push-2 -->
397
398         <div class="col-sm-2 col-sm-pull-10">
399             <aside>
400
401 [% IF op == 'list' %]
402   <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
403     <a href="#" id="filterbutton">Filters</a>
404     <fieldset class="brief" id="fundfilters">
405     <h4>Fund filters</h4>
406         <ol>
407         <li>
408             <label for="filter_budgetbranch2">Library: </label>
409             <select name="filter_budgetbranch" id="filter_budgetbranch2">
410                 <option value=""></option>
411                 [% PROCESS options_for_libraries libraries => Branches.all( selected => budget_branchcode, unfiltered => 1 ) %]
412             </select>
413         </li>
414         <li class="radio">
415
416         <label for="show_mine">Show my funds only:</label>
417             [% IF ( show_mine ) %]
418                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" checked="checked" />
419             [% ELSE %]
420                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" />
421         [% END %]
422         </li>
423
424         [% IF periods %]
425           <li>
426             <label for="periods">Budget:</label>
427             <select id="periods" name="budget_period_id">
428               <option value="">All budgets</option>
429               [% FOR period IN periods %]
430                 [% IF budget_period_id && period.budget_period_id == budget_period_id %]
431                   <option value="[% period.budget_period_id | html %]" selected="selected">[% period.budget_period_description | html %]</option>
432                 [% ELSE %]
433                   <option value="[% period.budget_period_id | html %]">[% period.budget_period_description | html %]</option>
434                 [% END %]
435               [% END %]
436             </select>
437           </li>
438         [% END %]
439         </ol>
440
441         <input type="hidden" name="op" value="list" />
442         <input type="submit" class="submit" name="filter" value="Go" />
443     </fieldset>
444 </form>[% END %]
445
446                 [% INCLUDE 'acquisitions-menu.inc' %]
447             </aside>
448         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
449      </div> <!-- /.row -->
450
451 [% MACRO jsinclude BLOCK %]
452     [% Asset.js("js/acq.js") | $raw %]
453     <script>
454         var MSG_BUDGET_PARENT_ALLOCATION = "- " + _("Fund amount exceeds parent allocation") + "\n";
455         var MSG_BUDGET_PERIOD_ALLOCATION = "- " + _("Fund amount exceeds period allocation") + "\n";
456         var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") + "\n";
457     </script>
458
459     [% Asset.js("js/acq.js") | $raw %]
460     [% IF op == 'add_form' %]
461         <script>
462         //<![CDATA[
463
464             function userPopup() {
465                 window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=add",
466                     'PatronPopup',
467                     'width=740,height=450,location=yes,toolbar=no,'
468                     + 'scrollbars=yes,resize=yes'
469                 );
470             }
471
472             function ownerPopup() {
473                 window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=select",
474                     'PatronPopup',
475                     'width=740,height=450,location=yes,toolbar=no,'
476                     + 'scrollbars=yes,resize=yes'
477                 );
478             }
479
480             function select_user(borrowernumber, borrower) {
481                 ownerRemove();
482                 var borrowername = borrower.firstname + ' ' + borrower.surname;
483                 if (borrowernumber) {
484                     var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
485                         + '?borrowernumber=' + borrowernumber + '">'
486                         + borrowername + '</a>';
487                     $('#budget_owner_name').html(ownerlink);
488                     $('#budget_owner_id').val(borrowernumber);
489                 }
490             }
491
492             function ownerRemove() {
493                 $('#budget_owner_name').empty();
494                 $('#budget_owner_id').val('');
495             }
496
497             function add_user(borrowernumber, borrowername) {
498                 var ids = $("#budget_users_id").val().split(':');
499                 if(borrowernumber && ids.indexOf(borrowernumber.toString()) == -1) {
500                     var li = '<li id="user_' + borrowernumber + '">'
501                         + '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='
502                         + borrowernumber + '">' + borrowername + '</a> '
503                         + ' &bull; <a data-borrowernumber=" + borrowernumber +" class="del_user" href="#"><i class="fa fa-trash"></i> '+_("Remove")+'</a> '
504                         + '</li>';
505                     $("#budget_users").prepend(li);
506                     ids.push(borrowernumber);
507                     $("#budget_users_id").val(ids.join(':'));
508                 } else {
509                     return -1;
510                 }
511                 return 0;
512             }
513
514             function del_user(borrowernumber) {
515                 var ids = $("#budget_users_id").val().split(':');
516                 if (borrowernumber) {
517                     var idx = ids.indexOf(borrowernumber+'');
518                     if (idx != -1) {
519                         ids.splice(idx, 1);
520                         $("#budget_users_id").val(ids.join(':'));
521                         $("li#user_" + borrowernumber).remove();
522                     }
523                 }
524             }
525
526             function Check(f) {
527                 var ok=1;
528                 var _alertString="";
529                 var alertString2;
530
531                 if (!(isNotNull(f.budget_code,1))) {
532                     _alertString += _("- Budget code cannot be blank") + "\n";
533                 }
534
535                 if (!(isNotNull(f.budget_name,1))) {
536                     _alertString += _("- Budget name cannot be blank") + "\n";
537                 }
538
539                 if (!(isNotNull(f.budget_amount,1))) {
540                     _alertString += _("- Budget amount cannot be blank") + "\n";
541                 }
542
543                 var budgetId;
544                 if   (typeof(f.budget_id ) != "undefined")  {
545                     budgetId = f.budget_id.value
546                 }
547
548                 var newBudgetParent;
549
550         //  hack to test if selected parent_id in scrolling-list...
551         //  if value == 'undef' its got a selected_parent :/
552                 if(f.budget_parent_id){
553                     var chkAdd   =  f.budget_parent_id.value ;
554                     if  (     typeof(chkAdd ) != "undefined") {
555                         newBudgetParent  =  f.budget_parent_id.value
556                     } else {
557                         newBudgetParent  =  f.budget_parent_id.item(0).value
558                     }
559
560                     if   (budgetId  > 0)  {  ; //its a mod ...
561                         // if parent == curent-budget, fail...
562                         if ( newBudgetParent  ==  budgetId     ) {
563                                 _alertString += _("- Budget parent is current budget") + "\n";
564                         }
565
566                         else if (newBudgetParent) {
567                             var result = checkBudgetParent(  budgetId , newBudgetParent   );
568                             if (result) {
569                                 _alertString += result;
570                             }
571                         }
572                     }
573                 }
574
575                  // else do lookup
576                 var budgetTotal = Math.abs(f.budget_amount.value);
577                 var result =   budgetExceedsParent  (budgetTotal, budgetId, newBudgetParent, f.budget_period_id.value)
578                 if (result) {
579                     _alertString += result;
580                 }
581
582                 if (_alertString.length==0) {
583                     document.Aform.submit();
584                 } else {
585                     alertString2 = _("Form not submitted because of the following problem(s)");
586                     alertString2 += "\n------------------------------------------------------------------------------------\n\n";
587                     alertString2 += _alertString;
588                     alert(alertString2);
589                 }
590             }
591             $(document).ready(function(){
592                 $("#remove_owner").on("click",function(e){
593                     e.preventDefault();
594                     ownerRemove();
595                 });
596                 $("#edit_owner").on("click",function(e){
597                     e.preventDefault();
598                     ownerPopup();
599                 });
600                 $("body").on("click",".del_user",function(e){
601                     e.preventDefault();
602                     var borrowernumber = $(this).data("borrowernumber");
603                     del_user(borrowernumber);
604                 });
605                 $("#add_user_button").on("click",function(e){
606                     e.preventDefault();
607                     userPopup();
608                 });
609                 $("#edit_fund").on("submit",function(e){
610                     e.preventDefault();
611                     Check(this);
612                 });
613             });
614         //]]>
615         </script>
616     [% ELSIF op == 'list' %]
617         [% INCLUDE 'datatables.inc' %]
618         [% Asset.js("lib/jquery/plugins/treetable/jquery.treetable.js") | $raw %]
619
620         <script>
621         //<![CDATA[
622             //
623             $(document).ready(function() {
624                 var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
625                     "fnDrawCallback": function ( oSettings ) {
626                         if ( oSettings.aiDisplay.length == 0 )
627                         {
628                             return;
629                         }
630
631                         var nTrs = $('#budgeth tbody tr');
632                         var iColspan = nTrs[0].getElementsByTagName('td').length;
633                         var sLastGroup = "";
634                         for ( var i=0 ; i<nTrs.length ; i++ )
635                         {
636                             var iDisplayIndex = oSettings._iDisplayStart + i;
637                             var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
638                             if ( sGroup != sLastGroup )
639                             {
640                                 var nGroup = document.createElement( 'tr' );
641                                 var nCell = document.createElement( 'td' );
642                                 nCell.colSpan = iColspan;
643                                 nCell.className = "group";
644                                 nCell.innerHTML = sGroup;
645                                 nGroup.appendChild( nCell );
646                                 nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
647                                 sLastGroup = sGroup;
648                             }
649                         }
650                     },
651                     "footerCallback": function ( row, data, start, end, display ) {
652                         var api = this.api(), data;
653                         footer_column_sum( api, [ 4, 6, 8, 10 ], 2 );
654                     },
655                     "aoColumnDefs": [
656                         { "bVisible": false, "aTargets": [ 0, 1 ] },
657                         { "bSortable": false, "aTargets": ["_all"] }
658                     ],
659                     'dom': '<"top pager"ilpf>tr<"bottom pager"ip>',
660                     'bSort': true,
661                     'aaSortingFixed': [[ 1, 'asc' ]],
662                     'bPaginate': false,
663                     "bAutoWidth": false
664                 }));
665
666                 $(oTable).treetable({
667                     expandable: true
668                 });
669                 $(oTable).treetable('expandAll');
670                 $("#expand_all").click(function(e){
671                     e.preventDefault();
672                     $(oTable).treetable('expandAll');
673                 });
674                 $("#collapse_all").click(function(e){
675                     e.preventDefault();
676                     $(oTable).treetable('collapseAll');
677                 });
678
679                 [% UNLESS budget_period_id %]
680                   $("#hide_inactive").click(function(e){
681                     e.preventDefault();
682                     oTable.fnFilter( 1, 0 ); // Show only active=1
683                   });
684                   $("#show_inactive").click(function(e){
685                     e.preventDefault();
686                     oTable.fnFilter( '', 0 );
687                   });
688                   $("#hide_inactive").click();
689                 [% END %]
690                 oTable.fnAddFilters("filter", 750);
691
692                 $("#filterbutton").click(function() {
693                     $("#fundfilters").slideToggle(0);
694                 });
695
696                 $(".deletefund-disabled").tooltip().on("click", function(e){
697                     e.preventDefault();
698                     alert(_("This fund has children. It cannot be deleted."));
699                 });
700             });
701         //]]>
702         </script>
703     [% END %]
704 [% END %]
705 [% INCLUDE 'intranet-bottom.inc' %]