Created
February 16, 2016 16:50
-
-
Save fhbash/2a7858aa3d153dec87c9 to your computer and use it in GitHub Desktop.
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
| myAppMobile.angular.controller('filtroController', ['$rootScope', '$scope', '$http', '$location', '$window', | |
| function ($rootScope, $scope, $http, $location, $window) { | |
| $scope.banners_loaded = false; | |
| $scope.detalhes_loaded = false; | |
| $scope.show_subcat_list = false; | |
| $scope.filtro_desc = $rootScope.soofertas_filtro_desc; | |
| $scope.filtro_path = $rootScope.soofertas_filtro_path; | |
| $scope.show_detalhes = false; | |
| $scope.subcategorias = []; | |
| $scope.goBack = function () { | |
| $scope.show_detalhes = false; | |
| }; | |
| existe = function (slug) { | |
| var res = false; | |
| for (var i = 0; i < $scope.subcategorias.length; i++) { | |
| if ($scope.subcategorias[i].slug == slug){ | |
| res = true; | |
| } | |
| } | |
| return res; | |
| }; | |
| $scope.toggle_subcat_list = function () { | |
| $scope.show_subcat_list = !$scope.show_subcat_list; | |
| }; | |
| $scope.onItemClicked = function (item) { | |
| $rootScope.produtoClicked = item; | |
| $scope.produto = item; | |
| if (debug) { | |
| console.log('Produto clicked'); | |
| console.log($rootScope.produtoClicked); | |
| } | |
| $scope.show_detalhes = true; | |
| //$location.path("/detailspage"); | |
| }; | |
| $scope.onSubCatClick = function (slug) { | |
| $rootScope.soofertas_filtro = $rootScope.soofertas_filtro + '&subcat=' + slug; | |
| $window.location.reload(); | |
| }; | |
| $scope.getDestaques = function () { | |
| if (debug) { | |
| console.log('Carregando Filtro...'); | |
| console.log($rootScope.soofertas_filtro); | |
| } | |
| $http.get(domain + '/api/v1/filtrar/?' + $rootScope.soofertas_filtro).then(function (result) { | |
| if (debug) { | |
| console.log(result); | |
| } | |
| $scope.detalhes = result.data; | |
| $scope.detalhes_loaded = true; | |
| for (var i = 0; i < result.data.length; i++) { | |
| if (result.data[i].produto.subcategoria != null) { | |
| var obj = { | |
| slug: result.data[i].produto.subcategoria.slug, | |
| descricao: result.data[i].produto.subcategoria.descricao | |
| }; | |
| if (!existe(obj.slug)) { | |
| $scope.subcategorias.push(obj); | |
| } | |
| } | |
| } | |
| console.log($scope.subcategorias); | |
| }, function (err) { | |
| console.error(err); | |
| }); | |
| }; | |
| $scope.getBanners = function () { | |
| if (debug) { | |
| console.log('Carregando Banners...'); | |
| } | |
| $http.get(domain + '/api/v1/banners/').then(function (result) { | |
| if (debug) { | |
| console.log(result); | |
| } | |
| $scope.banners = result.data; | |
| $scope.banners_loaded = true; | |
| }, function (err) { | |
| console.error(err); | |
| }); | |
| }; | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment