}
}
}
+
+var Cookies = {
+ default_exipration_time: 31536000000, // 1 year in miliseconds
+ set_cookie: function(name, value, expiration) {
+ var date = new Date();
+ date.setTime(date.getTime() + this.default_exipration_time);
+ var expires = 'expires=' + date.toUTCString();
+ document.cookie = name + '=' + value + '; ' + expires;
+ },
+ get_cookie: function(name) {
+ name += '=';
+ var values = document.cookie.split(';');
+ var cookie_val = null;
+ var value;
+ for (var i = 0; i < values.length; i++) {
+ value = values[i];
+ while (value.charAt(0) == ' ') {
+ value = value.substr(1);
+ }
+ if (value.indexOf(name) == 0) {
+ cookie_val = value.substring(name.length, value.length);
+ break;
+ }
+ }
+ return cookie_val;
+ }
+}
}.bind(this, tr));
}.bind(this));
Formatters.set_formatters();
+ this.revertSortingFromCookie();
},
isConfigurationOpen: function() {
return is_open;
},
- sortTable: function (col, reverse) {
+ sortTable: function (col, reverse, set_cookie) {
var table = document.getElementById(this.gridEl);
var tb = table.tBodies[0], tr = Array.prototype.slice.call(tb.rows, 0), i;
reverse = -((+reverse) || -1);
}
return reverse * (val);
});
- for(i = 0; i < tr.length; i++) {
- var even = ((i % 2) == 0);
+ var even;
+ for (i = 0; i < tr.length; i++) {
+ even = ((i % 2) == 0);
if (even) {
tr[i].className = this.elements.contentItems;
} else {
}
tb.appendChild(tr[i]);
}
+ if (set_cookie === true) {
+ Cookies.set_cookie(this.gridEl, col + ':' + reverse);
+ }
},
makeSortable: function () {
while (--i >= downCounter) (function (i) {
var dir = 1;
th[i].addEventListener('click', function () {
- self.sortTable(i, (dir = 1 - dir));
+ self.sortTable(i, (dir = 1 - dir), true);
});
}(i));
},
+ revertSortingFromCookie: function() {
+ var sorting = Cookies.get_cookie(this.gridEl);
+ if (sorting != null) {
+ var sort_param = sorting.split(':');
+ var col = parseInt(sort_param[0], 10);
+ var order = -(parseInt(sort_param[1], 10));
+ this.sortTable(col, order);
+ }
+ },
+
setSearch: function() {
var search_pattern = new RegExp(this.search.value)
$$('div[id="' + this.windowId + this.elements.containerSuffix + '"] div.' + this.elements.contentItems).each(function(value){