Debian Codegraph @

src/imports/Lomiri/Contacts/ContactList.js

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright 2012-2015 Canonical Ltd.
3 *
4 * This file is part of lomiri-addressbook-app.
5 *
6 * phone-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * phone-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 var sectionData = [];
19 var _sections = [];
20
21 function sectionValueForContact(contact) {
22 if (contact) {
•23 var text = ContactsJS.formatToDisplay(contact, "")
24 var section = text.charAt(0).toUpperCase()
25 return (section === "" ? "#" : section)
26 } else {
27 return null
28 }
29 }
30
31 function initSectionData(list) {
32 if (!list || !list.listModel) {
33 return;
34 }
35
36 sectionData = [];
37 _sections = [];
38
39 var current = "";
40 var item;
41 var contacts = list.listModel.contacts;
42
43 for (var i = 0, count = contacts.length; i < count; i++) {
44 item = sectionValueForContact(contacts[i])
45 if (item !== current) {
46 current = item;
47 _sections.push(current);
48 sectionData.push({ index: i, header: current});
49 }
50 }
51 }
52
53 function getIndexFor(sectionName) {
54 var index = _sections.indexOf(sectionName)
55 if (index != -1) {
56 var val = sectionData[_sections.indexOf(sectionName)].index;
57 return val === 0 || val > 0 ? val : -1;
58 } else {
59 return -1
60 }
61 }