Wallet/src/js/controllers/preferencesDelete.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
function($scope, $rootScope, $filter, $timeout, $modal, $log, notification, profileService, isCordova, go, gettext, gettextCatalog) {
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?');
var ok_msg = gettextCatalog.getString('OK');
var cancel_msg = gettextCatalog.getString('Cancel');
var confirm_msg = gettextCatalog.getString('Confirm');
2015-03-06 12:00:10 -03:00
var _modalDeleteWallet = function() {
var ModalInstanceCtrl = function($scope, $modalInstance, gettext) {
2015-07-29 20:12:37 +09:00
$scope.title = delete_msg;
2015-03-06 12:00:10 -03:00
$scope.loading = false;
$scope.ok = function() {
$scope.loading = true;
2015-07-29 20:12:37 +09:00
$modalInstance.close(ok_msg);
2015-03-06 12:00:10 -03:00
};
$scope.cancel = function() {
2015-07-29 20:12:37 +09:00
$modalInstance.dismiss(cancel_msg);
2015-03-06 12:00:10 -03:00
};
};
var modalInstance = $modal.open({
templateUrl: 'views/modals/confirmation.html',
windowClass: 'full',
controller: ModalInstanceCtrl
});
modalInstance.result.then(function(ok) {
if (ok) {
_deleteWallet();
}
});
};
var _deleteWallet = function() {
var fc = profileService.focusedClient;
2015-05-14 10:39:22 -03:00
var name = fc.credentials.walletName;
2015-07-14 17:39:20 -03:00
var walletName = (fc.alias||'') + ' [' + name + ']';
var self = this;
2015-03-06 12:00:10 -03:00
profileService.deleteWalletFC({}, function(err) {
if (err) {
self.error = err.message || err;
} else {
2015-07-29 20:12:37 +09:00
notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', {walletName: walletName}));
}
});
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) {
if (buttonIndex == 2) {
_deleteWallet();
}
},
2015-07-29 20:12:37 +09:00
confirm_msg, [cancel_msg, ok_msg]
2015-03-06 12:00:10 -03:00
);
} else {
_modalDeleteWallet();
}
};
2015-07-29 20:12:37 +09:00
});