-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathable-confirmation.js
More file actions
102 lines (97 loc) · 2.69 KB
/
able-confirmation.js
File metadata and controls
102 lines (97 loc) · 2.69 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
(function() {
'use strict';
angular.module('able').directive('confirmationElement', confirmationDirective)
function confirmationDirective() {
var directive = {
restrict: 'A',
controller: confirmationController,
controllerAs: 'confirmation',
bindToController: true
}
return directive
}
function confirmationController($rootScope, $state, auth, config, $http) {
var vm = this;
vm.last = $rootScope.last
vm.phone = ''
vm.save = save
vm.back = back
function get() {
var req_config = {
headers: {
'Authorization': auth.token
}
};
$http.get(config.api + '/users/' + auth.id, req_config).then(function successCallback(response) {
vm.phone = response.data.object.phone
}, function errorCallback(response) {
if (response.status == 401) {
if (navigator && navigator.notification) {
navigator.notification.alert('Você precisa se logar novamente.', false, 'Able', 'Ok')
} else {
window.alert('Você precisa se logar novamente.')
}
auth.signout()
return
}
if (response.status == 403) {
if (navigator && navigator.notification) {
navigator.notification.alert(response.data.errors[0].error, false, 'Able', 'Ok')
} else {
window.alert(response.data.errors[0].error)
}
return
}
if (navigator && navigator.notification) {
navigator.notification.alert('Verifique sua conexão.', false, 'Able', 'Ok')
return
} else {
window.alert('Verifique sua conexão.')
return
}
});
}
get();
function back() {
$state.go('storePage.offerPage')
}
function save() {
var req_config = {
headers: {
'Authorization': auth.token
}
};
var payload = {
phone: vm.phone
};
$http.patch(config.api + '/users/' + auth.id, payload, req_config).then(function successCallback(response) {
$state.go('storePage.offerPage')
}, function errorCallback(response) {
if (response.status == 401) {
if (navigator && navigator.notification) {
navigator.notification.alert('Você precisa se logar novamente.', false, 'Able', 'Ok')
} else {
window.alert('Você precisa se logar novamente.')
}
auth.signout()
return
}
if (response.status == 403) {
if (navigator && navigator.notification) {
navigator.notification.alert(response.data.errors[0].error, false, 'Able', 'Ok')
} else {
window.alert(response.data.errors[0].error)
}
return
}
if (navigator && navigator.notification) {
navigator.notification.alert('Verifique sua conexão.', false, 'Able', 'Ok')
return
} else {
window.alert('Verifique sua conexão.')
return
}
});
}
} // end controller
})();