From 5218f4f1821d46b7915b7525e1c36fc537dcdf1c 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 | 82 ++++++++++++++++---------------- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 87e05b3f77..923b6fb858 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 7ab0b32d98..37a5aeaaf0 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... +
- - -
- Executing query... - -
-
- Query in queue... - -
-
Error running query: {{queryResult.getError()}}
+
Error running query: {{queryResult.getError()}}
+