120 lines
3.3 KiB
QML
120 lines
3.3 KiB
QML
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
|
|
import magpie
|
|
import magpie.Forms as Forms
|
|
import magpie.Components as Components
|
|
|
|
Item {
|
|
StackView {
|
|
id: stack
|
|
initialItem: main
|
|
anchors.fill: parent
|
|
}
|
|
|
|
Component {
|
|
id: main
|
|
Main {
|
|
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);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Component {
|
|
id: addAssetForm
|
|
Forms.Asset {
|
|
onCancel: stack.pop()
|
|
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()
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: Magpie
|
|
function onDisplayError (err) {
|
|
modal.status = err;
|
|
modal.open();
|
|
}
|
|
}
|
|
|
|
Components.Modal {
|
|
id: modal
|
|
closable: true
|
|
}
|
|
}
|