summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2020-07-23 08:46:39 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2020-07-29 08:59:42 +0000
commit49d9771c56d9d5652eca34285ade04cc1a303718 (patch)
treeb22048a2f08d32a24b46cdae8138956ce342ef2a /addons/web/static/src/js/views/basic
parent97cdcc05f17eb9df0e6ca7896ace6fbf6450b356 (diff)
[IMP] web, base: action buttons in list's controlPanel
This commit introduces a new semantics to define action and method buttons in the list view. The aim of this feature is to be able to do some actions on selected records, or on the entire records' domain with the help of buttons located in the controlPanel, much like the form view header buttons. To define such buttons, one must add a `header` node in the list view's xml definition ``` <tree> <header> <button type="action|object" name="actionId|methodName" string="button's text" context="{}"/> </header> <field name="fieldName" /> </tree> ``` task-2246383
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js67
1 files changed, 43 insertions, 24 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index ec7255b9e60..e1d132c498e 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -263,31 +263,17 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
* @returns {Promise}
*/
_callButtonAction: function (attrs, record) {
- var self = this;
- var def = new Promise(function (resolve, reject) {
- var reload = function () {
- return self.isDestroyed() ? Promise.resolve() : self.reload();
- };
- record = record || self.model.get(self.handle);
-
- self.trigger_up('execute_action', {
- action_data: _.extend({}, attrs, {
- context: record.getContext({additionalContext: attrs.context || {}}),
- }),
- env: {
- context: record.getContext(),
- currentID: record.data.id,
- model: record.model,
- resIDs: record.res_ids,
- },
- on_success: resolve,
- on_fail: function () {
- self.update({}, { reload: false }).then(reject).guardedCatch(reject);
- },
- on_closed: reload,
- });
+ record = record || this.model.get(this.handle);
+ const actionData = Object.assign({}, attrs, {
+ context: record.getContext({additionalContext: attrs.context || {}})
});
- return this.alive(def);
+ const recordData = {
+ context: record.getContext(),
+ currentID: record.data.id,
+ model: record.model,
+ resIDs: record.res_ids,
+ };
+ return this._executeButtonAction(actionData, recordData);
},
/**
* Called by the field manager mixin to confirm that a change just occured
@@ -410,6 +396,39 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
}
},
/**
+ * Executes the action associated with a button
+ *
+ * @private
+ * @param {Object} actionData: the descriptor of the action
+ * @param {string} actionData.type: the button's action's type, accepts "object" or "action"
+ * @param {string} actionData.name: the button's action's name
+ * either the model method's name for type "object"
+ * or the action's id in database, or xml_id
+ * @param {string} actionData.context: the action's execution context
+ *
+ * @param {Object} recordData: basic information on the current record(s)
+ * @param {number[]} recordData.resIDs: record ids:
+ * - on which an object method applies
+ * - that will be used as active_ids to load an action
+ * @param {string} recordData.model: model name
+ * @param {Object} recordData.context: the records' context, will be used to load
+ * the action, and merged into actionData.context at execution time
+ *
+ * @returns {Promise}
+ */
+ async _executeButtonAction(actionData, recordData) {
+ const prom = new Promise((resolve, reject) => {
+ this.trigger_up('execute_action', {
+ action_data: actionData,
+ env: recordData,
+ on_closed: () => this.isDestroyed() ? Promise.resolve() : this.reload(),
+ on_success: resolve,
+ on_fail: () => this.update({}, { reload: false }).then(reject).guardedCatch(reject)
+ });
+ });
+ return this.alive(prom);
+ },
+ /**
* Override to add the current record ID (currentId) and the list of ids
* (resIds) in the current dataPoint to the exported state.
*