snappymail/dev/Model/ContactProperty.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
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-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
2014-10-04 19:58:01 +08:00
Utils = require('Common/Utils'),
AbstractModel = require('Knoin/AbstractModel')
2014-08-20 23:03:12 +08:00
;
/**
* @constructor
2014-08-20 23:03:12 +08:00
* @param {number=} iType = Enums.ContactPropertyType.Unknown
* @param {string=} sTypeStr = ''
* @param {string=} sValue = ''
* @param {boolean=} bFocused = false
* @param {string=} sPlaceholder = ''
*/
function ContactPropertyModel(iType, sTypeStr, sValue, bFocused, sPlaceholder)
{
2014-10-04 19:58:01 +08:00
AbstractModel.call(this, 'ContactPropertyModel');
2014-08-20 23:03:12 +08:00
this.type = ko.observable(Utils.isUnd(iType) ? Enums.ContactPropertyType.Unknown : iType);
this.typeStr = ko.observable(Utils.isUnd(sTypeStr) ? '' : sTypeStr);
this.focused = ko.observable(Utils.isUnd(bFocused) ? false : !!bFocused);
this.value = ko.observable(Utils.pString(sValue));
this.placeholder = ko.observable(sPlaceholder || '');
this.placeholderValue = ko.computed(function () {
var sPlaceholder = this.placeholder();
return sPlaceholder ? Utils.i18n(sPlaceholder) : '';
}, this);
this.largeValue = ko.computed(function () {
return Enums.ContactPropertyType.Note === this.type();
}, this);
2014-10-04 19:58:01 +08:00
this.regDisposables([this.placeholderValue, this.largeValue]);
2014-08-20 23:03:12 +08:00
}
2014-10-04 19:58:01 +08:00
_.extend(ContactPropertyModel.prototype, AbstractModel.prototype);
2014-08-20 23:03:12 +08:00
module.exports = ContactPropertyModel;
2014-09-05 06:49:03 +08:00
}());