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