forked from AdaGold/rolodex
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Carmen - completed wave 3 #34
Open
goaskcarmen
wants to merge
4
commits into
Ada-C6:master
Choose a base branch
from
goaskcarmen:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
import Application from 'app/models/application'; | ||
import ApplicationView from 'app/views/application_view'; | ||
import _ from 'underscore'; | ||
import $ from 'jquery'; | ||
|
||
import Contact from 'app/models/contact'; | ||
import ContactView from 'app/views/contact_view'; | ||
import RolodexView from 'app/views/rolodex_view'; | ||
import Rolodex from 'app/collections/rolodex'; | ||
|
||
var application = new Application(); | ||
|
||
var appView = new ApplicationView({ | ||
el: '#application', | ||
model: application | ||
}); | ||
|
||
var contactData = [ | ||
{ | ||
name: 'Charles', | ||
email: 'charles@email.com', | ||
phone: '0987654321' | ||
}, | ||
{ | ||
name: 'Chris', | ||
email: 'chris@email.com', | ||
phone: '3216540987' | ||
} | ||
]; | ||
|
||
var contactModel = new Rolodex(contactData); | ||
var rolView = new RolodexView({ | ||
el: 'body', | ||
model: contactModel | ||
}); | ||
rolView.render(); | ||
|
||
|
||
|
||
// var charlesmodel = new Contact(contactData[0]); | ||
// | ||
// var contactTemplate = _.template($('#tmpl-contact-card').html()); | ||
// // console.log("contact Template: ", contactTemplate); | ||
// | ||
// var charlesview = new ContactView({ | ||
// model: charlesmodel, | ||
// template: contactTemplate | ||
// }); | ||
// console.log("charlesview: ", charlesview); | ||
|
||
// $('#contact-cards').append(charlesview.render().$el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import Backbone from 'backbone'; | ||
import Contact from 'app/models/contact'; | ||
|
||
const Rolodex = Backbone.Collection.extend({ | ||
// This Rolodex represents a collection of Contacts | ||
// and should include any methods or attributes | ||
// that are involved in working with more than one | ||
// Contact. | ||
model: Contact | ||
|
||
}); | ||
|
||
export default Rolodex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
// contact.js | ||
|
||
import Backbone from 'backbone'; | ||
|
||
const Contact = Backbone.Model.extend({ | ||
// This model should have the attributes for | ||
// a single contact: name, phone number, and email. | ||
|
||
defaults: { | ||
name: "Person", | ||
phone: "1234567890", | ||
email: "email@email.com" | ||
}, | ||
|
||
initialize: function() { | ||
// console.log("contact created: " + this.name); | ||
} | ||
}); | ||
|
||
export default Contact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
import Backbone from 'backbone'; | ||
import Contact from 'app/models/contact'; | ||
import _ from 'underscore'; | ||
import $ from 'jquery'; | ||
|
||
const ContactView = Backbone.View.extend({ | ||
initialize: function(options) { | ||
// this.contact = options.contact; | ||
this.template = options.template; | ||
}, | ||
|
||
render: function() { | ||
this.delegateEvents(); | ||
var html = this.template({name: this.model.get("name")}); | ||
this.$el.html(html); | ||
|
||
// Enable chained calls | ||
return this; | ||
}, | ||
|
||
events: { | ||
'click': 'showDetail' | ||
}, | ||
|
||
showDetail: function(){ | ||
this.trigger( 'contactInfo', this.model); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of Trigger! |
||
event.stopPropagation(); | ||
} | ||
}); | ||
|
||
export default ContactView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// detail_view.js | ||
|
||
import Backbone from 'backbone'; | ||
import _ from 'underscore'; | ||
import $ from 'jquery'; | ||
|
||
const DetailView = Backbone.View.extend({ | ||
initialize: function(options){ | ||
this.template = options.template; | ||
}, | ||
|
||
render: function(){ | ||
var html = this.template({ | ||
name: this.model.get("name"), | ||
email: this.model.get("email"), | ||
phone: this.model.get("phone"), | ||
}); | ||
this.$el.html(html); | ||
|
||
return this; | ||
}, | ||
|
||
|
||
}); | ||
|
||
export default DetailView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,128 @@ | ||
import Backbone from 'backbone'; | ||
import _ from 'underscore'; | ||
import $ from 'jquery'; | ||
import ContactView from 'app/views/contact_view'; | ||
import DetailView from 'app/views/detail_view'; | ||
|
||
const RolodexView = Backbone.View.extend({ | ||
initialize: function(options) { | ||
|
||
// Store a the full list of tasks | ||
// this.contactData = options.contactData; | ||
|
||
// Compile a template to be shared between the individual tasks | ||
this.contactTemplate = _.template($('#tmpl-contact-card').html()); | ||
|
||
this.contactDetailTemplate = _.template($('#tmpl-contact-details').html()); | ||
|
||
// Keep track of the <ul> element | ||
this.listElement = this.$('#contact-cards'); | ||
|
||
// Create a TaskView for each task | ||
this.cardList = []; | ||
this.model.models.forEach(function(contact) { | ||
this.addContact(contact); | ||
}, this); // bind `this` so it's available inside forEach | ||
|
||
this.input = { | ||
name: this.$('.contact-form input[name="name"]'), | ||
email: this.$('.contact-form input[name="email"]'), | ||
phone: this.$('.contact-form input[name="phone"]') | ||
|
||
}; | ||
}, | ||
|
||
render: function() { | ||
|
||
// Make sure the list in the DOM is empty | ||
// before we start appending items | ||
this.listElement.empty(); | ||
|
||
// Loop through the data assigned to this view | ||
this.cardList.forEach(function(card) { | ||
// Cause the task to render | ||
card.render(); | ||
|
||
// Add that HTML to our task list | ||
this.listElement.append(card.$el); | ||
}, this); | ||
|
||
return this; // enable chained calls | ||
}, | ||
|
||
|
||
events: { | ||
'click .btn-save': 'createContact', | ||
'click .btn-cancel': 'clearInput', | ||
'click': 'hideDetail' | ||
}, | ||
|
||
clearInput: function(event) { | ||
this.input.name.val(''); | ||
this.input.email.val(''); | ||
this.input.phone.val(''); | ||
}, | ||
|
||
createContact: function(event) { | ||
// Normally a form submission will refresh the page. | ||
// Suppress that behavior. | ||
event.preventDefault(); | ||
|
||
// Get the input data from the form and turn it into a task | ||
var contact = this.getInput(); | ||
|
||
// Add the new task to our list of tasks | ||
// gotta figure out where the data is stored | ||
this.model.push(contact); | ||
|
||
// Create a card for the new task, and add it to our card list | ||
// var card = new ContactView({ | ||
// model: contact, | ||
// template: this.contactTemplate | ||
// }); | ||
// this.cardList.push(card); | ||
this.addContact(contact); | ||
|
||
// Re-render the whole list, now including the new card | ||
this.render(); | ||
|
||
// Clear the input form so the user can add another task | ||
this.clearInput(); | ||
}, // end createTast(); | ||
|
||
addContact: function(contact){ | ||
var card = new ContactView({ | ||
model: contact, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably fix this line here so that the view's model is a Backbone Model object and not a generic JavaScript object. |
||
template: this.contactTemplate | ||
}); | ||
this.cardList.push(card); | ||
this.listenTo(card, "contactInfo", this.showDetail); | ||
}, | ||
|
||
getInput: function() { | ||
var contact = { | ||
name: this.input.name.val(), | ||
email: this.input.email.val(), | ||
phone: this.input.phone.val(), | ||
}; | ||
return contact; | ||
}, // end getInput(); | ||
|
||
showDetail: function(model){ | ||
this.detail = new DetailView({ | ||
model: model, | ||
template: this.contactDetailTemplate, | ||
el: $('#contact-details') | ||
}); | ||
$('#contact-details').show(); | ||
this.detail.render(); | ||
}, | ||
|
||
hideDetail: function(){ | ||
console.log("hidedetail"); | ||
$('#contact-details').hide(); | ||
this.render(); | ||
} | ||
}); | ||
|
||
export default RolodexView; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error here, due to the fact that if you add a new card, the 'model' you've set for the view is a generic JavaScript object. You'll need to make a new model when you create the view for it to work.
ex:
newCard = new Card( { model: new Contact(contact), template: this.contactTemplate });