-
Notifications
You must be signed in to change notification settings - Fork 0
/
internalRequestController.js
133 lines (102 loc) · 4.37 KB
/
internalRequestController.js
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
app.controller('InternalRequestController', function ($controller, $scope, ApiResponseActions, InternalRequestRepo, InternalRequestsService, RemoteProductManagerRepo, RemoteProductsService) {
angular.extend(this, $controller('AbstractController', {
$scope: $scope
}));
$scope.internalRequests = InternalRequestRepo.getAll();
$scope.internalRequestToCreate = InternalRequestRepo.getScaffold();
$scope.internalRequestToEdit = {};
$scope.internalRequestToDelete = {};
$scope.featureRequestToPush = {};
$scope.resetInternalRequestForms = function () {
InternalRequestRepo.clearValidationResults();
for (var key in $scope.internalRequestForms) {
if ($scope.internalRequestForms[key] !== undefined && !$scope.internalRequestForms[key].$pristine && $scope.internalRequestForms[key].$setPristine) {
$scope.internalRequestForms[key].$setPristine();
}
}
$scope.closeModal();
};
$scope.resetInternalRequestForms();
if ($scope.isManager() || $scope.isAdmin()) {
$scope.remoteProductManagers = RemoteProductManagerRepo.getAll();
$scope.getRemoteProductManagerRemoteProducts = function (remoteProductManagerId) {
return RemoteProductManagerRepo.findById(remoteProductManagerId);
};
$scope.createInternalRequest = function () {
$scope.internalRequestToCreate.createdOn = new Date().getTime();
InternalRequestRepo.create($scope.internalRequestToCreate).then(function (res) {
if (angular.fromJson(res.body).meta.status === 'SUCCESS') {
$scope.resetCreateInternalRequest();
}
});
};
$scope.resetCreateInternalRequest = function () {
angular.extend($scope.internalRequestToCreate, InternalRequestRepo.getScaffold());
$scope.resetInternalRequestForms();
};
$scope.pushInternalRequest = function (internalRequest) {
$scope.featureRequestToPush = {
id: internalRequest.id,
title: internalRequest.title,
description: internalRequest.description,
productId: null,
scopeId: null
};
$scope.openModal('#pushInternalRequestModal');
};
$scope.pushFeatureRequest = function () {
InternalRequestsService.pushFeatureRequest($scope.featureRequestToPush).then(function (res) {
if (angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.cancelPushFeatureRequest();
}
});
};
$scope.cancelPushFeatureRequest = function () {
$scope.featureRequestToPush = {};
$scope.resetInternalRequestForms();
};
$scope.editInternalRequest = function (internalRequest) {
$scope.internalRequestToEdit = angular.copy(internalRequest);
$scope.openModal('#editInternalRequestModal');
};
$scope.updateInternalRequest = function () {
$scope.internalRequestToEdit.dirty(true);
$scope.internalRequestToEdit.save().then(function () {
$scope.cancelEditInternalRequest();
});
};
$scope.cancelEditInternalRequest = function () {
$scope.internalRequestToEdit.refresh();
$scope.resetInternalRequestForms();
};
$scope.confirmDeleteInternalRequest = function (internalRequest) {
$scope.internalRequestToDelete = angular.copy(internalRequest);
$scope.openModal('#deleteInternalRequestModal');
};
$scope.cancelDeleteInternalRequest = function () {
$scope.internalRequestToDelete = {};
$scope.closeModal();
};
$scope.deleteInternalRequest = function (internalRequest) {
InternalRequestRepo.delete(internalRequest).then(function (res) {
if (angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.cancelDeleteInternalRequest();
}
});
};
RemoteProductManagerRepo.listen([ApiResponseActions.CREATE, ApiResponseActions.DELETE, ApiResponseActions.UPDATE], function () {
var remoteProductManagers = RemoteProductManagerRepo.getAll();
$scope.remoteProductManagers.length = 0;
for (var i in remoteProductManagers) {
$scope.remoteProductManagers.push(remoteProductManagers[i]);
}
});
}
InternalRequestRepo.listen([ApiResponseActions.CREATE, ApiResponseActions.DELETE, ApiResponseActions.UPDATE], function () {
var internalRequests = InternalRequestRepo.getAll();
$scope.internalRequests.length = 0;
for (var i in internalRequests) {
$scope.internalRequests.push(internalRequests[i]);
}
});
});