Skip to content

Commit

Permalink
remove favorite from map
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Mar 7, 2015
1 parent 3ee5c1f commit 314ecff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

angular.module('starter.controllers', [])

.controller('MapCtrl', ['$scope', '$ionicPlatform', 'Settings', 'Favorites', 'Image', 'Faker', 'Id',
function ($scope, $ionicPlatform, Settings, Favorites, Image, Faker, Id) {
.controller('MapCtrl', ['$scope', '$ionicPlatform', '$timeout', 'Settings', 'Favorites', 'Image', 'Faker', 'Id',
function ($scope, $ionicPlatform, $timeout, Settings, Favorites, Image, Faker, Id) {

$scope.generate = function () {
// generate map tiles
Expand Down Expand Up @@ -43,9 +43,15 @@
};

$scope.starred = false;
$scope.star = function () {
Favorites.save($scope.mapData);
$scope.starred = true;
$scope.starToggle = function () {
$timeout(function(){
$scope.starred = !$scope.starred;
if ($scope.starred) {
Favorites.save($scope.mapData);
} else {
Favorites.remove($scope.mapData);
}
});
};
}])

Expand Down Expand Up @@ -109,14 +115,22 @@
$scope.items = Favorites.fetchAll();
});
});
$scope.$on('$ionicView.leave', function (event, data) {
$timeout(function () {
$ionicListDelegate.showDelete(false);
$scope.items = Favorites.fetchAll();
});
});

$scope.toggleDeleteButtons = function () {
$ionicListDelegate.showDelete(!$ionicListDelegate.showDelete());
};

$scope.deleteItem = function (mapData) {
Favorites.remove(mapData);
$scope.items = Favorites.fetchAll();
$timeout(function () {
Favorites.remove(mapData);
$scope.items = Favorites.fetchAll();
});
};
}])

Expand Down
2 changes: 1 addition & 1 deletion www/templates/tab-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ion-nav-buttons side="right">
<button ng-if="mapData.map"
class="button button-icon icon-right icon favorite-button"
ng-class="{'ion-checkmark': starred, 'ion-star': !starred}" ng-click="star()">
ng-class="{'ion-checkmark': starred, 'ion-star': !starred}" ng-click="starToggle()">
</button>
</ion-nav-buttons>
<ion-content class="padding" scroll="false">
Expand Down

0 comments on commit 314ecff

Please sign in to comment.