Skip to content

Commit

Permalink
Merge pull request #475 from simonv3/edit-guides
Browse files Browse the repository at this point in the history
Close #447. Location gets shown on page load.
  • Loading branch information
simonv3 committed Jan 28, 2015
2 parents 13fc43a + 8e32f69 commit 4d2d463
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
38 changes: 37 additions & 1 deletion app/assets/javascripts/angular-libs/angular.openfarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -137,3 +140,36 @@ openFarmModule.directive('alerts', ['$timeout',
'</alert>'
};
}]);

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);
}
};
});
36 changes: 1 addition & 35 deletions app/assets/javascripts/guides/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (){
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4d2d463

Please sign in to comment.