New backend copy package support
[osm/UI.git] / skyquake / plugins / composer / src / src / stores / CatalogDataStore.js
index 9345bc3..06d1342 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -460,27 +460,10 @@ class CatalogDataStore {
        }
 
        duplicateSelectedCatalogItem() {
-               const item = this.getFirstSelectedCatalogItem();
-               if (item) {
-                       const newItem = _cloneDeep(item);
-                       newItem.name = newItem.name + ' Copy';
-                       newItem.id = guid();
-                       UID.assignUniqueId(newItem.uiState);
-                       const nsd = this.addNewItemToCatalog(newItem);
-                       this.selectCatalogItem(nsd);
-                       nsd.uiState.isNew = true;
-                       nsd.uiState.modified = true;
-                       nsd.uiState['instance-ref-count'] = 0;
-                       // note duplicated items get a new id, map the layout position
-                       // of the old id to the new id in order to preserve the layout
-                       if (nsd.uiState.containerPositionMap) {
-                               nsd.uiState.containerPositionMap[nsd.id] = nsd.uiState.containerPositionMap[item.id];
-                               delete nsd.uiState.containerPositionMap[item.id];
-                       }
-                       setTimeout(() => {
-                               this.selectCatalogItem(nsd);
-                               CatalogItemsActions.editCatalogItem.defer(nsd);
-                       }, 200);
+               // make request to backend to duplicate an item
+               const srcItem = this.getFirstSelectedCatalogItem();
+               if (srcItem) {
+                       CatalogPackageManagerActions.copyCatalogPackage.defer(srcItem);
                }
        }
 
@@ -591,6 +574,13 @@ class CatalogDataStore {
                        this.resetSelectionState();
                }
        }
+       saveCatalogItemError(data){
+               let error = JSON.parse(data.error.responseText);
+               const errorMsg = error && error.body && error.body['rpc-reply'] && JSON.stringify(error.body['rpc-reply']['rpc-error'], null, ' ')
+               ComposerAppActions.showError.defer({
+                       errorMessage: 'Unable to save the descriptor.\n' + errorMsg
+               });
+       }
 }
 
 export default alt.createStore(CatalogDataStore, 'CatalogDataStore');