summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/survey/i18n/survey.pot14
-rw-r--r--addons/survey/static/src/js/survey_form.js37
2 files changed, 40 insertions, 11 deletions
diff --git a/addons/survey/i18n/survey.pot b/addons/survey/i18n/survey.pot
index 9ec98856fd5..600ee34c192 100644
--- a/addons/survey/i18n/survey.pot
+++ b/addons/survey/i18n/survey.pot
@@ -2208,6 +2208,20 @@ msgid "The badge for each survey should be unique!"
msgstr ""
#. module: survey
+#. openerp-web
+#: code:addons/survey/static/src/js/survey.js:0
+#, python-format
+msgid "The date you selected is greater than the maximum date: "
+msgstr ""
+
+#. module: survey
+#. openerp-web
+#: code:addons/survey/static/src/js/survey.js:0
+#, python-format
+msgid "The date you selected is lower than the minimum date: "
+msgstr ""
+
+#. module: survey
#: model:ir.model.fields,help:survey.field_survey_survey__description
msgid ""
"The description will be displayed on the home page of the survey. You can "
diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js
index eb8ac3a95be..09cf0a21d9f 100644
--- a/addons/survey/static/src/js/survey_form.js
+++ b/addons/survey/static/src/js/survey_form.js
@@ -5,9 +5,11 @@ var field_utils = require('web.field_utils');
var publicWidget = require('web.public.widget');
var time = require('web.time');
var core = require('web.core');
-var _t = core._t;
+var Dialog = require('web.Dialog');
var dom = require('web.dom');
+var _t = core._t;
+
publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
selector: '.o_survey_form',
events: {
@@ -611,12 +613,9 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
* Initialize datetimepicker in correct format and with constraints
*/
_initDateTimePicker: function ($dateGroup) {
- var disabledDates = [];
-
- var minDateData = $dateGroup.data('mindate');
- var minDate = minDateData ? this._formatDateTime(minDateData) : moment({ y: 1900 });
- var maxDateData = $dateGroup.data('maxdate');
- var maxDate = maxDateData ? this._formatDateTime(maxDateData) : moment().add(200, "y");
+ var disabledDates = []
+ var minDateData = $dateGroup.data('mindate')
+ var maxDateData = $dateGroup.data('maxdate')
var datetimepickerFormat = time.getLangDateFormat();
if ($dateGroup.find('input').data('questionType') === 'datetime') {
@@ -628,13 +627,20 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
disabledDates = [minDate, maxDate];
}
+ var minDate = minDateData
+ ? this._formatDateTime(minDateData, datetimepickerFormat)
+ : moment({ y: 1900 });
+ var maxDate = maxDateData
+ ? this._formatDateTime(maxDateData, datetimepickerFormat)
+ : moment().add(200, "y");
+
$dateGroup.datetimepicker({
format : datetimepickerFormat,
minDate: minDate,
maxDate: maxDate,
disabledDates: disabledDates,
useCurrent: false,
- viewDate: moment(new Date()).hours(0).minutes(0).seconds(0).milliseconds(0),
+ viewDate: moment(new Date()).hours(minDate.hours()).minutes(minDate.minutes()).seconds(minDate.seconds()).milliseconds(minDate.milliseconds()),
calendarWeeks: true,
icons: {
time: 'fa fa-clock-o',
@@ -647,13 +653,22 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
locale : moment.locale(),
allowInputToggle: true,
});
- $dateGroup.on('error.datetimepicker', function () {
+ $dateGroup.on('error.datetimepicker', function (err) {
+ if (err.date) {
+ if (err.date < minDate) {
+ Dialog.alert(this, _t('The date you selected is lower than the minimum date: ') + minDate.format(datetimepickerFormat));
+ }
+
+ if (err.date > maxDate) {
+ Dialog.alert(this, _t('The date you selected is greater than the maximum date: ') + maxDate.format(datetimepickerFormat));
+ }
+ }
return false;
});
},
- _formatDateTime: function (datetimeValue) {
- return field_utils.format.datetime(moment(datetimeValue), null, {timezone: true});
+ _formatDateTime: function (datetimeValue, format){
+ return moment(field_utils.format.datetime(moment(datetimeValue), null, {timezone: true}), format);
},
_initResultWidget: function () {