PageMenuMessage.qml 4.37 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 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 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 <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

import QtQuick 2.7
25
import QtQuick.Controls 2.1
26
import cz.nic.mobileDatovka 1.0
27
import cz.nic.mobileDatovka.messages 1.0
28
import cz.nic.mobileDatovka.models 1.0
29 30

Component {
31
    id: menuMessage
32 33
    Item {
        id: mainLayout
34 35

        /* These properties must be set by caller. */
36 37
        property var pageView
        property var statusBar
38 39 40 41 42
        property string acntName
        property string userName
        property int msgType
        property string msgId
        property bool canDeleteMsg
43
        property var accountModel: null
44
        property var messageModel: null
45

46
        Component.onCompleted: {
47 48
            var index = messageMenuList.get_model_index(messageMenuListModel, "funcName", "delMsg");
            if (index >= 0) {
49
                messageMenuListModel.setProperty(index, "showEntry", canDeleteMsg)
50
            }
51
        }
52

53 54
        PageHeader {
            id: headerBar
55 56 57
            title: qsTr("Message") + ": " + msgId
            onBackClicked: {
                pageView.pop(StackView.Immediate)
58 59
            }
        }
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

        /* Object (associative array) holding functions. */
        property var funcs: {
            "downlAttch": function callDownlAttch() {
                isds.doIsdsAction("downloadMessage", userName)
                pageView.pop(StackView.Immediate)
            },
            "markRead": function callMarkRead() {
                messages.markMessageAsLocallyRead(messageModel, userName, msgId, true)
                pageView.pop(StackView.Immediate)
            },
            "markUnread": function callMarkUnread() {
                messages.markMessageAsLocallyRead(messageModel, userName, msgId, false)
                pageView.pop(StackView.Immediate)
            },
            "delMsg": function callDelMsg() {
                messages.deleteMessageFromDbs(accountModel, messageModel, userName, msgId)
                pageView.pop(StackView.Immediate)
            }
        }

81 82 83 84
        ListModel {
            id: messageMenuListModel
            ListElement {
                image: "qrc:/ui/datovka-email-download.svg"
85
                showEntry: true
86
                showNext: false
87 88
                name: qsTr("Download attachments")
                funcName: "downlAttch"
89 90 91
            }
            ListElement {
                image: "qrc:/ui/email-open-outline.svg"
92
                showEntry: true
93
                showNext: false
94 95
                name: qsTr("Mark as read")
                funcName: "markRead"
96 97 98
            }
            ListElement {
                image: "qrc:/ui/email-outline.svg"
99
                showEntry: true
100
                showNext: false
101 102
                name: qsTr("Mark as unread")
                funcName: "markUnread"
103 104 105
            }
            ListElement {
                image: "qrc:/ui/delete.svg"
106
                showEntry: true
107
                showNext: false
108 109
                name: qsTr("Delete message")
                funcName: "delMsg"
110 111
            }
        }
112 113

        AccessibleMenu {
114 115 116 117 118 119 120
            id: messageMenuList
            anchors.top: headerBar.bottom
            anchors.bottom: parent.bottom
            width: parent.width
            clip: true
            spacing: 1
            opacity: 1
121 122

            funcArr: funcs
123
            model: messageMenuListModel
124
        }
125

126 127 128 129 130 131
        Connections {
            target: isds
            onRunDownloadMessageSig: {
                 isds.downloadMessage(messageModel, userName, msgType, msgId)
            }
        }
132 133
    }
}