-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontacts.js
More file actions
71 lines (53 loc) · 1.74 KB
/
contacts.js
File metadata and controls
71 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* pages.contacts
*
* handles contact list page actions
*/
(function (global) {
var contacts_page = { el : $('#page-main') };
contacts_page.initContactList = function(el) {
var li,
contacts = global.store.getContacts();
el.html("");
for (var i=0; i < contacts.length; ++i ) {
li = contacts_page.createContactListItem(contacts[i]);
el.append(li);
}
};
contacts_page.viewContact = function() {
var el = $(this),
contact = el.data('contact'),
viewer = $('#page-view');
viewer.find('span#view-name').text(contact.name);
viewer.find('span#view-phone').text(contact.phone);
viewer.find('span#view-email').text(contact.email);
$.mobile.changePage(viewer);
};
contacts_page.createContactListItem = function(contact) {
var li, a;
li = $(document.createElement('li'));
a = $(document.createElement('a'));
a.attr('href', '#');
a.text(contact.name);
a.data('contact', contact);
a.click(contacts_page.viewContact);
li.append(a);
return li;
};
contacts_page.refresh = function() {
var list_el = contacts_page.el.find('#all-contacts');
contacts_page.initContactList(list_el);
list_el.listview('refresh');
console.log('refresh');
};
$('#page-main').live('pagecreate', function() {
contacts_page.el = $(this);
var list_el = contacts_page.el.find('#all-contacts');
contacts_page.initContactList(list_el);
list_el.listview();
});
if ( typeof global.pages === 'undefined' ) {
global.pages = {};
}
global.pages.contacts = contacts_page;
}(this));