mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
import revert
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
<br>
|
||||
{{translate 'Updated' scope='Import'}}: {{result.countUpdated}}
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
{{#if result.countCreated}}
|
||||
<button class="btn btn-danger" data-action="revert">{{translate 'Revert' scope='Import'}}</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user