Browse Source

fix(save as): fixed issue with save as and overwriting a dashboard with the same name

Torkel Ödegaard 10 years ago
parent
commit
142a323efd
1 changed files with 25 additions and 8 deletions
  1. 25 8
      public/app/features/dashboard/saveDashboardAsCtrl.js

+ 25 - 8
public/app/features/dashboard/saveDashboardAsCtrl.js

@@ -14,16 +14,33 @@ function (angular) {
       $scope.clone.title = $scope.clone.title + " Copy";
     };
 
-    $scope.saveClone = function() {
-      backendSrv.saveDashboard($scope.clone)
-        .then(function(result) {
-          $scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + $scope.clone.title]);
+    function saveDashboard(options) {
+      return backendSrv.saveDashboard($scope.clone, options).then(function(result) {
+        $scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + $scope.clone.title]);
+
+        $location.url('/dashboard/db/' + result.slug);
 
-          $location.url('/dashboard/db/' + result.slug);
+        $scope.appEvent('dashboard-saved', $scope.clone);
+        $scope.dismiss();
+      });
+    }
+
+    $scope.saveClone = function() {
+      saveDashboard({overwrite: false}).then(null, function(err) {
+        if (err.data && err.data.status === "name-exists") {
+          err.isHandled = true;
 
-          $scope.appEvent('dashboard-saved', $scope.clone);
-          $scope.dismiss();
-        });
+          $scope.appEvent('confirm-modal', {
+            title: 'Another dashboard with the same name exists',
+            text: "Would you still like to save this dashboard?",
+            yesText: "Save & Overwrite",
+            icon: "fa-warning",
+            onConfirm: function() {
+              saveDashboard({overwrite: true});
+            }
+          });
+        }
+      });
     };
   });