Permalink
Browse files

Add a "Show me some Data" button

  • Loading branch information...
1 parent 695a637 commit d2ad9d453fd9287324fe67943b103bc8964ffa24 Lewis Marshall committed Oct 15, 2012
Showing with 25 additions and 0 deletions.
  1. +23 −0 public/app.js
  2. +2 −0 views/index.erb
View
@@ -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) {
@@ -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);
}
}));
View
@@ -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>

0 comments on commit d2ad9d4

Please sign in to comment.