Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete bbr-shirts branch #10

Open
wants to merge 3 commits into
base: bbr-shirts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/models/shirt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
(function () {

window.Shirt = Backbone.Model.extend({
// TODO: Add defaults property
defaults: {
small: 0,
medium: 0,
large: 0
}
});

})();
26 changes: 24 additions & 2 deletions src/views/inventory-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/views/shirt-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down