Bug 9877 - Use DataTables on funds administration page
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / aqbudgets.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Administration &rsaquo; Funds[% IF ( add_form ) %] &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
3 [% INCLUDE 'doc-head-close.inc' %]
4 <script type="text/javascript" src="[% themelang %]/js/acq.js"></script>
5
6 [% IF ( add_form ) %]
7 <script type="text/javascript">
8 //<![CDATA[
9
10     function userPopup() {
11         window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=user",
12             'PatronPopup',
13             'width=740,height=450,location=yes,toolbar=no,'
14             + 'scrollbars=yes,resize=yes'
15         );
16     }
17
18     function ownerPopup() {
19         window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=owner",
20             'PatronPopup',
21             'width=740,height=450,location=yes,toolbar=no,'
22             + 'scrollbars=yes,resize=yes'
23         );
24     }
25
26     function edit_owner(borrowernumber, surname, firstname) {
27         $('#budget_owner_name').empty();
28         $('#budget_owner_id').val('');
29         if (borrowernumber) {
30             var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
31                 + '?borrowernumber=' + borrowernumber + '">'
32                 + firstname + ' ' + surname + '</a>';
33             $('#budget_owner_name').html(ownerlink);
34             $('#budget_owner_id').val(borrowernumber);
35         }
36     }
37
38     function ownerRemove() {
39         edit_owner(0);
40     }
41
42     function add_user(borrowernumber, surname, firstname) {
43         var ids = $("#budget_users_id").val().split(':');
44         if(borrowernumber && ids.indexOf(borrowernumber) == -1) {
45             var li = '<li id="user_' + borrowernumber + '">'
46                 + '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='
47                 + borrowernumber + '">' + firstname + ' ' + surname
48                 + '</a> [<a style="cursor:pointer"'
49                 + 'onclick="del_user(' + borrowernumber +')">Remove</a>]</li>';
50             $(li).insertBefore("li#add_user_button");
51             ids.push(borrowernumber);
52             $("#budget_users_id").val(ids.join(':'));
53         } else {
54             return -1;
55         }
56         return 0;
57     }
58
59     function del_user(borrowernumber) {
60         var ids = $("#budget_users_id").val().split(':');
61         if (borrowernumber) {
62             var idx = ids.indexOf(borrowernumber+'');
63             if (idx != -1) {
64                 ids.splice(idx, 1);
65                 $("#budget_users_id").val(ids.join(':'));
66                 $("li#user_" + borrowernumber).remove();
67             }
68         }
69     }
70
71     function Check(f) {
72         var ok=1;
73         var _alertString="";
74         var alertString2;
75
76         if (!(isNotNull(f.budget_code,1))) {
77             _alertString += _("- Budget code cannot be blank") + "\n";
78         }
79
80         if (!(isNotNull(f.budget_name,1))) {
81             _alertString += _("- Budget name cannot be blank") + "\n";
82         }
83
84         if (!(isNotNull(f.budget_amount,1))) {
85             _alertString += _("- Budget amount cannot be blank") + "\n";
86         }
87
88         var budgetId;
89         if   (typeof(f.budget_id ) != "undefined")  {
90             budgetId = f.budget_id.value
91         }
92
93         var newBudgetParent;
94
95 //  hack to test if selected parent_id in scrolling-list...
96 //  if value == 'undef' its got a selected_parent :/
97         if(f.budget_parent_id){
98             var chkAdd   =  f.budget_parent_id.value ;
99             if  (     typeof(chkAdd ) != "undefined") {
100                 newBudgetParent  =  f.budget_parent_id.value
101             } else {
102                 newBudgetParent  =  f.budget_parent_id.item(0).value
103             }
104
105             if   (budgetId  > 0)  {  ; //its a mod ...
106                 // if parent == curent-budget, fail...
107                 if ( newBudgetParent  ==  budgetId     ) {
108                         _alertString += _("- Budget parent is current budget") + "\n";
109                 }
110
111                 else if (newBudgetParent) {
112                     var result = checkBudgetParent(  budgetId , newBudgetParent   );
113                     if (result) {
114                         _alertString += result;
115                     }
116                 }
117             }
118         }
119
120          // else do lookup
121         var budgetTotal = Math.abs(f.budget_amount.value);
122         var result =   budgetExceedsParent  (budgetTotal, budgetId, newBudgetParent, f.budget_period_id.value)
123         if (result) {
124             _alertString += result;
125         }
126
127         if (_alertString.length==0) {
128             document.Aform.submit();
129         } else {
130             alertString2 = _("Form not submitted because of the following problem(s)");
131             alertString2 += "\n------------------------------------------------------------------------------------\n\n";
132             alertString2 += _alertString;
133             alert(alertString2);
134         }
135     }
136 //]]>
137 </script>
138 [% ELSE %]
139     [% IF ( notree ) %]
140         <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
141         <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
142         [% INCLUDE 'datatables-strings.inc' %]
143         <script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
144     [% ELSE %]
145         <link href="[% themelang %]/lib/jquery/plugins/treetable/stylesheets/jquery.treeTable.css" rel="stylesheet" type="text/css" />
146         <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/treetable/jquery.treeTable.min.js"></script>
147     [% END %]
148
149 <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.qtip.js"></script>
150
151 <script type="text/javascript">
152 //<![CDATA[
153     //
154     $(document).ready(function() {
155         var tooltipcontent = $(".tooltipcontent");
156         tooltipcontent.hide();
157
158         $(".tooltiped td").each(function (){
159             contentelem = $(this).parent().children().filter(".tooltipcontent");
160             if(contentelem.html() != ""){
161             $(this).qtip({
162                 content: contentelem.html(),
163                 show: "mouseover",
164                 hide: "mouseout",
165                 style: {
166                     name: "light",
167                     tip: "bottomLeft",
168                     border: {
169                         radius: 5,
170                         color: "#356CA1"
171                     }
172                 },
173                 position: {
174                     corner: {
175                         target: "topRight",
176                         tooltip: "bottomRight"
177                     }
178                 }
179             });
180             }
181         });
182         [% IF ( notree ) %]
183             $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
184                 "aoColumnDefs": [
185                     { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
186                 ],
187                 "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
188                 "iDisplayLength": 20,
189                 "sPaginationType": "four_button"
190             }));
191         [% ELSE %]
192         $("#budgeth").treeTable();
193         [% END %]
194
195         $("#filterbutton").click(function() {
196             $("#fundfilters").slideToggle(0);
197         });
198     });
199 //]]>
200 </script>
201 [% END %]
202
203 </head>
204 <body id="admin_aqbudgets" class="admin">
205 [% INCLUDE 'header.inc' %]
206 [% INCLUDE 'budgets-admin-search.inc' %]
207
208 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
209     <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> &rsaquo; [% IF ( else ) %]Funds for '[% budget_period_description %]'[% END %][% IF ( add_form ) %]
210     <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]">Funds</a> &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund[% END %][% END %]  [% IF ( delete_confirm ) %]
211     <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> &rsaquo; Delete fund?[% END %]</div>
212
213 <div id="doc3" class="yui-t2">
214 <div id="bd">
215 <div id="yui-main">
216 <div class="yui-b" id="content">
217
218
219 [% UNLESS ( delete_confirm ) %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
220
221 [% IF (error_not_authorised_to_modify) %]
222     <div class="error">
223         <p>You are not authorised to modify this fund</p>
224     </div>
225 [% END %]
226
227 [% IF ( else ) %]
228
229 <h1>Funds for '[% budget_period_description %]'</h1>
230
231 [% INCLUDE 'budgets-active-currency.inc' %]
232
233 <table id="budgeth">
234     <thead>
235         <tr>
236             <th>Fund code</th>
237             <th>Fund name</th>
238             <th>Total<br />allocated</th>
239             <th>Base-level<br />allocated</th>
240             <th>Base-level<br />spent</th>
241             <th>Total sublevels<br />spent</th>
242             <th>Base-level<br />remaining</th>
243             <th class="tooltipcontent">&nbsp;</th>
244             <th>Actions</th>
245         </tr>
246     </thead>
247 <tfoot>
248     <tr>
249     <th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %]  </th>
250     <th nowrap="nowrap" class="data"> [% period_alloc_total %]</th>
251     <th nowrap="nowrap"  class="data"> [% base_alloc_total %]</th>
252     <th class="data">[% base_spent_total %]</th>
253     <th class="data">[% base_spent_total %]</th>
254     <th class="data">[% base_remaining_total %]</th>
255     <th class="tooltipcontent"></th>
256     <th></th>
257     </tr>
258     </tfoot>
259     <tbody>
260     [% IF ( budget ) %]
261         [% FOREACH budge IN budget %]
262     [% IF ( budge.toggle ) %]
263     <tr id="node-[% budge.budget_id %]" class="highlight[% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %] tooltiped">
264     [% ELSE %]
265     <tr id="node-[% budge.budget_id %]" class="tooltiped [% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %]">
266     [% END %]
267
268     <td>[% budge.budget_code_indent %]</td>
269     <td>[% budge.budget_name %]</td>
270     <td class="data">[% budge.budget_amount_total %]</td>
271     <td class="data">[% budge.budget_amount %] </td>
272     <td class="data">[% budge.budget_spent %] </td>
273     <td class="data">[% budge.total_levels_spent %]</td>
274     [% IF ( budge.remaining_pos ) %]
275         <td class="data" style="color: green;">
276     [% ELSIF ( budge.remaining_neg ) %] 
277         <td class="data" style="color: red;">
278     [% ELSE %]
279         <td class="data">
280     [% END %]
281             [% budge.budget_remaining %] </td>
282
283     <td class="tooltipcontent">[% IF ( budge.budget_owner_id ) %]<strong>Owner: </strong><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budge.budget_owner_id %]">[% budge.budget_owner_name %]</a>[% END %]
284         [% IF ( budge.budget_branchcode ) %]<br /><strong>Library: </strong>[% budge.budget_branchcode %][% END %]
285         [% IF ( budge.budget_notes ) %]<br /><strong>Notes: </strong>[% budge.budget_notes %][% END %]
286         [% IF ( budge.budget_hierarchy ) %]
287             <ul class="budget_hierarchy">[% FOREACH budget_hierarch IN budge.budget_hierarchy %]
288                 [% IF ( budget_hierarch.element_id ) %]
289                     <li><a href="?op=add_form&amp;budget_id=[% budget_hierarch.element_id %]&amp;budget_period_id=[% budget_hierarch.budget_period_id %]">[% budget_hierarch.element_name %]</a></li>
290                 [% ELSE %]
291                     <li><strong>[% budget_hierarch.element_name %] : </strong></li>
292                 [% END %]
293                 [% END %]
294             </ul>
295         [% END %]</td>
296     [% IF ( budge.budget_lock ) %]
297         <td> <span style="color: gray;"> Edit Delete </span> </td>
298     [% ELSE %]
299         <td>
300             <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]" >Edit</a>
301             <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&amp;budget_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]">Delete</a>
302             <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_parent_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]">Add child fund</a>
303         </td>
304     [% END %]
305     </tr>
306         [% END %]
307     [% ELSE %]
308         <tr><td>No fund found</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td class="tooltipcontent">&nbsp;</td><td>&nbsp;</td></tr>
309     [% END %]
310     </tbody>
311 </table>
312
313 [% IF ( pagination_bar ) %]<div class="pages">[% pagination_bar %]</div>[% END %]
314 [% END %] <!-- else -->
315
316 <!-- ********************************************************************************************** -->
317 <!-- create add/mod entry form -->
318 [% IF ( add_form && !error_not_authorised_to_modify ) %]
319 <form action="/cgi-bin/koha/admin/aqbudgets.pl" name="Aform" method="post">
320     <fieldset class="rows">
321     <legend>[% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund
322     [% IF ( budget_period_description ) %]
323         [% budget_name %] for Budget '[% budget_period_description %]'
324     [% END %]
325     </legend>
326
327     <input type="hidden" name="op" value="add_validate" />
328     <input type="hidden" name="checked" value="0" />
329     <ol>
330     [% IF ( budget_parent_id ) %]
331     <li>
332         <span class="label">Fund parent: </span>
333         [% budget_parent_name %]
334         [% budget_parent_id %] - [% budget_parent_name %]
335         <input type="hidden" name="budget_parent_id" value="[% budget_parent_id %]" />
336     </li>
337     [% END %]
338     <li>
339     <label class="required"  for="budget_code">Fund code: </label>
340     <input type="text" name="budget_code" id="budget_code" value="[% budget_code %]" size="30" />
341     </li>
342
343     <li>
344     <label class="required" for="budget_name">Fund name: </label>
345     <input type="text" name="budget_name" id="budget_name" value="[% budget_name %]" size="60" />
346     </li>
347
348     <li>
349     <label style="white-space: nowrap;" for="budget_amount" class="required">Amount: </label>
350     <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount %]" size="8" />
351     </li>
352
353     <li style="display:none;">
354     <label for="budget_encumb">Encumbrance: </label>
355     <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb %]" size="8" />
356     </li>
357
358     <li style="display:none;">
359     <label for="budget_expend">Expenditure: </label>
360     <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend %]" size="8" />
361     </li>
362
363     <li>
364         <span class="label">Owner: </span>
365         <span  id="budget_owner_name">
366         <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budget_owner_id %]">
367             [% budget_owner_name %]
368         </a>
369         </span>
370         <input type="hidden" name="budget_owner_id" id="budget_owner_id"
371             value="[% budget_owner_id %]" />
372
373         <!-- FIXME: hardcoded button positions :/ -->
374         <input type="button" id="edit_owner" value="Edit owner"
375             onclick="ownerPopup(); return false;" />
376         <input type="button" id="remove_owner" value="Remove owner"
377             onclick="ownerRemove(); return false;" />
378     </li>
379
380     <li>
381         <span class="label">Users:</span>
382         <ul style="float:left;" id="budget_users">
383             [% FOREACH user IN budget_users %]
384                 <li id="user_[% user.borrowernumber %]">
385                     <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% user.borrowernumber %]">
386                         [% user.firstname %] [% user.surname %]
387                     </a>
388                     [<a style="cursor:pointer"
389                     onclick="del_user([% user.borrowernumber %])">Remove</a>]
390                 </li>
391             [% END %]
392             <li id="add_user_button">
393                 <input type="button" onclick="userPopup()" value="Add users" />
394             </li>
395         </ul>
396         <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids %]" />
397     <li>
398     <label for="budget_branchcode">Library: </label>
399     <select name="budget_branchcode" id="budget_branchcode">
400     <option value=""></option>
401     [% FOREACH branchloop_selec IN branchloop_select %]
402         [% UNLESS ( branchloop_selec.selected ) %] <option value="[% branchloop_selec.value %]" > [% ELSE %] <option value="[% branchloop_selec.value %]" selected="selected"> [% END %] [% branchloop_selec.value %]-[% branchloop_selec.branchname %]</option>
403     [% END %]
404     </select>
405     </li>
406
407     <li>
408     <label for="budget_permission">Restrict access to: </label>
409     <select name="budget_permission" id="budget_permission">
410         [% IF ( budget_perm_0 ) %]
411             <option value="0" selected="selected">
412         [% ELSE %]
413             <option value="0">
414         [% END %]
415             None
416         </option>
417
418         [% IF ( budget_perm_1 ) %]
419             <option value="1" selected="selected">
420         [% ELSE %]
421             <option value="1">
422         [% END %]
423             Owner
424         </option>
425
426         [% IF ( budget_perm_3) %]
427             <option value="3" selected="selected">
428         [% ELSE %]
429             <option value="3">
430         [% END %]
431             Owner and users
432         </option>
433
434         [% IF ( budget_perm_2 ) %]
435             <option value="2" selected="selected">
436         [% ELSE %]
437             <option value="2">
438         [% END %]
439             Owner, users and library
440         </option>
441     </select>
442     </li>
443
444     <li>
445     <label for="budget_notes">Notes: </label>
446     <textarea name="budget_notes" id="budget_notes"  cols="80" rows="6">[% budget_notes %]</textarea>
447     </li>
448
449     <li>
450     <label  style="white-space: nowrap;" for="authorised_value_category1">Statistic 1 done on: </label>
451         <select name="sort1_authcat" id="authorised_value_category1">
452             <option value=""></option>
453             [% FOREACH authorised_value_categories IN authorised_value_categories1 %]
454                 [% IF ( authorised_value_categories.selected ) %]
455                     <option value="[% authorised_value_categories.category %]" selected="selected">
456                         [% authorised_value_categories.category %]
457                     </option>
458                 [% ELSE %]
459                     <option value="[% authorised_value_categories.category %]">
460                         [% authorised_value_categories.category %]
461                     </option>
462                 [% END %]
463             [% END %]
464         </select>
465     </li>
466     <li>
467     <label  style="white-space: nowrap;" for="authorised_value_category2">Statistic 2 done on: </label>
468         <select name="sort2_authcat" id="authorised_value_category2">
469             <option value=""></option>
470             [% FOREACH authorised_value_categories IN authorised_value_categories2 %]
471                 [% IF ( authorised_value_categories.selected ) %]
472                     <option value="[% authorised_value_categories.category %]" selected="selected">
473                         [% authorised_value_categories.category %]
474                     </option>
475                 [% ELSE %]
476                     <option value="[% authorised_value_categories.category %]">
477                         [% authorised_value_categories.category %]
478                     </option>
479                 [% END %]
480             [% END %]
481         </select>
482     </li>
483     </ol>
484
485     [% IF ( budget_id ) %]
486         <input type="hidden" name="budget_id" value="[% budget_id %]" />
487     [% END %]
488     </fieldset>
489
490     <fieldset class="action">
491         <input type="submit" value="Submit" onclick="Check(this.form); return false;" /> <a class="cancel" href="/cgi-bin/koha/admin/aqbudgets.pl">Cancel</a>
492         <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
493     </fieldset>
494 </form>
495
496 [% END %] <!-- add_form -->
497
498 [% IF ( delete_confirm ) %]
499 <div class="dialog alert"> <h3>Delete fund [% budget_name %]?</h3>
500 <table>
501     <tr>
502     <th scope="row">Fund amount:</th>
503     <td>[% budget_amount %]</td>
504     </tr>
505 </table>
506
507 <form action="[% action %]" method="post">
508     <input type="hidden" name="op" value="delete_confirmed" />
509     <input type="hidden" name="budget_id" value="[% budget_id %]" />
510     <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
511     <input type="submit" value="Delete" class="approve" />
512 </form>
513
514 <form action="[% action %]" method="get">
515     <input type="submit" class="deny" value="Cancel" />
516 </form>
517 </div>
518 [% END %]
519
520 </div>
521 </div>
522 <div class="yui-b">
523 [% IF ( else ) %]<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
524     <a href="#" id="filterbutton">Filters</a>
525     <fieldset class="brief" id="fundfilters">
526     <h4>Fund filters</h4>
527         <ol>
528         <li>
529             <label for="filter_budgetbranch2">Library: </label>
530             <select name="filter_budgetbranch" id="filter_budgetbranch2" style="width:10em;">
531                 <option value=""></option>
532                 [% FOREACH branchloo IN branchloop %]
533                 [% UNLESS ( branchloo.selected ) %]<option value="[% branchloo.value %]">
534                 [% ELSE %]<option value="[% branchloo.value %]" selected="selected">[% END %]
535                 [% branchloo.branchname %]</option>
536                 [% END %]
537             </select>
538         </li>
539         <li class="radio">
540
541         <label for="show_mine">Show my funds only</label>
542             [% IF ( show_mine ) %]
543                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" checked="checked" />
544             [% ELSE %]
545                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" />
546         [% END %]
547         </li>
548         </ol>
549
550         <input type="hidden" name="show" value="1" />
551         <input type="hidden"  name="budget_period_id" value="[% budget_period_id %]" />
552         <input type="submit" class="submit" name="filter" value="Go" />
553     </fieldset>
554 </form>[% END %]
555 [% INCLUDE 'acquisitions-menu.inc' %]
556 </div>
557 </div>
558 [% INCLUDE 'intranet-bottom.inc' %]