Created
October 10, 2013 18:51
-
-
Save sbosell/6923486 to your computer and use it in GitHub Desktop.
app.js controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lucuma tiene los modulos externales que usamos, safeApply y timeFunctions | |
var app = angular.module('plunker', ['ui.bootstrap', 'ui.slider', 'lucuma']); | |
app.value('stickerJson', 'animacion.json'); | |
app.controller('MainCtrl', function ($scope, $rootScope, $modal, stickerJson, $http) { | |
$scope.stickersData = []; // lista de stickers del servicio web | |
$scope.stickers = []; // lista de servicios para mostrar en la pagina web | |
$http.get(stickerJson).success(function (data) { | |
//$scope.stickersData = [pusheen, anooki, beast]; | |
$scope.stickersData = data; | |
}); | |
// function que abrirá el modal del buton stickers | |
// http://angular-ui.github.io/bootstrap/#/modal | |
$scope.open = function () { | |
// abrir modal | |
var modalInstance = $modal.open({ | |
templateUrl: 'sticker.html', | |
controller: ModalInstanceCtrl, | |
resolve: { | |
items: function () { | |
// queremos mandar stickersData al controlador de Modal | |
return $scope.stickersData; | |
} | |
} | |
}); | |
// despues de hacer click en ok, tenemos que hacer algo con su selecion | |
modalInstance.result.then(function (selectedItem) { | |
$scope.animation = selectedItem; | |
// copiaremos los datos de sticker | |
var cpy = angular.copy(selectedItem); | |
// colocar el sticker en un array, este array es lo que muestra los stickers en la pagina | |
$scope.stickers.push(cpy); | |
}, function () { | |
// dismiss modal | |
}); | |
}; | |
}); | |
// esta funcion es el controller para el modal. mandamos el array de stickers | |
// | |
var ModalInstanceCtrl = function ($scope, $modalInstance, items) { | |
$scope.items = items; | |
$scope.selected = { | |
item: $scope.items[0] | |
}; | |
$scope.ok = function () { | |
$modalInstance.close($scope.selected.item); | |
}; | |
$scope.changeSticker = function (item) { | |
$scope.selected.item = item; | |
$modalInstance.close($scope.selected.item); | |
}; | |
$scope.cancel = function () { | |
$modalInstance.dismiss('cancel'); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment