duvidas.controller.js
2.88 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
(function() {
'use strict';
angular
.module('dialoga')
.controller('DuvidasPageController', DuvidasPageController);
/** @ngInject */
function DuvidasPageController(DialogaService, APP, $interval, $window, vcRecaptchaService, $log) {
$log.debug('DuvidasPageController');
var vm = this;
vm.DialogaService = DialogaService;
vm.APP = APP;
vm.$interval = $interval;
vm.$window = $window;
vm.vcRecaptchaService = vcRecaptchaService;
vm.$log = $log;
vm.init();
vm.loadData();
vm.attachListeners();
}
DuvidasPageController.prototype.init = function () {
var vm = this;
vm.loadingQuestions = false;
vm.error = false;
vm.sendingContactForm = false;
vm.questions = [];
vm.recaptchaResponse = null;
vm.recaptchaWidgetId = null;
};
DuvidasPageController.prototype.loadData = function () {
var vm = this;
vm.loadingQuestions = true;
vm.DialogaService.getQuestions()
.then(function(data) {
// vm.$log.debug('data', data);
vm.questions = data.articles;
})
.catch(function(error){
vm.$log.error('error', error);
})
.finally(function(){
vm.loadingQuestions = false;
});
};
DuvidasPageController.prototype.attachListeners = function () {
var vm = this;
// reCaptcha Listeners
vm.setWidgetId = function(widgetId) {
// store the `widgetId` for future usage.
// For example for getting the response with
// `recaptcha.getResponse(widgetId)`.
vm.$log.info('Created widget ID:', widgetId);
vm.recaptchaWidgetId = widgetId;
};
vm.setResponse = function(response) {
// Update local captcha response
vm.$log.debug('Response available', response);
vm.recaptchaResponse = response;
};
vm.cbExpiration = function() {
// reset the 'response' object that is on scope
vm.$log.debug('cbExpiration');
};
};
DuvidasPageController.prototype.submitContactForm = function ($event, contactForm) {
var vm = this;
vm.$log.debug('submitContactForm contactForm', contactForm);
vm.sendingContactForm = true;
var data = {
name: contactForm.inputName.$modelValue,
email: contactForm.inputEmail.$modelValue,
subject: contactForm.inputSubject.$modelValue,
message: contactForm.inputMessage.$modelValue
};
data.g_recaptcha_response = vm.recaptchaResponse;
vm.DialogaService.sendContactForm(data)
.then(function(response){
vm.$log.debug('sendContactForm success', response);
vm.successMessage = 'Mensagem enviada com sucesso!';
}, function(response){
vm.$log.warn('sendContactForm error', response);
vm.errorMessage = 'Erro ao enviar mensagem. Tente novamente mais tarde.';
})
.finally(function(response){
vm.$log.debug('sendContactForm finally', response);
vm.sendingContactForm = false;
});
};
})();