copay/src/js/services/go.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-12-07 07:44:50 -08:00
'use strict';
2015-03-06 07:00:10 -08:00
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, profileService) {
2014-12-07 07:44:50 -08:00
var root = {};
var hideSidebars = function() {
2014-12-07 09:12:58 -08:00
if (typeof document === 'undefined')
return;
2014-12-07 07:44:50 -08:00
// hack to hide sidebars and use ng-click (no href=)
var win = angular.element($window);
2014-12-07 09:12:58 -08:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'))
2014-12-07 07:44:50 -08:00
elem.removeClass('move-right');
elem.removeClass('move-left');
};
2014-12-08 07:45:12 -08:00
var toggleSidebar = function(invert) {
if (typeof document === 'undefined')
return;
2014-12-08 07:45:12 -08:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'));
var leftbarActive = angular.element(document.getElementsByClassName('move-right')).length;
2015-03-06 07:00:10 -08:00
if (invert) {
2015-03-06 07:00:10 -08:00
if (profileService.profile && !$rootScope.hideNavigation) {
2014-12-18 13:58:35 -08:00
elem.addClass('move-right');
2014-12-08 07:45:12 -08:00
}
2015-03-06 07:00:10 -08:00
} else {
2014-12-08 07:45:12 -08:00
if (leftbarActive) {
hideSidebars();
}
}
};
2014-12-09 11:11:56 -08:00
root.openExternalLink = function(url) {
var ref = window.open(url, '_blank', 'location=no');
};
root.path = function(path) {
2015-03-06 07:00:10 -08:00
$state.transitionTo(path);
2014-12-07 07:44:50 -08:00
hideSidebars();
};
root.swipe = function(invert) {
2014-12-08 07:45:12 -08:00
toggleSidebar(invert);
};
root.walletHome = function() {
2015-03-06 07:00:10 -08:00
var fc = profileService.focusedClient;
2014-12-09 06:52:01 -08:00
2015-03-06 07:00:10 -08:00
if (fc && !fc.isComplete()) {
root.path('copayers');
} else {
2015-03-06 07:00:10 -08:00
root.path('walletHome');
2015-04-23 11:19:30 -07:00
$rootScope.$emit('Local/SetTab', 'walletHome');
}
};
2015-04-23 11:19:30 -07:00
root.send = function() {
root.path('walletHome');
$rootScope.$emit('Local/SetTab', 'walletHome');
};
root.home = function() {
if ($rootScope.iden)
root.walletHome();
else
2015-03-06 07:00:10 -08:00
root.path('signin');
};
2015-03-06 07:00:10 -08:00
root.addWallet = function() {
$state.go('add');
};
2015-03-06 07:00:10 -08:00
root.preferences = function() {
$state.go('preferences');
};
root.reload = function() {
$state.reload();
};
2014-12-10 07:07:26 -08:00
// Global go. This should be in a better place TODO
// We dont do a 'go' directive, to use the benefits of ng-touch with ng-click
2015-03-06 07:00:10 -08:00
$rootScope.go = function(path) {
2014-12-10 07:07:26 -08:00
root.path(path);
};
2015-03-06 07:00:10 -08:00
$rootScope.openExternalLink = function(url) {
2014-12-10 07:07:26 -08:00
root.openExternalLink(url);
};
2014-12-07 07:44:50 -08:00
return root;
});