From e4f766c349a0365d167a0a95015475af29deddf5 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Sun, 31 Jul 2011 12:01:37 +0200 Subject: [PATCH] Moved JavaScript to its own file --- application/application.pro | 3 +- .../resources/harmattan/qml/StationListPage.js | 30 ++++++++++++++++ .../resources/harmattan/qml/StationListPage.qml | 37 ++++++-------------- 3 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 application/resources/harmattan/qml/StationListPage.js diff --git a/application/application.pro b/application/application.pro index d0393a4..b555f7f 100644 --- a/application/application.pro +++ b/application/application.pro @@ -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 index 0000000..096eefc --- /dev/null +++ b/application/resources/harmattan/qml/StationListPage.js @@ -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 = "

Loading station " + name + "

Lorem ipsum

" + 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, '' + + match + '') + } else { + return s + } +} + diff --git a/application/resources/harmattan/qml/StationListPage.qml b/application/resources/harmattan/qml/StationListPage.qml index 7955711..8d27815 100644 --- a/application/resources/harmattan/qml/StationListPage.qml +++ b/application/resources/harmattan/qml/StationListPage.qml @@ -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 = "

Hello World

Lorem ipsum

" - } - 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, '' + - match + '') - } 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) } } } -- 1.7.9.5