snappymail/dev/Model/ContactProperty.js
djmaze d0bcb5483a Changes for https://github.com/the-djmaze/snappymail/issues/30
And remove some memory cleanup due to issues with the Contacts view
2020-10-30 11:49:05 +01:00

58 lines
1.3 KiB
JavaScript

import { ContactPropertyType } from 'Common/Enums';
import { pInt, pString } from 'Common/Utils';
import { i18n } from 'Common/Translator';
import { AbstractModel } from 'Knoin/AbstractModel';
const trim = text => null == text ? "" : (text + "").trim();
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.addObservables({
type: pInt(type),
typeStr: pString(typeStr),
focused: !!focused,
value: pString(value),
placeholder: placeholder
});
this.addComputables({
placeholderValue: () => {
const v = this.placeholder();
return v ? i18n(v) : '';
},
largeValue: () => ContactPropertyType.Note === this.type()
});
}
isType(type) {
return this.type && type === this.type();
}
isValid() {
return this.value && !!trim(this.value());
}
toJSON() {
return {
type: this.type(),
typeStr: this.typeStr(),
value: this.value()
};
}
// static reviveFromJson(json) {}
}
export { ContactPropertyModel, ContactPropertyModel as default };