magpie/qml/Application/Root.qml

120 lines
3.3 KiB
QML
Raw Permalink Normal View History

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
2024-01-21 19:22:56 +00:00
import magpie
2024-01-17 21:57:34 +00:00
import magpie.Forms as Forms
2024-01-21 19:22:56 +00:00
import magpie.Components as Components
2024-01-17 21:57:34 +00:00
Item {
StackView {
id: stack
initialItem: main
anchors.fill: parent
}
Component {
id: main
Main {
2024-01-17 21:57:34 +00:00
onAddAsset: stack.push(addAssetForm);
onEditAsset: function(id) {
const asset = Magpie.assets.getAssetByID(id);
stack.push(editAssetForm, {
name: asset.title,
icon: asset.icon,
color: asset.color,
currency: asset.currencyID,
assetID: asset.assetID,
title: qsTr("Editing asset") + " " + asset.title
});
}
onRemoveAsset: function(id) {
API.deleteAsset(id, function(err) {
if (err)
Magpie.displayError("Error deleting asset " + Magpie.assets.getAssetByID(id).title + ": " + err);
});
}
2024-01-17 21:57:34 +00:00
}
}
2024-01-17 21:57:34 +00:00
Component {
id: addAssetForm
2024-04-05 16:17:24 +00:00
Forms.Asset {
2024-01-17 21:57:34 +00:00
onCancel: stack.pop()
2024-04-05 16:17:24 +00:00
onConfirm: function (title, icon, color, currency) {
if (modal.inProgress)
return;
modal.inProgress = true;
modal.status = qsTr("Creating new asset ") + " " + title + "...";
modal.open();
API.addAsset(title, icon, color, currency, function (err, result) {
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
else
modal.status = qsTr("Success");
if (!!result) {
modal.close();
stack.pop()
}
});
}
}
}
2024-01-21 19:22:56 +00:00
Component {
id: editAssetForm
Forms.Asset {
required property int assetID
onCancel: stack.pop()
onConfirm: function (title, icon, color, currency) {
if (modal.inProgress)
return;
modal.inProgress = true;
modal.status = qsTr("Updating asset ") + " " + Magpie.assets.getAssetByID(assetID).title + "...";
modal.open();
API.updateAsset(assetID, title, icon, color, currency, function (err, result) {
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
else
modal.status = qsTr("Success");
if (!!result) {
modal.close();
stack.pop()
}
});
}
}
}
2024-01-21 19:22:56 +00:00
Connections {
target: Magpie
function onDisplayError (err) {
modal.status = err;
modal.open();
}
}
Components.Modal {
id: modal
closable: true
}
}