diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/survey/static/src/js/survey_quick_access.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/survey/static/src/js/survey_quick_access.js')
| -rw-r--r-- | addons/survey/static/src/js/survey_quick_access.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/addons/survey/static/src/js/survey_quick_access.js b/addons/survey/static/src/js/survey_quick_access.js new file mode 100644 index 00000000..ff0f3e88 --- /dev/null +++ b/addons/survey/static/src/js/survey_quick_access.js @@ -0,0 +1,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; + +}); |
