diff --git a/src/models/shirt.js b/src/models/shirt.js index 624d37c..28bc60c 100644 --- a/src/models/shirt.js +++ b/src/models/shirt.js @@ -1,7 +1,11 @@ (function () { window.Shirt = Backbone.Model.extend({ - // TODO: Add defaults property + defaults: { + small: 0, + medium: 0, + large: 0 + } }); })(); diff --git a/src/views/inventory-view.js b/src/views/inventory-view.js index 9d2fce9..364a859 100644 --- a/src/views/inventory-view.js +++ b/src/views/inventory-view.js @@ -4,10 +4,32 @@ events: { 'click .add-shirts': 'addShirts' }, - addShirts: function (e) { var type = $(e.currentTarget).data('type'); - console.log('Adding one of every', type, 'shirt for', this.options.shirts); + + var myShirts = this.options.shirts; + + for (var s = 0; s < myShirts.length; s++){ + + var eachShirts = myShirts[s] + + if (type === 'small') { + var newSmall = myShirts[s].get('small'); + newSmall += 1; + //myShirts[s].set({ small: newSmall }); + eachShirts.set(type, newSmall) + } else if (type === 'medium') { + var newMedium = myShirts[s].get('medium'); + newMedium += 1; + //myShirts[s].set({ medium: newMedium }); + eachShirts.set(type, newMedium) + } else if (type === 'large') { + var newLarge = myShirts[s].get('large'); + newLarge += 1; + //myShirts[s].set({ large: newLarge }); + eachShirts.set(type, newLarge) + } + } // TODO: Write a for loop to iterate through this.options.shirts and // add +1 to each of that shirt's `type` inventory. // For example, if type === 'small', then add +1 to every small stock diff --git a/src/views/shirt-view.js b/src/views/shirt-view.js index da6f40f..b6c83a6 100644 --- a/src/views/shirt-view.js +++ b/src/views/shirt-view.js @@ -4,10 +4,13 @@ var shirtTemplate = _.template(shirtTemplateHtml); window.ShirtView = Backbone.View.extend({ + initialize: function(){ + this.listenTo(this.model, 'change', this.render); + }, className: 'shirt', render: function () { // TODO: Complete the following line - var newShirtHtml = shirtTemplate( ??? ); + var newShirtHtml = shirtTemplate( this.model.toJSON() ) ; $(this.el).html(newShirtHtml); } });