Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

If the user is authenticated, proceed to login and fill the calendar lis... #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ angular.module('demo', ["googleApi"])
})
.controller('DemoCtrl', ['$scope', 'googleLogin', 'googleCalendar', 'googlePlus', function ($scope, googleLogin, googleCalendar, googlePlus) {

$scope.authenticated = false;

$scope.$on("google:authenticated", function(){
$scope.authenticated = true;
$scope.$on('googleCalendar:loaded', function(){
$scope.calendars = googleCalendar.listCalendars();
$scope.$apply();
});
});

function checkAuth() {
setTimeout(function(){
gapi.auth === undefined ? checkAuth() : googleLogin.checkAuth();
}, 20);
}
checkAuth();


$scope.login = function () {
googleLogin.login();
};
Expand Down
10 changes: 5 additions & 5 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

<div>
<div>
<button ng-click="login()">Login</button>
<select name="calendar" ng-model="selectedCalendar" ng-options="cal.summary for cal in calendars"></select>
<button ng-click="loadCalendars()">Get Calendars</button>
<button ng-click="loadEvents()">Get Calendar Entries</button>
<button ng-hide="authenticated" ng-click="login()">Login</button>
<select ng-show="authenticated" name="calendar" ng-model="selectedCalendar" ng-options="cal.summary for cal in calendars"></select>
<button ng-show="authenticated" ng-click="loadCalendars()">Get Calendars</button>
<button ng-show="authenticated" ng-click="loadEvents()">Get Calendar Entries</button>
</div>

<ul>
<li ng-repeat="item in calendarItems">{{item.summary}}</li>
</ul>
<div ng-show="currentUser">
<div ng-cloak ng-show="currentUser" >
<h1>You're authenticated!</h1>

Logged in as {{currentUser.displayName}}
Expand Down