Wallet/src/js/controllers/preferencesDelete.js

66 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
2016-06-13 15:25:40 -03:00
function($scope, $rootScope, $filter, $timeout, $modal, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService, ongoingProcess) {
2016-05-31 19:02:00 -03:00
var isCordova = platformInfo.isCordova;
2015-03-06 12:00:10 -03:00
this.isCordova = isCordova;
this.error = null;
2015-07-29 20:12:37 +09:00
var delete_msg = gettextCatalog.getString('Are you sure you want to delete this wallet?');
2015-07-29 12:37:51 -03:00
var accept_msg = gettextCatalog.getString('Accept');
2015-07-29 20:12:37 +09:00
var cancel_msg = gettextCatalog.getString('Cancel');
var confirm_msg = gettextCatalog.getString('Confirm');
2015-03-06 12:00:10 -03:00
var _modalDeleteWallet = function() {
$scope.title = delete_msg;
$scope.accept_msg = accept_msg;
$scope.cancel_msg = cancel_msg;
$scope.confirm_msg = confirm_msg;
$scope.okAction = doDeleteWallet;
$scope.loading = false;
$ionicModal.fromTemplateUrl('views/modals/confirmation.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.confirmationModal = modal;
$scope.confirmationModal.show();
2015-03-06 12:00:10 -03:00
});
};
2016-06-06 12:21:15 -03:00
var doDeleteWallet = function() {
2016-06-13 15:25:40 -03:00
ongoingProcess.set('deletingWallet', true);
var fc = profileService.focusedClient;
2015-05-14 10:39:22 -03:00
var name = fc.credentials.walletName;
var walletName = (fc.alias || '') + ' [' + name + ']';
var self = this;
2015-03-06 12:00:10 -03:00
2016-06-06 12:21:15 -03:00
profileService.deleteWalletClient(fc, function(err) {
2016-06-13 15:25:40 -03:00
ongoingProcess.set('deletingWallet', false);
if (err) {
self.error = err.message || err;
} else {
2015-11-06 16:54:25 -03:00
notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', {
walletName: walletName
}));
2016-04-11 10:50:50 -03:00
applicationService.restart();
}
});
2015-03-06 12:00:10 -03:00
};
this.deleteWallet = function() {
if (isCordova) {
navigator.notification.confirm(
2015-07-29 20:12:37 +09:00
delete_msg,
2015-03-06 12:00:10 -03:00
function(buttonIndex) {
2015-07-29 12:37:51 -03:00
if (buttonIndex == 1) {
2016-06-06 12:21:15 -03:00
doDeleteWallet();
2015-03-06 12:00:10 -03:00
}
},
2015-07-29 12:37:51 -03:00
confirm_msg, [accept_msg, cancel_msg]
2015-03-06 12:00:10 -03:00
);
} else {
_modalDeleteWallet();
}
};
2015-07-29 12:37:51 -03:00
});