From 8e32f6975e10bde76873edf606525384d6172bd6 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 28 Jan 2015 08:13:35 +0700 Subject: [PATCH] Close #447. Location gets shown on page load. --- .../angular-libs/angular.openfarm.js | 38 ++++++++++++++++++- app/assets/javascripts/guides/new.js | 36 +----------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/angular-libs/angular.openfarm.js b/app/assets/javascripts/angular-libs/angular.openfarm.js index 9f787f69b..dd11e6d8f 100644 --- a/app/assets/javascripts/angular-libs/angular.openfarm.js +++ b/app/assets/javascripts/angular-libs/angular.openfarm.js @@ -62,9 +62,12 @@ openFarmModule.directive('location', [ function ($scope, $element, $attrs) { $scope.loadingText = $attrs.loadingText; - $scope.location = $scope.ngModel; + $scope.$watch('ngModel', function(){ + $scope.location = $scope.ngModel; + }); $scope.getLocation = function(val) { + console.log('getting location'); $scope.ngModel = val; if (geocoder) { geocoder.geocode({ 'address': val }, function (results, status) { @@ -137,3 +140,36 @@ openFarmModule.directive('alerts', ['$timeout', '' }; }]); + +openFarmApp.directive('clearOn', function() { + return function(scope, elem, attr) { + scope.$on('clearOn', function(e, name) { + if(name === attr.clearOn) { + elem[0].value = ''; + } + }); + }; +}); + +// Source: http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/14837021#14837021 +openFarmApp.directive('focusOn', function() { + return function(scope, elem, attr) { + scope.$on('focusOn', function(e, name) { + if(name === attr.focusOn) { + elem[0].focus(); + } + }); + }; +}); + +// Source: http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/14837021#14837021 +openFarmApp.directive('autoFocus', function($timeout) { + return { + restrict: 'AC', + link: function(_scope, _element) { + $timeout(function(){ + _element[0].focus(); + }, 0); + } + }; +}); diff --git a/app/assets/javascripts/guides/new.js b/app/assets/javascripts/guides/new.js index 6b401e94a..0c6d1e55a 100644 --- a/app/assets/javascripts/guides/new.js +++ b/app/assets/javascripts/guides/new.js @@ -48,41 +48,6 @@ openFarmApp.directive('formChecker', function(){ }; }); -openFarmApp.directive('clearOn', function() { - return function(scope, elem, attr) { - scope.$on('clearOn', function(e, name) { - if(name === attr.clearOn) { - elem[0].value = ''; - } - }); - }; -}); - -// TODO: Does this belong here? -// Source: http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/14837021#14837021 -openFarmApp.directive('focusOn', function() { - return function(scope, elem, attr) { - scope.$on('focusOn', function(e, name) { - if(name === attr.focusOn) { - elem[0].focus(); - } - }); - }; -}); - -// TODO: Does this belong here? -// Source: http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/14837021#14837021 -openFarmApp.directive('autoFocus', function($timeout) { - return { - restrict: 'AC', - link: function(_scope, _element) { - $timeout(function(){ - _element[0].focus(); - }, 0); - } - }; -}); - openFarmApp.factory('focus', function ($rootScope, $timeout) { return function(name) { $timeout(function (){ @@ -282,6 +247,7 @@ openFarmApp.controller('newGuideCtrl', ['$scope', '$http', '$filter', $scope.newGuide.featured_image = r.guide.featured_image; $scope.s3upload = r.guide.featured_image; $scope.newGuide.name = r.guide.name; + console.log(r.guide.location); $scope.newGuide.location = r.guide.location; $scope.newGuide.overview = r.guide.overview;