Lines 1-86
Link Here
|
|
|
1 |
/* global dataTablesDefaults allColumns */ |
1 |
// Set expiration date for cookies |
2 |
// Set expiration date for cookies |
2 |
var date = new Date(); |
3 |
var date = new Date(); |
3 |
date.setTime(date.getTime()+(365*24*60*60*1000)); |
4 |
date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000)); |
4 |
var expiration = date.toGMTString(); |
|
|
5 |
|
5 |
|
6 |
|
6 |
function hideColumns() { |
7 |
function hideColumns(){ |
7 |
var valCookie = $.cookie("showColumns"); |
8 |
valCookie = $.cookie("showColumns"); |
8 |
if (valCookie) { |
9 |
if(valCookie){ |
9 |
valCookie = valCookie.split("/"); |
10 |
valCookie = valCookie.split("/"); |
10 |
$("#showall").prop("checked", false).parent().removeClass("selected"); |
11 |
$("#showall").prop("checked", false).parent().removeClass("selected"); |
11 |
for ( var i = 0; i < valCookie.length; i++ ) { |
12 |
for( i=0; i<valCookie.length; i++ ){ |
12 |
if (valCookie[i] !== '') { |
13 |
if(valCookie[i] !== ''){ |
13 |
var index = valCookie[i] - 3; |
14 |
index = valCookie[i] - 3; |
14 |
$("#itemst td:nth-child(" + valCookie[i] + "),#itemst th:nth-child(" + valCookie[i] + ")").toggle(); |
15 |
$("#itemst td:nth-child("+valCookie[i]+"),#itemst th:nth-child("+valCookie[i]+")").toggle(); |
15 |
$("#checkheader" + index).prop("checked", false).parent().removeClass("selected"); |
16 |
$("#checkheader"+index).prop("checked", false).parent().removeClass("selected"); |
16 |
} |
17 |
} |
17 |
} |
18 |
} |
18 |
} |
19 |
} |
|
|
20 |
} |
19 |
} |
21 |
|
20 |
|
22 |
function hideColumn(num) { |
21 |
function hideColumn(num) { |
23 |
$("#hideall,#showall").prop("checked", false).parent().removeClass("selected"); |
22 |
$("#hideall,#showall").prop("checked", false).parent().removeClass("selected"); |
24 |
valCookie = $.cookie("showColumns"); |
23 |
var valCookie = $.cookie("showColumns"); |
25 |
// set the index of the table column to hide |
24 |
// set the index of the table column to hide |
26 |
$("#"+num).parent().removeClass("selected"); |
25 |
$("#" + num).parent().removeClass("selected"); |
27 |
var hide = Number(num.replace("checkheader","")) + 3; |
26 |
var hide = Number(num.replace("checkheader", "")) + 3; |
28 |
// hide header and cells matching the index |
27 |
// hide header and cells matching the index |
29 |
$("#itemst td:nth-child("+hide+"),#itemst th:nth-child("+hide+")").toggle(); |
28 |
$("#itemst td:nth-child(" + hide + "),#itemst th:nth-child(" + hide + ")").toggle(); |
30 |
// set or modify cookie with the hidden column's index |
29 |
// set or modify cookie with the hidden column's index |
31 |
if(valCookie){ |
30 |
if (valCookie) { |
32 |
valCookie = valCookie.split("/"); |
31 |
valCookie = valCookie.split("/"); |
33 |
var found = false; |
32 |
var found = false; |
34 |
for( $i=0; $i<valCookie.length; $i++ ){ |
33 |
for ( var i = 0; i < valCookie.length; i++ ) { |
35 |
if (hide == valCookie[i]) { |
34 |
if (hide == valCookie[i]) { |
36 |
found = true; |
35 |
found = true; |
37 |
break; |
36 |
break; |
|
|
37 |
} |
38 |
} |
38 |
} |
|
|
39 |
if (!found) { |
40 |
valCookie.push(hide); |
41 |
var cookieString = valCookie.join("/"); |
42 |
$.cookie("showColumns", cookieString, { expires: date, path: '/' }); |
43 |
} |
44 |
} else { |
45 |
$.cookie("showColumns", hide, { expires: date, path: '/' }); |
39 |
} |
46 |
} |
40 |
if( !found ){ |
|
|
41 |
valCookie.push(hide); |
42 |
var cookieString = valCookie.join("/"); |
43 |
$.cookie("showColumns", cookieString, { expires : date, path: '/' }); |
44 |
} |
45 |
} else { |
46 |
$.cookie("showColumns", hide, { expires : date, path: '/' }); |
47 |
} |
48 |
} |
47 |
} |
49 |
|
48 |
|
50 |
// Array Remove - By John Resig (MIT Licensed) |
49 |
// Array Remove - By John Resig (MIT Licensed) |
51 |
// http://ejohn.org/blog/javascript-array-remove/ |
50 |
// http://ejohn.org/blog/javascript-array-remove/ |
52 |
Array.prototype.remove = function(from, to) { |
51 |
Array.prototype.remove = function (from, to) { |
53 |
var rest = this.slice((to || from) + 1 || this.length); |
52 |
var rest = this.slice((to || from) + 1 || this.length); |
54 |
this.length = from < 0 ? this.length + from : from; |
53 |
this.length = from < 0 ? this.length + from : from; |
55 |
return this.push.apply(this, rest); |
54 |
return this.push.apply(this, rest); |
56 |
}; |
55 |
}; |
57 |
|
56 |
|
58 |
function showColumn(num){ |
57 |
function showColumn(num) { |
59 |
$("#hideall").prop("checked", false).parent().removeClass("selected"); |
58 |
$("#hideall").prop("checked", false).parent().removeClass("selected"); |
60 |
$("#"+num).parent().addClass("selected"); |
59 |
$("#" + num).parent().addClass("selected"); |
61 |
valCookie = $.cookie("showColumns"); |
60 |
var valCookie = $.cookie("showColumns"); |
62 |
// set the index of the table column to hide |
61 |
// set the index of the table column to hide |
63 |
show = Number(num.replace("checkheader","")) + 3; |
62 |
var show = Number(num.replace("checkheader", "")) + 3; |
64 |
// hide header and cells matching the index |
63 |
// hide header and cells matching the index |
65 |
$("#itemst td:nth-child("+show+"),#itemst th:nth-child("+show+")").toggle(); |
64 |
$("#itemst td:nth-child(" + show + "),#itemst th:nth-child(" + show + ")").toggle(); |
66 |
// set or modify cookie with the hidden column's index |
65 |
// set or modify cookie with the hidden column's index |
67 |
if(valCookie){ |
66 |
if (valCookie) { |
68 |
valCookie = valCookie.split("/"); |
67 |
valCookie = valCookie.split("/"); |
69 |
var found = false; |
68 |
var found = false; |
70 |
for( i=0; i<valCookie.length; i++ ){ |
69 |
for ( var i = 0; i < valCookie.length; i++ ) { |
71 |
if (show == valCookie[i]) { |
70 |
if (show == valCookie[i]) { |
72 |
valCookie.remove(i); |
71 |
valCookie.remove(i); |
73 |
found = true; |
72 |
found = true; |
|
|
73 |
} |
74 |
} |
75 |
if (found) { |
76 |
var cookieString = valCookie.join("/"); |
77 |
$.cookie("showColumns", cookieString, { expires: date, path: '/' }); |
74 |
} |
78 |
} |
75 |
} |
79 |
} |
76 |
if( found ){ |
|
|
77 |
var cookieString = valCookie.join("/"); |
78 |
$.cookie("showColumns", cookieString, { expires : date, path: '/' }); |
79 |
} |
80 |
} |
81 |
} |
80 |
} |
82 |
function showAllColumns(){ |
81 |
|
83 |
$("#selections input:checkbox").each(function(){ |
82 |
function showAllColumns() { |
|
|
83 |
$("#selections input:checkbox").each(function () { |
84 |
$(this).prop("checked", true); |
84 |
$(this).prop("checked", true); |
85 |
}); |
85 |
}); |
86 |
$("#selections span").addClass("selected"); |
86 |
$("#selections span").addClass("selected"); |
Lines 88-146
function showAllColumns(){
Link Here
|
88 |
$.removeCookie("showColumns", { path: '/' }); |
88 |
$.removeCookie("showColumns", { path: '/' }); |
89 |
$("#hideall").prop("checked", false).parent().removeClass("selected"); |
89 |
$("#hideall").prop("checked", false).parent().removeClass("selected"); |
90 |
} |
90 |
} |
91 |
function hideAllColumns(){ |
91 |
|
92 |
$("#selections input:checkbox").each(function(){ |
92 |
function hideAllColumns() { |
|
|
93 |
$("#selections input:checkbox").each(function () { |
93 |
$(this).prop("checked", false); |
94 |
$(this).prop("checked", false); |
94 |
}); |
95 |
}); |
95 |
$("#selections span").removeClass("selected"); |
96 |
$("#selections span").removeClass("selected"); |
96 |
$("#itemst td:nth-child(3),#itemst th:nth-child(3)").nextAll().hide(); |
97 |
$("#itemst td:nth-child(3),#itemst th:nth-child(3)").nextAll().hide(); |
97 |
$("#hideall").prop("checked", true).parent().addClass("selected"); |
98 |
$("#hideall").prop("checked", true).parent().addClass("selected"); |
98 |
var cookieString = allColumns.join("/"); |
99 |
var cookieString = allColumns.join("/"); |
99 |
$.cookie("showColumns", cookieString, { expires : date, path: '/' }); |
100 |
$.cookie("showColumns", cookieString, { expires: date, path: '/' }); |
100 |
} |
101 |
} |
101 |
|
102 |
|
102 |
$(document).ready(function() { |
103 |
$(document).ready(function () { |
103 |
hideColumns(); |
104 |
hideColumns(); |
104 |
$("#itemst").dataTable($.extend(true, {}, dataTablesDefaults, { |
105 |
$("#itemst").dataTable($.extend(true, {}, dataTablesDefaults, { |
105 |
"sDom": 't', |
106 |
"sDom": 't', |
106 |
"aoColumnDefs": [ |
107 |
"aoColumnDefs": [ |
107 |
{ "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }, |
108 |
{ "aTargets": [0], "bSortable": false, "bSearchable": false }, |
108 |
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] } |
109 |
{ "sType": "anti-the", "aTargets": ["anti-the"] } |
109 |
], |
110 |
], |
110 |
"bPaginate": false, |
111 |
"bPaginate": false, |
111 |
})); |
112 |
})); |
112 |
$("#selectallbutton").click(function(e){ |
113 |
$("#selectallbutton").click(function (e) { |
113 |
e.preventDefault(); |
114 |
e.preventDefault(); |
114 |
$("#itemst input:checkbox").each(function(){ |
115 |
$("#itemst input:checkbox").each(function () { |
115 |
$(this).prop("checked", true); |
116 |
$(this).prop("checked", true); |
116 |
}); |
117 |
}); |
117 |
}); |
118 |
}); |
118 |
$("#clearallbutton").click(function(e){ |
119 |
$("#clearallbutton").click(function (e) { |
119 |
e.preventDefault(); |
120 |
e.preventDefault(); |
120 |
$("#itemst input:checkbox").each(function(){ |
121 |
$("#itemst input:checkbox").each(function () { |
121 |
$(this).prop("checked", false); |
122 |
$(this).prop("checked", false); |
122 |
}); |
123 |
}); |
123 |
}); |
124 |
}); |
124 |
$("#clearonloanbutton").click(function(){ |
125 |
$("#clearonloanbutton").click(function () { |
125 |
$("#itemst input[name='itemnumber'][data-is-onloan='1']").each(function(){ |
126 |
$("#itemst input[name='itemnumber'][data-is-onloan='1']").each(function () { |
126 |
$(this).prop('checked', false); |
127 |
$(this).prop('checked', false); |
127 |
}); |
128 |
}); |
128 |
return false; |
129 |
return false; |
129 |
}); |
130 |
}); |
130 |
$("#selections input").change(function(e){ |
131 |
$("#selections input").change(function (e) { |
131 |
var num = $(this).attr("id"); |
132 |
var num = $(this).attr("id"); |
132 |
if(num == 'showall'){ |
133 |
if (num == 'showall') { |
133 |
showAllColumns(); |
134 |
showAllColumns(); |
134 |
e.stopPropagation(); |
135 |
e.stopPropagation(); |
135 |
} else if(num == 'hideall'){ |
136 |
} else if (num == 'hideall') { |
136 |
hideAllColumns(); |
137 |
hideAllColumns(); |
137 |
e.stopPropagation(); |
138 |
e.stopPropagation(); |
138 |
} else { |
|
|
139 |
if($(this).prop("checked")){ |
140 |
showColumn(num); |
141 |
} else { |
139 |
} else { |
142 |
hideColumn(num); |
140 |
if ($(this).prop("checked")) { |
|
|
141 |
showColumn(num); |
142 |
} else { |
143 |
hideColumn(num); |
144 |
} |
143 |
} |
145 |
} |
144 |
} |
|
|
145 |
}); |
146 |
}); |
146 |
}); |
147 |
}); |
147 |
- |
|
|