UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

114 lines (102 loc) 3.19 kB
(function (module) { 'use strict'; module .controller('instapageController', instapageController); instapageController.$inject = ['$scope', 'lodash', 'Onboarding', 'CoupleAccount','Category', 'ProductTemplate', '$filter', 'instapageServices']; function instapageController($scope, lodash, Onboarding, CoupleAccount, Category, ProductTemplate, $filter, instapageServices) { $scope.view = { step: 0, account: { productsRegistryList: [], campa_a: 'Luna de miel', weddingData: { nameP1: '', nameP2: '' } } } $scope.textBtn = "Siguiente"; var categories = $scope.categories = Category.find({ filter: { where: { visible: false } } }); $scope.selectCategory = function (category) { $scope.categorySelected = category; }; $scope.prevStep = function() { $scope.view.step -= 1; if($scope.view.step == 3) { $scope.textBtn = "Continuar"; } } $scope.nextStep = function() { switch($scope.view.step) { case 0: if(!$scope.view.account.weddingData.nameP1) { $scope.error_p1 = "Falta nombre "; } if(!$scope.view.account.weddingData.nameP2) { $scope.error_p2 = "Falta nombre"; } if($scope.view.account.weddingData.nameP1 && $scope.view.account.weddingData.nameP2) { $scope.error_p1 = null; $scope.error_p2 = null; $scope.view.step += 1; } break; case 1: $scope.view.account.url = $scope.view.account.currentUrl; instapageServices.account = $scope.view.account; $scope.textBtn = "Continuar"; $scope.view.step += 5; break; case 2: $scope.view.step += 1; break; case 3: $scope.textBtn = "Siguiente"; if($scope.categorySelected) { var filter = {"where":{"id":{"nin":[]},"categoriesIds":$scope.categorySelected.id}} ProductTemplate.find({filter: filter},function(err , products) { var productCategories = $scope.categorySelected.name; lodash.forEach(products, function (product) { $scope.view.account.productsRegistryList.push(product); $analytics.eventTrack('Item Added to registry', { 'Name': product.name, 'Category': productCategories, 'Brand': product.store ? product.store.name : '', 'Price': product.price, 'Edited': false //there always will be false. }); }); $scope.view.step += 1; }); } else { $scope.view.step += 1; } break; case 4: if($scope.view.account.currentUrl) { CoupleAccount.isValidURL({url: $scope.view.account.currentUrl}).$promise.then(function(data) { if(data.isValid) { $scope.view.step += 1; } else { $scope.urlInvalid = true; } }); } else { $scope.view.step += 1; } break; case 5: $scope.view.account.url = $scope.view.account.currentUrl; instapageServices.account = $scope.view.account; $scope.view.step += 1; break; } } } })(angular.module('uniko.instapage'));