diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index 25c3e5f914..2a7ae09ebb 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -199,7 +199,7 @@ class Record extends Base ); } - public function actionMassUpdate($params, $data) + public function actionMassUpdate($params, $data, $request) { if (!$this->getAcl()->check($this->name, 'edit')) { throw new Forbidden(); @@ -214,7 +214,7 @@ class Record extends Base return $idsUpdated; } - public function actionMassDelete($params, $data) + public function actionMassDelete($params, $data, $request) { if (!$this->getAcl()->check($this->name, 'delete')) { throw new Forbidden(); @@ -223,9 +223,9 @@ class Record extends Base $ids = $data['ids']; $where = $data['where']; - $idsDeleted = $this->getRecordService()->massDelete($ids, $where); + $idsRemoved = $this->getRecordService()->massRemove($ids, $where); - return $idsDeleted; + return $idsRemoved; } public function actionCreateLink($params, $data) diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index a2a7776ffe..b398a844d8 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -151,7 +151,13 @@ "resetPreferencesConfirmation": "Are you sure you want to reset preferences to defaults?", "removeRecordConfirmation": "Are you sure you want to remove the record?", "unlinkRecordConfirmation": "Are you sure you want to unlink relationship?", - "removeSelectedRecordsConfirmation": "Are you sure you want to remove selected records?" + "removeSelectedRecordsConfirmation": "Are you sure you want to remove selected records?", + "massUpdateResult": "{count} records have been updated", + "massUpdateResultSinle": "{count} record has been updated", + "noRecordsUpdated": "No records were updated", + "massRemoveResult": "{count} records have been removed", + "massRemoveResultSingle": "{count} record has been removed", + "noRecordsRemoved": "No records were removed" }, "boolFilters": { "onlyMy": "Only My", diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index a0cbf80aa0..bcdb38c7a8 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -483,6 +483,27 @@ class Record extends \Espo\Core\Services\Base // TODO update $where } + + public function massRemove($ids = array(), $where = array()) + { + $idsRemoved = array(); + $repository = $this->getRepository(); + + if (!empty($ids)) { + foreach ($ids as $id) { + $entity = $this->getEntity($id); + if ($this->getAcl()->check($entity, 'remove')) { + if ($repository->remove($entity)) { + $idsRemoved[] = $id; + } + } + } + } + + return $idsRemoved; + + // TODO update $where + } public function follow($id, $userId = null) { diff --git a/frontend/client/src/views/modals/mass-update.js b/frontend/client/src/views/modals/mass-update.js index 7e120282e1..b924120ec6 100644 --- a/frontend/client/src/views/modals/mass-update.js +++ b/frontend/client/src/views/modals/mass-update.js @@ -143,10 +143,14 @@ Espo.define('Views.Modals.MassUpdate', 'Views.Modal', function (Dep) { }), success: function (idsUpdated) { var count = idsUpdated.length; - if (count) { - Espo.Ui.success(count + ' ' + self.translate('records were updated')); + if (count) { + var msg = 'massUpdateResult'; + if (count == 1) { + msg = 'massUpdateResultSingle' + } + Espo.Ui.success(self.translate(msg, 'messages').replace('{count}', count)); } else { - self.notify('No records were updated', 'error'); + Espo.Ui.success(self.translate('noRecordsUpdated', 'messages')); } self.trigger('after:update'); }, diff --git a/frontend/client/src/views/record/list.js b/frontend/client/src/views/record/list.js index a48cefc3e9..fe2bc301eb 100644 --- a/frontend/client/src/views/record/list.js +++ b/frontend/client/src/views/record/list.js @@ -260,28 +260,42 @@ Espo.define('Views.Record.List', 'View', function (Dep) { var self = this; if (confirm(this.translate('removeSelectedRecordsConfirmation', 'messages'))) { - // TODO mass delete this.notify('Removing...'); + var ids = []; for (var i in this.checkedList) { - var id = this.checkedList[i]; - var model = this.collection.get(id); - - this.collection.remove(model); - this.$el.find('tr[data-id="'+id+'"]').remove(); - - model.once('sync', function (model) { - deletedCount ++; - if (deletedCount == count) { - Espo.Ui.notify(false); - } - }, this); - model.destroy({ - error: function () { - self.notify('Error occured', 'error'); - }, - }); + ids.push(this.checkedList[i]); } - this.checkedList = []; + + $.ajax({ + url: this.collection.url + '/action/massDelete', + type: 'POST', + data: JSON.stringify({ + ids: ids + }) + }).done(function (idsRemoved) { + var count = idsRemoved.length; + if (count) { + idsRemoved.forEach(function (id) { + Espo.Ui.notify(false); + this.checkedList = []; + var model = this.collection.get(id); + this.collection.remove(model); + + this.$el.find('tr[data-id="' + id + '"]').remove(); + if (this.collection.length == 0) { + this.render(); + } + }, this); + var msg = 'massRemoveResult'; + if (count == 1) { + msg = 'massRemoveResultSingle' + } + Espo.Ui.success(self.translate(msg, 'messages').replace('{count}', count)); + } else { + Espo.Ui.success(self.translate('noRecordsRemoved', 'messages')); + } + }.bind(this)); + } } }); @@ -753,6 +767,9 @@ Espo.define('Views.Record.List', 'View', function (Dep) { self.notify('Removed', 'success'); self.$el.find('tr[data-id="' + id + '"]').remove(); self.collection.total--; + if (self.collection.length == 0) { + self.render(); + } }, error: function () { self.notify('Error occured', 'error');