Repository navigation
Expand file tree
/
Copy pathModalService.js
More file actions
142 lines (132 loc) · 6.07 KB
/
Copy pathModalService.js
File metadata and controls
142 lines (132 loc) · 6.07 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Service to create bootstrap modals that TaskBoard application uses widely. All application
* modals are created by this service.
*
* Naming of service methods must follow structure below:
* {modelName}{actionName}
*
* Where
* modelName = Name of the model that modal covers, eg. project, user, story
* actionName = Modal action this is one of following 'Edit', 'View' or 'Create'
*
* Currently this service has following modals:
* 1) userProfile(userId)
* 2) projectEdit(projectId)
*
* Also note that this service handles modal queue handling, so that latest opened modal
* is automatic opened when user closes current one.
*/
(function() {
'use strict';
angular.module('Taskboard.services')
.factory('ModalService',
[
'$modal',
'ModalQueue',
'TimeZoneModel', 'LanguageModel', 'UserModel', 'ProjectModel',
function($modal,
ModalQueue,
TimeZoneModel, LanguageModel, UserModel, ProjectModel
) {
var service = this;
/**
* Initializer function for all modal instances, this will take care of modal
* queue handling so whenever user closes current modal it will automatically
* open previous one.
*
* @param {bootstrap.modalInstance} modalInstance
* @param {string} method
* @param {*[]} parameters
*
* @returns {bootstrap.modalInstance}
*/
var initializeModalInstance = function(modalInstance, method, parameters) {
// Whenever modal is opened add it to modal queue
modalInstance.opened.then(function() {
ModalQueue.set(modalInstance, method, parameters);
});
// Whenever modal is closed check if we need to open previous one
modalInstance.result.then(function(openPreviousModal) {
if (openPreviousModal !== false) {
var previous = ModalQueue.get();
// Yeah we have previous modal so open it again
if (previous) {
service[previous.method].apply(service, previous.parameters);
}
}
});
return modalInstance;
};
/**
* Returns user profile modal instance. This modal contains following user
* specified data:
* - Basic information
* - Language and region
* - Password change
* - User projects
* - Activity log
* - Login history
* - Object history
*
* If given, modal resolve will determine if current user is admin or not
* and if not => show error and do not open modal.
*
* @param {number} userId User id
*
* @returns {bootstrap.modalInstance}
*/
service.userProfile = function(userId) {
var modalInstance = $modal
.open({
controller: 'ModalUserProfileController',
templateUrl: '/Taskboard/partials/Modals/UserProfile/profile.html',
backdrop: 'static',
size: 'lg',
resolve: {
_user: function() {
return UserModel.fetch(userId);
},
_timezones: function() {
return TimeZoneModel.get();
},
_languages: function() {
return LanguageModel.get();
}
}
});
return initializeModalInstance(modalInstance, 'userProfile', [userId]);
};
/**
* Returns project edit modal instance. This modal contains following project
* specified data:
* - Basic information
* - Sprints
* - Milestones
* - Epics
* - Users
* - Object history
*
* @param {number} projectId Project id
*
* @returns {bootstrap.modalInstance}
*/
service.projectEdit = function(projectId) {
var modalInstance = $modal
.open({
controller: 'ModalProjectEditController',
templateUrl: '/Taskboard/partials/Modals/Project/edit.html',
backdrop: 'static',
size: 'lg',
resolve: {
_project: function() {
return ProjectModel.fetch(projectId);
}
}
});
return initializeModalInstance(modalInstance, 'projectEdit', [projectId]);
};
return service;
}
]
);
}());