2014-05-24 06:14:16 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function FilterModel()
|
|
|
|
{
|
|
|
|
this.enabled = ko.observable(true);
|
|
|
|
|
2014-06-18 04:57:38 +08:00
|
|
|
this.name = ko.observable('');
|
|
|
|
|
|
|
|
this.conditionsType = ko.observable(Enums.FilterRulesType.And);
|
|
|
|
|
2014-05-24 06:14:16 +08:00
|
|
|
this.conditions = ko.observableArray([]);
|
2014-06-18 04:57:38 +08:00
|
|
|
this.actions = ko.observableArray([]);
|
|
|
|
|
|
|
|
this.conditions.subscribe(function () {
|
|
|
|
Utils.windowResize();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.actions.subscribe(function () {
|
|
|
|
Utils.windowResize();
|
|
|
|
});
|
2014-05-24 06:14:16 +08:00
|
|
|
|
2014-06-18 04:57:38 +08:00
|
|
|
this.conditionsCanBeDeleted = ko.computed(function () {
|
|
|
|
return 1 < this.conditions().length;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.actionsCanBeDeleted = ko.computed(function () {
|
|
|
|
return 1 < this.actions().length;
|
|
|
|
}, this);
|
2014-05-24 06:14:16 +08:00
|
|
|
}
|
|
|
|
|
2014-06-18 04:57:38 +08:00
|
|
|
FilterModel.prototype.addCondition = function ()
|
2014-05-24 06:14:16 +08:00
|
|
|
{
|
2014-06-18 04:57:38 +08:00
|
|
|
this.conditions.push(new FilterConditionModel(this.conditions, this.conditionsCanBeDeleted));
|
2014-05-24 06:14:16 +08:00
|
|
|
};
|
|
|
|
|
2014-06-18 04:57:38 +08:00
|
|
|
FilterModel.prototype.addAction = function ()
|
2014-05-24 06:14:16 +08:00
|
|
|
{
|
2014-06-18 04:57:38 +08:00
|
|
|
this.actions.push(new FilterActionModel(this.actions, this.actionsCanBeDeleted));
|
2014-05-24 06:14:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
FilterModel.prototype.parse = function (oItem)
|
|
|
|
{
|
|
|
|
var bResult = false;
|
|
|
|
if (oItem && 'Object/Filter' === oItem['@Object'])
|
|
|
|
{
|
|
|
|
this.name(Utils.pString(oItem['Name']));
|
|
|
|
|
|
|
|
bResult = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
};
|