|
@@ -1,14 +1,13 @@
|
|
|
import { Model } from '@converse/skeletor';
|
|
|
-import { _converse, api, log } from "@converse/headless";
|
|
|
+import { _converse, api, log } from '@converse/headless';
|
|
|
import { compressImage, isImageWithAlphaChannel } from 'utils/file.js';
|
|
|
-import BaseModal from "plugins/modal/modal.js";
|
|
|
+import BaseModal from 'plugins/modal/modal.js';
|
|
|
import { __ } from 'i18n';
|
|
|
import '../password-reset.js';
|
|
|
-import tplProfileModal from "../templates/profile_modal.js";
|
|
|
+import tplProfileModal from '../templates/profile_modal.js';
|
|
|
|
|
|
import './styles/profile.scss';
|
|
|
|
|
|
-
|
|
|
export default class ProfileModal extends BaseModal {
|
|
|
/**
|
|
|
* @typedef {import('@converse/headless/types/plugins/vcard/types').VCardData} VCardData
|
|
@@ -18,17 +17,17 @@ export default class ProfileModal extends BaseModal {
|
|
|
static properties = {
|
|
|
_submitting: { state: true },
|
|
|
model: { type: Model },
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* @param {Object} options
|
|
|
*/
|
|
|
- constructor (options) {
|
|
|
+ constructor(options) {
|
|
|
super(options);
|
|
|
this.tab = 'profile';
|
|
|
}
|
|
|
|
|
|
- initialize () {
|
|
|
+ initialize() {
|
|
|
super.initialize();
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
/**
|
|
@@ -40,27 +39,29 @@ export default class ProfileModal extends BaseModal {
|
|
|
api.trigger('profileModalInitialized', this.model);
|
|
|
}
|
|
|
|
|
|
- renderModal () {
|
|
|
+ renderModal() {
|
|
|
return tplProfileModal(this);
|
|
|
}
|
|
|
|
|
|
- getModalTitle () { // eslint-disable-line class-methods-use-this
|
|
|
+ getModalTitle() {
|
|
|
return __('Your Profile');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param {VCardData} data
|
|
|
*/
|
|
|
- async setVCard (data) {
|
|
|
+ async setVCard(data) {
|
|
|
const bare_jid = _converse.session.get('bare_jid');
|
|
|
try {
|
|
|
await api.vcard.set(bare_jid, data);
|
|
|
} catch (err) {
|
|
|
log.fatal(err);
|
|
|
- this.alert([
|
|
|
- __("Sorry, an error happened while trying to save your profile data."),
|
|
|
- __("You can check your browser's developer console for any error output.")
|
|
|
- ].join(" "));
|
|
|
+ this.alert(
|
|
|
+ [
|
|
|
+ __('Sorry, an error happened while trying to save your profile data.'),
|
|
|
+ __("You can check your browser's developer console for any error output."),
|
|
|
+ ].join(' ')
|
|
|
+ );
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
@@ -69,14 +70,14 @@ export default class ProfileModal extends BaseModal {
|
|
|
/**
|
|
|
* @param {SubmitEvent} ev
|
|
|
*/
|
|
|
- async onFormSubmitted (ev) {
|
|
|
+ async onFormSubmitted(ev) {
|
|
|
ev.preventDefault();
|
|
|
this._submitting = true;
|
|
|
|
|
|
- const form_data = new FormData(/** @type {HTMLFormElement} */(ev.target));
|
|
|
- const image_file = /** @type {File} */(form_data.get('avatar_image'));
|
|
|
+ const form_data = new FormData(/** @type {HTMLFormElement} */ (ev.target));
|
|
|
+ const image_file = /** @type {File} */ (form_data.get('avatar_image'));
|
|
|
|
|
|
- const data = /** @type {VCardData} */({
|
|
|
+ const data = /** @type {VCardData} */ ({
|
|
|
fn: form_data.get('fn'),
|
|
|
nickname: form_data.get('nickname'),
|
|
|
role: form_data.get('role'),
|
|
@@ -85,14 +86,15 @@ export default class ProfileModal extends BaseModal {
|
|
|
});
|
|
|
|
|
|
if (image_file?.size) {
|
|
|
- const image_data = isImageWithAlphaChannel ? image_file : await compressImage(image_file);
|
|
|
+ const image_data = await compressImage(image_file);
|
|
|
const reader = new FileReader();
|
|
|
reader.onloadend = async () => {
|
|
|
Object.assign(data, {
|
|
|
- image: btoa(/** @type {string} */(reader.result)),
|
|
|
- image_type: image_file.type
|
|
|
+ image: btoa(/** @type {string} */ (reader.result)),
|
|
|
+ image_type: image_file.type,
|
|
|
});
|
|
|
if (await this.setVCard(data)) {
|
|
|
+ this._submitting = false;
|
|
|
this.modal.hide();
|
|
|
}
|
|
|
};
|
|
@@ -100,14 +102,14 @@ export default class ProfileModal extends BaseModal {
|
|
|
} else {
|
|
|
Object.assign(data, {
|
|
|
image: this.model.vcard.get('image'),
|
|
|
- image_type: this.model.vcard.get('image_type')
|
|
|
+ image_type: this.model.vcard.get('image_type'),
|
|
|
});
|
|
|
if (await this.setVCard(data)) {
|
|
|
this.modal.hide();
|
|
|
- api.toast.show('vcard-updated', { body: __("Profile updated successfully") });
|
|
|
+ api.toast.show('vcard-updated', { body: __('Profile updated successfully') });
|
|
|
}
|
|
|
+ this._submitting = false;
|
|
|
}
|
|
|
- this._submitting = false;
|
|
|
}
|
|
|
}
|
|
|
|