forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteLink.js
101 lines (93 loc) · 3.65 KB
/
deleteLink.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
'use strict';
angular.module("openshiftConsole")
.directive("deleteLink", function ($uibModal, $location, $filter, hashSizeFilter, DataService, AlertMessageService, Navigate, Logger) {
return {
restrict: "E",
scope: {
resourceType: "@",
// Optional display name for resourceType. If not specified, humanizeResourceTypeFilter is used.
typeDisplayName: "@?",
resourceName: "@",
projectName: "@",
alerts: "=",
displayName: "@",
// Set to true to disable the delete button.
disableDelete: "=?",
// Only show the button and no text.
buttonOnly: "@"
},
templateUrl: function(elem, attr) {
if (angular.isDefined(attr.buttonOnly)) {
return "views/directives/delete-button.html";
}
return "views/directives/delete-link.html";
},
// Replace so ".dropdown-menu > li > a" styles are applied.
replace: true,
link: function(scope, element, attrs) {
if (attrs.resourceType === 'project') {
scope.isProject = true;
// scope.biggerButton = true;
}
scope.openDeleteModal = function() {
if (scope.disableDelete) {
return;
}
// opening the modal with settings scope as parent
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/modals/delete-resource.html',
controller: 'DeleteModalController',
scope: scope
});
modalInstance.result.then(function() {
// upon clicking delete button, delete resource and send alert
var resourceType = scope.resourceType;
var resourceName = scope.resourceName;
var projectName = scope.projectName;
var typeDisplayName = scope.typeDisplayName || $filter('humanizeResourceType')(resourceType);
var formattedResource = typeDisplayName + ' ' + "\'" + (scope.displayName ? scope.displayName : resourceName) + "\'";
var context = (scope.resourceType === 'project') ? {} : {namespace: scope.projectName};
DataService.delete(resourceType + 's', resourceName, context)
.then(function() {
if (resourceType !== 'project') {
AlertMessageService.addAlert({
name: resourceName,
data: {
type: "success",
message: formattedResource + " was marked for deletion."
}
});
Navigate.toResourceList(resourceType, projectName);
}
else {
if ($location.path() === '/') {
scope.$emit('deleteProject');
}
else if ($location.path().indexOf('settings') > '-1') {
var homeRedirect = URI('/');
AlertMessageService.addAlert({
name: resourceName,
data: {
type: "success",
message: formattedResource + " was marked for deletion."
}
});
$location.url(homeRedirect);
}
}
})
.catch(function(err) {
// called if failure to delete
scope.alerts[resourceName] = {
type: "error",
message: formattedResource + "\'" + " could not be deleted.",
details: $filter('getErrorDetails')(err)
};
Logger.error(formattedResource + " could not be deleted.", err);
});
});
};
}
};
});