Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add start/stop methods in Backbone code.
  • Loading branch information
akavlie committed Feb 28, 2012
1 parent 20c056e commit 479b0ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions public/javascripts/main.js
Expand Up @@ -6,6 +6,10 @@
var App = Backbone.Model.extend({
// properties: name, port, status
// actions: start, stop, show logs, show info, destroy
idAttribute: 'name',
// The Nodester API exposes individual apps at /app, while the list of apps
// is at /apps
url: function() { return '/api/app/' + this.id; }
});

var Apps = Backbone.Collection.extend({
Expand All @@ -20,13 +24,31 @@ var apps = new Apps;
// -----
var AppView = Backbone.View.extend({
tagName: 'tr',

events: {
'click .start': 'startApp',
'click .stop': 'stopApp',
},

initialize: function() {
this.tmpl = $('#app-tmpl').html();
// this.model.bind('change', this.render(), this);
},

render: function() {
var html = Mustache.to_html(this.tmpl, this.model.toJSON());
this.$el.html(html);
return this;
},

startApp: function(e) {
e.preventDefault();
this.model.set('running', true);
this.model.save();
},

stopApp: function() {

}
});

Expand Down
8 changes: 4 additions & 4 deletions views/frontend-templates.jade
Expand Up @@ -10,10 +10,10 @@ script(id="app-tmpl", type="text/html")
td.port {{port}}
td.status {{running}}
td.actions
a(href="/app", data-params="start_action", rel="put") start
a(href="/app", data-params="stop_action", rel="put") stop
a.applogs(href="/applogs/{{name}}", data-params="{{name}}", rel="modal") logs
a.app_info(href="/app/{{name}}", data-params="{{name}}", rel="modal") info
a.start(href="/app") start
a.stop(href="/app") stop
a.applogs(href="/applogs/{{name}}") logs
a.app_info(href="/app/{{name}}") info


// script(id="app-body-tmpl", type="text/html")
Expand Down

0 comments on commit 479b0ea

Please sign in to comment.