mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Merged from sub repository (filters - step 4)
This commit is contained in:
parent
67e45a6a6f
commit
e4b286e257
58 changed files with 1176 additions and 236 deletions
|
|
@ -17,13 +17,16 @@
|
|||
*
|
||||
* @param {string} sEmail
|
||||
* @param {boolean=} bCanBeDelete = true
|
||||
* @param {number=} iCount = 0
|
||||
*/
|
||||
function AccountModel(sEmail, bCanBeDelete)
|
||||
function AccountModel(sEmail, bCanBeDelete, iCount)
|
||||
{
|
||||
AbstractModel.call(this, 'AccountModel');
|
||||
|
||||
this.email = sEmail;
|
||||
|
||||
this.count = ko.observable(iCount || 0);
|
||||
|
||||
this.deleteAccess = ko.observable(false);
|
||||
this.canBeDalete = ko.observable(Utils.isUnd(bCanBeDelete) ? true : !!bCanBeDelete);
|
||||
this.canBeEdit = this.canBeDalete;
|
||||
|
|
|
|||
|
|
@ -21,42 +21,20 @@
|
|||
{
|
||||
AbstractModel.call(this, 'FilterModel');
|
||||
|
||||
this.isNew = ko.observable(true);
|
||||
this.enabled = ko.observable(true);
|
||||
|
||||
this.name = ko.observable('');
|
||||
|
||||
this.conditionsType = ko.observable(Enums.FilterRulesType.All);
|
||||
this.name.error = ko.observable(false);
|
||||
this.name.focused = ko.observable(false);
|
||||
|
||||
this.conditions = ko.observableArray([]);
|
||||
this.conditionsType = ko.observable(Enums.FilterRulesType.All);
|
||||
|
||||
// Actions
|
||||
this.actionMarkAsRead = ko.observable(false);
|
||||
this.actionSkipOtherFilters = ko.observable(true);
|
||||
this.actionValue = ko.observable('');
|
||||
this.actionMarkAsRead = ko.observable(false);
|
||||
|
||||
this.actionType = ko.observable(Enums.FiltersAction.Move);
|
||||
this.actionTypeOptions = [ // TODO i18n
|
||||
{'id': Enums.FiltersAction.None, 'name': 'None'},
|
||||
{'id': Enums.FiltersAction.Move, 'name': ' Move to'},
|
||||
// {'id': Enums.FiltersAction.Forward, 'name': 'Forward to'},
|
||||
{'id': Enums.FiltersAction.Discard, 'name': 'Discard'}
|
||||
];
|
||||
|
||||
this.enableSkipOtherFilters = ko.computed(function () {
|
||||
return -1 === Utils.inArray(this.actionType(), [
|
||||
Enums.FiltersAction.Move, Enums.FiltersAction.Forward, Enums.FiltersAction.Discard
|
||||
]);
|
||||
}, this);
|
||||
|
||||
this.actionSkipOtherFiltersResult = ko.computed({
|
||||
'read': function () {
|
||||
return this.actionSkipOtherFilters() ||
|
||||
!this.enableSkipOtherFilters();
|
||||
},
|
||||
'write': this.actionSkipOtherFilters,
|
||||
'owner': this
|
||||
});
|
||||
|
||||
this.actionTemplate = ko.computed(function () {
|
||||
|
||||
|
|
@ -84,14 +62,42 @@
|
|||
Utils.windowResize();
|
||||
}));
|
||||
|
||||
this.regDisposables([this.enableSkipOtherFilters, this.actionSkipOtherFiltersResult, this.actionTemplate]);
|
||||
this.regDisposables(this.name.subscribe(function (sValue) {
|
||||
this.name.error('' === sValue);
|
||||
}, this));
|
||||
|
||||
this.regDisposables([this.actionTemplate]);
|
||||
|
||||
this.deleteAccess = ko.observable(false);
|
||||
this.canBeDalete = ko.observable(true);
|
||||
}
|
||||
|
||||
_.extend(FilterModel.prototype, AbstractModel.prototype);
|
||||
|
||||
FilterModel.prototype.toJson = function ()
|
||||
{
|
||||
return {
|
||||
'Enabled': this.enabled(),
|
||||
'Name': this.name(),
|
||||
'ConditionsType': this.conditionsType(),
|
||||
'Conditions': _.map(this.conditions(), function (oItem) {
|
||||
return oItem.toJson();
|
||||
}),
|
||||
'ActionMarkAsRead': this.actionMarkAsRead(),
|
||||
'ActionValue': this.actionValue(),
|
||||
'ActionType': this.actionType()
|
||||
};
|
||||
};
|
||||
|
||||
FilterModel.prototype.addCondition = function ()
|
||||
{
|
||||
this.conditions.push(new FilterConditionModel(this.conditions));
|
||||
this.conditions.push(new FilterConditionModel());
|
||||
};
|
||||
|
||||
FilterModel.prototype.removeCondition = function (oConditionToDelete)
|
||||
{
|
||||
this.conditions.remove(oConditionToDelete);
|
||||
Utils.delegateRunOnDestroy(oConditionToDelete);
|
||||
};
|
||||
|
||||
FilterModel.prototype.parse = function (oItem)
|
||||
|
|
@ -107,6 +113,29 @@
|
|||
return bResult;
|
||||
};
|
||||
|
||||
FilterModel.prototype.cloneSelf = function ()
|
||||
{
|
||||
var oClone = new FilterModel();
|
||||
|
||||
oClone.enabled(this.enabled());
|
||||
|
||||
oClone.name(this.name());
|
||||
oClone.name.error(this.name.error());
|
||||
|
||||
oClone.conditionsType(this.conditionsType());
|
||||
|
||||
oClone.actionMarkAsRead(this.actionMarkAsRead());
|
||||
oClone.actionValue(this.actionValue());
|
||||
|
||||
oClone.actionType(this.actionType());
|
||||
|
||||
oClone.conditions(_.map(this.conditions(), function (oCondition) {
|
||||
return oCondition.cloneSelf();
|
||||
}));
|
||||
|
||||
return oClone;
|
||||
};
|
||||
|
||||
module.exports = FilterModel;
|
||||
|
||||
}());
|
||||
|
|
@ -16,29 +16,12 @@
|
|||
* @param {*} oKoList
|
||||
* @constructor
|
||||
*/
|
||||
function FilterConditionModel(oKoList)
|
||||
function FilterConditionModel()
|
||||
{
|
||||
AbstractModel.call(this, 'FilterConditionModel');
|
||||
|
||||
this.parentList = oKoList;
|
||||
|
||||
this.field = ko.observable(Enums.FilterConditionField.From);
|
||||
|
||||
this.fieldOptions = [ // TODO i18n
|
||||
{'id': Enums.FilterConditionField.From, 'name': 'From'},
|
||||
{'id': Enums.FilterConditionField.Recipient, 'name': 'Recipient (To or CC)'},
|
||||
{'id': Enums.FilterConditionField.Subject, 'name': 'Subject'}
|
||||
];
|
||||
|
||||
this.type = ko.observable(Enums.FilterConditionType.EqualTo);
|
||||
|
||||
this.typeOptions = [ // TODO i18n
|
||||
{'id': Enums.FilterConditionType.EqualTo, 'name': 'Equal To'},
|
||||
{'id': Enums.FilterConditionType.NotEqualTo, 'name': 'Not Equal To'},
|
||||
{'id': Enums.FilterConditionType.Contains, 'name': 'Contains'},
|
||||
{'id': Enums.FilterConditionType.NotContains, 'name': 'Not Contains'}
|
||||
];
|
||||
|
||||
this.value = ko.observable('');
|
||||
|
||||
this.template = ko.computed(function () {
|
||||
|
|
@ -60,9 +43,24 @@
|
|||
|
||||
_.extend(FilterConditionModel.prototype, AbstractModel.prototype);
|
||||
|
||||
FilterConditionModel.prototype.removeSelf = function ()
|
||||
FilterConditionModel.prototype.toJson = function ()
|
||||
{
|
||||
this.parentList.remove(this);
|
||||
return {
|
||||
'Field': this.field(),
|
||||
'Type': this.type(),
|
||||
'Value': this.value()
|
||||
};
|
||||
};
|
||||
|
||||
FilterConditionModel.prototype.cloneSelf = function ()
|
||||
{
|
||||
var oClone = new FilterConditionModel();
|
||||
|
||||
oClone.field(this.field());
|
||||
oClone.type(this.type());
|
||||
oClone.value(this.value());
|
||||
|
||||
return oClone;
|
||||
};
|
||||
|
||||
module.exports = FilterConditionModel;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue