Permalink
Browse files

Better handling of page loads for logged in users.

  • Loading branch information...
miccolis committed Jan 24, 2012
1 parent a7cc289 commit da15eaea99d6ef416a5770c6c50850c6ad957729
Showing with 16 additions and 10 deletions.
  1. +1 −1 app.js
  2. +15 −9 attachments/site.js
View
2 app.js
@@ -28,7 +28,7 @@ ddoc = {
query: {reduce: 'false', include_docs: 'true'}
},
{from:"/api/session", to:'../../_session'},
- //{from:"/api/*", to:'../../*'},
+ {from:"/api/*", to:'../../*'},
{from:"/*", to:'*'},
]
};
View
@@ -51,13 +51,13 @@
var rootURI = 'http://localhost:5984/portal/_design/app/_rewrite';
var authURI = 'http://localhost:5984/_session';
+
// Begin Backbone setup.
var models = {};
models.Session = Backbone.Model.extend({
url: authURI,
parse: function(resp) {
- debugger;
if (typeof resp == 'object') {
// from read we get an object here...
if (resp.ok && resp.userCtx) return resp.userCtx;
@@ -376,22 +376,27 @@ views.Controls = Backbone.View.extend({
},
initialize: function(options) {
this.app = options.app;
+ _(this).bindAll('update', 'controls', 'render');
+ },
+ update: function(view) {
+ this.pageView = view;
+ return this;
},
controls: function() {
var links = [];
- if (this.app.auth) {
+ if (this.app.session.isAuth()) {
links.push({name: 'Logout', link: 'logout', klass: 'logout'});
}
else {
links.push({name: 'Login', link: 'login', klass: 'login'});
}
return {links: links};
},
- render: function(view) {
+ render: function() {
var context = this.controls();
// Allow views to add thier own business.
- if (view && view.controls !== undefined) {
+ if (this.pageView && this.pageView.controls !== undefined) {
context = _(context).extend(view.controls());
}
@@ -404,7 +409,6 @@ views.Controls = Backbone.View.extend({
},
showLoginError: function(model, resp, options) {
var err = resp.status +': '+ resp.statusText;
- // TODO better error presentation.
alert(err);
},
sessionCreate: function() {
@@ -604,14 +608,16 @@ var App = Backbone.Router.extend({
initialize: function(options) {
this.session = options.session;
- this.session.fetch();
this.controls = new views.Controls({
el: $('#controls'),
app: this
});
+ this.session.fetch({
+ success: this.controls.render
+ });
},
update: function(view) {
- this.controls.render(view);
+ this.controls.update(view).render();
},
routes: {
'': 'home',
@@ -657,13 +663,13 @@ var App = Backbone.Router.extend({
model.fetch();
},
newPackage: function() {
- if (this.auth) {
+ if (this.session.isAuth()) {
var model = new models.Package({id: 'new'});
this.update(new views.EditPackage({el: $('#main'), model: model}));
}
},
editPackage: function(id) {
- if (this.auth) {
+ if (this.session.isAuth()) {
var model = new models.Package({id:id});
this.update(new views.EditPackage({el: $('#main'), model: model}));
model.fetch();

0 comments on commit da15eae

Please sign in to comment.