summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-03-25 10:05:27 +0000
committerChristophe Simonis <chs@odoo.com>2019-03-25 11:13:41 +0000
commit5df4746c9aa144e6e3fce44fea43dac1089a5c51 (patch)
treef4ce932a76563e26b8d131805d49b405fcf9ad8f /addons/web/static/src/js/fields
parent39e71353c5d58f7af6b3270911a24d98b73cad4e (diff)
parent230ad8c381e927025efabff0f5f8c2debc432249 (diff)
[MERGE] forward port branch saas-12.2 up to 230ad8c381e
closes odoo/odoo#32088 Signed-off-by: Christophe Simonis <chs@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 15b7975aa42..ef916d31ff7 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -21,6 +21,7 @@ var dialogs = require('web.view_dialogs');
var core = require('web.core');
var data = require('web.data');
var Dialog = require('web.Dialog');
+var KanbanRecord = require('web.KanbanRecord');
var KanbanRenderer = require('web.KanbanRenderer');
var ListRenderer = require('web.ListRenderer');
var Pager = require('web.Pager');
@@ -1407,6 +1408,59 @@ var FieldX2Many = AbstractField.extend({
},
});
+var One2ManyKanbanRecord = KanbanRecord.extend({
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * Apply same logic as in the ListRenderer: buttons with type="object"
+ * are disabled for no saved yet records, as calling the python method
+ * with no id would make no sense.
+ *
+ * To avoid to expose this logic inside all Kanban views, we define
+ * a specific KanbanRecord Class for the One2many case.
+ *
+ * This could be refactored to prevent from duplicating this logic in
+ * list and kanban views.
+ *
+ * @private
+ */
+ _postProcessObjectButtons: function () {
+ var self = this;
+ // if the res_id is defined, it's already correctly handled by the Kanban record global event click
+ if (!this.state.res_id) {
+ this.$('.oe_kanban_action[data-type=object]').each(function (index, button) {
+ var $button = $(button);
+ if ($button.attr('warn')) {
+ $button.on('click', function (e) {
+ e.stopPropagation();
+ self.do_warn(_t('Warning'), _t('Please click on the "save" button first.'));
+ });
+ } else {
+ $button.attr('disabled', 'disabled');
+ }
+ });
+ }
+ },
+ /**
+ * @override
+ * @private
+ */
+ _render: function () {
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ self._postProcessObjectButtons();
+ });
+ },
+});
+
+var One2ManyKanbanRenderer = KanbanRenderer.extend({
+ config: _.extend({}, KanbanRenderer.prototype.config, {
+ KanbanRecord: One2ManyKanbanRecord,
+ }),
+});
+
var FieldOne2Many = FieldX2Many.extend({
className: 'o_field_one2many',
supportedFieldTypes: ['one2many'],
@@ -1461,6 +1515,16 @@ var FieldOne2Many = FieldX2Many.extend({
//--------------------------------------------------------------------------
/**
+ * @override
+ * @private
+ */
+ _getRenderer: function () {
+ if (this.view.arch.tag === 'kanban') {
+ return One2ManyKanbanRenderer;
+ }
+ return this._super.apply(this, arguments);
+ },
+ /**
* Overrides to only render the buttons if the 'create' action is available.
*
* @override