Skip to content

Instantly share code, notes, and snippets.

@softauthor
Last active December 24, 2017 15:34
Show Gist options
  • Save softauthor/4fa43da042054bc213619890158b9509 to your computer and use it in GitHub Desktop.
Save softauthor/4fa43da042054bc213619890158b9509 to your computer and use it in GitHub Desktop.
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