2018-07-02 16:30:51 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-update-license',
|
|
|
|
templateUrl: 'update-license.component.html',
|
|
|
|
})
|
|
|
|
export class UpdateLicenseComponent {
|
|
|
|
@Input() user = true;
|
|
|
|
@Output() onUpdated = new EventEmitter();
|
|
|
|
@Output() onCanceled = new EventEmitter();
|
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2018-07-03 15:55:59 +02:00
|
|
|
private analytics: Angulartics2, 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]);
|
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
if (this.user) {
|
2018-07-03 15:55:59 +02:00
|
|
|
this.formPromise = this.apiService.postAccountLicense(fd);
|
|
|
|
} else {
|
|
|
|
// TODO
|
2018-07-02 16:30:51 +02:00
|
|
|
}
|
2018-07-03 15:55:59 +02:00
|
|
|
|
2018-07-02 16:30:51 +02:00
|
|
|
await this.formPromise;
|
2018-07-03 15:55:59 +02:00
|
|
|
this.analytics.eventTrack.next({ action: 'Updated License' });
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|