2014-05-24 06:14:16 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-08-25 23:49:01 +08:00
|
|
|
|
|
|
|
'use strict';
|
2014-08-07 05:02:20 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
2014-10-04 19:58:01 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
2014-10-04 19:58:01 +08:00
|
|
|
FilterConditionModel = require('Model/FilterCondition'),
|
|
|
|
|
|
|
|
AbstractModel = require('Knoin/AbstractModel')
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
2014-05-24 06:14:16 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function FilterModel()
|
|
|
|
{
|
2014-10-04 19:58:01 +08:00
|
|
|
AbstractModel.call(this, 'FilterModel');
|
|
|
|
|
2014-08-29 23:30:52 +08:00
|
|
|
this.isNew = ko.observable(true);
|
2014-08-20 23:03:12 +08:00
|
|
|
this.enabled = ko.observable(true);
|
|
|
|
|
|
|
|
this.name = ko.observable('');
|
|
|
|
|
|
|
|
this.conditionsType = ko.observable(Enums.FilterRulesType.And);
|
|
|
|
|
|
|
|
this.conditions = ko.observableArray([]);
|
|
|
|
|
2014-10-04 19:58:01 +08:00
|
|
|
this.regDisposables(this.conditions.subscribe(function () {
|
2014-08-20 23:03:12 +08:00
|
|
|
Utils.windowResize();
|
2014-10-04 19:58:01 +08:00
|
|
|
}));
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
this.actionMarkAsRead = ko.observable(false);
|
|
|
|
this.actionSkipOtherFilters = ko.observable(true);
|
|
|
|
this.actionValue = ko.observable('');
|
|
|
|
|
|
|
|
this.actionType = ko.observable(Enums.FiltersAction.Move);
|
|
|
|
this.actionTypeOptions = [ // TODO i18n
|
|
|
|
{'id': Enums.FiltersAction.None, 'name': 'Action - None'},
|
|
|
|
{'id': Enums.FiltersAction.Move, 'name': 'Action - Move to'},
|
|
|
|
// {'id': Enums.FiltersAction.Forward, 'name': 'Action - Forward to'},
|
|
|
|
{'id': Enums.FiltersAction.Discard, 'name': 'Action - Discard'}
|
|
|
|
];
|
|
|
|
|
|
|
|
this.actionMarkAsReadVisiblity = ko.computed(function () {
|
|
|
|
return -1 < Utils.inArray(this.actionType(), [
|
|
|
|
Enums.FiltersAction.None, Enums.FiltersAction.Forward, Enums.FiltersAction.Move
|
|
|
|
]);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.actionTemplate = ko.computed(function () {
|
|
|
|
|
|
|
|
var sTemplate = '';
|
|
|
|
switch (this.actionType())
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case Enums.FiltersAction.Move:
|
|
|
|
sTemplate = 'SettingsFiltersActionValueAsFolders';
|
|
|
|
break;
|
|
|
|
case Enums.FiltersAction.Forward:
|
|
|
|
sTemplate = 'SettingsFiltersActionWithValue';
|
|
|
|
break;
|
|
|
|
case Enums.FiltersAction.None:
|
|
|
|
case Enums.FiltersAction.Discard:
|
|
|
|
sTemplate = 'SettingsFiltersActionNoValue';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sTemplate;
|
|
|
|
|
|
|
|
}, this);
|
2014-10-04 19:58:01 +08:00
|
|
|
|
|
|
|
this.regDisposables([this.actionMarkAsReadVisiblity, this.actionTemplate]);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2014-05-24 06:14:16 +08:00
|
|
|
|
2014-10-04 19:58:01 +08:00
|
|
|
_.extend(FilterModel.prototype, AbstractModel.prototype);
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
FilterModel.prototype.addCondition = function ()
|
2014-05-24 06:14:16 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
this.conditions.push(new FilterConditionModel(this.conditions));
|
|
|
|
};
|
2014-05-24 06:14:16 +08:00
|
|
|
|
2014-08-20 23:03:12 +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;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FilterModel;
|
2014-05-24 06:14:16 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|