profile-image-editor.component.ts
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { StateConfig, Component, Input, Output, Inject, provide } from 'ng-forward';
import { TranslateProfile } from "../../shared/pipes/translate-profile.filter";
import { ProfileService } from "../../../lib/ng-noosfero-api/http/profile.service";
export class ProfileImageEditorComponent {
croppedDataUrl: string;
static $inject = ["picFile", "profile", "profileService", "$uibModalInstance"];
constructor(public picFile: any, public profile: noosfero.Profile, public profileService: ProfileService,
public modalInstance: ng.ui.bootstrap.IModalServiceInstance) {
}
uploadImage(dataUrl: any, name: any) {
let base64ImageJson = this.getBase64ImageJson(dataUrl, name);
this.profileService.uploadImage(this.profile, base64ImageJson).then((result: any) => {
this.modalInstance.close(name);
});
}
getBase64ImageJson(dataUrl: any, name: any): any {
let data = this.getData(dataUrl);
let image_name = this.getImageName(name);
return {
tempfile: data,
filename: image_name,
type: this.picFile.type
};
}
getImageName(name: any): string {
return this.profile.name + "_" + name;
}
getData(dataUrl: any): string {
return dataUrl.substring(dataUrl.indexOf('base64,') + 7);
}
cancel() {
this.modalInstance.close();
}
}