summaryrefslogtreecommitdiffstats
path: root/examples/qmlorganizer/contents/timeline.js
blob: 42b956eeefd0decc9a5c5f5509340806b041aa01 (plain)
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
function changeDate() {
   //TODO
}

function changeToday() {
    yearList.currentIndex = timelineView.year - yearModel.start;
    monthList.currentIndex = timelineView.month;
    dayList.positionViewAtIndex(timelineView.day, ListView.Center);
    dayList.currentIndex = timelineView.day;
}
function extendYearModel(init) {

    var start = yearModel.start;
    var end = yearModel.end;
    var now = new Date();
    var year = 1900 + now.getYear();

    if (init) {
        //initializes the year model
        if (yearModel.count == 1) {
            yearModel.set(0, {"year" : year});
            start = year;
            end = year;
        }
    }

    if (start == 0) return;

    //extends forward
    if (yearList.currentIndex == yearList.count - 1) {
        for (var i = 0; i < 10; i ++) {
            end++;
            yearModel.append({"year" : end});
        }
    }


    //extends backward
    if (yearList.currentIndex == 0) {
        if (start == 1900)
             break;
        for (var i = 0; i < 10; i ++) {
            start--;
            yearModel.insert(1, {"year" : start});
        }
        yearModel.move(0, 10, 1);
    }
    yearModel.start = start;
    yearModel.end = end;
    if (init) {
        yearList.currentIndex = year - start;
    }
}