Clean code. Modal view

This commit is contained in:
Gustavo Maximiliano Cortez 2017-07-26 16:25:12 -03:00
commit 60f049c0d3
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
2 changed files with 6 additions and 68 deletions

View file

@ -2,77 +2,15 @@
angular.module('copayApp.controllers').controller('mercadoLibreCardDetailsController', function($scope, $log, $timeout, $ionicScrollDelegate, bwcError, mercadoLibreService, lodash, ongoingProcess, popupService, externalLinkService) {
$scope.cancelGiftCard = function() {
ongoingProcess.set('cancelingGiftCard', true);
mercadoLibreService.cancelGiftCard($scope.card, function(err, data) {
ongoingProcess.set('cancelingGiftCard', false);
if (err) {
popupService.showAlert('Error canceling gift card', bwcError.msg(err));
return;
}
$scope.card.cardStatus = data.cardStatus;
$timeout(function() {
$ionicScrollDelegate.resize();
$ionicScrollDelegate.scrollTop();
}, 10);
mercadoLibreService.savePendingGiftCard($scope.card, null, function(err) {
$scope.refreshGiftCard();
});
});
};
$scope.remove = function() {
mercadoLibreService.savePendingGiftCard($scope.card, {
remove: true
}, function(err) {
$scope.cancel();
$scope.close();
});
};
$scope.refreshGiftCard = function() {
ongoingProcess.set('updatingGiftCard', true);
mercadoLibreService.getPendingGiftCards(function(err, gcds) {
if (lodash.isEmpty(gcds)) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (err) {
popupService.showAlert('Error', err);
return;
}
var index = 0;
lodash.forEach(gcds, function(dataFromStorage) {
if (++index == Object.keys(gcds).length) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) {
$log.debug("creating gift card");
mercadoLibreService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
popupService.showAlert('Error', bwcError.msg(err));
return;
}
if (!lodash.isEmpty(giftCard)) {
var newData = {};
lodash.merge(newData, dataFromStorage, giftCard);
mercadoLibreService.savePendingGiftCard(newData, null, function(err) {
$log.debug("Saving new gift card");
$scope.card = newData;
$timeout(function() {
$scope.$digest();
});
});
} else $log.debug("pending gift card not available yet");
});
}
});
});
};
$scope.cancel = function() {
$scope.close = function() {
$scope.mercadoLibreCardDetailsModal.hide();
};

View file

@ -1,6 +1,6 @@
<ion-modal-view id="meli-card" ng-controller="mercadoLibreCardDetailsController">
<ion-header-bar align-title="center" class="bar-royal">
<button class="button button-back button-clear" ng-click="cancel()" translate>
<button class="button button-back button-clear" ng-click="close()" translate>
Close
</button>
<h1 class="title" translate>Details</h1>
@ -9,7 +9,7 @@
<ion-content>
<div class="card-head">
<img src="img/mercado-libre/giftcard-pt.svg" alt="Mercado Libre Gift Card" width="230" ng-click="refreshGiftCard()">
<img src="img/mercado-libre/giftcard-pt.svg" alt="Mercado Livre Brazil Gift Card" width="230">
<div class="amount">
{{card.amount | currency : '' : 2}} {{card.currency}}
@ -59,9 +59,9 @@
</span>
</div>
<div class="item item-icon-right" ng-click="openExternalLink(card.invoiceUrl)" translate>
<div class="item item-icon-right" ng-click="openExternalLink(card.invoiceUrl)">
<i class="icon bp-arrow-right"></i>
See invoice
<span translate>See invoice</span>
</div>
</div>