Moved JavaScript to its own file
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 31 Jul 2011 10:01:37 +0000 (12:01 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Tue, 27 Dec 2011 22:16:49 +0000 (23:16 +0100)
application/application.pro
application/resources/harmattan/qml/StationListPage.js [new file with mode: 0644]
application/resources/harmattan/qml/StationListPage.qml

index 595e31d..679f2b3 100644 (file)
@@ -113,7 +113,8 @@ OTHER_FILES += \
     resources/harmattan/qml/StationPage.qml \
     resources/harmattan/qml/SearchBar.qml \
     resources/harmattan/qml/PageHeader.qml \
-    resources/harmattan/qml/uiconstants.js
+    resources/harmattan/qml/uiconstants.js \
+    resources/harmattan/qml/StationListPage.js
 
 unix {
     isEmpty(PREFIX) {
diff --git a/application/resources/harmattan/qml/StationListPage.js b/application/resources/harmattan/qml/StationListPage.js
new file mode 100644 (file)
index 0000000..096eefc
--- /dev/null
@@ -0,0 +1,30 @@
+var view = undefined
+
+function loadStation(name)
+{
+    var component = Qt.createComponent("StationPage.qml");
+    if (component.status == Component.Ready) {
+        view = component.createObject(stationListPage)
+        stationListPage.stationView = view
+        pageStack.push(view)
+        view.html = "<h1>Loading station " + name + "</h1><p>Lorem ipsum</p>"
+        provider.stationSchedule(name)
+    }
+    else
+        console.log('Cannot load component: ' + component.errorString());
+}
+
+function highlightSearch(s)
+{
+    // TODO compile RegExp on change, or find a way to cleanly use
+    // stationListProxyModel.filterRegExp
+    if (searchField.text.length) {
+        var r = new RegExp(searchField.text, 'i')
+        var match = r.exec(s)
+        return s.replace(r, '<span style="text-decoration:underline">' +
+                         match + '</span>')
+    } else {
+        return s
+    }
+}
+
index 7955711..8d27815 100644 (file)
@@ -3,6 +3,7 @@ import QtMobility.location 1.1
 import com.nokia.meego 1.0
 import net.cirulla.quandoparte 1.0
 import "uiconstants.js" as UiConstants
+import "StationListPage.js" as Private
 
 Page {
     property variant stationView
@@ -17,33 +18,15 @@ Page {
         ToolIcon { iconId: "icon-m-toolbar-view-menu"; }
     }
 
-    function loadStation()
-    {
-        var component = Qt.createComponent("StationPage.qml");
-        if (component.status == Component.Ready) {
-            var view = component.createObject(stationListPage)
-            stationListPage.stationView = view
-            pageStack.push(view)
-            view.html = "<h1>Hello World</h1><p>Lorem ipsum</p>"
-        }
-        else
-            console.log('Cannot load component: ' + component.errorString());
-    }
-
-    function highlightSearch(s)
-    {
-        // TODO compile RegExp on change, or find a way to cleanly use
-        // stationListProxyModel.filterRegExp
-        if (searchField.text.length) {
-            var r = new RegExp(searchField.text, 'i')
-            var match = r.exec(s)
-            return s.replace(r, '<span style="text-decoration:underline">' +
-                             match + '</span>')
-        } else {
-            return s
+    DataProvider {
+        id: provider
+        onStationScheduleReady: {
+            if (Private.view !== undefined) {
+                Private.view.html = result
+                //Private.view.url = url
+            }
         }
     }
-
     PageHeader {
         id: header
         anchors.top: parent.top
@@ -117,7 +100,7 @@ Page {
 
                         Label {
                             id: mainText
-                            text: highlightSearch(model.display)
+                            text: Private.highlightSearch(model.display)
                             font.bold: true
                         }
                     }
@@ -126,7 +109,7 @@ Page {
                     id: mouseArea
                     anchors.fill: background
                     onClicked: {
-                        stationListPage.loadStation(model.display)
+                        Private.loadStation(model.display)
                     }
                 }
             }