profile-image.component.ts
2.67 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 { Inject, Input, Component, provide } from "ng-forward";
import { ProfileService } from "../../../lib/ng-noosfero-api/http/profile.service";
import { PermissionService } from "../../shared/services/permission.service";
import { ProfileImageEditorComponent } from "./profile-image-editor.component";
/**
* @ngdoc controller
* @name components.noosfero.profile-image.ProfileImage
* @description The component responsible for rendering the profile image
* @exports ProfileImage
*/
@Component({
selector: "noosfero-profile-image",
templateUrl: 'app/profile/image/profile-image.html',
providers: [provide('profileService', { useClass: ProfileService })]
})
@Inject(ProfileService, PermissionService, "$uibModal", "$scope")
export class ProfileImageComponent {
/**
* @ngdoc property
* @name profile
* @propertyOf components.noosfero.profile-image.ProfileImage
* @description
* The Noosfero {@link models.Profile} holding the image.
*/
@Input() profile: noosfero.Profile;
/**
* @ngdoc property
* @name defaultIcon
* @propertyOf components.noosfero.profile-image.ProfileImage
* @descritpion
* The default icon used by this profile
*/
defaultIcon: string;
@Input() editable: boolean;
picFile: any;
modalInstance: any;
constructor(private profileService: ProfileService, private permissionService: PermissionService, private $uibModal: ng.ui.bootstrap.IModalService, private $scope: ng.IScope) {
}
fileSelected(file: any, errFiles: any) {
if (file) {
this.picFile = file;
this.modalInstance = this.$uibModal.open({
templateUrl: 'app/profile/image/profile-image-editor.html',
controller: ProfileImageEditorComponent,
controllerAs: 'ctrl',
scope: this.$scope,
bindToController: true,
backdrop: 'static',
resolve: {
picFile: this.picFile,
profile: this.profile,
profileService: this.profileService
}
});
}
}
isEditable() {
return this.editable && this.permissionService.isAllowed(this.profile, 'allow_edit');
}
/**
* @ngdoc method
* @name ngOnInit
* @methodOf components.noosfero.profile-image.ProfileImage
* @description
* Initializes the icon names to their corresponding values depending on the profile type passed to the controller
*/
ngOnInit() {
this.defaultIcon = 'fa-users';
if (this.profile && this.profile.type === 'Person') {
this.defaultIcon = 'fa-user';
}
}
}