From f2f61a1fc918dcbb19964c3afa2bebb384216c16 Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Tue, 25 Mar 2014 14:04:18 +0200 Subject: [PATCH] [#138] onQuerySave callback --- rd_ui/app/scripts/controllers/query_edit.js | 11 +++++++++++ rd_ui/app/scripts/controllers/query_view.js | 15 +++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/rd_ui/app/scripts/controllers/query_edit.js b/rd_ui/app/scripts/controllers/query_edit.js index 6d055394..5b65e5e6 100644 --- a/rd_ui/app/scripts/controllers/query_edit.js +++ b/rd_ui/app/scripts/controllers/query_edit.js @@ -7,12 +7,14 @@ var isNewQuery = !$scope.query.id, + queryText = $scope.query.query, shortcuts = { 'meta+s': $scope.saveQuery }; $scope.sourceMode = true; $scope.canEdit = currentUser.canEdit($scope.query); + $scope.isDirty = false; $scope.newVisualization = undefined; @@ -21,6 +23,11 @@ return $scope.isDirty; }); + $scope.onQuerySave = function(savedQuery) { + $scope.isDirty = false; + queryText = savedQuery.query; + }; + $scope.deleteVisualization = function($e, vis) { $e.preventDefault(); if (confirm('Are you sure you want to delete ' + vis.name + ' ?')) { @@ -36,6 +43,10 @@ } }; + $scope.$watch('query.query', function(newQueryText) { + $scope.isDirty = (newQueryText !== queryText); + }); + $scope.$on('$destroy', function destroy() { KeyboardShortcuts.unbind(shortcuts); }); diff --git a/rd_ui/app/scripts/controllers/query_view.js b/rd_ui/app/scripts/controllers/query_view.js index abe944be..f39d3a64 100644 --- a/rd_ui/app/scripts/controllers/query_view.js +++ b/rd_ui/app/scripts/controllers/query_view.js @@ -2,11 +2,7 @@ 'use strict'; function QueryViewCtrl($scope, $route, $location, notifications, growl, Query, DataSource) { - var - DEFAULT_TAB = 'table', - queryText; - - $scope.isDirty = false; + var DEFAULT_TAB = 'table'; $scope.query = $route.current.locals.query; $scope.queryResult = $scope.query.getQueryResult(); @@ -19,7 +15,7 @@ $scope.query.data_source_id = $scope.query.data_source_id || dataSources[0].id; }); - queryText = $scope.query.query; + $scope.onQuerySave = angular.noop; $scope.lockButton = function(lock) { $scope.queryExecuting = lock; @@ -39,8 +35,7 @@ delete $scope.query.latest_query_data; $scope.query.$save(function(savedQuery) { - queryText = savedQuery.query; - $scope.isDirty = false; + $scope.onQuerySave(savedQuery); if (oldId != savedQuery.id) { // redirect to new/duplicated query page @@ -80,10 +75,6 @@ $scope.executeQuery(); }; - $scope.$watch('query.query', function(newQueryText) { - $scope.isDirty = (newQueryText !== queryText); - }); - $scope.$watch('query.name', function() { $scope.$parent.pageTitle = $scope.query.name; });