blob: ff0f3e88473a522daa9ab0f5a3a842de8602448a (
plain)
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
|
odoo.define('survey.quick.access', function (require) {
'use strict';
var publicWidget = require('web.public.widget');
publicWidget.registry.SurveyQuickAccessWidget = publicWidget.Widget.extend({
selector: '.o_survey_quick_access',
events: {
'click button[type="submit"]': '_onSubmit',
},
//--------------------------------------------------------------------------
// Widget
//--------------------------------------------------------------------------
/**
* @override
*/
start: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
// Init event listener
if (!self.readonly) {
$(document).on('keypress', self._onKeyPress.bind(self));
}
self.$('input').focus();
});
},
// -------------------------------------------------------------------------
// Private
// -------------------------------------------------------------------------
// Handlers
// -------------------------------------------------------------------------
_onKeyPress: function (event) {
if (event.keyCode === 13) { // Enter
event.preventDefault();
this._submitCode();
}
},
_onSubmit: function (event) {
event.preventDefault();
this._submitCode();
},
_submitCode: function () {
var self = this;
this.$('.o_survey_error').addClass("d-none");
var $sessionCodeInput = this.$('input#session_code');
this._rpc({
route: `/survey/check_session_code/${$sessionCodeInput.val()}`,
}).then(function (response) {
if (response.survey_url) {
window.location = response.survey_url;
} else {
self.$('.o_survey_error').removeClass("d-none");
}
});
},
});
return publicWidget.registry.SurveyQuickAccessWidget;
});
|