~pkunal-parmar/ubuntu-calendar-app/MakeEditorVisible

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
 * Copyright (C) 2013-2014 Canonical Ltd
 *
 * This file is part of Ubuntu Calendar App
 *
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * Ubuntu Calendar App 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
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import QtQuick 2.3
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Themes.Ambiance 1.0
import Ubuntu.Components.Popups 1.0
import QtOrganizer 5.0

import "Defines.js" as Defines

Page {
    id: root
    objectName: "eventDetails"

    property var event
    property var model

    anchors{
        left: parent.left
        right: parent.right
        bottom: parent.bottom
    }

    flickable: null

    title: i18n.tr("Event Details")

    Component.onCompleted: {
        showEvent(event)
    }

    Connections{
        target: pageStack
        onCurrentPageChanged:{
            if( pageStack.currentPage === root) {
                showEvent(event)
            }
        }
    }

    RemindersModel {
        id: reminderModel
    }

    function updateCollection(event) {
        var collection = model.collection( event.collectionId );
        calendarIndicator.color = collection.color
        eventInfo.color=collection.color
        calendarName.text = i18n.tr("%1 Calendar").arg( collection.name)
    }

    function updateRecurrence( event ) {
        var index = 0;
        if (event.recurrence) {
            if(event.recurrence.recurrenceRules[0] !== undefined){
                var rule =  event.recurrence.recurrenceRules[0];
                repeatLabel.text = eventUtils.getRecurrenceString(rule)
            }
        }
    }

    function updateContacts(event) {
        var attendees = event.attendees;
        contactModel.clear();
        if( attendees !== undefined ) {
            for (var j = 0 ; j < attendees.length ; ++j) {
                contactModel.append( {"name": attendees[j].name,"participationStatus": attendees[j].participationStatus }  );
            }
        }
    }

    function updateReminder(event) {
        var reminder = event.detail( Detail.VisualReminder)
        if( reminder ) {
            for(var i=0; i<reminderModel.count; i++) {
                if(reminder.secondsBeforeStart === reminderModel.get(i).value)
                    reminderHeader.subText = reminderModel.get(i).label
            }
        } else {
            reminderHeader.subText = reminderModel.get(0).label
        }
    }

    function updateLocation(event) {
        if( event.location ) {
            locationLabel.text = i18n.tr("%1").arg(event.location)
        }
    }

    function showEvent(e) {
        var startTime = e.startDateTime.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
        var endTime = e.endDateTime.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)

        dateLabel.text = e.allDay === true ? i18n.tr("%1 (All Day)").arg( e.startDateTime.toLocaleDateString(Qt.locale(), Locale.LongFormat))
                                           : e.startDateTime.toLocaleDateString(Qt.locale(), Locale.LongFormat) + ", " +startTime + " - "  + endTime;

        if( e.itemType === Type.EventOccurrence ){
            var requestId = -1;
            model.onItemsFetched.connect( function(id,fetchedItems){
                if(requestId === id && fetchedItems.length > 0) {
                    internal.parentEvent = fetchedItems[0];
                    updateRecurrence(internal.parentEvent);
                    updateContacts(internal.parentEvent);
                }
            });
            requestId = model.fetchItems([e.parentId]);
        }
        // This is the event title
        if( e.displayLabel) {
            titleLabel.text = e.displayLabel;
        }

        if( e.description ) {
            descLabel.text = e.description;
        }

        updateCollection(e);

        updateContacts(e);

        updateRecurrence(e);

        updateReminder(e);

        updateLocation(e);
    }

    Keys.onEscapePressed: {
        pageStack.pop();
    }

    Keys.onPressed: {
        if ((event.key === Qt.Key_E) && ( event.modifiers & Qt.ControlModifier)) {
            pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"event": root.event});
        }
    }

    head.actions: [
        Action {
            text: i18n.tr("Delete");
            objectName: "delete"
            iconName: "delete"
            onTriggered: {
                var dialog = PopupUtils.open(Qt.resolvedUrl("DeleteConfirmationDialog.qml"),root,{"event": event});
                dialog.deleteEvent.connect( function(eventId){
                    model.removeItem(eventId);
                    pageStack.pop();
                });
            }
        },

        Action {
            text: i18n.tr("Edit");
            objectName: "edit"
            iconName: "edit";
            onTriggered: {
                if( event.itemType === Type.EventOccurrence ) {
                    var dialog = PopupUtils.open(Qt.resolvedUrl("EditEventConfirmationDialog.qml"),root,{"event": event});
                    dialog.editEvent.connect( function(eventId){
                        if( eventId === event.parentId ) {
                            pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"event":internal.parentEvent,"model":model});
                        } else {
                            pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"event":event,"model":model});
                        }
                    });
                } else {
                    pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"event":event,"model":model});
                }
            }
        }
    ]

    EventUtils{
        id:eventUtils
    }

    QtObject{
        id: internal
        property var parentEvent;
    }

    Rectangle {
        id: bg
        color: "white"
        anchors.fill: parent
    }

    Scrollbar {
        flickableItem: flicable
        align: Qt.AlignTrailing
    }

    Flickable{
        id: flicable

        clip: interactive
        anchors.fill: parent
        interactive: contentHeight > height

        contentWidth: parent.width
        contentHeight: column.height + eventInfo.height + units.gu(3) /*top margin + spacing */

        Rectangle{
            id: eventInfo

            width: parent.width
            height: eventInfoList.height + units.gu(5)

            Column{
                id:eventInfoList

                anchors {
                    left: parent.left
                    right: parent.right
                    top: parent.top
                    margins: units.gu(2)
                }

                spacing: units.gu(0.5)

                Label{
                    id: titleLabel
                    objectName: "titleLabel"
                    fontSize: "x-large"
                    width: parent.width
                    wrapMode: Text.WordWrap
                    color: "white"
                }

                Label{
                    id: dateLabel
                    objectName: "dateLabel"
                    color: "white"
                    fontSize: "medium"
                    width: parent.width
                    wrapMode: Text.WordWrap
                }

                Label{
                    id: repeatLabel
                    objectName: "repeatLabel"
                    color: "white"
                    fontSize: "small"
                    width: parent.width
                    wrapMode: Text.WordWrap
                    visible: repeatLabel.text !== ""
                }

                Label{
                    id: locationLabel
                    objectName: "locationLabel"
                    color: "white"
                    fontSize: "small"
                    width: parent.width
                    wrapMode: Text.WordWrap
                    visible: locationLabel.text !== ""
                }
            }
        }

        Column{
            id: column

            spacing: units.gu(1)
            anchors{
                top: eventInfo.bottom
                right: parent.right
                left:parent.left
                margins: units.gu(2)
            }

            Row{
                width: parent.width
                spacing: units.gu(1)
                UbuntuShape{
                    id: calendarIndicator
                    width: parent.height
                    height: width
                    anchors.verticalCenter: parent.verticalCenter
                }
                Label{
                    id:calendarName
                    objectName: "calendarName"
                    anchors.verticalCenter: parent.verticalCenter
                }
            }

            Label{
                id: descLabel
                objectName: "descriptionLabel"
                visible: text != ""
                width: parent.width
                wrapMode: Text.WordWrap
            }

            Column {
                anchors{
                    right: parent.right
                    left:parent.left
                    margins: units.gu(-2)
                }

                ListItem.Header {
                    text: i18n.tr("Guests")
                    visible: contactModel.count !== 0
                }

                //Guest Entery Model starts
                Column{
                    id: contactList
                    objectName: 'contactList'

                    anchors {
                        left: parent.left
                        right: parent.right
                    }

                    ListModel {
                        id: contactModel
                    }

                    Repeater{
                        model: contactModel
                        delegate: ListItem.Standard {
                            Label {
                                text: name
                                objectName: "eventGuest%1".arg(index)
                                color: UbuntuColors.midAubergine
                                anchors {
                                    left: parent.left
                                    leftMargin: units.gu(2)
                                    verticalCenter: parent.verticalCenter
                                }
                            }

                            control: CheckBox {
                                enabled: false
                                checked: participationStatus
                            }
                        }
                    }
                }
                //Guest Entries ends

                ListItem.Subtitled {
                    id: reminderHeader
                    text: i18n.tr("Reminder")
                }
            }
        }
    }
}