cobuild-angular-stack
Version:
Base stack angular sass jade gulp
69 lines (58 loc) • 2.36 kB
JavaScript
(function () {
'use strict';
angular.module('uniko.authSatellizer')
.controller('GiftReceivedController', GiftReceivedController);
GiftReceivedController.$inject = ['$scope', 'CoupleAccount', 'LoopBackAuth', 'toastr', '$uibModal', 'lodash'];
function GiftReceivedController($scope, CoupleAccount, LoopBackAuth, toastr, $uibModal, lodash) {
var controller = this;
$scope.user = CoupleAccount.getCurrent();
$scope.cantReceived = 0;
$scope.popup = function() {
if (!($scope.user).payInformationData.isPaid) {
var modalInstance;
modalInstance = $uibModal.open({
animation: true,
templateUrl: 'partials/auth.pay.modal.html',
controller: 'CoupleCheckoutModalController',
controllerAs: 'ccCtrl',
size: 'lg'
});
return modalInstance.result
.then(function (result) {
$translate('copy-url').then(function (translation) {
toastr.success(translation);
});
});
}
}
setTimeout(function(){
$scope.popup();
}, 10000);
$scope.user
.$promise
.then(function () {
return loadData();
});
function loadData() {
$scope.cantReceived = 0;
return CoupleAccount
.cashOutInformation({id: $scope.user.id})
.$promise
.then(function (cashOutInformation) {
$scope.user.cashOutInformationList = cashOutInformation;
return $scope.user;
})
.then(function (user) {
lodash.forEach(user.giftList, function (gift) {
$scope.cantReceived += gift.gift.price;
});
lodash.forEach(user.cashOutInformationList, function (cashout) {
$scope.cantReceived -= cashout.requiredAmount;
});
});
}
$scope.$on('cashoutUpdate', function () {
loadData();
});
}
})();