snappymail/dev/Model/FilterCondition.js

94 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-20 23:03:12 +08:00
2014-08-25 23:49:01 +08:00
'use strict';
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-10-04 19:58:01 +08:00
Enums = require('Common/Enums'),
2015-01-22 04:15:40 +08:00
Utils = require('Common/Utils'),
2014-10-04 19:58:01 +08:00
AbstractModel = require('Knoin/AbstractModel')
2014-08-20 23:03:12 +08:00
;
/**
* @constructor
*/
function FilterConditionModel()
2014-08-20 23:03:12 +08:00
{
2014-10-04 19:58:01 +08:00
AbstractModel.call(this, 'FilterConditionModel');
2014-08-20 23:03:12 +08:00
this.field = ko.observable(Enums.FilterConditionField.From);
2015-01-22 04:15:40 +08:00
this.type = ko.observable(Enums.FilterConditionType.Contains);
2014-08-20 23:03:12 +08:00
this.value = ko.observable('');
2015-01-22 04:15:40 +08:00
this.value.error = ko.observable(false);
2014-08-20 23:03:12 +08:00
this.template = ko.computed(function () {
var sTemplate = '';
switch (this.type())
{
default:
sTemplate = 'SettingsFiltersConditionDefault';
break;
}
return sTemplate;
}, this);
2014-10-04 19:58:01 +08:00
this.regDisposables([this.template]);
2014-08-20 23:03:12 +08:00
}
2014-10-04 19:58:01 +08:00
_.extend(FilterConditionModel.prototype, AbstractModel.prototype);
2015-01-22 04:15:40 +08:00
FilterConditionModel.prototype.verify = function ()
{
if ('' === this.value())
{
this.value.error(true);
return false;
}
return true;
};
FilterConditionModel.prototype.parse = function (oItem)
{
if (oItem && oItem['Field'] && oItem['Type'])
{
this.field(Utils.pString(oItem['Field']));
this.type(Utils.pString(oItem['Type']));
this.value(Utils.pString(oItem['Value']));
return true;
}
return false;
};
FilterConditionModel.prototype.toJson = function ()
2014-08-20 23:03:12 +08:00
{
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;
2014-08-20 23:03:12 +08:00
};
module.exports = FilterConditionModel;
2014-09-05 06:49:03 +08:00
}());