summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2020-03-30 20:44:04 +0200
committerGitHub <noreply@github.com>2020-03-30 20:44:04 +0200
commite3ae7c6492bbd580e51f0674a79d56df29a6aff5 (patch)
tree5044b2fba4cfa4c543984ddbae08b46b09759063 /addons/web/static/src/js/views/basic
parentb53cf339e4e3728672ad2a8d505878274f4294c4 (diff)
parent7c740639fd78b6b59509e07ef2478913a183c9c1 (diff)
[MERGE] web,*: selection in list views
*account This commit allows the user to apply actions to all records matching the current domain in list views. It also ensures that the user is aware of the set of records actually selected. The number of selected records is now displayed in the control panel, and the user can, with an additional click, select all records matching the current domain instead of the ones of the current page. Task 2185145 closes odoo/odoo#48305 Related: odoo/enterprise#9537 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js26
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js23
2 files changed, 36 insertions, 13 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 8b4672bc291..bbfee26e51f 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -239,6 +239,25 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
});
},
/**
+ * Archive the current selection
+ *
+ * @private
+ * @param {number[]} ids
+ * @param {boolean} archive
+ * @returns {Promise}
+ */
+ _archive: async function (ids, archive) {
+ if (ids.length === 0) {
+ return Promise.resolve();
+ }
+ if (archive) {
+ await this.model.actionArchive(ids, this.handle);
+ } else {
+ await this.model.actionUnarchive(ids, this.handle);
+ }
+ return this.update({}, {reload: false});
+ },
+ /**
* When the user clicks on a 'action button', this function determines what
* should happen.
*
@@ -327,9 +346,10 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
.then(self._onDeletedRecords.bind(self, ids));
}
if (this.confirmOnDelete) {
- Dialog.confirm(this, _t("Are you sure you want to delete this record ?"), {
- confirm_callback: doIt,
- });
+ const message = ids.length > 1 ?
+ _t("Are you sure you want to delete these records?") :
+ _t("Are you sure you want to delete this record?");
+ Dialog.confirm(this, message, { confirm_callback: doIt });
} else {
doIt();
}
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index a69f6878023..8dc540a8861 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -812,6 +812,15 @@ var BasicModel = AbstractModel.extend({
});
},
/**
+ * Returns the list of res_ids for a given list of local ids.
+ *
+ * @param {string[]} localIds
+ * @returns {integer[]}
+ */
+ localIdsToResIds: function (localIds) {
+ return localIds.map(localId => this.localData[localId].res_id);
+ },
+ /**
* This helper method is designed to help developpers that want to use a
* field widget outside of a view. In that case, we want a way to create
* data without actually performing a fetch.
@@ -1286,16 +1295,13 @@ var BasicModel = AbstractModel.extend({
/**
* Archive the given records
*
- * @param {Array} recordIDs local ids of the records to (un)archive
+ * @param {integer[]} resIDs ids of the records to archive
* @param {string} parentID id of the parent resource to reload
* @returns {Promise<string>} resolves to the parent id
*/
- actionArchive: function (recordIDs, parentID) {
+ actionArchive: function (resIDs, parentID) {
var self = this;
var parent = this.localData[parentID];
- var resIDs = _.map(recordIDs, function (recordID) {
- return self.localData[recordID].res_id;
- });
return this._rpc({
model: parent.model,
method: 'action_archive',
@@ -1318,16 +1324,13 @@ var BasicModel = AbstractModel.extend({
/**
* Unarchive the given records
*
- * @param {Array} recordIDs local ids of the records to (un)archive
+ * @param {integer[]} resIDs ids of the records to unarchive
* @param {string} parentID id of the parent resource to reload
* @returns {Promise<string>} resolves to the parent id
*/
- actionUnarchive: function (recordIDs, parentID) {
+ actionUnarchive: function (resIDs, parentID) {
var self = this;
var parent = this.localData[parentID];
- var resIDs = _.map(recordIDs, function (recordID) {
- return self.localData[recordID].res_id;
- });
return this._rpc({
model: parent.model,
method: 'action_unarchive',