From 60f049c0d31fe71410494b68a49bcd5107dde2ed Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 26 Jul 2017 16:25:12 -0300 Subject: [PATCH] Clean code. Modal view --- .../modals/mercadoLibreCardDetails.js | 66 +------------------ .../modals/mercadolibre-card-details.html | 8 +-- 2 files changed, 6 insertions(+), 68 deletions(-) diff --git a/src/js/controllers/modals/mercadoLibreCardDetails.js b/src/js/controllers/modals/mercadoLibreCardDetails.js index 1b1628c9d..cbb2a6af6 100644 --- a/src/js/controllers/modals/mercadoLibreCardDetails.js +++ b/src/js/controllers/modals/mercadoLibreCardDetails.js @@ -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(); }; diff --git a/www/views/modals/mercadolibre-card-details.html b/www/views/modals/mercadolibre-card-details.html index f4366ad79..3d272e3de 100644 --- a/www/views/modals/mercadolibre-card-details.html +++ b/www/views/modals/mercadolibre-card-details.html @@ -1,6 +1,6 @@ -

Details

@@ -9,7 +9,7 @@
- Mercado Libre Gift Card + Mercado Livre Brazil Gift Card
{{card.amount | currency : '' : 2}} {{card.currency}} @@ -59,9 +59,9 @@
-
+
- See invoice + See invoice