-
Notifications
You must be signed in to change notification settings - Fork 0
phoneApp #19
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
base: master
Are you sure you want to change the base?
phoneApp #19
Changes from 1 commit
15f323a
14228cb
4ff03c0
eee1fa2
283863e
7725d89
3b946f2
59872b9
ec0a97f
cbf117d
8baa4ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>homework_15</title> | ||
| <meta charset="utf-8" /> | ||
| <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
| <link rel="stylesheet" type="text/css" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <script src="index.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| class UsersContacts { | ||
| constructor() { | ||
| this.dataUsers = [ | ||
| { | ||
| name: 'Иван', | ||
| lastName: 'Петров', | ||
| email: 'IvanPetrov@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Сергей', | ||
| lastName: 'Сергей', | ||
| email: 'SergeiSergeev@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Иван', | ||
| lastName: 'Иванов', | ||
| email: 'IvanIvanov@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Александр', | ||
| lastName: 'Александров', | ||
| email: 'AlexAlex@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Алекс', | ||
| lastName: 'Смирнов', | ||
| email: 'AlexSmirnov@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Сергей', | ||
| lastName: 'Волков', | ||
| email: 'VolkovSergey@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Мария', | ||
| lastName: 'Шарапова', | ||
| email: 'MariyaSharapova@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Александр', | ||
| lastName: 'Винник', | ||
| email: 'AlexVinnik@ec.u' | ||
| }, | ||
| { | ||
| name: 'Дарий', | ||
| lastName: 'Смирнов', | ||
| email: 'DariySmirnov@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Елена', | ||
| lastName: 'Лещенко', | ||
| email: 'ElenaLeshenko@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Ольга', | ||
| lastName: 'Новикова', | ||
| email: 'OlgaNovikova@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Наталья', | ||
| lastName: 'Шемякина', | ||
| email: 'ShemyakinaN@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Анна', | ||
| lastName: 'Донцова', | ||
| email: 'AnnaDontsova@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Влад', | ||
| lastName: 'Яма', | ||
| email: 'VladYama@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Кира', | ||
| lastName: 'Воробьева', | ||
| email: 'Kira1990@ec.ua' | ||
| }, | ||
| { | ||
| name: 'Виктор', | ||
| lastName: 'Кривенко', | ||
| email: 'ViktorKriv@ec.ua' | ||
| } | ||
| ]; | ||
| this.columnHeadings = ['Name', 'Last name', 'Email']; | ||
| }; | ||
|
|
||
| render() { | ||
|
|
||
| document.body.innerHTML += this.createHeader(); | ||
|
Member
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. document.body.innerHTML not sure I like to use document.body. You have to create an additional tag at index.html and call it, for example, <div id="mountNode"></div>And update content only inside such node. updating the whole document.body is too risky |
||
| document.body.innerHTML += this.createMain(); | ||
| let insert = document.querySelector('main > div'); | ||
| insert.appendChild(this.createTable()); | ||
|
Member
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. pretty sure you have to create table with inner HTML also |
||
| document.body.innerHTML += this.createFooter(); | ||
| }; | ||
|
|
||
| createNewElement(newElem) { | ||
| return document.createElement(newElem); | ||
| }; | ||
|
|
||
| createTable() { | ||
| let table = this.createNewElement('table'); | ||
| table.setAttribute('class', 'table table-hover contacts'); | ||
| table.appendChild(this.cteateTheadInTable()); | ||
| table.appendChild(this.cteateTbodyInTable()); | ||
| return table; | ||
| }; | ||
|
|
||
| cteateTheadInTable() { | ||
| let thead = this.createNewElement('thead'); | ||
| let tr = this.createNewElement('tr'); | ||
| thead.appendChild(tr); | ||
| this.columnHeadings.forEach((elem) => { | ||
| let th = this.createNewElement('th'); | ||
| th.textContent = elem; | ||
| tr.appendChild(th); | ||
| }); | ||
| return thead; | ||
| }; | ||
|
|
||
| cteateTbodyInTable() { | ||
| let tbody = this.createNewElement('tbody'); | ||
| //table.appendChild(tbody); | ||
| this.dataUsers.forEach((elem) => { | ||
| let tr = this.createNewElement('tr') | ||
| tbody.appendChild(tr); | ||
| let arrObjkeys = Object.keys(elem); | ||
| arrObjkeys.forEach((elemTd) => { | ||
| let td = this.createNewElement('td'); | ||
| td.textContent = elem[elemTd]; | ||
| tr.appendChild(td); | ||
| }); | ||
| }); | ||
| return tbody; | ||
| }; | ||
|
|
||
| createHeader() { | ||
| return ` | ||
| <header class = 'header'> | ||
| <div class = 'container top-radius'> | ||
| <h2>Contacts</h2> | ||
| </div> | ||
| </header> | ||
| ` | ||
| }; | ||
|
|
||
| createMain() { | ||
| return ` | ||
| <main> | ||
| <div class="container"> | ||
| <form class="form-inline search-form"> | ||
| <div class="form-group"> | ||
| <label class="sr-only" for="search">Search</label> | ||
| <input type="text" class="form-control" id= "search" placeholder="Search"> | ||
| </div> | ||
| </form> | ||
|
|
||
| </main> | ||
| ` | ||
| } | ||
|
|
||
| createFooter() { | ||
| return ` | ||
| <footer class="footer"> | ||
| <div class="container bottom-radius"> | ||
| <nav class="main-nav"> | ||
| <a href="index.html" class="tab active"> | ||
|
Member
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. I believe you could make links more reusable. What if one day you have to set class but the click ? or something more expensive. I guess it could look that way <nav class="main-nav">
this.renderLink({ content:'Contacts', className:'active', icon:'search'});
this.renderLink({ content:'Keypad', icon:'th'});
this.renderLink({ content:'Edit contact' });
...
</nav>We could reuse some HTML parts and create a smaller reusable blocks |
||
| <span class="glyphicon glyphicon-search" aria-hidden="true"></span> | ||
| <span class = "tab-text">Contacts</span> | ||
| </a> | ||
| <a href="keypad.html" class="tab"> | ||
| <span class="glyphicon glyphicon-th" aria-hidden="true"></span> | ||
| <span class = "tab-text">Keypad</span> | ||
| </a> | ||
| <a href="edit-contact.html" class="tab"> | ||
| <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> | ||
| <span class = "tab-text">Edit contact</span> | ||
| </a> | ||
| <a href="user.html" class="tab"> | ||
| <span class="glyphicon glyphicon-user" aria-hidden="true"></span> | ||
| <span class = "tab-text">User</span> | ||
| </a> | ||
| <a href="add-user.html" class="tab"> | ||
| <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> | ||
| <span class = "tab-text">Add user</span> | ||
| </a> | ||
| </nav> | ||
| </div> | ||
| </footer> | ||
| ` | ||
| } | ||
| }; | ||
|
|
||
| let usersContacts = new UsersContacts(); | ||
| usersContacts.render(); | ||
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.
oyy!
as I see you updating innerHTML several times, it's better to update it only once