diff --git a/app.rb b/app.rb index 26bfebc..2b2975a 100644 --- a/app.rb +++ b/app.rb @@ -14,3 +14,28 @@ { :name => 'Blog Posts' } ].to_json end + +get '/data-fields' do + content_type :json + + case params['data_type'] + when 'Accounts' + [ + { :name => 'First Name' }, + { :name => 'Last Name' }, + { :name => 'Email Address' } + ].to_json + when 'Reports' + [ + { :name => 'Name' }, + { :name => 'Published Date' }, + { :name => 'Featured?' } + ].to_json + when 'Blog Posts' + [ + { :name => 'Title' }, + { :name => 'Published At' }, + { :name => 'No. of views' } + ].to_json + end +end diff --git a/public/app.css b/public/app.css new file mode 100644 index 0000000..190fb18 --- /dev/null +++ b/public/app.css @@ -0,0 +1,4 @@ +#data-fields label { + float: left; + width: 200px; +} diff --git a/public/app.js b/public/app.js index a3eb85c..5226cdc 100644 --- a/public/app.js +++ b/public/app.js @@ -13,13 +13,29 @@ DataTypeView = Backbone.View.extend({ "click": "chooseDataType" }, chooseDataType: function() { - console.log(this.model.get('name')); + DataFieldCollection.fetch({ data: { data_type: this.model.get('name') } }); + } +}); + +DataFieldCollection = new (Backbone.Collection.extend({ + url: "/data-fields" +})); + +DataFieldView = Backbone.View.extend({ + tagName: 'label', + template: function(attributes) { + return _.template($('#data-field-template').html(), attributes); + }, + render: function() { + this.$el.html(this.template(this.model.toJSON())); + return this; } }); App = new (Backbone.View.extend({ initialize: function() { DataTypeCollection.bind('reset', this.renderDataTypes, this); + DataFieldCollection.bind('reset', this.renderDataFields, this); DataTypeCollection.fetch(); }, renderDataTypes: function(data_types) { @@ -27,5 +43,13 @@ App = new (Backbone.View.extend({ var view = new DataTypeView({ model: data_type }); $('#data-types').append(view.render().el); }); + }, + renderDataFields: function(data_fields) { + $('#data-fields').empty(); + + data_fields.each(function(data_field) { + var view = new DataFieldView({ model: data_field }); + $('#data-fields').append(view.render().el); + }); } })); diff --git a/views/index.erb b/views/index.erb index b9b6840..e3956b9 100644 --- a/views/index.erb +++ b/views/index.erb @@ -4,6 +4,7 @@ JSON Table + @@ -18,6 +19,16 @@

Choose the type of data you want to view:

+ +

Choose some fields:

+ +
+

Choose a data type above first

+
+ +