Bug 33939: Preserve order budget dropdowns and default budget dropdowns seperately
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / funds_sorts.js
1 /* getAuthValueDropbox from js/acq.js is needed */
2 $(document).ready(function() {
3     // keep copy of the inactive budgets
4     disabledAllBudgetsCopy = $("select[name='all_budget_id']").html();
5     disabledBudgetsCopy = $("select[name='budget_id']").first().html();
6     $("select[name='all_budget_id'] .b_inactive").remove();
7     $("select[name='budget_id'] .b_inactive").remove();
8
9     $("#showallbudgets").click(function() {
10         if ($(this).is(":checked")) {
11             $("select[name='budget_id']").html(disabledBudgetsCopy)
12         }
13         else {
14             $("select[name='budget_id'] .b_inactive").remove();
15         }
16     });
17
18     $("#all_showallbudgets").click(function() {
19         if ($(this).is(":checked")) {
20             $("select[name='all_budget_id']").html(disabledAllBudgetsCopy);
21         }
22         else {
23             $("select[name='all_budget_id'] .b_inactive").remove();
24         }
25     });
26
27     $("select[name='budget_id']").change(function(){
28         var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
29         var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
30         var destination_sort1 = $(this).parents('fieldset').find('li.sort1').find('input[name="sort1"]');
31         var sort1 = $(destination_sort1).val() || "";
32         if ( destination_sort1.length < 1 ) {
33             destination_sort1 = $(this).parents('fieldset').find('li.sort1 > select[name="sort1"]');
34         }
35         var destination_sort2 = $(this).parents('fieldset').find('li.sort2').find('input[name="sort2"]');
36         var sort2 = $(destination_sort2).val() || "";
37         if ( destination_sort2.length < 1 ) {
38             destination_sort2 = $(this).parents('fieldset').find('li.sort2').find('select[name="sort2"]');
39         }
40         getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
41
42         getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
43     } );
44
45     $("select[name='budget_id']").change();
46
47     $("select[name='all_budget_id']").change(function(){
48         var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
49         var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
50         var destination_sort1 = $(this).parent().siblings('li').find('input[name="all_sort1"]');
51         if ( destination_sort1.length < 1 ) {
52             destination_sort1 = $(this).parent().siblings('li').find('select[name="all_sort1"]');
53         }
54         var destination_sort2 = $(this).parent().siblings('li').find('input[name="all_sort2"]');
55         if ( destination_sort2.length < 1 ) {
56             destination_sort2 = $(this).parent().siblings('li').find('select[name="all_sort2"]');
57         }
58         getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1 );
59         getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2 );
60         $(this).parent().siblings('li').find('select[name="sort1"]').attr('name', 'all_sort1');
61         $(this).parent().siblings('li').find('input[name="sort1"]').attr('name', 'all_sort1');
62         $(this).parent().siblings('li').find('select[name="sort2"]').attr('name', 'all_sort2');
63         $(this).parent().siblings('li').find('input[name="sort2"]').attr('name', 'all_sort2');
64     } );
65
66     $("select[name='all_budget_id']").change();
67
68 });