UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

62 lines (55 loc) 1.91 kB
(function (module) { module.controller('AdminExperienceShowController', AdminExperienceShowController) AdminExperienceShowController.$inject = ['$scope', '$rootScope', '$stateParams', '$timeout', '$state', '$uibModal', 'toastr', 'Experiences']; function AdminExperienceShowController($scope, $rootScope, $stateParams, $timeout, $state, $uibModal, toastr, Experiences) { $scope.view = { products: [], experience: { id: $stateParams.id, productsRegistryList: [] }, load: true }; $scope.getExperience = function() { Experiences.findOne({ id: $scope.view.experience.id, }).$promise.then(function(experience) { $scope.view.experience = experience; $scope.view.load = false; }).catch(function(err) { $scope.view.load = false; console.log(err); toastr.error('No se puso cargar el detalle'); }); } $scope.add = function() { var modalInstance = $uibModal.open({ animation: true, templateUrl: 'partials/admin.experiences.add.articles.html', controller: 'AdminExperiencesAddArticlesController', resolve: { experience: $scope.view.experience } }); modalInstance.result.then(function() { $scope.getExperience(); }, $scope.error).catch($scope.error) } $scope.remove = function(article) { var articles = []; _.each($scope.view.experience.productsRegistryList, function(product) { if(product.id != article.id)articles.push(product); }); $scope.view.experience.productsRegistryList = articles; Experiences.save({id: $scope.view.experience.id},$scope.view.experience).$promise.then(function(data) { $scope.view.experience = data; }, $scope.error).catch($scope.error); } $scope.error = function(err) { if(err === 'cancel') return false; toastr.error(err); $scope.getExperience(); } $scope.getExperience(); } })(angular.module('uniko.admin.experiences'));