implement model-based copy for inventories

This commit is contained in:
Jake McDermott 2017-12-05 16:19:59 -05:00
parent a02eda1bea
commit e9ce9621f2
No known key found for this signature in database
GPG Key ID: 3B02CAD476EECB35
2 changed files with 21 additions and 0 deletions

View File

@ -100,6 +100,15 @@ export default ['i18n', function(i18n) {
dataPlacement: 'top',
ngShow: '!inventory.pending_deletion && inventory.summary_fields.user_capabilities.edit'
},
copy: {
label: i18n._('Copy'),
ngClick: 'copyInventory(inventory)',
"class": 'btn-danger btn-xs',
awToolTip: i18n._('Copy inventory'),
dataPlacement: 'top',
// requires future api rbac changes
//ngShow: 'project.summary_fields.user_capabilities.copy'
},
view: {
label: i18n._('View'),
ngClick: 'editInventory(inventory)',

View File

@ -73,6 +73,18 @@ function InventoriesList($scope,
inventory.linkToDetails = (inventory.kind && inventory.kind === 'smart') ? `inventories.editSmartInventory({smartinventory_id:${inventory.id}})` : `inventories.edit({inventory_id:${inventory.id}})`;
}
$scope.copyInventory = inventory => {
Wait('start');
new Inventory('get', inventory.id)
.then(model => model.copy())
.then(copy => $scope.editInventory(copy))
.catch(({ data, status }) => {
const params = { hdr: 'Error!', msg: `Call to copy failed. Return status: ${status}` };
ProcessErrors($scope, data, status, null, params);
})
.finally(() => Wait('stop'));
};
$scope.editInventory = function (inventory) {
if(inventory.kind && inventory.kind === 'smart') {
$state.go('inventories.editSmartInventory', {smartinventory_id: inventory.id});