Skip to content

Commit

Permalink
Improve add/update/delete clients.
Browse files Browse the repository at this point in the history
Update backbone from HEAD.

Signed-off-by: François de Metz <fdemetz@af83.com>
  • Loading branch information
francois2metz committed Apr 14, 2011
1 parent ab96722 commit 927018f
Show file tree
Hide file tree
Showing 5 changed files with 1,120 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/middlewares/web_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function createClient(req, res) {
return res.end(err.toString());
}
res.writeHead(200);
res.end();
res.end(client.toJSON());
});
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/ms_templates/app.ms
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<script type="text/javascript" src="/js/libs/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/libs/underscore-min.js"></script>
<script type="text/javascript" src="/js/libs/backbone-min.js"></script>
<script type="text/javascript" src="/js/libs/backbone.js"></script>
<script type="text/javascript" src="/js/libs/mustache.js"></script>

<script type="text/javascript" src="/js/templates_fr.js"></script>
Expand Down
49 changes: 33 additions & 16 deletions src/static/js/clients.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Client = Backbone.Model.extend({
urlRoot: '/clients'
});
var Clients = Backbone.Collection.extend({
url: '/clients',
Expand Down Expand Up @@ -56,8 +57,16 @@ var AuthServerClientShowView = Backbone.View.extend({
"click .delete": "del"
},

render: function() {
initialize: function() {
this.model.bind('change:name', _.bind(this.renderTitle, this));
},

renderTitle: function() {
$('#overview').html('<h1>' + this.model.get('name') + '</h1>');
},

render: function() {
this.renderTitle();
var data = {
client: this.model.toJSON(),
};
Expand Down Expand Up @@ -90,9 +99,7 @@ var AuthServerClientShowView = Backbone.View.extend({
var client_label = '"'+name+'" ['+redirect_uri+']';
var msg = "Are you sure you want to delete the client " + client_label + "?";
if(confirm(msg)) {
this.model.destroy({success: function() {

}})
this.model.destroy();
}
}
});
Expand All @@ -117,40 +124,50 @@ var AuthServerClientsController = Backbone.Controller.extend({
});
}, this));
this.clients.fetch();
// clean all new models
this.bind('all', _.bind(function(e) {
if (e == 'route:new') return;
this.clients.remove(this.clients.filter(function(client) {
return client.isNew();
}));
}, this));
},

index: function() {
document.location.hash = "/c";
},

clients: function() {
new AuthServerClientsIndexView({collection: this.clients,
el: $("#content")}).render();
this.render(new AuthServerClientsIndexView({collection: this.clients}));
},

new: function() {
var client = new Client();
this.clients.add(client);
new AuthServerClientsNewView({el: $("#content"),
model: client}).render()
.bind("success", function() {
console.log("on success");
}).bind("error", function() {
console.log("on error");
});
console.log(client.collection);
client.bind('change:id', function(e) {
document.location.hash = '#/c';
});
this.render(new AuthServerClientsNewView({model: client}));
},

show: function(id) {
var onReady = _.bind(function() {
var client = this.clients.get(id);
new AuthServerClientShowView({el: $("#content"),
model: client}).render();
if (!client) return document.location.hash = "#/c";
this.render(new AuthServerClientShowView({model: client}));
client.bind('destroy', function(e) {
document.location.hash = "#/c";
});
}, this);
if (this.initialized) {
onReady();
} else {
this.callbacks.push(onReady);
}
},

render: function(view) {
$('#main').empty().append(view.render().el);
}
});

27 changes: 0 additions & 27 deletions src/static/js/libs/backbone-min.js

This file was deleted.

Loading

0 comments on commit 927018f

Please sign in to comment.