Warning, /plasma-mobile/calindori/src/contents/ui/TodoEditorPage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 import QtQuick 2.7
0008 import QtQuick.Controls 2.0 as Controls2
0009 import QtQuick.Layouts 1.3
0010 import org.kde.kirigami 2.12 as Kirigami
0011 import org.kde.calindori 0.1 as Calindori
0012 
0013 Kirigami.Page {
0014     id: root
0015 
0016     property alias startDt: startDateSelector.selectorDate
0017     property string uid
0018     property alias summary: summary.text
0019     property alias description: incidenceEditor.description
0020     property alias startHour: startTimeSelector.selectorHour
0021     property alias startMinute: startTimeSelector.selectorMinutes
0022     property alias startPm: startTimeSelector.selectorPm
0023     property alias dueDt: dueDateSelector.selectorDate
0024     property alias dueHour: dueDtTimeSelector.selectorHour
0025     property alias dueMinute: dueDtTimeSelector.selectorMinutes
0026     property alias duePm: dueDtTimeSelector.selectorPm
0027     property alias allDay: allDaySelector.checked
0028     property alias location: incidenceEditor.location
0029     property alias completed: incidenceEditor.completed
0030     property var incidenceData
0031     property bool isEditorPage: true
0032 
0033     signal editcompleted
0034 
0035     title: uid === "" ? i18n("Create Task") : root.summary
0036 
0037     ColumnLayout {
0038         anchors.centerIn: parent
0039         spacing: Kirigami.Units.smallSpacing
0040 
0041         Kirigami.FormLayout {
0042             id: basicInfo
0043 
0044             Layout.fillWidth: true
0045 
0046             Controls2.TextField {
0047                 id: summary
0048 
0049                 enabled: !root.completed
0050                 text: incidenceData ? incidenceData.summary : ""
0051                 Kirigami.FormData.label: i18n("Summary:")
0052             }
0053 
0054             RowLayout {
0055                 Kirigami.FormData.label: i18n("Start:")
0056                 spacing: 0
0057                 enabled: !root.completed
0058 
0059                 Layout.fillWidth: true
0060 
0061                 DateSelectorButton {
0062                     id: startDateSelector
0063 
0064                     selectorTitle: i18n("Start Date")
0065                     invalidDateStr: "-"
0066                     Layout.fillWidth: true
0067                 }
0068 
0069                 TimeSelectorButton {
0070                     id: startTimeSelector
0071 
0072                     property bool validSelectedDt: startDateSelector.selectorDate != undefined && !isNaN(startDateSelector.selectorDate)
0073 
0074                     selectorDate: startDateSelector.selectorDate
0075                     selectorTitle: i18n("Start Time")
0076                     selectorHour: validSelectedDt ? selectorDate.getHours() % 12 : 0
0077                     selectorMinutes: validSelectedDt ? selectorDate.getMinutes() : 0
0078                     selectorPm: (validSelectedDt && (selectorDate.toLocaleTimeString(Qt.locale("en_US"), "AP") == "PM")) ? true : false
0079                     enabled: !allDaySelector.checked && validSelectedDt
0080                     Layout.alignment: Qt.AlignRight
0081                     Layout.minimumWidth: Kirigami.Units.gridUnit * 3
0082                 }
0083 
0084                 Controls2.ToolButton {
0085                     id: clearStartDt
0086 
0087                     icon.name: "edit-clear-all"
0088                     Layout.alignment: Qt.AlignRight
0089                     Layout.minimumWidth: Kirigami.Units.gridUnit * 2
0090 
0091                     onClicked: {
0092                         startDateSelector.selectorDate = new Date("invalid");
0093                         incidenceAlarmsModel.removeAll();
0094                     }
0095                 }
0096             }
0097 
0098             RowLayout {
0099                 Kirigami.FormData.label: i18n("Due:")
0100                 spacing: 0
0101                 enabled: !root.completed
0102                 Layout.fillWidth: true
0103 
0104                 DateSelectorButton {
0105                     id: dueDateSelector
0106 
0107                     selectorTitle: i18n("Due Date")
0108                     invalidDateStr: "-"
0109                     Layout.fillWidth: true
0110 
0111                     Component.onCompleted: {
0112                         // Do not bind, just initialize
0113                         if (root.incidenceData && root.incidenceData.validDueDt) {
0114                             selectorDate = root.incidenceData.due;
0115                         }
0116                         else if (root.incidenceData == undefined && (root.startDt != undefined) && !isNaN(root.startDt)) {
0117                             var t = root.startDt;
0118                             t.setHours(root.startHour + (startPm ? 12 : 0));
0119                             t.setMinutes(root.startMinute);
0120                             t.setSeconds(0);
0121                             selectorDate = t;
0122                         }
0123                         else {
0124                             selectorDate = new Date("invalid");
0125                         }
0126                     }
0127                 }
0128 
0129                 TimeSelectorButton {
0130                     id: dueDtTimeSelector
0131 
0132                     property bool validSelectedDt: dueDateSelector.selectorDate != undefined && !isNaN(dueDateSelector.selectorDate)
0133 
0134                     selectorDate: dueDateSelector.selectorDate
0135                     selectorTitle: i18n("Due Time")
0136                     selectorHour: validSelectedDt ? selectorDate.getHours() % 12 : 0
0137                     selectorMinutes: validSelectedDt ? selectorDate.getMinutes() : 0
0138                     selectorPm: validSelectedDt && (selectorDate.toLocaleTimeString(Qt.locale("en_US"), "AP") == "PM") ? true : false
0139                     enabled: !allDaySelector.checked && validSelectedDt
0140                     Layout.alignment: Qt.AlignRight
0141                     Layout.minimumWidth: Kirigami.Units.gridUnit * 3
0142                 }
0143 
0144                 Controls2.ToolButton {
0145                     id: clearDueDt
0146 
0147                     icon.name: "edit-clear-all"
0148                     Layout.alignment: Qt.AlignRight
0149                     Layout.minimumWidth: Kirigami.Units.gridUnit * 2
0150 
0151                     onClicked: dueDateSelector.selectorDate = new Date("invalid")
0152                 }
0153             }
0154 
0155             Controls2.CheckBox {
0156                 id: allDaySelector
0157 
0158                 enabled: (!isNaN(root.startDt) || !isNaN(root.dueDt)) && !root.completed
0159                 checked: incidenceData ? incidenceData.allday: false
0160                 Kirigami.FormData.label: i18n("All day:")
0161             }
0162 
0163             Item {
0164                 height: Kirigami.Units.largeSpacing
0165             }
0166         }
0167 
0168         Controls2.TabBar {
0169             id: bar
0170 
0171             Layout.fillWidth: true
0172 
0173             Controls2.TabButton {
0174                 text: i18n("Details")
0175             }
0176 
0177             Controls2.TabButton {
0178                 text: i18n("Reminders")
0179             }
0180         }
0181 
0182         StackLayout {
0183             currentIndex: bar.currentIndex
0184 
0185             IncidenceEditor {
0186                 id: incidenceEditor
0187 
0188                 calendar: Calindori.CalendarController.activeCalendar
0189                 incidenceData: root.incidenceData
0190                 incidenceType: 1
0191             }
0192 
0193             Reminders {
0194                 enabled: root.startDt !== undefined && !isNaN(root.startDt) && !root.completed
0195 
0196                 alarmsModel: incidenceAlarmsModel
0197             }
0198         }
0199     }
0200 
0201     actions {
0202         left: Kirigami.Action {
0203             id: cancelAction
0204 
0205             text: i18n("Cancel")
0206             icon.name : "dialog-cancel"
0207             shortcut: "Esc"
0208 
0209             onTriggered: {
0210                 editcompleted();
0211             }
0212         }
0213 
0214         main: Kirigami.Action {
0215             text: i18n("Save")
0216             icon.name : "dialog-ok"
0217             enabled: summary.text
0218 
0219             onTriggered: {
0220                 var vtodo = { "uid": root.uid, "summary":root.summary, "startDate": root.startDt , "startHour": root.startHour + (root.startPm ? 12 : 0), "startMinute": root.startMinute, "allDay": root.allDay, "description":  root.description, "location": root.location, "completed": root.completed, "dueDate": root.dueDt, "dueHour": root.dueHour + (root.duePm ? 12 : 0), "dueMinute": root.dueMinute, "alarms": incidenceAlarmsModel.alarms() };
0221 
0222                 var validation = Calindori.CalendarController.validateTodo(vtodo);
0223 
0224                 if(validation.success) {
0225                     validationFooter.visible = false;
0226                     Calindori.CalendarController.upsertTodo(Calindori.CalendarController.activeCalendar, vtodo);
0227                     editcompleted();
0228                 }
0229                 else {
0230                     validationFooter.text = validation.reason;
0231                     validationFooter.visible = true;
0232                 }
0233             }
0234         }
0235     }
0236 
0237     footer: Kirigami.InlineMessage {
0238         id: validationFooter
0239 
0240         showCloseButton: true
0241         type: Kirigami.MessageType.Warning
0242         visible: false
0243     }
0244 
0245     Calindori.IncidenceAlarmsModel {
0246 
0247         id: incidenceAlarmsModel
0248 
0249         alarmProperties: { "calendar" : Calindori.CalendarController.activeCalendar, "uid": root.uid }
0250     }
0251 
0252 }