Warning, /plasma-mobile/calindori/src/contents/ui/EventEditorPage.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.ScrollablePage {
0014     id: root
0015 
0016     property string uid
0017     property alias summary: summary.text
0018     property alias description: incidenceEditor.description
0019     property alias startDt: startDateSelector.selectorDate
0020     property alias startHour: startTimeSelector.selectorHour
0021     property alias startMinute: startTimeSelector.selectorMinutes
0022     property alias startPm: startTimeSelector.selectorPm
0023     property alias allDay: allDaySelector.checked
0024     property alias location: incidenceEditor.location
0025     property var calendar
0026     property var incidenceData
0027     property alias endDt: endDateSelector.selectorDate
0028     property alias endHour: endTimeSelector.selectorHour
0029     property alias endMinute: endTimeSelector.selectorMinutes
0030     property alias endPm: endTimeSelector.selectorPm
0031     property alias repeatType: repeatSelector.repeatType
0032     property alias repeatEvery: repeatSelector.repeatEvery
0033     property alias repeatStopAfter: repeatSelector.stopAfter
0034     property alias incidenceStatus: incidenceEditor.incidenceStatus
0035     property bool isEditorPage: true
0036 
0037     signal editcompleted(var vevent)
0038 
0039     Component.onCompleted: {
0040         if(incidenceData == null && Calindori.CalindoriConfig.alwaysRemind)
0041         {
0042             incidenceAlarmsModel.addAlarm(Calindori.CalindoriConfig.preEventRemindTime * 60)
0043         }
0044     }
0045 
0046     title: uid === "" ? i18n("Create Event") : root.summary
0047 
0048     ColumnLayout {
0049         anchors.centerIn: parent
0050         spacing: Kirigami.Units.smallSpacing
0051 
0052         Kirigami.FormLayout {
0053             id: basicInfo
0054 
0055             Layout.fillWidth: true
0056 
0057             Controls2.TextField {
0058                 id: summary
0059 
0060                 text: incidenceData ? incidenceData.summary : ""
0061                 Kirigami.FormData.label: i18n("Summary:")
0062             }
0063 
0064             RowLayout {
0065                 spacing: 0
0066                 Kirigami.FormData.label: i18n("Start:")
0067                 Layout.fillWidth: true
0068 
0069                 DateSelectorButton {
0070                     id: startDateSelector
0071 
0072                     selectorTitle: i18n("Start Date")
0073                     invalidDateStr: "-"
0074                     Layout.fillWidth: true
0075                 }
0076 
0077                 TimeSelectorButton {
0078                     id: startTimeSelector
0079 
0080                     selectorTitle: i18n("Start Time")
0081                     selectorDate: root.startDt
0082                     selectorHour: (root.incidenceData ? root.incidenceData.dtstart.getHours() : root.startDt.getHours() ) % 12
0083                     selectorMinutes: root.incidenceData ? root.incidenceData.dtstart.getMinutes() : root.startDt.getMinutes()
0084                     selectorPm: root.incidenceData ? (root.incidenceData.dtstart.getHours() >=12) : (root.startDt.getHours() >=12)
0085                     enabled: !allDaySelector.checked
0086                     Layout.alignment: Qt.AlignRight
0087                     Layout.minimumWidth: Kirigami.Units.gridUnit * 4
0088                 }
0089             }
0090 
0091             RowLayout {
0092                 spacing: 0
0093                 Kirigami.FormData.label: i18n("End:")
0094                 Layout.fillWidth: true
0095 
0096                 DateSelectorButton {
0097                     id: endDateSelector
0098 
0099                     enabled: !allDaySelector.checked
0100                     selectorTitle: i18n("End Date")
0101                     invalidDateStr: "-"
0102                     Layout.fillWidth: true
0103 
0104                     Component.onCompleted: {
0105                         var newDt;
0106 
0107                         if(root.incidenceData) {
0108                             newDt = root.incidenceData.dtend;
0109                         }
0110                         else {
0111                             newDt= root.startDt;
0112                             newDt.setMinutes(newDt.getMinutes() + Calindori.CalindoriConfig.eventsDuration);
0113                             newDt.setSeconds(0);
0114                         }
0115 
0116                         selectorDate = newDt;
0117                     }
0118                 }
0119 
0120                 TimeSelectorButton {
0121                     id: endTimeSelector
0122 
0123                     selectorTitle: i18n("End Time")
0124                     selectorDate: root.endDt
0125                     selectorHour: root.endDt.getHours() % 12
0126                     selectorMinutes: root.endDt.getMinutes()
0127                     selectorPm: (root.endDt.getHours() >=12)
0128                     enabled: !allDaySelector.checked && (root.endDt != undefined && !isNaN(root.endDt))
0129                     Layout.alignment: Qt.AlignRight
0130                     Layout.minimumWidth: Kirigami.Units.gridUnit * 4
0131                 }
0132             }
0133 
0134             Controls2.CheckBox {
0135                 id: allDaySelector
0136 
0137                 enabled: !isNaN(root.startDt)
0138                 checked: incidenceData ? incidenceData.allday: false
0139                 text: i18n("All day")
0140             }
0141 
0142             Controls2.ToolButton {
0143                 id: repeatSelector
0144 
0145                 property int repeatType: incidenceData != null && incidenceData.isRepeating ? incidenceData.repeatType : _repeatModel.noRepeat
0146                 property int repeatEvery: incidenceData != null && incidenceData.isRepeating ? incidenceData.repeatEvery : 1
0147                 property string repeatDescription: _repeatModel && _repeatModel.periodDecription(repeatType)
0148                 property int stopAfter: incidenceData != null && incidenceData.isRepeating ? incidenceData.repeatStopAfter: -1
0149 
0150                 contentItem: Controls2.Label {
0151                     leftPadding: Kirigami.Units.largeSpacing
0152                     rightPadding: Kirigami.Units.largeSpacing
0153                     text: _repeatModel && _repeatModel.repeatDescription(parent.repeatType, parent.repeatEvery, parent.stopAfter)
0154                 }
0155 
0156                 Kirigami.FormData.label: i18n("Repeat:")
0157                 Layout.fillWidth: true
0158 
0159                 onClicked: recurPickerSheet.init(repeatType, repeatEvery, stopAfter)
0160             }
0161 
0162         }
0163 
0164         Item {
0165             height: Kirigami.Units.largeSpacing
0166         }
0167 
0168         Controls2.TabBar {
0169             id: bar
0170 
0171             Layout.fillWidth: Kirigami.Settings.isMobile
0172             Layout.alignment: Qt.AlignHCenter
0173 
0174             Controls2.TabButton {
0175                 text: i18n("Details")
0176             }
0177 
0178             Controls2.TabButton {
0179                 text: i18n("Reminders")
0180             }
0181 
0182             Controls2.TabButton {
0183                 text: i18n("Attendees")
0184             }
0185         }
0186 
0187         StackLayout {
0188             currentIndex: bar.currentIndex
0189 
0190             IncidenceEditor {
0191                 id: incidenceEditor
0192 
0193                 calendar: root.calendar
0194                 incidenceData: root.incidenceData
0195                 incidenceType: 0
0196             }
0197 
0198             Reminders {
0199                 enabled: (root.startDt !== undefined) && !isNaN(root.startDt)
0200                 alarmsModel: incidenceAlarmsModel
0201             }
0202 
0203             Attendees {
0204                 attendeesModel: incidenceAttendeesModel
0205                 incidenceData: root.incidenceData
0206             }
0207 
0208         }
0209     }
0210 
0211     actions {
0212 
0213         left: Kirigami.Action {
0214             id: cancelAction
0215 
0216             text: i18n("Cancel")
0217             icon.name : "dialog-cancel"
0218             shortcut: "Esc"
0219 
0220             onTriggered: editcompleted(null)
0221         }
0222 
0223         main: Kirigami.Action {
0224             text: i18n("Save")
0225             icon.name: "dialog-ok"
0226             enabled: summary.text
0227 
0228             onTriggered: {
0229                 var vevent = { "uid" : root.uid, "startDate": root.startDt, "summary": root.summary, "description": root.description, "startHour": root.startHour + (root.startPm ? 12 : 0), "startMinute": root.startMinute, "allDay": root.allDay, "location": root.location, "endDate": root.endDt, "endHour": root.endHour + (root.endPm ? 12 : 0), "endMinute": root.endMinute, "alarms": incidenceAlarmsModel.alarms(), "periodType": root.repeatType, "repeatEvery": root.repeatEvery, "stopAfter": root.repeatStopAfter, "status": root.incidenceStatus};
0230 
0231                 var validation = Calindori.CalendarController.validateEvent(vevent);
0232 
0233                 if(validation.success) {
0234                     validationFooter.visible = false;
0235                     Calindori.CalendarController.upsertEvent(vevent, incidenceAttendeesModel.attendees());
0236                     editcompleted(vevent);
0237                 }
0238                 else {
0239                     validationFooter.text = validation.reason;
0240                     validationFooter.visible = true;
0241                 }
0242             }
0243         }
0244     }
0245 
0246     footer: Kirigami.InlineMessage {
0247         id: validationFooter
0248 
0249         showCloseButton: true
0250         type: Kirigami.MessageType.Warning
0251         visible: false
0252     }
0253 
0254     Calindori.IncidenceAlarmsModel {
0255         id: incidenceAlarmsModel
0256 
0257         alarmProperties: { "calendar" : root.calendar, "uid": root.uid }
0258     }
0259 
0260     Calindori.AttendeesModel {
0261         id: incidenceAttendeesModel
0262 
0263         uid: root.uid
0264     }
0265 
0266     RecurrencePickerSheet {
0267         id: recurPickerSheet
0268 
0269         onRecurrencePicked: {
0270             repeatSelector.repeatType = recurPickerSheet.selectedRepeatType;
0271             repeatSelector.repeatEvery = recurPickerSheet.selectedRepeatEvery
0272             repeatSelector.stopAfter = recurPickerSheet.selectedStopAfter;
0273         }
0274     }
0275 }