| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import QtQuick 2.0
- import ru.ded.noolight 1.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, true, Settings.login, Settings.password)
- request.withCredentials = true
- 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)
- })
- }
- }
|