Improved new AddressBook system

This commit is contained in:
the-djmaze 2022-09-06 14:26:07 +02:00
parent 497193750b
commit c9ad0ef170
53 changed files with 589 additions and 459 deletions

View file

@ -108,12 +108,16 @@ export class ContactModel extends AbstractModel {
middleName: '', // MiddleName
namePrefix: '', // NamePrefix
nameSuffix: '', // NameSuffix
nickname: null
nickname: null,
encryptpref: '',
signpref: ''
});
// this.email = koArrayWithDestroy();
this.email = ko.observableArray();
this.tel = ko.observableArray();
this.url = ko.observableArray();
this.adr = ko.observableArray();
this.addComputables({
hasValidName: () => !!(this.givenName() || this.surName()),
@ -156,7 +160,7 @@ export class ContactModel extends AbstractModel {
/**
* @static
* @param {FetchJsonContact} json
* @param {jCard} json
* @returns {?ContactModel}
*/
static reviveFromJson(json) {
@ -181,6 +185,26 @@ export class ContactModel extends AbstractModel {
});
});
props = jCard.get('adr');
props && props.forEach(prop => {
contact.adr.push({
street: ko.observable(prop.value[2]),
street_ext: ko.observable(prop.value[1]),
locality: ko.observable(prop.value[3]),
region: ko.observable(prop.value[4]),
postcode: ko.observable(prop.value[5]),
pobox: ko.observable(prop.value[0]),
country: ko.observable(prop.value[6]),
preferred: ko.observable(prop.params.pref),
type: ko.observable(prop.params.type) // HOME | WORK
});
});
props = jCard.getOne('x-Crypto');
contact.signpref(props?.params.signpref || 'Ask');
contact.encryptpref(props?.params.encryptpref || 'Ask');
// contact.encryptpref(props?.params.allowed || 'PGP/INLINE,PGP/MIME,S/MIME,S/MIMEOpaque');
contact.jCard = jCard;
}
return contact;
@ -249,6 +273,12 @@ export class ContactModel extends AbstractModel {
values.forEach(value => value && jCard.add(field, value));
});
jCard.set('x-Crypto', '', {
allowed: 'PGP/INLINE,PGP/MIME,S/MIME,S/MIMEOpaque',
signpref: this.signpref(),
encryptpref: this.encryptpref()
}, 'x-crypto');
// Done by server
// jCard.set('rev', '2022-05-21T10:59:52Z')

View file

@ -1,86 +0,0 @@
import { pInt, pString } from 'Common/Utils';
import { i18n } from 'Common/Translator';
import { AbstractModel } from 'Knoin/AbstractModel';
const trim = text => null == text ? "" : (text + "").trim();
/**
* @enum {number}
*/
export const ContactPropertyType = {
Unknown: 0,
FullName: 10,
FirstName: 15,
LastName: 16,
MiddleName: 17,
Nick: 18,
NamePrefix: 20,
NameSuffix: 21,
Email: 30,
Phone: 31,
Web: 32,
Birthday: 40,
Facebook: 90,
Skype: 91,
GitHub: 92,
Note: 110,
Custom: 250
};
export 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) {}
}