From 01e393cf8c5b821f7f025c44eb676fa3404c8262 Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Thu, 16 Jan 2014 13:44:13 +0200 Subject: [PATCH] use ngForm in queryFiddle page for detecting pristine and dirty states --- rd_ui/app/scripts/controllers.js | 15 ++---- rd_ui/app/views/queryfiddle.html | 90 ++++++++++++++++---------------- 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 87e05b3f..923b6fb8 100644 --- a/rd_ui/app/scripts/controllers.js +++ b/rd_ui/app/scripts/controllers.js @@ -35,10 +35,9 @@ var QueryFiddleCtrl = function ($scope, $window, $routeParams, $http, $location, growl, notifications, Query) { var leavingPageText = "You will lose your changes if you leave"; - var pristineQuery = null; $window.onbeforeunload = function(){ - if (currentUser.canEdit($scope.query) && $scope.queryChanged) { + if (currentUser.canEdit($scope.query) && $scope.queryForm.$dirty) { return leavingPageText; } } @@ -60,7 +59,7 @@ return; } - if($scope.queryChanged && + if($scope.queryForm.$dirty && !confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) { event.preventDefault(); } else { @@ -92,8 +91,7 @@ } delete $scope.query.latest_query_data; $scope.query.$save(function (q) { - pristineQuery = q.query; - $scope.queryChanged = false; + $scope.queryForm.$setPristine(); if (duplicate) { growl.addInfoMessage("Query duplicated.", {ttl: 2000}); @@ -186,7 +184,7 @@ if ($routeParams.queryId != undefined) { $scope.query = Query.get({id: $routeParams.queryId}, function(q) { - pristineQuery = q.query; + $scope.queryForm.$setPristine(); $scope.queryResult = $scope.query.getQueryResult(); }); } else { @@ -197,11 +195,6 @@ $scope.$watch('query.name', function() { $scope.$parent.pageTitle = $scope.query.name; }); - $scope.$watch('query.query', function(q) { - if (q) { - $scope.queryChanged = (q != pristineQuery); - } - }); $scope.executeQuery = function() { $scope.queryResult = $scope.query.getQueryResult(0); diff --git a/rd_ui/app/views/queryfiddle.html b/rd_ui/app/views/queryfiddle.html index 7ab0b32d..37a5aeaa 100644 --- a/rd_ui/app/views/queryfiddle.html +++ b/rd_ui/app/views/queryfiddle.html @@ -1,53 +1,55 @@
-
-
-

+
+
+
+

+

+ +

+

- -

-

-

- -

-
-
- - -
- - Download Data Set - - - -
- - - -
+ +

+
+ -
- -
+
+ + Download Data Set + + -
- Executing query... - -
-
- Query in queue... - -
-
Error running query: {{queryResult.getError()}}
+
+ + + +
+
+ +
+ +
+ +
+ Executing query... + +
+
+ Query in queue... + +
+
Error running query: {{queryResult.getError()}}
+