DetailsPage.qml 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
15
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25
*/

import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.0 as Kirigami
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App

26
Kirigami.ScrollablePage {
27
    id: root
28 29
    /** The reservation batch identifier (@see ReservationManager). */
    property var batchId
30 31
    /** Currently selected reservation of the batch. */
    property var currentReservationId: batchId
32
    /** @deprecated */
33
    readonly property var reservation: _reservationManager.reservation(currentReservationId);
34
    /** Reservation::reservationFor, unique for all travelers on a multi-traveler reservation set */
35 36
    readonly property var reservationFor: reservation.reservationFor
    property var editor
37
    readonly property string passId: _pkpassManager.passId(reservation)
38

39 40 41 42
    Kirigami.OverlaySheet {
        id: deleteWarningSheet

        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
43
            text: i18n("Do you really want to delete this event?")
44 45 46 47 48 49
            wrapMode: Text.WordWrap
        }

        footer: RowLayout {
            QQC2.Button {
                Layout.alignment: Qt.AlignHCenter
Volker Krause's avatar
Volker Krause committed
50
                text: i18n("Delete")
51 52
                icon.name: "edit-delete"
                onClicked: {
53
                    _reservationManager.removeBatch(root.batchId);
54
                    applicationWindow().pageStack.pop();
55 56 57 58 59
                }
            }
        }
    }

Volker Krause's avatar
Volker Krause committed
60 61 62 63 64 65 66
    Component {
        id: pkpassComponent
        App.PkPassPage {
            pass: _pkpassManager.passObject(passId)
        }
    }

67
    // TODO this needs multi-traveler support!
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    Instantiator {
        model: reservation.potentialAction
        delegate: Component {
            Kirigami.Action {
                text: {
                    if (modelData.className == "CancelAction") return i18n("Cancel Reservation");
                    if (modelData.className == "CheckInAction") return i18n("Check-in");
                    if (modelData.className == "DownloadAction") return i18n("Download");
                    if (modelData.className == "UpdateAction") return i18n("Change Reservation");
                    if (modelData.className == "ViewAction") return i18n("View Reservation");
                }
                iconName: {
                    if (modelData.className == "CancelAction") return "dialog-cancel";
                    if (modelData.className == "CheckInAction") return "checkmark";
                    if (modelData.className == "DownloadAction") return "edit-download";
                    if (modelData.className == "UpdateAction") return "document-edit";
                    if (modelData.className == "ViewAction") return "document-open";
                }
                onTriggered: Qt.openUrlExternally(modelData.target)
            }
        }
        onObjectAdded: actions.contextualActions.push(object)
    }

92 93 94 95
    actions {
        contextualActions: [
            Kirigami.Action {
                iconSource: root.passId !== "" ? "image://org.kde.pkpass/" + passId + "/icon" : ""
96
                text: i18n("Show Boarding Pass")
97
                visible: _pkpassManager.hasPass(root.passId)
98
                onTriggered: applicationWindow().pageStack.push(pkpassComponent, {"passId": root.passId });
99 100 101 102 103 104 105 106 107 108 109
            },
            Kirigami.Action {
                iconName: "document-edit"
                text: i18n("Edit")
                visible: root.editor != undefined
                onTriggered: applicationWindow().pageStack.push(editor);
            },
            Kirigami.Action {
                iconName: "edit-delete"
                text: i18n("Delete")
                onTriggered: deleteWarningSheet.sheetOpen = true
110 111 112
            }
        ]
    }
113 114 115

    onBackRequested: pageStack.pop()
}