magpie/qml/Forms/AddAsset.qml

113 lines
2.6 KiB
QML
Raw Normal View History

2024-01-17 21:57:34 +00:00
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
2024-01-20 21:17:21 +00:00
import magpie
2024-01-17 21:57:34 +00:00
import magpie.Components as Components
Item {
signal success
signal cancel
Column {
id: inner
spacing: 5
anchors.centerIn: parent
Label {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("New asset")
font.pixelSize: 14
}
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2
columnSpacing: 10
rowSpacing: 5
verticalItemAlignment: Grid.AlignVCenter
horizontalItemAlignment: Grid.AlignRight
Label {
text: qsTr("Title") + ":";
}
TextField {
id: titleField
2024-04-02 01:45:48 +00:00
text: "New Asset"
2024-01-17 21:57:34 +00:00
}
Label {
text: qsTr("Icon") + ":";
}
2024-04-02 01:45:48 +00:00
Components.IconPicker {
2024-01-17 21:57:34 +00:00
id: iconField
2024-04-02 01:45:48 +00:00
icon: "list-add"
2024-01-17 21:57:34 +00:00
}
Label {
text: qsTr("Color") + ":";
}
TextField {
id: colorField
}
}
Row {
spacing: 5
anchors.horizontalCenter: parent.horizontalCenter
Button {
text: qsTr("Cancel")
onClicked: cancel()
}
Button {
text: qsTr("Create")
2024-04-02 01:45:48 +00:00
onClicked: inner.confirm()
2024-01-17 21:57:34 +00:00
}
}
Components.Modal {
id: modal
}
2024-04-02 01:45:48 +00:00
function confirm () {
//TODO validation
send(titleField.text, iconField.icon, colorField.text);
}
2024-01-17 21:57:34 +00:00
function send (title, icon, color) {
if (modal.inProgress)
return;
titleField.text = title;
2024-04-02 01:45:48 +00:00
iconField.icon = icon;
2024-01-17 21:57:34 +00:00
colorField.text = color;
modal.inProgress = true;
modal.status = qsTr("Creating new asset ") + " " + title + "...";
modal.open();
2024-01-21 19:22:56 +00:00
API.addAsset(title, icon, "blue", function (err, result) {
2024-01-17 21:57:34 +00:00
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
else
modal.status = qsTr("Success");
if (!!result) {
modal.close();
success();
}
});
}
}
}