Merge pull request #3153 from troggy/set-tab-change-state

Allow addon menu items to run arbitrary code on click
This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-12 15:01:08 -03:00
commit 1ba60ebcf8
2 changed files with 43 additions and 20 deletions

View File

@ -1,4 +1,4 @@
<a ng-click="index.setTab(item.link)" ng-class="{'active': index.tab == item.link}" id="menu-{{item.link}}"> <a ng-click="index.setTab(item, false, 0, true)" ng-class="{'active': index.tab == item.link}" id="menu-{{item.link}}">
<i class="size-24 {{item.icon}} db"></i> <i class="size-24 {{item.icon}} db"></i>
<div class="size-10 tu"> <div class="size-10 tu">
{{ item.title|translate }} {{ item.title|translate }}

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, glideraService) { angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, glideraService, $state) {
var self = this; var self = this;
self.isCordova = isCordova; self.isCordova = isCordova;
self.onGoingProcess = {}; self.onGoingProcess = {};
@ -143,21 +143,34 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.setTab = function(tab, reset, tries) { self.setTab = function(tab, reset, tries, switchState) {
tries = tries || 0; tries = tries || 0;
// check if the whole menu item passed
if (typeof tab == 'object') {
if (tab.open) {
if (tab.link) {
self.tab = tab.link;
}
tab.open();
return;
} else {
return self.setTab(tab.link, reset, tries, switchState);
}
}
if (self.tab === tab && !reset) if (self.tab === tab && !reset)
return; return;
if (!document.getElementById('menu-' + tab) && ++tries < 5) { if (!document.getElementById('menu-' + tab) && ++tries < 5) {
return $timeout(function() { return $timeout(function() {
self.setTab(tab, reset, tries); self.setTab(tab, reset, tries, switchState);
}, 300); }, 300);
} }
if (!self.tab) if (!self.tab || !$state.is('walletHome'))
self.tab = 'walletHome'; self.tab = 'walletHome';
var changeTab = function() {
if (document.getElementById(self.tab)) { if (document.getElementById(self.tab)) {
document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab; document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab;
var old = document.getElementById('menu-' + self.tab); var old = document.getElementById('menu-' + self.tab);
@ -178,6 +191,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$emit('Local/TabChanged', tab); $rootScope.$emit('Local/TabChanged', tab);
}; };
if (switchState && !$state.is('walletHome')) {
go.path('walletHome', function() {
changeTab();
});
return;
}
changeTab();
};
self._updateRemotePreferencesFor = function(clients, prefs, cb) { self._updateRemotePreferencesFor = function(clients, prefs, cb) {
var client = clients.shift(); var client = clients.shift();