From cfb9d3640c5fc7e28942352b96f3d4a297dcb4de Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 16 Apr 2014 12:36:06 +0300 Subject: [PATCH] import revert --- application/Espo/Controllers/Import.php | 5 ++++ application/Espo/Services/Import.php | 16 ++++++++++- .../client/res/templates/import/step-3.tpl | 6 ++++ frontend/client/src/views/import/step3.js | 28 ++++++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/application/Espo/Controllers/Import.php b/application/Espo/Controllers/Import.php index 4d1b7b0cc6..d8d101608b 100644 --- a/application/Espo/Controllers/Import.php +++ b/application/Espo/Controllers/Import.php @@ -54,6 +54,11 @@ class Import extends \Espo\Core\Controllers\Base ); } + public function actionRevert($params, $data) + { + return $this->getService('Import')->revert($data['entityType'], $data['idsToRemove']); + } + public function actionCreate($params, $data) { $importParams = array( diff --git a/application/Espo/Services/Import.php b/application/Espo/Services/Import.php index 515800d414..f40e1c0b0d 100644 --- a/application/Espo/Services/Import.php +++ b/application/Espo/Services/Import.php @@ -159,7 +159,20 @@ class Import extends \Espo\Core\Services\Base $string = substr($string, $i); return $o; } - + + public function revert($scope, array $idsToRemove) + { + $ids = array(); + if (!empty($scope) && !empty($idsToRemove)) { + foreach ($idsToRemove as $id) { + $entity = $this->getEntityManager()->getEntity($scope, $id); + if ($this->getEntityManager()->removeEntity($entity)) { + $ids[] = $id; + } + } + } + return $ids; + } public function import($scope, array $fields, $attachmentId, array $params = array()) { @@ -207,6 +220,7 @@ class Import extends \Espo\Core\Services\Base return array( 'countCreated' => count($result['importedIds']), 'countUpdated' => count($result['updatedIds']), + 'importedIds' => $result['importedIds'], 'duplicateIds' => $result['duplicateIds'], ); } diff --git a/frontend/client/res/templates/import/step-3.tpl b/frontend/client/res/templates/import/step-3.tpl index 36a40258c2..45ee31a39e 100644 --- a/frontend/client/res/templates/import/step-3.tpl +++ b/frontend/client/res/templates/import/step-3.tpl @@ -7,6 +7,12 @@
{{translate 'Updated' scope='Import'}}: {{result.countUpdated}} + +
+ {{#if result.countCreated}} + + {{/if}} +
diff --git a/frontend/client/src/views/import/step3.js b/frontend/client/src/views/import/step3.js index 0aef34e43e..40a11ec6a8 100644 --- a/frontend/client/src/views/import/step3.js +++ b/frontend/client/src/views/import/step3.js @@ -31,12 +31,38 @@ Espo.define('Views.Import.Step3', 'View', function (Dep) { }; }, + events: { + 'click button[data-action="revert"]': function () { + this.revert(); + }, + }, + setup: function () { this.formData = this.options.formData; this.scope = this.formData.entityType; this.result = this.options.result || {}; - }, + }, + + revert: function () { + this.notify('Please wait...'); + + this.$el.find('[data-action="revert"]').addClass('disabled'); + + $.ajax({ + type: 'POST', + url: 'Import/action/revert', + data: JSON.stringify({ + entityType: this.formData.entityType, + idsToRemove: this.result.importedIds + }), + timeout: 150000, + success: function (result) { + Espo.Ui.success(this.translate('Reverted', 'labels', 'Import')); + this.$el.find('[data-action="revert"]').remove(); + }.bind(this) + }); + } }); });