Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a "Show me some Data" button

  • Loading branch information...
commit d2ad9d453fd9287324fe67943b103bc8964ffa24 1 parent 695a637
Lewis Marshall authored
Showing with 25 additions and 0 deletions.
  1. +23 −0 public/app.js
  2. +2 −0  views/index.erb
View
23 public/app.js
@@ -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
2  views/index.erb
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.