2014-12-07 12:44:50 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-05-18 15:15:14 -03:00
|
|
|
angular.module('copayApp.services').factory('go', function($window, $ionicSideMenuDelegate, $rootScope, $location, $state, $timeout, $log, profileService, platformInfo, nodeWebkit) {
|
2014-12-07 12:44:50 -03:00
|
|
|
var root = {};
|
|
|
|
|
|
2015-09-09 14:15:08 -03:00
|
|
|
root.openExternalLink = function(url, target) {
|
2016-05-18 15:15:14 -03:00
|
|
|
if (platformInfo.isNW) {
|
2015-05-28 10:52:33 -03:00
|
|
|
nodeWebkit.openExternalLink(url);
|
2015-11-24 17:16:52 -03:00
|
|
|
} else {
|
2015-09-09 14:15:08 -03:00
|
|
|
target = target || '_blank';
|
|
|
|
|
var ref = window.open(url, target, 'location=no');
|
2015-05-28 10:52:33 -03:00
|
|
|
}
|
2014-12-09 16:11:56 -03:00
|
|
|
};
|
|
|
|
|
|
2016-05-20 11:50:55 -03:00
|
|
|
root.is = function(name) {
|
|
|
|
|
return $state.is(name);
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-23 16:17:18 -03:00
|
|
|
root.path = function(path, cb) {
|
|
|
|
|
$state.transitionTo(path)
|
|
|
|
|
.then(function() {
|
|
|
|
|
if (cb) return cb();
|
2015-05-18 12:43:15 -03:00
|
|
|
}, function() {
|
|
|
|
|
if (cb) return cb('animation in progress');
|
2015-04-23 16:17:18 -03:00
|
|
|
});
|
2014-12-07 12:44:50 -03:00
|
|
|
};
|
|
|
|
|
|
2016-05-18 15:15:14 -03:00
|
|
|
root.toggleLeftMenu = function() {
|
2016-05-18 17:28:12 -03:00
|
|
|
$ionicSideMenuDelegate.toggleLeft();
|
2014-12-08 05:34:59 -03:00
|
|
|
};
|
|
|
|
|
|
2016-02-18 17:16:07 -03:00
|
|
|
root.walletHome = function() {
|
2016-08-19 13:14:23 -03:00
|
|
|
var wallet = profileService.getWallet($stateParams.walletId);
|
|
|
|
|
if (wallet && !wallet.isComplete()) {
|
2016-08-18 00:27:23 -03:00
|
|
|
$log.debug("Wallet not complete at startup... redirecting");
|
2016-08-19 13:14:23 -03:00
|
|
|
$state.transitionTo('wallet.details', {
|
|
|
|
|
walletId: wallet.credentials.walletId
|
|
|
|
|
})
|
2014-12-08 18:26:18 -03:00
|
|
|
} else {
|
2016-08-17 15:23:17 -03:00
|
|
|
root.path('tabs.home');
|
2014-12-08 18:26:18 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-17 19:25:07 -03:00
|
|
|
root.confirm = function(params) {
|
2016-08-19 14:14:21 -03:00
|
|
|
$state.transitionTo('send.confirm', params)
|
2016-08-17 19:25:07 -03:00
|
|
|
};
|
|
|
|
|
|
2015-04-23 15:19:30 -03:00
|
|
|
root.send = function() {
|
2016-08-17 15:23:17 -03:00
|
|
|
root.path('tabs.send');
|
2015-04-23 15:19:30 -03:00
|
|
|
};
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
root.addWallet = function() {
|
2016-06-11 13:52:44 -03:00
|
|
|
$state.transitionTo('add');
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
2014-12-08 18:26:18 -03:00
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
root.preferences = function() {
|
2016-06-11 13:52:44 -03:00
|
|
|
$state.transitionTo('preferences');
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
2015-11-13 16:00:28 -03:00
|
|
|
root.preferencesGlobal = function() {
|
2016-08-15 17:42:04 -03:00
|
|
|
$state.transitionTo('tabs.settings');
|
2015-11-13 16:00:28 -03:00
|
|
|
};
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
root.reload = function() {
|
|
|
|
|
$state.reload();
|
2014-12-08 18:26:18 -03:00
|
|
|
};
|
|
|
|
|
|
2014-12-10 12:07:26 -03:00
|
|
|
|
|
|
|
|
// Global go. This should be in a better place TODO
|
2016-01-16 17:04:01 -06:00
|
|
|
// We don't do a 'go' directive, to use the benefits of ng-touch with ng-click
|
2015-03-06 12:00:10 -03:00
|
|
|
$rootScope.go = function(path) {
|
2014-12-10 12:07:26 -03:00
|
|
|
root.path(path);
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-09 14:15:08 -03:00
|
|
|
$rootScope.openExternalLink = function(url, target) {
|
|
|
|
|
root.openExternalLink(url, target);
|
2014-12-10 12:07:26 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-07 12:44:50 -03:00
|
|
|
return root;
|
|
|
|
|
});
|