custom-content.component.ts
2.62 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Component, Input, Inject } from 'ng-forward';
import { ProfileService } from '../../../lib/ng-noosfero-api/http/profile.service';
import { NotificationService } from '../../shared/services/notification.service';
import { PermissionDirective } from '../../shared/components/permission/permission.directive';
import { DesignModeService } from '../../admin/layout-edit/designMode.service';
@Component({
selector: 'custom-content',
templateUrl: "app/profile/custom-content/custom-content.html",
directives: [PermissionDirective]
})
@Inject("$uibModal", "$scope", ProfileService, NotificationService, DesignModeService)
export class CustomContentComponent {
// @Inject doesn't works with uibModal.open
static $inject = ["DesignModeService"];
@Input() attribute: string;
@Input() profile: noosfero.Profile;
@Input() label: string;
content: string;
originalContent: string;
private modalInstance: ng.ui.bootstrap.IModalServiceInstance;
constructor(
private $uibModal: ng.ui.bootstrap.IModalService,
private $scope: ng.IScope,
private profileService: ProfileService,
private notificationService: NotificationService,
private designModeService: DesignModeService) { }
ngOnInit() {
this.$scope.$watch(() => {
return this.profile ? (<any>this.profile)[this.attribute] : null;
}, () => {
if (this.profile) this.content = (<any>this.profile)[this.attribute];
});
}
inEditMode() {
return this.designModeService.isInDesignMode();
}
openEdit() {
if (!this.originalContent) this.originalContent = this.content;
this.modalInstance = this.$uibModal.open({
templateUrl: 'app/profile/custom-content/edit-content.html',
size: 'lg',
controller: CustomContentComponent,
controllerAs: 'modal',
bindToController: true,
scope: this.$scope,
backdrop: 'static'
});
}
save() {
let profile: any = { id: this.profile.id };
profile[this.attribute] = this.content;
this.profileService.update(profile).then(() => {
this.closeEdit();
this.notificationService.success({ title: "profile.content.success.title", message: "profile.content.success.message" });
});
}
preview() {
this.closeEdit();
}
cancel() {
this.content = this.originalContent;
this.closeEdit();
}
private closeEdit() {
if (this.modalInstance) {
this.modalInstance.close();
this.modalInstance = null;
}
}
}