Last active
December 24, 2017 15:34
-
-
Save softauthor/4fa43da042054bc213619890158b9509 to your computer and use it in GitHub Desktop.
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
class AddressBookCtrl { | |
constructor(addressBookApi) { | |
this.addressBookAPI = addressBookApi; | |
} | |
init() { | |
this.renderContactListModule(); | |
this.renderContactDetailsModule(0); | |
this.addContactModule(); | |
} | |
// ADD | |
addContactModule() { | |
const $addContact = document.getElementById('add-contact-btn'); | |
$addContact.addEventListener("click", this.addContactBtnClicked.bind(this)); | |
} | |
addContactBtnClicked() { | |
// get the add contact form inputs | |
const $addContactInputs = document.getElementsByClassName('add-contact-input'); | |
// this object will hold the new contact information | |
let newContact = {}; | |
// loop through View to get the data for the model | |
for (let i = 0, len = $addContactInputs.length; i < len; i++) { | |
let key = $addContactInputs[i].getAttribute('data-key'); | |
let value = $addContactInputs[i].value; | |
newContact[key] = value; | |
} | |
// passing new object to the addContact method | |
this.addressBookAPI.addContact(newContact); | |
// render the contact list with the new data set | |
this.renderContactListModule(); | |
} | |
renderContactDetailsModule(e){...} | |
hightlightCurrentListItem(selectedIndex) {...} | |
renderContactListModule(){...} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment