51 lines
1.2 KiB
QML
51 lines
1.2 KiB
QML
import QtQuick 2.0
|
|
|
|
QtObject {
|
|
id: root
|
|
|
|
property string serviceUrl: undefined
|
|
|
|
signal modelLoad(var data)
|
|
signal error(string text)
|
|
|
|
function _get(url, callback) {
|
|
var request = new XMLHttpRequest()
|
|
|
|
request.open('GET', url)
|
|
request.onreadystatechange = function () {
|
|
if (request.readyState !== XMLHttpRequest.DONE) {
|
|
return
|
|
}
|
|
|
|
if (request.status === 200) {
|
|
if (callback !== undefined) {
|
|
callback(JSON.parse(request.responseText))
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
root.error(qsTr("[%1] Request error: %2").
|
|
arg(request.status).
|
|
arg(request.statusText))
|
|
}
|
|
|
|
request.send()
|
|
}
|
|
|
|
function loadModel() {
|
|
_get(root.serviceUrl + '/static/channels.js', root.modelLoad)
|
|
}
|
|
|
|
function sendCommand(command, channelId) {
|
|
_get(root.serviceUrl + '/noolite/%1/%2'.arg(command).arg(channelId), function (data) {
|
|
if (data.error) {
|
|
root.error(qsTr("Server error: %1").arg(data.error))
|
|
return
|
|
}
|
|
|
|
console.log(data.command, data.channel)
|
|
})
|
|
}
|
|
}
|