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-05 12:10:00 +11:00

79 lines
2.1 KiB
JavaScript

define(["exports", "../cookie"], function (exports, _cookie) {
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Cookie = _cookie.Cookie;
var Store = (function () {
var Store = function Store(tf) {
var f = tf.fObj;
this.duration = !isNaN(f.set_cookie_duration) ? parseInt(f.set_cookie_duration, 10) : 100000;
this.tf = tf;
};
_classProps(Store, null, {
saveFilterValues: {
writable: true,
value: 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);
}
},
getFilterValues: {
writable: true,
value: function (name) {
var flts = Cookie.read(name);
var rgx = new RegExp(this.tf.separator, "g");
// filters' values array
return flts.split(rgx);
}
},
savePageNb: {
writable: true,
value: function (name) {
Cookie.write(name, this.tf.currentPageNb, this.duration);
}
},
getPageNb: {
writable: true,
value: function (name) {
return Cookie.read(name);
}
},
savePageLength: {
writable: true,
value: function (name) {
Cookie.write(name, this.tf.resultsPerPageSlc.selectedIndex, this.duration);
}
},
getPageLength: {
writable: true,
value: function (name) {
return Cookie.read(name);
}
}
});
return Store;
})();
exports.Store = Store;
});