diff --git a/native/AddData.qml b/native/AddData.qml new file mode 100644 index 0000000..1e55c6d --- /dev/null +++ b/native/AddData.qml @@ -0,0 +1,104 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Layouts 2.15 +import QtQuick.Controls 2.15 + +Window { + SystemPalette { id: activeColors; colorGroup: SystemPalette.Active } + SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive } + SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled } + + function getColors() { + return dataScreen.active ? activeColors : inactiveColors; + } + + id: dataScreen + width: 640 + height: 480 + visible: true + color: getColors().window + + title: qsTr("Alisa - Add License") + + property string authToken: "" + + TextField { + id: nameT + anchors { + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: parent.top // Assuming there's no loginL defined in your code + } + placeholderText: qsTr("Name") + Keys.onReturnPressed: keyT.focus = true + } + + TextField { + id: keyT + anchors { + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: nameT.bottom + } + placeholderText: qsTr("Key") + Keys.onReturnPressed: amountT.focus = true + } + + TextField { + id: amountT + anchors { + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: keyT.bottom + } + placeholderText: qsTr("Amount") + inputMethodHints: Qt.ImhDigitsOnly + + validator: DoubleValidator { + bottom: 0 + top: 1000000 + } + + onTextChanged: { + text = text.replace(/[^0-9]/g, "") + } + + Keys.onReturnPressed: submitB.focus = true + } + + Button { + id: submitB + anchors { + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: amountT.bottom + } + text: qsTr("Submit") + + onClicked: submit() + Keys.onReturnPressed: submit() + } + + function submit() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://api.clan-war.net/api/v1/licenses"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.setRequestHeader("Authorization", "Bearer " + authToken); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status != 200) { + console.log("Submission failed: " + xhr.status); + } + } + } + + var data = JSON.stringify({ + name: nameT.text, + key: keyT.text, + amount: parseInt(amountT.text), + group_id: "f7604976-1e3c-49b7-841b-6a4025257c70", + }); + + xhr.send(data); + } +} diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index d8f2e91..533d9e4 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -20,11 +20,10 @@ qt_add_qml_module(alisa Test.qml MainPage.qml LoginScreen.qml + AddData.qml RESOURCES Assets/Icons/turbo.svg - - ) set_target_properties(alisa PROPERTIES diff --git a/native/MainPage.qml b/native/MainPage.qml index 28e5fc4..5844bba 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -27,19 +27,18 @@ Rectangle { color: getColors().midlight TextField { - anchors{ - verticalCenter: s1.verticalCenter - rightMargin: 5 - right: loginB.left + anchors { + verticalCenter: s1.verticalCenter + rightMargin: 5 + right: loginB.left } placeholderText: qsTr("Search") - } - Button{ + Button { id: loginB - anchors{ + anchors { verticalCenter: s1.verticalCenter rightMargin: 10 right: s1.right @@ -50,9 +49,27 @@ Rectangle { logout(); } } + + Button { + text: qsTr("Add License") + anchors { + verticalCenter: s1.verticalCenter + rightMargin: 10 + right: loginB.left + } + onClicked: { + // Create and show a new window + var newWindow = newWindowComponent.createObject(null, { authToken: authToken }); + if (newWindow !== null) { + newWindow.show(); + } else { + console.log("Failed to create new window"); + } + } + } } - Rectangle{ + Rectangle { id: s2 anchors { top: s1.bottom @@ -113,6 +130,14 @@ Rectangle { } } + Component { + id: newWindowComponent + AddData { + id: dataWindow + authToken: authToken + } + } + Component.onCompleted: { var xhr = new XMLHttpRequest(); xhr.open("GET", "https://api.clan-war.net/api/v1/licenses");