Skip to content

Instantly share code, notes, and snippets.

@brobles82
Created August 15, 2013 11:14
Show Gist options
  • Save brobles82/6240073 to your computer and use it in GitHub Desktop.
Save brobles82/6240073 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars">
<header>
<pre>ember.js globally available controllers like currentUser</pre>
</header>
<h1>Comments for {{controllers.currentUser.timer}}
{{input value=controllers.currentUser.timer}}
</h1>
<button {{action login target="controllers.currentUser"}}>Login</button>
<button {{action logout target="controllers.currentUser"}}>Logout</button>
<hr/>
{{#if controllers.currentUser.timer}}
YOU ARE LOGGED IN
<p>Signed in as {{controllers.currentUser.content}}</p>
{{else}}
Please sigin for see extra content
{{/if}}
<div>
</div>
<hr/>
</script>
</body>
</html>
window.App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
needs: ['currentUser']
});
App.CurrentUserController = Ember.ObjectController.extend({
timer: null,
init: function () {
//Here you cna put Meteor.userId()
this.set('timer', 'true');
},
content: function() {
return (this.timer)? true: false;
}.property('timer'),
login: function() {
this.set('timer', new Date().getTime());
},
logout: function() {
this.set('timer', null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment