// Generated by CoffeeScript 1.10.0 (function() { window.AppView = Backbone.D3View.extend({ events: { 'click .create_btn': 'new_item' }, initialize: function() { this.bar = this.d3el.append('div').attr({ "class": 'bar' }); this.input = this.bar.append('input').attr({ "class": 'input_field' }); this.input.node().value = 'Empty item'; this.bar.append('button').text('Create').attr({ "class": 'create_btn' }); this.list = this.d3el.append('div').attr({ "class": 'list' }); this.listenTo(this.collection, 'add', this.render_one); this.listenTo(this.collection, 'reset', this.render_all); return this.collection.fetch(); }, render_one: function(item) { var view; view = new ItemView({ model: item }); this.list.node().appendChild(view.el); return view.render(); }, render_all: function() { return this.collection.each(this.render_one, this); }, new_item: function() { return this.collection.create({ string: this.input.node().value, color: [Math.random() * 360, 20, 90] }); } }); }).call(this);