mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 12:15:20 +08:00
93 lines
No EOL
2.2 KiB
JavaScript
93 lines
No EOL
2.2 KiB
JavaScript
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
'use strict';
|
|
|
|
(function (module) {
|
|
|
|
var
|
|
ko = require('../External/ko.js'),
|
|
Enums = require('../Common/Enums.js'),
|
|
Utils = require('../Common/Utils.js'),
|
|
FilterConditionModel = require('./FilterConditionModel.js')
|
|
;
|
|
|
|
/**
|
|
* @constructor
|
|
*/
|
|
function FilterModel()
|
|
{
|
|
this.new = ko.observable(true);
|
|
this.enabled = ko.observable(true);
|
|
|
|
this.name = ko.observable('');
|
|
|
|
this.conditionsType = ko.observable(Enums.FilterRulesType.And);
|
|
|
|
this.conditions = ko.observableArray([]);
|
|
|
|
this.conditions.subscribe(function () {
|
|
Utils.windowResize();
|
|
});
|
|
|
|
// 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);
|
|
}
|
|
|
|
FilterModel.prototype.addCondition = function ()
|
|
{
|
|
this.conditions.push(new FilterConditionModel(this.conditions));
|
|
};
|
|
|
|
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;
|
|
|
|
}(module)); |