import revert

This commit is contained in:
Yuri Kuznetsov
2014-04-16 12:36:06 +03:00
parent dbf1e7bf44
commit cfb9d3640c
4 changed files with 53 additions and 2 deletions

View File

@@ -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(

View File

@@ -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'],
);
}

View File

@@ -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>

View File

@@ -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)
});
}
});
});