diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index 9ca6f190c63..cdea7aab3c6 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -13,6 +13,7 @@ define([ './viewStateSrv', './time_srv', './unsavedChangesSrv', + './unsaved_changes_modal', './timepicker/timepicker', './graphiteImportCtrl', './impression_store', diff --git a/public/app/features/dashboard/unsavedChangesSrv.js b/public/app/features/dashboard/unsavedChangesSrv.js index df38c7843f8..766ebce0b59 100644 --- a/public/app/features/dashboard/unsavedChangesSrv.js +++ b/public/app/features/dashboard/unsavedChangesSrv.js @@ -134,34 +134,31 @@ function(angular, _) { return currentJson !== originalJson; }; + p.discardChanges = function() { + this.original = null; + this.gotoNext(); + }; + p.open_modal = function() { - var tracker = this; - var dashboard = this.current; - - var modalScope = this.scope.$new(); - var clone = dashboard.getSaveModelClone(); - - modalScope.clone = clone; - modalScope.ignore = function() { - tracker.original = null; - tracker.goto_next(); - }; - - var cancel = $rootScope.$on('dashboard-saved', function() { - cancel(); - $timeout(function() { - tracker.goto_next(); - }); - }); - $rootScope.appEvent('show-modal', { - src: 'public/app/partials/unsaved-changes.html', - scope: modalScope, - modalClass: 'modal--narrow' + templateHtml: '', + modalClass: 'modal--narrow confirm-modal' }); }; - p.goto_next = function() { + p.saveChanges = function() { + var self = this; + var cancel = $rootScope.$on('dashboard-saved', function() { + cancel(); + $timeout(function() { + self.gotoNext(); + }); + }); + + $rootScope.appEvent('save-dashboard'); + }; + + p.gotoNext = function() { var baseLen = $location.absUrl().length - $location.url().length; var nextUrl = this.next.substring(baseLen); $location.url(nextUrl); @@ -169,7 +166,8 @@ function(angular, _) { this.Tracker = Tracker; this.init = function(dashboard, scope) { - return new Tracker(dashboard, scope, 1000); + this.tracker = new Tracker(dashboard, scope, 1000); + return this.tracker; }; }); }); diff --git a/public/app/features/dashboard/unsaved_changes_modal.ts b/public/app/features/dashboard/unsaved_changes_modal.ts new file mode 100644 index 00000000000..c206ecc2d21 --- /dev/null +++ b/public/app/features/dashboard/unsaved_changes_modal.ts @@ -0,0 +1,63 @@ +/// + +import coreModule from 'app/core/core_module'; + +const template = ` + +`; + +export class UnsavedChangesModalCtrl { + clone: any; + dismiss: () => void; + + /** @ngInject */ + constructor(private $rootScope, private unsavedChangesSrv) { + } + + discard() { + this.dismiss(); + this.unsavedChangesSrv.tracker.discardChanges(); + } + + save() { + this.dismiss(); + this.unsavedChangesSrv.tracker.saveChanges(); + } +} + +export function unsavedChangesModalDirective() { + return { + restrict: 'E', + template: template, + controller: UnsavedChangesModalCtrl, + bindToController: true, + controllerAs: 'ctrl', + scope: {dismiss: "&"} + }; +} + +coreModule.directive('unsavedChangesModal', unsavedChangesModalDirective); diff --git a/public/app/partials/unsaved-changes.html b/public/app/partials/unsaved-changes.html deleted file mode 100644 index 949cef55e7b..00000000000 --- a/public/app/partials/unsaved-changes.html +++ /dev/null @@ -1,54 +0,0 @@ - -