~om26er/address-book-app/abook_navigation_favorites

« back to all changes in this revision

Viewing changes to src/imports/ContactList.js

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2013-06-27 20:05:52 UTC
  • Revision ID: renato.filho@canonical.com-20130627200552-b115j5fcqfnpy7ez
First commit of Address Book Application

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2013 Canonical Ltd
 
4
**
 
5
****************************************************************************/
 
6
 
 
7
var sectionData = [];
 
8
var _sections = [];
 
9
 
 
10
function initSectionData(list) {
 
11
    if (!list || !list.model) {
 
12
        return;
 
13
    }
 
14
 
 
15
    sectionData = [];
 
16
    _sections = [];
 
17
 
 
18
    var current = "",
 
19
        prop = list.section.property,
 
20
        item;
 
21
 
 
22
    for (var i = 0, count = list.model.contacts.length; i < count; i++) {
 
23
        item = list.sectionValueForContact(list.model.contacts[i])
 
24
        if (item !== current) {
 
25
            current = item;
 
26
            _sections.push(current);
 
27
            sectionData.push({ index: i, header: current });
 
28
        }
 
29
    }
 
30
}
 
31
 
 
32
function getIndexFor(sectionName) {
 
33
    var val = sectionData[_sections.indexOf(sectionName)].index;
 
34
    return val === 0 || val > 0 ? val : -1;
 
35
}