diff --git a/src/app/pages/customization/background-upload.component.ts b/src/app/pages/customization/background-upload.component.ts
index 996b407..c5886a3 100644
--- a/src/app/pages/customization/background-upload.component.ts
+++ b/src/app/pages/customization/background-upload.component.ts
@@ -9,60 +9,64 @@ declare var UIkit;
selector: 'background-upload',
template: `
-
+
- upload image
+ upload image
-
-
-
-
+
`,
- styles:[`
- .upload{
- border: 1px dotted grey;
- }
+ styles: [`
+ .upload {
+ border: 1px dotted grey;
+ }
`]
})
export class BackgroundUploadComponent implements OnInit {
- @Input() label:string = "";
+ @Input() label: string = "";
@Input() background;
@Input() oldBackground;
// @Input() light:boolean;
- @Input() communityId:string = "";
-
+ @Input() communityId: string = "";
+
public file: File;
// public photo: string | ArrayBuffer;
private maxsize: number = 2000 * 1024;
properties;
private subscriptions: any[] = [];
-
-
+
+
constructor(private utilsService: UtilitiesService) {
}
-
-
+
+
ngOnInit() {
this.properties = properties;
}
+
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscription) {
@@ -70,30 +74,29 @@ export class BackgroundUploadComponent implements OnInit {
}
});
}
-
+
removePhoto() {
-
- if (typeof document != 'undefined') {
- (
document.getElementById("photo")).value = "";
- }
- // this.initPhoto();
+
+ if (typeof document != 'undefined') {
+ (document.getElementById("photo")).value = "";
+ }
+ // this.initPhoto();
console.log(this.background.imageFile + " " + this.oldBackground.imageFile)
- if(this.background.imageFile != this.oldBackground.imageFile){
- this.deletePhoto();
- }
- this.background.imageFile = null;
- this.file = null;
-
+ if (this.background.imageFile != this.oldBackground.imageFile) {
+ this.deletePhoto();
+ }
+ this.background.imageFile = null;
+ this.file = null;
+
}
-
-
-
+
+
public deletePhoto() {
if (this.background.imageFile) {
- this.subscriptions.push(this.utilsService.deletePhoto(properties.utilsService + '/delete/community/' + this.communityId + "/" +this.background.imageFile).subscribe());
+ this.subscriptions.push(this.utilsService.deletePhoto(properties.utilsService + '/delete/community/' + this.communityId + "/" + this.background.imageFile).subscribe());
}
}
-
+
fileChangeEvent(event) {
if (event.target.files && event.target.files[0]) {
this.file = event.target.files[0];
@@ -105,7 +108,7 @@ export class BackgroundUploadComponent implements OnInit {
});
this.removePhoto();
} else if (this.file.size > this.maxsize) {
- UIkit.notification('File exceeds size\'s limit ('+this.maxsize/1024+'KB)! ', {
+ UIkit.notification('File exceeds size\'s limit (' + this.maxsize / 1024 + 'KB)! ', {
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
@@ -122,27 +125,34 @@ export class BackgroundUploadComponent implements OnInit {
}
}
}
-
+
public save() {
if (this.file) {
- this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/community/"+ this.communityId + "/" + encodeURIComponent(this.communityId+"-"+this.label)+"?big=1", this.file).subscribe(res => {
+ this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/community/" + this.communityId + "/" + encodeURIComponent(this.communityId + "-" + this.label) + "?big=1", this.file).subscribe(res => {
this.deletePhoto();
this.removePhoto();
this.background.imageFile = res.filename;
-
+
}, error => {
- UIkit.notification("An error has been occurred during upload your image. Try again later", {
- status: 'danger',
- timeout: 6000,
- pos: 'bottom-right'
- });
+ if (error.error.message) {
+ UIkit.notification('The maximum size of an image is 1MB, please check if your file exceeds this limit.', {
+ status: 'danger',
+ timeout: 6000,
+ pos: 'bottom-right'
+ });
+ } else {
+ UIkit.notification("An error has been occurred during upload your image. Try again later", {
+ status: 'danger',
+ timeout: 6000,
+ pos: 'bottom-right'
+ });
+ }
}));
}
}
-
- getUrl()
- {
- return "url('" +(this.background.imageFile.indexOf('data:')==-1?(this.properties.utilsService +
- '/download/'+this.background.imageFile):this.background.imageFile) +"')";
+
+ getUrl() {
+ return "url('" + (this.background.imageFile.indexOf('data:') == -1 ? (this.properties.utilsService +
+ '/download/' + this.background.imageFile) : this.background.imageFile) + "')";
}
}