Wallet/src/js/controllers/tab-send.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-08-12 12:44:16 -03:00
'use strict';
2016-08-15 18:11:36 -03:00
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, configService, lodash) {
2016-08-12 15:11:52 -03:00
2016-08-15 18:11:36 -03:00
var originalList = [];
$scope.search = '';
2016-08-12 15:11:52 -03:00
$scope.init = function() {
2016-08-15 18:11:36 -03:00
var wallets = profileService.getWallets();
lodash.each(wallets, function(v) {
originalList.push({
color: v.color,
label: v.name,
isWallet: true,
});
2016-08-12 15:11:52 -03:00
});
2016-08-15 18:11:36 -03:00
addressbookService.list(function(err, ab) {
if (err) $log.error(err);
2016-08-12 15:11:52 -03:00
2016-08-15 18:11:36 -03:00
var contacts = [];
lodash.each(ab, function(v, k) {
contacts.push({
label: k,
address: v,
});
});
2016-08-12 15:11:52 -03:00
2016-08-15 18:11:36 -03:00
originalList = originalList.concat(contacts);
$scope.list = lodash.clone(originalList);
});
2016-08-12 16:30:50 -03:00
};
$scope.findContact = function() {
2016-08-15 18:11:36 -03:00
if (!$scope.search || $scope.search.length<2){
$scope.list = originalList;
$timeout(function() {
$scope.$apply();
},10);
return;
}
2016-08-12 16:30:50 -03:00
var result = lodash.filter($scope.list, function(item) {
var val = item.label || item.alias || item.name;
return lodash.includes(val.toLowerCase(), $scope.search.toLowerCase());
});
2016-08-12 16:30:50 -03:00
$scope.list = result;
2016-08-12 15:11:52 -03:00
};
$scope.openInputAmountModal = function(recipient) {
$scope.recipientName = recipient.name || recipient.label;
$scope.recipientColor = recipient.color;
2016-08-12 12:44:16 -03:00
$ionicModal.fromTemplateUrl('views/modals/inputAmount.html', {
scope: $scope
}).then(function(modal) {
$scope.inputAmountModal = modal;
$scope.inputAmountModal.show();
});
};
});