search box for currency

This commit is contained in:
Gabriel Bazán 2016-12-13 16:48:22 -03:00
parent 11f063b85d
commit 39a2c80133
2 changed files with 32 additions and 11 deletions

View File

@ -12,23 +12,36 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
isoCode: 'BTC'
}];
var config = configService.getSync();
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
function init() {
var config = configService.getSync();
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
rateService.whenAvailable(function() {
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
rateService.whenAvailable(function() {
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
$scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || [];
$scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || [];
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
return idx[c.isoCode] || idx2[c.isoCode];
$scope.completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
return idx[c.isoCode] || idx2[c.isoCode];
});
$scope.altCurrencyList = $scope.completeAlternativeList;
});
$scope.altCurrencyList = completeAlternativeList;
});
});
}
$scope.findCurrency = function(search) {
if (!search) init();
$scope.altCurrencyList = lodash.filter($scope.completeAlternativeList, function(item) {
var val = item.name;
return lodash.includes(val.toLowerCase(), search.toLowerCase());
});
$timeout(function() {
$scope.$apply();
});
};
$scope.save = function(newAltCurrency) {
var opts = {
@ -58,4 +71,5 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
};
init();
});

View File

@ -7,6 +7,13 @@
</ion-nav-back-button>
</ion-nav-bar>
<ion-content>
<div class="bar bar-header item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="search" ng-init="searchedAltCurrency = ''" ng-model="searchedAltCurrency" ng-change="findCurrency(searchedAltCurrency)"
placeholder="{{'Search your currency' | translate}}">
</label>
</div>
<div class="list" ng-if="lastUsedAltCurrencyList[0]">
<ion-radio ng-repeat="lastUsedAltCurrency in lastUsedAltCurrencyList" ng-value="lastUsedAltCurrency.isoCode" ng-model="currentCurrency"
ng-click="save(lastUsedAltCurrency)">{{lastUsedAltCurrency.name}}