2018-07-02 16:30:51 +02:00
|
|
|
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-12-07 20:41:45 +01:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
2018-07-02 16:30:51 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-update-license",
|
|
|
|
templateUrl: "update-license.component.html",
|
|
|
|
})
|
|
|
|
export class UpdateLicenseComponent {
|
2018-07-18 04:49:53 +02:00
|
|
|
@Input() organizationId: string;
|
2018-07-02 16:30:51 +02:00
|
|
|
@Output() onUpdated = new EventEmitter();
|
|
|
|
@Output() onCanceled = new EventEmitter();
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
formPromise: Promise<any>;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
private i18nService: I18nService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private logService: LogService
|
2018-07-02 16:30:51 +02:00
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
async submit() {
|
|
|
|
const fileEl = document.getElementById("file") as HTMLInputElement;
|
2018-07-03 15:55:59 +02:00
|
|
|
const files = fileEl.files;
|
2018-07-18 04:49:53 +02:00
|
|
|
if (files == null || files.length === 0) {
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("errorOccurred"),
|
|
|
|
this.i18nService.t("selectFile")
|
2018-07-02 16:30:51 +02:00
|
|
|
);
|
2021-10-20 18:30:04 +02:00
|
|
|
return;
|
2018-07-02 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
try {
|
2018-07-02 16:30:51 +02:00
|
|
|
const fd = new FormData();
|
2018-07-03 15:55:59 +02:00
|
|
|
fd.append("license", files[0]);
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
let updatePromise: Promise<any> = null;
|
|
|
|
if (this.organizationId == null) {
|
|
|
|
updatePromise = this.apiService.postAccountLicense(fd);
|
2018-07-02 16:30:51 +02:00
|
|
|
} else {
|
|
|
|
updatePromise = this.apiService.postOrganizationLicenseUpdate(this.organizationId, fd);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
this.formPromise = updatePromise.then(() => {
|
|
|
|
return this.apiService.refreshIdentityToken();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
await this.formPromise;
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("updatedLicense"));
|
2018-07-02 16:30:51 +02:00
|
|
|
this.onUpdated.emit();
|
|
|
|
} catch (e) {
|
2021-10-20 18:30:04 +02:00
|
|
|
this.logService.error(e);
|
2018-07-02 16:30:51 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
2018-07-02 16:30:51 +02:00
|
|
|
this.onCanceled.emit();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-02 16:30:51 +02:00
|
|
|
}
|