-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeleteController.js
More file actions
67 lines (59 loc) · 2.34 KB
/
Copy pathdeleteController.js
File metadata and controls
67 lines (59 loc) · 2.34 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
var app = angular.module("ive");
// Location delete controller
app.controller("locationDeleteController", function($http, $scope, $rootScope, $routeParams, $filter, $translate, $location, config, $window, $authenticationService, $locationService) {
/*************************************************
FUNCTIONS
*************************************************/
/**
* [redirect description]
* @param {[type]} path [description]
* @return {[type]} [description]
*/
$scope.redirect = function(path){
$location.url(path);
};
/**
* [delete description]
* @return {[type]} [description]
*/
$scope.delete = function(){
$scope.$parent.loading = { status: true, message: $filter('translate')('DELETING_LOCATION') };
$locationService.remove($scope.location.location_id)
.then(function onSuccess(response) {
$scope.redirect("/locations");
})
.catch(function onError(response) {
if (response.data == "Token expired!") {
$http.post(config.getApiEndpoint() + "/refreshToken", { refresh: $authenticationService.getRefreshToken() })
.then(res => {
$authenticationService.updateUser(res.data);
$locationService.remove($scope.location.location_id)
.then(function onSuccess(response) {
$scope.redirect("/locations");
})
.catch(function onError(response) {
if (response.status > 0) {
$window.alert(response.data);
}
});
})
} else {
$window.alert(response.data);
}
});
};
/*************************************************
INIT
*************************************************/
$scope.$parent.loading = { status: true, message: $filter('translate')('LOADING_LOCATION') };
$scope.input = "";
// Load location
$locationService.retrieve($routeParams.location_id)
.then(function onSuccess(response) {
$scope.location = response.data;
$scope.$parent.loading = { status: false, message: "" };
})
.catch(function onError(response) {
$window.alert(response.data);
});
});