MassRemove and remove fixes

This commit is contained in:
Yuri Kuznetsov
2014-10-23 16:52:51 +03:00
parent 873c683ffb
commit 2ab50c2dcc
5 changed files with 75 additions and 27 deletions
+4 -4
View File
@@ -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)
@@ -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",
+21
View File
@@ -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)
{
@@ -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');
},
+36 -19
View File
@@ -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');