UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

72 lines (64 loc) 3.22 kB
(function (module) { 'use strict'; module.controller('ImportController', ImportController); ImportController.$inject = ['$scope', '$rootScope', 'CoupleAccount', '$translate', 'toastr', '$state', '$timeout', '$interval', 'CAccounts']; function ImportController($scope, $rootScope, CoupleAccount, $translate, toastr, $state, $timeout, $interval, CAccounts) { var importCtrl = this; $scope.event = {}; $scope.coupleAccount = CoupleAccount.getCurrent(); $scope.sources = [ { id: 'liverpool', name: 'Liverpool' }, { id: 'palaciohierro', name: 'El Palacio de Hierro' } ]; $scope.method = { id: $scope.sources[0].id }; $scope.coupleAccount .$promise.then(function () { var coupleAccountId = $scope.coupleAccount.id; $scope.url = 'http://front.uniko.co/' + $scope.coupleAccount.url; importCtrl.import = function (event, method) { $rootScope.pendingImport = true; $scope.coupleAccount .$prototype$import({method: method, eventId: event.id}, function (response) { $timeout(function () { $translate('import-count').then(function (translation) { $translate('products').then(function (translationProducts) { toastr.success(translation + ' ' + response.count + ' ' + translationProducts); $state.go('registry'); }); }); }, 1000); var intervalP = $interval(function () { CAccounts.checkImport(coupleAccountId, event.id, 'liverpool') .then(function (response) { if (response.data.finished) { $state.go('registry', {}, {reload: true}); $rootScope.pendingImport = false; $interval.cancel(intervalP); } }); }, 5000); }, function (response) { $rootScope.pendingImport = false; $timeout(function () { $translate('import-count').then(function (translation) { $translate('products').then(function (translationProducts) { toastr.error(translation + ' 0 ' + translationProducts); $state.go('registry'); }); }); }, 1000); }); }; }); } })(angular.module('uniko.import'));