-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathable-orders.js
More file actions
64 lines (61 loc) · 1.75 KB
/
able-orders.js
File metadata and controls
64 lines (61 loc) · 1.75 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
(function() {
'use strict';
angular.module('able').directive('elementOrders', ordersDirective)
function ordersDirective() {
var directive = {
restrict: 'A',
controller: ordersController,
controllerAs: 'orders',
bindToController: true
}
return directive
}
function ordersController($scope, $http, $q, config, auth, $localStorage) {
var vm = this;
vm.list = $localStorage.orders
get();
function get() {
vm.loading = true
var req_config = {
headers: {
'Authorization': auth.token
}
};
$http.get(config.api + '/users/' + auth.id + '/orders', req_config).then(function successCallback(response) {
for (var key in response.data.resources) {
response.data.resources[key].object.place = JSON.parse(response.data.resources[key].object.place)
}
vm.list = response.data.resources;
$localStorage.orders = response.data.resources;
vm.loading = false
}, function errorCallback(response) {
vm.loading = false
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.', get, 'Able', 'Ok')
return
} else {
window.alert('Verifique sua conexão.')
get()
return
}
})
}
} // end controller
})();