snappymail/dev/Model/ContactProperty.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-07-07 05:03:30 +08:00
import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { ContactPropertyType } from 'Common/Enums';
import { pInt, pString } from 'Common/Utils';
import { i18n } from 'Common/Translator';
2016-07-07 05:03:30 +08:00
2019-07-05 03:19:24 +08:00
import { AbstractModel } from 'Knoin/AbstractModel';
2016-07-07 05:03:30 +08:00
2019-07-05 03:19:24 +08:00
class ContactPropertyModel extends AbstractModel {
2016-07-07 05:03:30 +08:00
/**
* @param {number=} type = Enums.ContactPropertyType.Unknown
* @param {string=} typeStr = ''
* @param {string=} value = ''
* @param {boolean=} focused = false
* @param {string=} placeholder = ''
*/
2019-07-05 03:19:24 +08:00
constructor(type = ContactPropertyType.Unknown, typeStr = '', value = '', focused = false, placeholder = '') {
2020-10-19 01:19:45 +08:00
super();
2016-07-07 05:03:30 +08:00
this.type = ko.observable(pInt(type));
this.typeStr = ko.observable(pString(typeStr));
this.focused = ko.observable(!!focused);
this.value = ko.observable(pString(value));
this.placeholder = ko.observable(placeholder);
this.placeholderValue = ko.computed(() => {
const v = this.placeholder();
return v ? i18n(v) : '';
});
this.largeValue = ko.computed(() => ContactPropertyType.Note === this.type());
this.regDisposables([this.placeholderValue, this.largeValue]);
}
}
2019-07-05 03:19:24 +08:00
export { ContactPropertyModel, ContactPropertyModel as default };