From 142a323efdc4f69b2880a8f0c8fd7cf95e5c0aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 17 Jul 2015 15:34:15 +0200 Subject: [PATCH] fix(save as): fixed issue with save as and overwriting a dashboard with the same name --- .../features/dashboard/saveDashboardAsCtrl.js | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/public/app/features/dashboard/saveDashboardAsCtrl.js b/public/app/features/dashboard/saveDashboardAsCtrl.js index 16dc291e9fa..ec8327755f8 100644 --- a/public/app/features/dashboard/saveDashboardAsCtrl.js +++ b/public/app/features/dashboard/saveDashboardAsCtrl.js @@ -14,16 +14,33 @@ function (angular) { $scope.clone.title = $scope.clone.title + " Copy"; }; + 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); + + $scope.appEvent('dashboard-saved', $scope.clone); + $scope.dismiss(); + }); + } + $scope.saveClone = function() { - backendSrv.saveDashboard($scope.clone) - .then(function(result) { - $scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + $scope.clone.title]); + saveDashboard({overwrite: false}).then(null, function(err) { + if (err.data && err.data.status === "name-exists") { + err.isHandled = true; - $location.url('/dashboard/db/' + result.slug); - - $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}); + } + }); + } + }); }; });