1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-22 00:06:56 +02:00
TableFilter/src/modules/store.js
2014-12-13 09:11:54 +00:00

65 lines
1.6 KiB
JavaScript

define(["exports", "../cookie"], function (exports, _cookie) {
"use strict";
var Cookie = _cookie.Cookie;
var Store = (function () {
var Store =
/**
* Store, persistence manager
* @param {Object} tf TableFilter instance
*/
function Store(tf) {
var f = tf.fObj;
this.duration = !isNaN(f.set_cookie_duration) ? parseInt(f.set_cookie_duration, 10) : 100000;
this.tf = tf;
};
Store.prototype.saveFilterValues = function (name) {
var tf = this.tf;
var fltValues = [];
//store filters' values
for (var i = 0; i < tf.fltIds.length; i++) {
var value = tf.GetFilterValue(i);
if (value === "") {
value = " ";
}
fltValues.push(value);
}
//adds array size
fltValues.push(tf.fltIds.length);
//writes cookie
Cookie.write(name, fltValues.join(tf.separator), this.duration);
};
Store.prototype.getFilterValues = function (name) {
var flts = Cookie.read(name);
var rgx = new RegExp(this.tf.separator, "g");
// filters' values array
return flts.split(rgx);
};
Store.prototype.savePageNb = function (name) {
Cookie.write(name, this.tf.currentPageNb, this.duration);
};
Store.prototype.getPageNb = function (name) {
return Cookie.read(name);
};
Store.prototype.savePageLength = function (name) {
Cookie.write(name, this.tf.resultsPerPageSlc.selectedIndex, this.duration);
};
Store.prototype.getPageLength = function (name) {
return Cookie.read(name);
};
return Store;
})();
exports.Store = Store;
});