forked from AdaGold/rolodex
-
Notifications
You must be signed in to change notification settings - Fork 44
Wave two is complete #47
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
Open
BrandiPhillips
wants to merge
7
commits into
Ada-C6:master
Choose a base branch
from
BrandiPhillips: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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4bba29
I gotta name\!
BrandiPhillips 10e8d55
Merge pull request #1 from BrandiPhillips/bmpWave1
BrandiPhillips f9048cf
set up rolodex collection and view
BrandiPhillips 91fed18
trying to get wave two to work without success
BrandiPhillips c3128a1
working on adding contacts with form
BrandiPhillips 970371a
I get by with a little help from my friends - wave two complete
BrandiPhillips 2c71430
Merge pull request #2 from BrandiPhillips/bmpCollection
BrandiPhillips 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 hidden or 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
This file contains hidden or 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,42 @@ | ||
| import $ from 'jquery'; | ||
| import Backbone from 'backbone'; | ||
| import _ from 'underscore'; | ||
| import ContactView from 'app/views/contact_view'; | ||
| import Rolodex from 'app/collections/rolodex'; | ||
| import RolodexView from 'app/views/rolodex_view'; | ||
|
|
||
|
|
||
| import Application from 'app/models/application'; | ||
| import ApplicationView from 'app/views/application_view'; | ||
|
|
||
| var application = new Application(); | ||
| var contactData = [ | ||
| { | ||
| name: "Malika", | ||
| email: "Malika.NZY@gmail.com", | ||
| phone: "206-555-1212" | ||
| }, { | ||
| name: "Taybor", | ||
| email: "Tay@ada.com", | ||
| phone: "206-123-1234" | ||
| } | ||
| ]; | ||
|
|
||
|
|
||
| $(document).ready(function(){ | ||
| var contactTemplate = _.template($('#tmpl-contact-details').html()); | ||
|
|
||
| var cardList = new Rolodex(contactData); | ||
| var rolodex = new RolodexView({ | ||
| el: $('#application'), | ||
| model: cardList | ||
| }); | ||
| rolodex.render(); | ||
| // $('#contact-details').append(cardList[0].render().$el); | ||
|
|
||
| var appView = new ApplicationView({ | ||
| el: '#application', | ||
| model: application | ||
| // var application = new Application(); | ||
| // var appView = new ApplicationView({ | ||
| // el: '#application', | ||
| // model: application | ||
| // }); | ||
| // application.render(); | ||
| }); |
This file contains hidden or 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,12 @@ | ||
| 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 hidden or 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,16 @@ | ||
| 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: 'name', | ||
| email: 'name@email.com', | ||
| phone: '777-777-777' | ||
| }, | ||
| initialize: function(options){ | ||
| console.log('new contact created for: ' + | ||
| this.get("name")); | ||
| } | ||
| }); | ||
|
|
||
| export default Contact; |
This file contains hidden or 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,28 @@ | ||
| import Backbone from 'backbone'; | ||
| import Contact from 'app/models/contact'; | ||
|
|
||
| const ContactView = Backbone.View.extend({ | ||
| initialize: function(options){ | ||
| // this.name = options.name, | ||
| // this.email = options.email, | ||
| // this.phone = options.phone, | ||
| this.model = options.model; | ||
| this.template = options.template; | ||
|
|
||
| this.listenTo(this.model, 'update', this.render); | ||
| }, | ||
| // have the contact vew listen for a click event: | ||
| events: { | ||
| 'click .contact-card': 'showHandler' | ||
| }, | ||
| showHandler: function(event){ | ||
| this.trigger('showCardDetails', this.model); | ||
| }, | ||
| render: function(){ | ||
| var html = this.template({contact: this.model.attributes}); | ||
| this.$el.html(html); | ||
| return this; | ||
| } | ||
| }); | ||
|
|
||
| export default ContactView; | ||
This file contains hidden or 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,110 @@ | ||
| import Backbone from 'backbone'; | ||
| import $ from 'jquery'; | ||
| import _ from 'underscore'; | ||
|
|
||
| import Contact from 'app/models/contact'; | ||
| import ContactView from 'app/views/contact_view'; | ||
|
|
||
|
|
||
| const RolodexView = Backbone.View.extend({ | ||
| }); | ||
| initialize: function(options) { | ||
|
|
||
| // template for the individual contact cards | ||
| this.contactCardTemplate = _.template($('#tmpl-contact-card').html()); | ||
|
|
||
| this.contactDetailsTemplate = _.template($('#tmpl-contact-details').html()); | ||
|
|
||
| // keep track of the elements that will be used to render the contact card and the contact details | ||
| this.listElement = this.$('#contact-cards'); | ||
| this.detailsElement = this.$('#contact-details'); | ||
|
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. Great use of |
||
|
|
||
| // list of card views: | ||
| this.cardList = []; | ||
|
|
||
| // process each task as they are created: | ||
| this.model.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[email="email"]'), | ||
| phone: this.$('.contact-form input[phone="phone"]') | ||
| }; | ||
|
|
||
| // when a model is added to the collection, add a contactCard for it | ||
| this.listenTo(this.model, 'add', this.addContact); | ||
|
|
||
| // re-render the list when the collection changes: | ||
| this.listenTo(this.model, 'update', this.render); | ||
|
|
||
|
|
||
| }, | ||
| render: function() { | ||
| // need to make sure the list in the DOM is empty before appending new items | ||
|
|
||
| this.listElement.empty(); | ||
|
|
||
| // iterate through the data assigned: | ||
| this.cardList.forEach(function(contactCard){ | ||
| contactCard.render(); | ||
| this.listElement.append(contactCard.$el); | ||
| }, this); | ||
| return this; | ||
| }, | ||
| events: { | ||
| 'click .btn-save': 'createContact', | ||
| 'click .btn-cancel': 'clearInput', | ||
|
|
||
| }, | ||
|
|
||
| createContact: function(event) { | ||
| event.preventDefault(); // supress the refreshing of page with a form submission | ||
|
|
||
| // get the input and turn it into a contact: | ||
| var rawContact = this.getInput(); | ||
|
|
||
| // add the contact to the model?? | ||
| var contact = this.model.add(rawContact); | ||
|
|
||
| // this.addContact(contact); | ||
| // this.render(); | ||
| // clear the input form: | ||
| this.clearInput(); | ||
| }, // end create contact | ||
|
|
||
| getInput: function(){ | ||
| var contact = { | ||
| name: this.input.name.val(), | ||
| email: this.input.email.val(), | ||
| phone: this.input.phone.val() | ||
| }; | ||
| return contact; | ||
| }, // end getInput | ||
|
|
||
| addContact: function(contact){ | ||
| // this is to make a view for new contacts and add them to the cardList: | ||
| var contactCard = new ContactView({ | ||
| model: contact, | ||
| template: this.contactCardTemplate | ||
| }); | ||
| // have each card listen for a click event: | ||
| this.listenTo(contactCard, 'showCardDetails', this.showDetails); | ||
| // add the card to the list | ||
| this.cardList.push(contactCard); | ||
|
|
||
| }, | ||
|
|
||
| clearInput: function(event){ | ||
| this.input.name.val(''); | ||
| this.input.email.val(''); | ||
| this.input.phone.val(''); | ||
| }, | ||
| // need to show the details when a name is clicked: | ||
| showDetails: function(contactModel){ | ||
| var details = this.contactDetailsTemplate({name: contactModel.get('name'), email: contactModel.get('email'), phone: contactModel.get('phone')}) | ||
| this.detailsElement.html(details); | ||
| } | ||
|
|
||
| }); // end of RolodexView | ||
|
|
||
| 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.
Excellent use of Trigger!