native: add group selector
This commit is contained in:
parent
f1001578d5
commit
e398cbb1f7
1 changed files with 40 additions and 2 deletions
|
@ -22,6 +22,10 @@ Window {
|
||||||
|
|
||||||
property string authToken: ""
|
property string authToken: ""
|
||||||
|
|
||||||
|
ListModel {
|
||||||
|
id: groupsModel
|
||||||
|
}
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: nameT
|
id: nameT
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -63,6 +67,18 @@ Window {
|
||||||
text = text.replace(/[^0-9]/g, "")
|
text = text.replace(/[^0-9]/g, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onReturnPressed: groupSelector.focus = true
|
||||||
|
}
|
||||||
|
|
||||||
|
ComboBox {
|
||||||
|
id: groupSelector
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
topMargin: 5
|
||||||
|
top: amountT.bottom
|
||||||
|
}
|
||||||
|
model: groupsModel
|
||||||
|
textRole: "name"
|
||||||
Keys.onReturnPressed: submitB.focus = true
|
Keys.onReturnPressed: submitB.focus = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +87,7 @@ Window {
|
||||||
anchors {
|
anchors {
|
||||||
horizontalCenter: parent.horizontalCenter
|
horizontalCenter: parent.horizontalCenter
|
||||||
topMargin: 5
|
topMargin: 5
|
||||||
top: amountT.bottom
|
top: groupSelector.bottom
|
||||||
}
|
}
|
||||||
text: qsTr("Submit")
|
text: qsTr("Submit")
|
||||||
|
|
||||||
|
@ -96,9 +112,31 @@ Window {
|
||||||
name: nameT.text,
|
name: nameT.text,
|
||||||
key: keyT.text,
|
key: keyT.text,
|
||||||
amount: parseInt(amountT.text),
|
amount: parseInt(amountT.text),
|
||||||
group_id: "ff664d29-68c9-45c2-a6bc-8f378876c90d",
|
group_id: groupSelector.currentIndex !== -1 ? groupsModel.get(groupSelector.currentIndex).id : "",
|
||||||
});
|
});
|
||||||
|
|
||||||
xhr.send(data);
|
xhr.send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fetchGroups() {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", "https://api.clan-war.net/api/v1/licenses");
|
||||||
|
xhr.setRequestHeader("Authorization", "Bearer " + authToken);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
var response = JSON.parse(xhr.responseText);
|
||||||
|
groupsModel.clear();
|
||||||
|
for (var i = 0; i < response.length; i++) {
|
||||||
|
groupsModel.append(response[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Failed to fetch groups: " + xhr.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: fetchGroups()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue