function init() { //wait for angular to load angular.element(document).ready(function () { window.initInAngular(); // Calls the init function defined on the window }); } angular.module('agileApp', ['angularMoment', 'ui.bootstrap', 'ui.sortable', 'xeditable', 'ngAnimate', 'ngRoute', 'monospaced.elastic']) .run(function(editableOptions) { editableOptions.theme = 'bs3'; }) .constant("BACKEND_CONSTANTS", { "BACKEND_URL": "https://sauce-agile.appspot.com/_ah/api", "WEB_CLIENT_ID": "677067502417-4473u2kdf1vn6oknlq4u8denhsd54u0o.apps.googleusercontent.com" }) .run(['$rootScope', '$location', 'UserAuthService', function ($rootScope, $location, userAuthService) { $rootScope.$on('$routeChangeStart', function (event) { //console.log(event); if($location.path() == '/tasks') { if (!userAuthService.isLoggedIn()) { console.log('not logged in, rerouting'); event.preventDefault(); userAuthService.logout(); } else { console.log('logged in, doing nothing'); } } }); }]) .config(function($routeProvider){ $routeProvider .when('/tasks',{ templateUrl: 'views/task-lists-view.html' }) .when('/',{ templateUrl: 'views/landing-view.html' }); }) .factory('cloudendpoint', ['$q', 'BACKEND_CONSTANTS', function ($q, BACKEND_CONSTANTS) { return { init:function() { var ROOT = BACKEND_CONSTANTS.BACKEND_URL; var webClientId = BACKEND_CONSTANTS.WEB_CLIENT_ID; var hwdefer=$q.defer(); var oauthloaddefer=$q.defer(); var oauthdefer=$q.defer(); gapi.client.load('sync', 'v1', function() { hwdefer.resolve(gapi); //alert('sync'); }, ROOT); gapi.client.load('oauth2', 'v2', function(){ oauthloaddefer.resolve(gapi); //alert('oauth2'); }); var chain=$q.all([hwdefer.promise,oauthloaddefer.promise]); return chain; }, doCall: function(callback) { var p=$q.defer(); gapi.auth.authorize({client_id: webClientId, scope: 'https://www.googleapis.com/auth/userinfo.email', immediate: true}, function(){ var request = gapi.client.oauth2.userinfo.get().execute(function(resp) { console.log("userinfo get" + resp); if (!resp.code) { p.resolve(gapi); } else { p.reject(gapi); } }); }); return p.promise; }, sigin:function(callback) { gapi.auth.authorize({client_id: webClientId, scope: 'https://www.googleapis.com/auth/userinfo.email', immediate: false}, callback); } }}])