-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathable-quest.js
More file actions
130 lines (127 loc) · 3.73 KB
/
able-quest.js
File metadata and controls
130 lines (127 loc) · 3.73 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
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
(function() {
'use strict';
angular.module('able').directive('elementQuest', questDirective).directive('validateCpf', validateCpfDirective)
function questDirective() {
var directive = {
restrict: 'A',
controller: questController,
controllerAs: 'quest',
bindToController: true
}
return directive
}
function questController($http, auth, $scope, $state, $location, $anchorScroll, $timeout, $element) {
var vm = this;
vm.payload = {};
vm.user = {};
vm.tags = [];
vm.send = send;
vm.answered = 0;
vm.sending = false;
vm.tags_length = 1;
//load tags quest only when quest page is loaded.
$http.get('quest_tags.json').success(function(data) {
vm.tags = data;
vm.tags_length = vm.tags.length
});
// Este watch verifica se todo o questionário foi respondido.
// É chamado em cada resposta.
$scope.$watch(function w(scope) {
return (Object.keys(vm.payload).length)
}, function c(n, o) {
vm.answered = Object.keys(vm.payload).length
vm.least_tags = (Object.keys(vm.payload).length < vm.tags_length) ? true : false;
});
function send() {
vm.sending = true
auth.signupQuest(vm.user.name, vm.user.document, vm.user.email, vm.user.password, JSON.stringify(vm.payload)).then(function(resolve) {
$state.go('storePage')
// vm.sending = false
}, function(reject) {
vm.sending = false
if (reject.data && reject.data.errors && reject.data.errors[0].reference == "repeated_email") {
if (navigator && navigator.notification) {
navigator.notification.alert("Este e-mail já possui um perfil. Recupere sua senha ou use outro e-mail.", false, 'Able', 'Ok')
return
} else {
window.alert("Este e-mail já possui um perfil. Recupere sua senha ou use outro e-mail.")
return
}
} else {
if (navigator && navigator.notification) {
navigator.notification.alert("Não foi possível criar sua conta. Verifique a qualidade da sua conexão.", false, 'Able', 'Ok')
return
} else {
window.alert("Não foi possível criar sua conta. Verifique a qualidade da sua conexão.")
return
}
}
});
}
// function signin(){
// var signin = auth.signin(vm.user.email, vm.user.password);
// signin.then(
// function(resolve) {
// console.log(resolve);
// sendQuest();
// },
// function(reject) {
// console.log(reject);
// }
// );
// }
// function sendQuest(){
// var sendquest = sendQuestPromisse();
// sendquest.then(
// function(resolve) {
// console.log(resolve);
// $state.go('storePage')
// },
// function(reject) {
// console.log(reject);
// }
// );
// }
// function sendQuestPromisse(){
// return $q(function(resolve, reject) {
// var req_config = {headers: {'Authorization': auth.token}}
//
// // for (var key in vm.payload) {
// // if (!vm.payload.hasOwnProperty(key)) continue;
// // vm.payload[key] = parseInt(key)
// // }
//
// var payload = {
// kind: "start_quest",
// responses: JSON.stringify(vm.payload),
// }
// $http.post(config.api + '/users/' + auth.id + '/quests', payload, req_config)
// .then(
// function successCallback(response) {
// resolve();
// },
// function errorCallback(response) {
// reject();
// }
// );
// });
// }
} // end questController
function validateCpfDirective() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
function customValidator(ngModelValue) {
if (testCpf(ngModelValue)) {
ctrl.$setValidity('cpf', true)
} else {
ctrl.$setValidity('cpf', false)
}
return ngModelValue
}
ctrl.$parsers.push(customValidator)
}
};
};
})(); //end strict