[#138] onQuerySave callback

This commit is contained in:
Amir Nissim 2014-03-25 14:04:18 +02:00
parent b93132e5d9
commit f2f61a1fc9
2 changed files with 14 additions and 12 deletions

View File

@ -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);
});

View File

@ -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;
});