Skip to content

Commit

Permalink
Add a "Show me some Data" button
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis Marshall committed Oct 15, 2012
1 parent 695a637 commit d2ad9d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions public/app.js
Expand Up @@ -56,10 +56,30 @@ DataColumnView = Backbone.View.extend({
}
});

Button = new Backbone.Model({ visible: false });

new (Backbone.View.extend({
tagName: 'button',
initialize: function() {
Button.bind('change:visible', this.toggleVisible, this);
},
render: function() {
this.$el.addClass('btn btn-primary').text('Show me some Data!');
return this;
},
toggleVisible: function() {
if(Button.get('visible'))
$('#data-fields').after(this.render().el);
else
this.remove();
}
}));

App = new (Backbone.View.extend({
initialize: function() {
DataTypeCollection.bind('reset', this.renderDataTypes, this);
DataFieldCollection.bind('reset', this.renderDataFields, this);
DataFieldCollection.bind('change:visible', this.toggleButton, this);
DataTypeCollection.fetch();
},
renderDataTypes: function(data_types) {
Expand All @@ -77,5 +97,8 @@ App = new (Backbone.View.extend({

var column_view = new DataColumnView({ model: data_field });
});
},
toggleButton: function() {
Button.set('visible', DataFieldCollection.where({ visible: true }).length > 0);
}
}));
2 changes: 2 additions & 0 deletions views/index.erb
Expand Up @@ -26,6 +26,8 @@
<p><em>Choose a data type above first</em></p>
</div>

<button id="button" class="btn btn-primary" style="display: none">Show me some Data!</button>

<table class="table">
<thead>
<tr></tr>
Expand Down

0 comments on commit d2ad9d4

Please sign in to comment.