extract statioenSheet to own qml file
[pywienerlinien] / qml / StationSheet.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "UIConstants.js" as UIConstants
4 import "ExtrasConstants.js" as ExtrasConstants
5
6 Sheet {
7     id: stationSheet
8     property string currentLine: ''
9     property string currentDirection: ''
10     property string currentStation: ''
11
12     acceptButtonText: 'Select'
13     rejectButtonText: 'Cancel'
14
15     function loadData(lineName) {
16         stationSheet.currentLine = lineName
17
18         directionChooser.direction1 = ''
19         directionChooser.direction2 = ''
20
21         directionChooserBusyIndicator.running = true
22         itip.load_directions(stationSheet.currentLine)
23
24         firstDirection.clicked()
25         directionChooser.checkedButton = firstDirection
26     }
27
28     Connections {
29         target: itip
30
31         onDirectionsLoaded: {
32             directionChooserBusyIndicator.running = false
33
34             directionChooser.direction1 = itip.get_direction(0)
35             directionChooser.direction2 = itip.get_direction(1)
36
37             firstDirection.clicked()
38             directionChooser.checkedButton = firstDirection
39         }
40     }
41
42     content: Item {
43         anchors.fill: parent
44
45         ButtonColumn {
46             id: directionChooser
47             property string direction1
48             property string direction2
49
50             visible: !directionChooserBusyIndicator.running
51
52             function chosen(idx) {
53                 console.log('direction chosen: '+ idx)
54
55                 stationSelectorListView.selectedIndex = -1
56
57                 if (idx == 1) {
58                     stationSheet.currentDirection = directionChooser.direction1
59                 } else {
60                     stationSheet.currentDirection = directionChooser.direction2
61                 }
62
63                 directionChooserModel.clear()
64                 var stations = itip.get_stations(stationSheet.currentLine, stationSheet.currentDirection)
65
66                 for (var s in stations) {
67                     directionChooserModel.append({'station': stations[s]})
68                 }
69             }
70
71             anchors {
72                 margins: 10
73                 top: parent.top
74                 left: parent.left
75                 right: parent.right
76             }
77
78             Button {
79                 id: firstDirection
80                 text: 'Richtung ' + directionChooser.direction1
81                 onClicked: directionChooser.chosen(1)
82             }
83
84             Button {
85                 id: secondDirection
86                 text: 'Richtung ' + directionChooser.direction2
87                 onClicked: directionChooser.chosen(2)
88             }
89         }
90
91         ListView {
92             id: stationSelectorListView
93             visible: !directionChooserBusyIndicator.running
94
95             property int selectedIndex: -1
96             onSelectedIndexChanged: {
97                 console.log('current index: ' + selectedIndex)
98                 if (selectedIndex != -1) {
99                     stationSheet.currentStation = directionChooserModel.get(selectedIndex).station
100                 } else {
101                     stationSheet.currentStation = ''
102                 }
103             }
104
105             anchors {
106                 margins: 10
107                 top: directionChooser.bottom
108                 left: parent.left
109                 right: parent.right
110                 bottom: parent.bottom
111             }
112
113             clip: true
114
115             model: ListModel {
116                 id: directionChooserModel
117             }
118
119             delegate: SheetListItem { selector: stationSelectorListView }
120         }
121
122         ScrollDecorator {
123             flickableItem: stationSelectorListView
124         }
125
126         BusyIndicator {
127             id: directionChooserBusyIndicator
128             anchors.centerIn: parent
129             visible: running
130             platformStyle: BusyIndicatorStyle { size: 'large' }
131         }
132     }
133
134     onAccepted: {
135         gstation.text = stationSheet.currentStation
136
137         realtimeResult.gline = stationSheet.currentLine
138         realtimeResult.gstation = stationSheet.currentStation
139         realtimeResult.gdirection = stationSheet.currentDirection
140
141         realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
142         console.log('url to get: ' + realtimeResult.sourceUrl)
143
144     }
145 }