2018-07-02 16:30:51 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.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();
|
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2021-04-14 23:43:40 +02:00
|
|
|
private toasterService: ToasterService) { }
|
2018-07-02 16:30:51 +02:00
|
|
|
|
|
|
|
async submit() {
|
|
|
|
const fileEl = document.getElementById('file') as HTMLInputElement;
|
|
|
|
const files = fileEl.files;
|
|
|
|
if (files == null || files.length === 0) {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('selectFile'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-07-03 15:55:59 +02:00
|
|
|
const fd = new FormData();
|
|
|
|
fd.append('license', files[0]);
|
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
let updatePromise: Promise<any> = null;
|
2018-07-18 04:49:53 +02:00
|
|
|
if (this.organizationId == null) {
|
2019-01-24 14:54:33 +01:00
|
|
|
updatePromise = this.apiService.postAccountLicense(fd);
|
2018-07-03 15:55:59 +02:00
|
|
|
} else {
|
2019-01-24 14:54:33 +01:00
|
|
|
updatePromise = this.apiService.postOrganizationLicenseUpdate(this.organizationId, fd);
|
2018-07-02 16:30:51 +02:00
|
|
|
}
|
2018-07-03 15:55:59 +02:00
|
|
|
|
2019-01-24 14:54:33 +01:00
|
|
|
this.formPromise = updatePromise.then(() => {
|
|
|
|
return this.apiService.refreshIdentityToken();
|
|
|
|
});
|
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
await this.formPromise;
|
2018-07-03 15:55:59 +02:00
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('updatedLicense'));
|
2018-07-02 16:30:51 +02:00
|
|
|
this.onUpdated.emit();
|
|
|
|
} catch { }
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.onCanceled.emit();
|
|
|
|
}
|
|
|
|
}
|