diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-12-06 12:02:58 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-12-06 12:02:58 +0100 |
| commit | 8ef7af6afe54fbd59051bbbce76daadd6fdb0e86 (patch) | |
| tree | b21971e972eacc87e198fbc38b48ac9b70d168fc /addons/web | |
| parent | 010add290342ae1e2887450a381e0d1f0acd34e5 (diff) | |
| parent | f96a797fe6238306ec70d3db013b8a4d348ef181 (diff) | |
[MERGE] forward port branch 11.0 up to f96a797fe62
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/lib/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js | 8 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/action_manager.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/search_filters.js | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/search_inputs.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/search_view.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/view_manager.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/time.js | 24 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 14 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 15 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/calendar/calendar_model.js | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/graph/graph_renderer.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/widgets/date_picker.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/less/bootstrap_overridden.less | 16 | ||||
| -rw-r--r-- | addons/web/static/src/less/modal.less | 24 | ||||
| -rw-r--r-- | addons/web/static/src/less/rainbow.less | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 45 |
16 files changed, 128 insertions, 40 deletions
diff --git a/addons/web/static/lib/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js b/addons/web/static/lib/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js index 8f0724bbb00..19f261ff4fc 100644 --- a/addons/web/static/lib/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js +++ b/addons/web/static/lib/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js @@ -479,8 +479,12 @@ }, notifyEvent = function (e) { - if (e.type === 'dp.change' && ((e.date && e.date.isSame(e.oldDate)) || (!e.date && !e.oldDate))) { - return; + if (e.type === 'dp.change') { + // check _isUTC flag to ensure that we are not comparing apples and oranges + var bothUTC = e.date && e.oldDate && e.date._isUTC === e.oldDate._isUTC; + if ((bothUTC && e.date.isSame(e.oldDate)) || (!e.date && !e.oldDate)) { + return; + } } element.trigger(e); }, diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index 25ee9c20cf6..c9eed9b2e64 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -608,7 +608,7 @@ var ActionManager = Widget.extend({ }); } - return $.when(action_loaded || null).done(function() { + return $.when(action_loaded || null).then(function() { if (self.inner_widget && self.inner_widget.do_load_state) { return self.inner_widget.do_load_state(state, warm); } diff --git a/addons/web/static/src/js/chrome/search_filters.js b/addons/web/static/src/js/chrome/search_filters.js index e2eff03546d..582af7e70ef 100644 --- a/addons/web/static/src/js/chrome/search_filters.js +++ b/addons/web/static/src/js/chrome/search_filters.js @@ -248,6 +248,10 @@ var Date = DateTime.extend({ attributes: { type: 'date' }, + get_value: function (index) { + // retrieve the datepicker value + return this["datewidget_" + (index || 0)].getValue(); + }, _get_widget_class: function () { return datepicker.DateWidget; }, diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js index e3e5fec6839..d937a6e246e 100644 --- a/addons/web/static/src/js/chrome/search_inputs.js +++ b/addons/web/static/src/js/chrome/search_inputs.js @@ -153,7 +153,7 @@ var Field = Input.extend( /** @lends instance.web.search.Field# */ { value_to_domain = function (facetValue) { return Domain.prototype.stringToArray( domain, - {self: self.value_from(facetValue)} + {self: self.value_from(facetValue), raw_value: facetValue.attributes.value} ); }; } else { diff --git a/addons/web/static/src/js/chrome/search_view.js b/addons/web/static/src/js/chrome/search_view.js index ecd7db41a7d..7b7b3afcd70 100644 --- a/addons/web/static/src/js/chrome/search_view.js +++ b/addons/web/static/src/js/chrome/search_view.js @@ -339,7 +339,7 @@ var SearchView = Widget.extend({ }, set_default_filters: function () { var self = this, - default_custom_filter = this.$buttons && this.favorite_menu.get_default_filter(); + default_custom_filter = this.$buttons && this.favorite_menu && this.favorite_menu.get_default_filter(); if (!self.options.disable_custom_filters && default_custom_filter) { return this.favorite_menu.toggle_filter(default_custom_filter, true); } diff --git a/addons/web/static/src/js/chrome/view_manager.js b/addons/web/static/src/js/chrome/view_manager.js index 5c32715a98f..75029d4cc27 100644 --- a/addons/web/static/src/js/chrome/view_manager.js +++ b/addons/web/static/src/js/chrome/view_manager.js @@ -542,7 +542,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, { stateChanged = true; } if (stateChanged) { - this.switch_mode(state.view_type); + return this.switch_mode(state.view_type); } }, /** diff --git a/addons/web/static/src/js/core/time.js b/addons/web/static/src/js/core/time.js index 3ed4165abaa..8bce87e3109 100644 --- a/addons/web/static/src/js/core/time.js +++ b/addons/web/static/src/js/core/time.js @@ -279,6 +279,27 @@ var normalize_format_table = { }; var inverse_normalize_format_table = _.invert(normalize_format_table); +/** + * Get date format of the user's language + */ +function getLangDateFormat() { + return this.strftime_to_moment_format(_t.database.parameters.date_format); +} + +/** + * Get time format of the user's language + */ +function getLangTimeFormat() { + return this.strftime_to_moment_format(_t.database.parameters.time_format); +} + +/** + * Get date time format of the user's language + */ +function getLangDatetimeFormat() { + return this.strftime_to_moment_format(_t.database.parameters.date_format + " " + _t.database.parameters.time_format); +} + return { @@ -293,6 +314,9 @@ return { auto_date_to_str: auto_date_to_str, strftime_to_moment_format: strftime_to_moment_format, moment_to_strftime_format: moment_to_strftime_format, + getLangDateFormat: getLangDateFormat, + getLangTimeFormat: getLangTimeFormat, + getLangDatetimeFormat: getLangDatetimeFormat, }; }); diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 1b0e3a6c8a3..de5f80b0e92 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1233,7 +1233,7 @@ var FieldBinaryFile = AbstractFieldBinary.extend({ template: 'FieldBinaryFile', events: _.extend({}, AbstractFieldBinary.prototype.events, { 'click': function (event) { - if (this.mode === 'readonly' && this.value) { + if (this.mode === 'readonly' && this.value && this.recordData.id) { this.on_save_as(event); } }, @@ -1250,10 +1250,20 @@ var FieldBinaryFile = AbstractFieldBinary.extend({ this.do_toggle(!!this.value); if (this.value) { this.$el.empty().append($("<span/>").addClass('fa fa-download')); + if (this.recordData.id) { + this.$el.css('cursor', 'pointer'); + } else { + this.$el.css('cursor', 'not-allowed'); + } if (this.filename_value) { this.$el.append(" " + this.filename_value); } } + if (!this.res_id) { + this.$el.css('cursor', 'not-allowed'); + } else { + this.$el.css('cursor', 'pointer'); + } }, _renderEdit: function () { if (this.value) { @@ -1278,7 +1288,7 @@ var FieldBinaryFile = AbstractFieldBinary.extend({ if (!this.value) { this.do_warn(_t("Save As..."), _t("The field is empty, there's nothing to save !")); ev.stopPropagation(); - } else { + } else if (this.res_id) { framework.blockUI(); var c = crash_manager; var filename_fieldname = this.attrs.filename; diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 7ba4122cccb..bca74acc088 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -97,8 +97,7 @@ function formatDate(value, field, options) { value = value.clone().add(session.getTZOffset(value), 'minutes'); } } - var l10n = core._t.database.parameters; - var date_format = time.strftime_to_moment_format(l10n.date_format); + var date_format = time.getLangDateFormat(); return value.format(date_format); } @@ -122,11 +121,7 @@ function formatDateTime(value, field, options) { if (!options || !('timezone' in options) || options.timezone) { value = value.clone().add(session.getTZOffset(value), 'minutes'); } - var l10n = core._t.database.parameters; - var date_format = time.strftime_to_moment_format(l10n.date_format); - var time_format = time.strftime_to_moment_format(l10n.time_format); - var datetime_format = date_format + ' ' + time_format; - return value.format(datetime_format); + return value.format(time.getLangDatetimeFormat()); } /** @@ -349,7 +344,7 @@ function parseDate(value, field, options) { if (!value) { return false; } - var datePattern = time.strftime_to_moment_format(core._t.database.parameters.date_format); + var datePattern = time.getLangDateFormat(); var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D'); var date; if (options && options.isUTC) { @@ -388,8 +383,8 @@ function parseDateTime(value, field, options) { if (!value) { return false; } - var datePattern = time.strftime_to_moment_format(core._t.database.parameters.date_format), - timePattern = time.strftime_to_moment_format(core._t.database.parameters.time_format); + var datePattern = time.getLangDateFormat(), + timePattern = time.getLangTimeFormat(); var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D'), timePatternWoZero = timePattern.replace('HH','H').replace('mm','m').replace('ss','s'); var pattern1 = datePattern + ' ' + timePattern; diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index a0f6515b98c..fac6845a31f 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -382,8 +382,8 @@ return AbstractModel.extend({ allDayText: _t("All day"), views: { week: { - columnFormat: 'ddd ' + time.strftime_to_moment_format(_t.database.parameters.date_format), - titleFormat: time.strftime_to_moment_format(_t.database.parameters.time_format), + columnFormat: 'ddd ' + time.getLangDateFormat(), + titleFormat: time.getLangTimeFormat(), } }, monthNames: moment.months(), diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js index 414e51b31b4..178d3ef3bd5 100644 --- a/addons/web/static/src/js/views/graph/graph_renderer.js +++ b/addons/web/static/src/js/views/graph/graph_renderer.js @@ -80,7 +80,7 @@ return AbstractRenderer.extend({ setTimeout(function () { self.$el.empty(); var chart = self['_render' + _.str.capitalize(self.state.mode) + 'Chart'](); - if (chart) { + if (chart && chart.tooltip.chartContainer) { self.to_remove = chart.update; nv.utils.onWindowResize(chart.update); chart.tooltip.chartContainer(self.el); diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js index 3573e9232e5..8d0b04332ad 100644 --- a/addons/web/static/src/js/widgets/date_picker.js +++ b/addons/web/static/src/js/widgets/date_picker.js @@ -26,7 +26,7 @@ var DateWidget = Widget.extend({ this.name = parent.name; this.options = _.defaults(options || {}, { - format : time.strftime_to_moment_format((this.type_of_date === 'datetime')? (l10n.date_format + ' ' + l10n.time_format) : l10n.date_format), + format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat(), minDate: moment({ y: 1900 }), maxDate: moment().add(200, "y"), calendarWeeks: true, diff --git a/addons/web/static/src/less/bootstrap_overridden.less b/addons/web/static/src/less/bootstrap_overridden.less index 0582ec8c384..ca6383e0116 100644 --- a/addons/web/static/src/less/bootstrap_overridden.less +++ b/addons/web/static/src/less/bootstrap_overridden.less @@ -72,6 +72,22 @@ @modal-inner-padding: @odoo-horizontal-padding; @modal-title-padding: @odoo-horizontal-padding; +// Change the z-index of the modal-backdrop elements to be equal to the +// modal elements' ones. Bootstrap does not support multi-modals, and without +// this rule all the modal-backdrops are below all the opened modals. +// Indeed, bootstrap forces them to a lower z-index as the modal-backdrop +// element (unique in their supported cases) might be put after the modal +// element (if the modal is already in the DOM, hidden, then opened). This +// cannot happen in odoo though as modals are not hidden but removed from +// the DOM and are always put at the end of the body when opened. +// +// Note that the variable @zindex-modal-background may be renamed/removed in +// newer versions of bootstrap. +// +// TODO the following code was disabled because it is saas-incompatible +// +// @zindex-modal-background: @zindex-modal; + //== Navs @nav-link-padding: 10px 15px; @nav-pills-border-radius: 0; diff --git a/addons/web/static/src/less/modal.less b/addons/web/static/src/less/modal.less index 95a14420773..a223deb55ef 100644 --- a/addons/web/static/src/less/modal.less +++ b/addons/web/static/src/less/modal.less @@ -77,21 +77,11 @@ } } -// Change the z-index of the modal-backdrop elements to be equal to the -// modal elements' ones. Bootstrap does not support multi-modals, and without -// this rule all the modal-backdrops are below all the opened modals. -// Indeed, bootstrap forces them to a lower z-index as the modal-backdrop -// element (unique in their supported cases) might be put after the modal -// element (if the modal is already in the DOM, hidden, then opened). This -// cannot happen in odoo though as modals are not hidden but removed from -// the DOM and are always put at the end of the body when opened. -// -// Note that the variable @zindex-modal-background may be renamed/removed in -// newer versions of bootstrap. -@zindex-modal-background: @zindex-modal; - // Temporary fix for modals which are not instantiated thanks to the Dialog -// JS classes (deprecated case) + Frontend. -:not(body) > .modal { - z-index: @zindex-modal-background + 1; -} +// JS classes (deprecated case) (see bootstrap_overridden.less) + Frontend. +// +// TODO the following code was disabled because it is saas-incompatible +// +// :not(body) > .modal { +// z-index: @zindex-modal-background + 1; +// } diff --git a/addons/web/static/src/less/rainbow.less b/addons/web/static/src/less/rainbow.less index 2342a7f2718..b86387b18ca 100644 --- a/addons/web/static/src/less/rainbow.less +++ b/addons/web/static/src/less/rainbow.less @@ -9,7 +9,7 @@ // o_reward .o_reward { will-change: transform; - z-index: @zindex-modal + 1; + z-index: @zindex-modal; padding: 50px; margin: -5% auto 0 -(@reward-size / 2); @media (max-width: @screen-xs-max) { diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 2f2f43b181a..08e255777eb 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1426,6 +1426,51 @@ QUnit.module('basic_fields', { session.get_file = oldGetFile; }); + QUnit.test('binary fields that are readonly in create mode do not download', function (assert) { + assert.expect(2); + + // save the session function + var oldGetFile = session.get_file; + session.get_file = function (option) { + assert.step('We shouldn\'t be getting the file.'); + return oldGetFile.bind(session)(option); + }; + + this.data.partner.onchanges = { + product_id: function (obj) { + obj.document = "onchange==\n"; + }, + }; + + this.data.partner.fields.document.readonly = true; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="product_id"/>' + + '<field name="document" filename="\'yooo\'"/>' + + '</form>', + res_id: 1, + }); + + form.$buttons.find('.o_form_button_create').click(); + var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); + + form.$('.o_field_many2one input').click(); + $dropdown.find('li:not(.o_m2o_dropdown_option):contains(xphone)').click(); + + assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, + 'The link to download the binary should be present'); + + form.$('a.o_field_widget[name="document"]').click(); + + assert.verifySteps([]); // We shoudln't have passed through steps + + form.destroy(); + session.get_file = oldGetFile; + }); QUnit.test('text field rendering in list view', function (assert) { assert.expect(1); |
