mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-28 23:05:54 +00:00
This will be better for future use of JSON.stringify() and JSON.parse() For now the difference between the PHP JSON being PascalCase and the JS object properties being camelCase is handled by AbstractModel
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import ko from 'ko';
|
|
|
|
import { ContactPropertyType } from 'Common/Enums';
|
|
import { pInt, pString } from 'Common/Utils';
|
|
import { i18n } from 'Common/Translator';
|
|
|
|
import { AbstractModel } from 'Knoin/AbstractModel';
|
|
|
|
class ContactPropertyModel extends AbstractModel {
|
|
/**
|
|
* @param {number=} type = Enums.ContactPropertyType.Unknown
|
|
* @param {string=} typeStr = ''
|
|
* @param {string=} value = ''
|
|
* @param {boolean=} focused = false
|
|
* @param {string=} placeholder = ''
|
|
*/
|
|
constructor(type = ContactPropertyType.Unknown, typeStr = '', value = '', focused = false, placeholder = '') {
|
|
super();
|
|
|
|
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]);
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
type: this.type(),
|
|
typeStr: this.typeStr(),
|
|
value: this.value()
|
|
};
|
|
}
|
|
|
|
// static reviveFromJson(json) {}
|
|
}
|
|
|
|
export { ContactPropertyModel, ContactPropertyModel as default };
|