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

« back to all changes in this revision

Viewing changes to NewEvent.qml

New Calendar App management tests. Fixes: https://bugs.launchpad.net/bugs/1300354.

Approved by Ubuntu Phone Apps Jenkins Bot, Nicholas Skaggs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 2.0
2
 
import Ubuntu.Components 0.1
3
 
import Ubuntu.Components.Popups 0.1
4
 
import Ubuntu.Components.ListItems 0.1 as ListItem
5
 
 
6
 
import "dataService.js" as DataService
7
 
 
8
 
Popover {
9
 
    id: popover
10
 
    property var defaultDate;
11
 
    property alias errorText: errorPopupDialog.text;
12
 
    property var startDate: new Date()
13
 
    property var endDate: new Date()
14
 
 
15
 
    Column {
16
 
        id: containerLayout
17
 
        anchors {
18
 
            left: parent.left
19
 
            top: parent.top
20
 
            right: parent.right
21
 
        }
22
 
 
23
 
        ListItem.Header { text: i18n.tr("Create event") }
24
 
        ListItem.Empty {
25
 
            highlightWhenPressed: false
26
 
            TextField {
27
 
                objectName: "newEventName"
28
 
                id: titleEdit
29
 
                placeholderText: i18n.tr("Add event name")
30
 
                anchors {
31
 
                    fill: parent
32
 
                    margins: units.gu(1)
33
 
                }
34
 
            }
35
 
        }
36
 
 
37
 
        ListItem.Empty {
38
 
            id: dateItem
39
 
 
40
 
            height: column.height
 
1
/*
 
2
 * Copyright (C) 2013-2014 Canonical Ltd
 
3
 *
 
4
 * This file is part of Ubuntu Calendar App
 
5
 *
 
6
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License version 3 as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.3
 
20
import QtOrganizer 5.0
 
21
import Ubuntu.Components 1.1
 
22
import Ubuntu.Components.Popups 1.0
 
23
import Ubuntu.Components.ListItems 1.0 as ListItem
 
24
import Ubuntu.Components.Themes.Ambiance 1.0
 
25
import Ubuntu.Components.Pickers 1.0
 
26
import QtOrganizer 5.0
 
27
import "Defines.js" as Defines
 
28
 
 
29
Page {
 
30
    id: root
 
31
    objectName: 'newEventPage'
 
32
 
 
33
    property var date;
 
34
 
 
35
    property var event:null;
 
36
    property var rule :null;
 
37
    property var model;
 
38
 
 
39
    property var startDate;
 
40
    property var endDate;
 
41
 
 
42
    property alias scrollY: flickable.contentY
 
43
    property bool isEdit: false
 
44
 
 
45
    signal eventAdded(var event);
 
46
 
 
47
    onStartDateChanged: {
 
48
        startDateTimeInput.dateTime = startDate;
 
49
        adjustEndDateToStartDate()
 
50
    }
 
51
 
 
52
    onEndDateChanged: {
 
53
        endDateTimeInput.dateTime = endDate;
 
54
    }
 
55
 
 
56
    head.actions: Action {
 
57
        iconName: "ok"
 
58
        objectName: "save"
 
59
        text: i18n.tr("Save")
 
60
        enabled: !!titleEdit.text.trim()
 
61
        onTriggered: saveToQtPim();
 
62
    }
 
63
 
 
64
    Component.onCompleted: {
 
65
        //If current date is setted by an argument we don't have to change it.
 
66
        if(typeof(date) === 'undefined'){
 
67
            date = new Date();
 
68
        }
 
69
 
 
70
        if( typeof(date) == 'undefined' || (date.getHours() == 0 && date.getMinutes() == 0) ) {
 
71
            var newDate = new Date();
 
72
            date.setHours(newDate.getHours(), newDate.getMinutes());
 
73
        }
 
74
 
 
75
        // If startDate is setted by argument we have to not change it
 
76
        //Set the nearest current time.
 
77
        if (typeof(startDate) === 'undefined')
 
78
            startDate = new Date(root.roundDate(date))
 
79
 
 
80
        // If endDate is setted by argument we have to not change it
 
81
        if (typeof(endDate) === 'undefined') {
 
82
            endDate = new Date(root.roundDate(date))
 
83
            endDate.setMinutes(endDate.getMinutes() + 30)
 
84
            endTimeInput.text = Qt.formatDateTime(endDate, Qt.locale().timeFormat(Locale.ShortFormat));
 
85
        }
 
86
 
 
87
        if(event === null){
 
88
            isEdit = false;
 
89
            addEvent();
 
90
        }
 
91
 
 
92
        else{
 
93
            isEdit = true;
 
94
            editEvent(event);
 
95
        }
 
96
    }
 
97
 
 
98
    function selectCalendar(collectionId) {
 
99
        var index = 0;
 
100
        for(var i=0; i < calendarsOption.model.length; ++i){
 
101
            if(calendarsOption.model[i].collectionId === collectionId){
 
102
                index = i;
 
103
                break;
 
104
            }
 
105
        }
 
106
        calendarsOption.selectedIndex = index
 
107
        internal.collectionId = collectionId;
 
108
    }
 
109
 
 
110
    //Data for Add events
 
111
    function addEvent() {
 
112
        event = Qt.createQmlObject("import QtOrganizer 5.0; Event { }", Qt.application,"NewEvent.qml");
 
113
        //Create fresh Recurrence Object.
 
114
        rule = Qt.createQmlObject("import QtOrganizer 5.0; RecurrenceRule {}", event.recurrence,"EventRepetition.qml");
 
115
        selectCalendar(model.defaultCollection().collectionId);
 
116
    }
 
117
 
 
118
    //Editing Event
 
119
    function editEvent(e) {
 
120
        //If there is a ReccruenceRule use that , else create fresh Recurrence Object.
 
121
        if(e.itemType === Type.Event){
 
122
            rule = (e.recurrence.recurrenceRules[0] === undefined || e.recurrence.recurrenceRules[0] === null) ?
 
123
                        Qt.createQmlObject("import QtOrganizer 5.0; RecurrenceRule {}", event.recurrence,"EventRepetition.qml")
 
124
                      : e.recurrence.recurrenceRules[0];
 
125
        }
 
126
        startDate =new Date(e.startDateTime);
 
127
        endDate = new Date(e.endDateTime);
 
128
 
 
129
        if(e.displayLabel) {
 
130
            titleEdit.text = e.displayLabel;
 
131
        }
 
132
        if(e.allDay){
 
133
            allDayEventCheckbox.checked =true;
 
134
        }
 
135
 
 
136
        if(e.location) {
 
137
            locationEdit.text = e.location;
 
138
        }
 
139
 
 
140
        if( e.description ) {
 
141
            messageEdit.text = e.description;
 
142
        }
 
143
 
 
144
        allDayEventCheckbox.checked = e.allDay;
 
145
        var index = 0;
 
146
 
 
147
        if( e.itemType === Type.Event ) {
 
148
            if(e.attendees){
 
149
                for( var j = 0 ; j < e.attendees.length ; ++j ) {
 
150
                    contactList.array.push(e.attendees[j]);
 
151
                    contactModel.append(e.attendees[j]);
 
152
                }
 
153
            }
 
154
        }
 
155
        var reminder = e.detail( Detail.VisualReminder);
 
156
        if (reminder) {
 
157
            visualReminder.secondsBeforeStart = reminder.secondsBeforeStart;
 
158
        } else {
 
159
            visualReminder.secondsBeforeStart = reminderModel.get(0).value;
 
160
        }
 
161
 
 
162
        selectCalendar(e.collectionId);
 
163
    }
 
164
    //Save the new or Existing event
 
165
    function saveToQtPim() {
 
166
        internal.clearFocus()
 
167
        if ( startDate >= endDate && !allDayEventCheckbox.checked) {
 
168
            PopupUtils.open(errorDlgComponent,root,{"text":i18n.tr("End time can't be before start time")});
 
169
        } else {
 
170
            var newCollection = calendarsOption.model[calendarsOption.selectedIndex].collectionId;
 
171
            if( internal.collectionId !== newCollection ){
 
172
                //collection change to event is not suported
 
173
                //to change collection we create new event with same data with different collection
 
174
                //and remove old event
 
175
                var eventId = event.itemId;
 
176
                model.removeItem(event.itemId)
 
177
                event = Qt.createQmlObject("import QtOrganizer 5.0; Event {}", Qt.application,"NewEvent.qml");
 
178
            }
 
179
 
 
180
            event.startDateTime = startDate;
 
181
            event.endDateTime = endDate;
 
182
            event.displayLabel = titleEdit.text;
 
183
            event.description = messageEdit.text;
 
184
            event.location = locationEdit.text
 
185
 
 
186
            event.allDay = allDayEventCheckbox.checked;
 
187
 
 
188
            if( event.itemType === Type.Event ) {
 
189
                event.attendees = []; // if Edit remove all attendes & add them again if any
 
190
                var contacts = [];
 
191
                for(var i=0; i < contactList.array.length ; ++i) {
 
192
                    var contact = contactList.array[i]
 
193
                    contacts.push(contact);
 
194
                }
 
195
                event.attendees = contacts;
 
196
            }
 
197
 
 
198
            //Set the Rule object to an event
 
199
            if(rule !== null && rule !== undefined) {
 
200
                event.recurrence.recurrenceRules = [rule]
 
201
            }
 
202
 
 
203
            //remove old reminder value
 
204
            var oldVisualReminder = event.detail(Detail.VisualReminder);
 
205
            if(oldVisualReminder) {
 
206
                event.removeDetail(oldVisualReminder);
 
207
            }
 
208
 
 
209
            var oldAudibleReminder = event.detail(Detail.AudibleReminder);
 
210
            if(oldAudibleReminder) {
 
211
                event.removeDetail(oldAudibleReminder);
 
212
            }
 
213
            if(visualReminder.secondsBeforeStart >= 0) {
 
214
                event.setDetail(visualReminder);
 
215
                event.setDetail(audibleReminder);
 
216
            }
 
217
            event.collectionId = calendarsOption.model[calendarsOption.selectedIndex].collectionId;
 
218
            model.saveItem(event);
 
219
            pageStack.pop();
 
220
            root.eventAdded(event);
 
221
        }
 
222
    }
 
223
 
 
224
    VisualReminder{
 
225
        id:visualReminder
 
226
    }
 
227
    AudibleReminder{
 
228
        id:audibleReminder
 
229
    }
 
230
 
 
231
    function getDaysOfWeek(){
 
232
        var daysOfWeek = [];
 
233
        switch(recurrenceOption.selectedIndex){
 
234
        case 2:
 
235
            daysOfWeek = Qt.locale().weekDays;
 
236
            break;
 
237
        case 3:
 
238
            daysOfWeek = [Qt.Monday,Qt.Wednesday,Qt.Friday];
 
239
            break;
 
240
        case 4:
 
241
            daysOfWeek = [Qt.Tuesday,Qt.Thursday];
 
242
            break;
 
243
        case 5:
 
244
            daysOfWeek = internal.weekDays.length === 0 ? [date.getDay()] : internal.weekDays;
 
245
            break;
 
246
        }
 
247
        return daysOfWeek;
 
248
    }
 
249
 
 
250
    // Calucate default hour and minute for start and end time on event
 
251
    function roundDate(date) {
 
252
        var tempDate = new Date(date)
 
253
        tempDate.setHours(date.getHours(), date.getMinutes(), 0, 0);
 
254
        if(tempDate.getMinutes() < 30)
 
255
            return tempDate.setMinutes(30)
 
256
        tempDate.setMinutes(0)
 
257
        return tempDate.setHours(tempDate.getHours() + 1)
 
258
    }
 
259
 
 
260
    function adjustEndDateToStartDate() {
 
261
        // set time forward to one hour
 
262
        var time_forward = 3600000;
 
263
        endDate = new Date( startDate.getTime() + time_forward );
 
264
    }
 
265
 
 
266
    ScrollAnimation{id:scrollAnimation}
 
267
 
 
268
    function scrollOnExpand(Self,Container,Target,Margin,Visible)
 
269
    {
 
270
        // Self is needed for "onXxxxxChange" triggers. OnExpansionCompleted however can just write "true".
 
271
        // Container is the item which encapsulates everything, such as a column.
 
272
        // Target is the Flickable id you wish to scroll
 
273
        // Margin is the space between the bottom of the screen and the bottom of the item you are scrolling to.
 
274
        // Visible is needed if there is anything that appears under the item you are scrolling to.
 
275
        if (Self === false){return}
 
276
        var v = units.gu(Margin)
 
277
        for (var i in Visible){if(Visible[i].visible === true){v+=Visible[i].height};}
 
278
 
 
279
        scrollAnimation.target = Target
 
280
        scrollAnimation.to = Container.height-height - v
 
281
        scrollAnimation.start()
 
282
    }
 
283
 
 
284
    width: parent.width
 
285
    height: parent.height
 
286
 
 
287
    title: isEdit ? i18n.tr("Edit Event"):i18n.tr("New Event")
 
288
 
 
289
    Keys.onEscapePressed: {
 
290
        pageStack.pop();
 
291
    }
 
292
 
 
293
    Component{
 
294
        id: errorDlgComponent
 
295
        Dialog {
 
296
            id: dialog
 
297
            title: i18n.tr("Error")
 
298
            Button {
 
299
                text: i18n.tr("OK")
 
300
                onClicked: PopupUtils.close(dialog)
 
301
            }
 
302
        }
 
303
    }
 
304
 
 
305
    EventUtils{
 
306
        id:eventUtils
 
307
    }
 
308
 
 
309
    Flickable{
 
310
        id: flickable
 
311
 
 
312
        property var activeItem: null
 
313
 
 
314
        function makeMeVisible(item) {
 
315
            if (!item) {
 
316
                return
 
317
            }
 
318
 
 
319
            activeItem = item
 
320
            var position = flickable.contentItem.mapFromItem(item, 0, 0);
 
321
 
 
322
            // check if the item is already visible
 
323
            var bottomY = flickable.contentY + flickable.height
 
324
            var itemBottom = position.y + item.height
 
325
            if (position.y >= flickable.contentY && itemBottom <= bottomY) {
 
326
                return;
 
327
            }
 
328
 
 
329
            // if it is not, try to scroll and make it visible
 
330
            var targetY = position.y + item.height - flickable.height
 
331
            if (targetY >= 0 && position.y) {
 
332
                flickable.contentY = targetY;
 
333
            } else if (position.y < flickable.contentY) {
 
334
                // if it is hidden at the top, also show it
 
335
                flickable.contentY = position.y;
 
336
            }
 
337
            flickable.returnToBounds()
 
338
        }
 
339
 
 
340
        anchors.fill: parent
 
341
        contentWidth: width
 
342
        contentHeight: column.height + units.gu(10)
 
343
 
 
344
        Column {
 
345
            id: column
 
346
 
41
347
            width: parent.width
42
348
 
43
 
            Column {
44
 
                id: column
45
 
 
46
 
                anchors {
47
 
                    left: parent.left
48
 
                    right: parent.right
49
 
                }
50
 
 
51
 
                Item {
52
 
                    width: popover.width
53
 
                    height: dateLabel.height
54
 
                    Label {
55
 
                        id: dateLabel
56
 
                        text: Qt.formatDateTime(defaultDate, "ddd, d MMMM yyyy");
57
 
                        anchors {
58
 
                            left: parent.left
59
 
                            right: parent.right
60
 
                            margins: units.gu(1)
61
 
                        }
62
 
                    }
63
 
                }
64
 
 
65
 
                Component {
66
 
                    id: timePicker
67
 
                    TimePicker {
68
 
                    }
69
 
                }
70
 
 
71
 
                Item {
72
 
                    id: timeContainer
73
 
                    width: parent.width
74
 
                    height: startTimeItem.height
75
 
 
76
 
                    ListItem.Empty {
77
 
                        id: startTimeItem
78
 
                        anchors.left: timeContainer.left
79
 
                        width: units.gu(12)
80
 
                        Button {
81
 
                            objectName: "startTimeInput"
82
 
                            id: startTimeButton
83
 
                            text: Qt.formatDateTime(startDate,"hh:mm")
84
 
                            anchors {
85
 
                                fill: parent
86
 
                                margins: units.gu(1)
87
 
                            }
88
 
                            onClicked: {
89
 
                                internal.clearFocus()
90
 
                                var popupObj = PopupUtils.open(timePicker);
91
 
                                popupObj.accepted.connect(function(startHour, startMinute) {
92
 
                                    var newDate = startDate;
93
 
                                    newDate.setHours(startHour, startMinute);
94
 
                                    startDate = newDate;
95
 
                                })
96
 
                            }
97
 
                        }
98
 
                    }
99
 
 
100
 
                    Label {
101
 
                        id: endTimeLabel
102
 
                        text: i18n.tr("to");
103
 
                        anchors {
104
 
                            horizontalCenter: parent.horizontalCenter;
105
 
                            verticalCenter: startTimeItem.verticalCenter;
106
 
                        }
107
 
                    }
108
 
 
109
 
                   ListItem.Empty {
110
 
                        id: endTimeItem
111
 
                        highlightWhenPressed: false
112
 
                        anchors.right: timeContainer.right
113
 
                        width: units.gu(12)
114
 
                        Button {
115
 
                            objectName: "endTimeInput"
116
 
                            id: endTimeButton
117
 
                            text: Qt.formatDateTime(endDate,"hh:mm")
118
 
                            anchors {
119
 
                                fill: parent
120
 
                                margins: units.gu(1)
121
 
                            }
122
 
                            onClicked: {
123
 
                                internal.clearFocus()
124
 
                                var popupObj = PopupUtils.open(timePicker);
125
 
                                popupObj.accepted.connect(function(endHour, endMinute) {
126
 
                                    var newDate = endDate;
127
 
                                    newDate.setHours(endHour, endMinute);
128
 
                                    endDate = newDate;
129
 
                                })
130
 
                            }
131
 
                        }
132
 
                    }
133
 
                }
134
 
            }
135
 
        }
136
 
 
137
 
        ListItem.Header { text: i18n.tr("Location & People") }
138
 
        ListItem.Empty {
139
 
            highlightWhenPressed: false
140
 
            TextField {
141
 
                objectName: "eventLocationInput"
142
 
                id: locationEdit
143
 
                placeholderText: i18n.tr("Add Location")
144
 
                anchors {
145
 
                    fill: parent
146
 
                    margins: units.gu(1)
147
 
                }
148
 
            }
149
 
        }
150
 
 
151
 
        ListItem.Empty {
152
 
            highlightWhenPressed: false
153
 
            TextField {
154
 
                objectName: "eventPeopleInput"
155
 
                id: personEdit
156
 
                placeholderText: i18n.tr("Invite People")
157
 
                anchors {
158
 
                    fill: parent
159
 
                    margins: units.gu(1)
160
 
                }
161
 
            }
162
 
        }
163
 
 
164
 
        ListItem.Empty {
165
 
            highlightWhenPressed: false
166
 
            Dialog {
167
 
                id: errorPopupDialog
168
 
                title: i18n.tr("Error")
169
 
                text: ""
170
 
                Button {
171
 
                    text: i18n.tr("Ok")
172
 
                    onClicked: PopupUtils.close(errorPopupDialog)
173
 
                }
174
 
            }
175
 
            Button {
176
 
                objectName: "eventSaveButton"
177
 
                text: i18n.tr("Save")
178
 
                anchors {
179
 
                    fill: parent
180
 
                    margins: units.gu(1)
181
 
                }
182
 
 
183
 
                onClicked: {
184
 
                    internal.clearFocus()
185
 
 
186
 
                    var error = 0;
187
 
 
188
 
                    if (startDate > endDate)
189
 
                        error = 2;
190
 
 
191
 
                    startDate.setDate(defaultDate.getDate());
192
 
                    endDate.setDate(defaultDate.getDate());
193
 
 
194
 
                    var event = {
195
 
                        title: titleEdit.text,
196
 
                        message: null,
197
 
                        startTime: startDate.getTime(),
198
 
                        endTime: endDate.getTime()
199
 
                    }
200
 
 
201
 
                    if (!error) {
202
 
                        DataService.addEvent(event);
203
 
                        PopupUtils.close(popover);
 
349
            NewEventTimePicker{
 
350
                id: startDateTimeInput
 
351
                header: i18n.tr("From")
 
352
                showTimePicker: !allDayEventCheckbox.checked
 
353
                anchors {
 
354
                    left: parent.left
 
355
                    right: parent.right
 
356
                }
 
357
                onDateTimeChanged: {
 
358
                    startDate = dateTime;
 
359
                }
 
360
            }
 
361
 
 
362
            NewEventTimePicker{
 
363
                id: endDateTimeInput
 
364
                header: i18n.tr("To")
 
365
                showTimePicker: !allDayEventCheckbox.checked
 
366
                anchors {
 
367
                    left: parent.left
 
368
                    right: parent.right
 
369
                }
 
370
                onDateTimeChanged: {
 
371
                    endDate = dateTime;
 
372
                }
 
373
            }
 
374
 
 
375
            ListItem.Standard {
 
376
                anchors {
 
377
                    left: parent.left
 
378
                    right: parent.right
 
379
                }
 
380
 
 
381
                text: i18n.tr("All day event")
 
382
                showDivider: false
 
383
                control: CheckBox {
 
384
                    objectName: "allDayEventCheckbox"
 
385
                    id: allDayEventCheckbox
 
386
                    checked: false
 
387
                }
 
388
            }
 
389
 
 
390
            ListItem.ThinDivider {}
 
391
 
 
392
            Column {
 
393
                width: parent.width
 
394
                spacing: units.gu(1)
 
395
 
 
396
                ListItem.Header{
 
397
                    text: i18n.tr("Event Details")
 
398
                }
 
399
 
 
400
                TextField {
 
401
                    id: titleEdit
 
402
                    objectName: "newEventName"
 
403
 
 
404
                    anchors {
 
405
                        left: parent.left
 
406
                        right: parent.right
 
407
                        margins: units.gu(2)
 
408
                    }
 
409
 
 
410
                    placeholderText: i18n.tr("Event Name")
 
411
                }
 
412
 
 
413
                TextArea{
 
414
                    id: messageEdit
 
415
                    objectName: "eventDescriptionInput"
 
416
 
 
417
                    anchors {
 
418
                        left: parent.left
 
419
                        right: parent.right
 
420
                        margins: units.gu(2)
 
421
                    }
 
422
 
 
423
                    placeholderText: i18n.tr("Description")
 
424
                }
 
425
 
 
426
                TextField {
 
427
                    id: locationEdit
 
428
                    objectName: "eventLocationInput"
 
429
 
 
430
                    anchors {
 
431
                        left: parent.left
 
432
                        right: parent.right
 
433
                        margins: units.gu(2)
 
434
                    }
 
435
 
 
436
                    placeholderText: i18n.tr("Location")
 
437
                }
 
438
            }
 
439
 
 
440
            Column {
 
441
                width: parent.width
 
442
                spacing: units.gu(1)
 
443
 
 
444
                ListItem.Header {
 
445
                    text: i18n.tr("Calendar")
 
446
                }
 
447
 
 
448
                OptionSelector{
 
449
                    id: calendarsOption
 
450
                    objectName: "calendarsOption"
 
451
 
 
452
                    anchors {
 
453
                        left: parent.left
 
454
                        right: parent.right
 
455
                        margins: units.gu(2)
 
456
                    }
 
457
 
 
458
                    containerHeight: itemHeight * 4
 
459
                    model: root.model.getCollections();
 
460
 
 
461
                    delegate: OptionSelectorDelegate{
 
462
                        text: modelData.name
 
463
 
 
464
                        UbuntuShape{
 
465
                            id: calColor
 
466
                            width: height
 
467
                            height: parent.height - units.gu(2)
 
468
                            color: modelData.color
 
469
                            anchors.right: parent.right
 
470
                            anchors.rightMargin: units.gu(2)
 
471
                            anchors.verticalCenter: parent.verticalCenter
 
472
                        }
 
473
                    }
 
474
                    onExpandedChanged: Qt.inputMethod.hide();
 
475
                }
 
476
            }
 
477
 
 
478
            Column {
 
479
                width: parent.width
 
480
                spacing: units.gu(1)
 
481
 
 
482
                ListItem.Header {
 
483
                    text: i18n.tr("Guests")
 
484
                }
 
485
 
 
486
                Button{
 
487
                    text: i18n.tr("Add Guest")
 
488
                    objectName: "addGuestButton"
 
489
 
 
490
                    anchors {
 
491
                        left: parent.left
 
492
                        right: parent.right
 
493
                        margins: units.gu(2)
 
494
                    }
 
495
 
 
496
                    onClicked: {
 
497
                        var popup = PopupUtils.open(Qt.resolvedUrl("ContactChoicePopup.qml"), contactList);
 
498
                        popup.contactSelected.connect( function(contact) {
 
499
                            var t = internal.contactToAttendee(contact);
 
500
                            if( !internal.isContactAlreadyAdded(contact) ) {
 
501
                                contactModel.append(t);
 
502
                                contactList.array.push(t);
 
503
                            }
 
504
                        });
 
505
                    }
 
506
                }
 
507
 
 
508
                UbuntuShape {
 
509
                    anchors {
 
510
                        left: parent.left
 
511
                        right: parent.right
 
512
                        margins: units.gu(2)
 
513
                    }
 
514
 
 
515
                    height: contactList.height
 
516
 
 
517
                    Column{
 
518
                        id: contactList
 
519
                        objectName: "guestList"
 
520
 
 
521
                        spacing: units.gu(1)
 
522
                        width: parent.width
 
523
                        clip: true
 
524
 
 
525
                        property var array: []
 
526
 
 
527
                        ListModel{
 
528
                            id: contactModel
 
529
                        }
 
530
 
 
531
                        Repeater{
 
532
                            model: contactModel
 
533
                            delegate: ListItem.Standard {
 
534
                                objectName: "eventGuest%1".arg(index)
 
535
                                height: units.gu(4)
 
536
                                text: name
 
537
                                removable: true
 
538
                                onItemRemoved: {
 
539
                                    contactList.array.splice(index, 1)
 
540
                                    contactModel.remove(index)
 
541
                                }
 
542
                            }
 
543
                        }
 
544
                    }
 
545
                }
 
546
 
 
547
                ListItem.ThinDivider {
 
548
                    visible: event.itemType === Type.Event
 
549
                }
 
550
 
 
551
            }
 
552
 
 
553
            ListItem.Subtitled{
 
554
                id:thisHappens
 
555
                objectName :"thisHappens"
 
556
 
 
557
                anchors {
 
558
                    left: parent.left
 
559
                }
 
560
 
 
561
                showDivider: false
 
562
                progression: true
 
563
                visible: event.itemType === Type.Event
 
564
                text: i18n.tr("Repeats")
 
565
                subText: event.itemType === Type.Event ? eventUtils.getRecurrenceString(rule) : ""
 
566
                onClicked: pageStack.push(Qt.resolvedUrl("EventRepetition.qml"),{"rule": rule,"date":date,"isEdit":isEdit});
 
567
            }
 
568
 
 
569
            ListItem.ThinDivider {
 
570
                visible: event.itemType === Type.Event
 
571
            }
 
572
 
 
573
            ListItem.Subtitled{
 
574
                id:eventReminder
 
575
                objectName  : "eventReminder"
 
576
 
 
577
                anchors{
 
578
                    left:parent.left
 
579
                }
 
580
                showDivider: false
 
581
                progression: true
 
582
                text: i18n.tr("Reminder")
 
583
 
 
584
                RemindersModel {
 
585
                    id: reminderModel
 
586
                }
 
587
 
 
588
                subText:{
 
589
                    if(visualReminder.secondsBeforeStart !== -1) {
 
590
                        for(var i=0; i<reminderModel.count; i++) {
 
591
                            if(visualReminder.secondsBeforeStart === reminderModel.get(i).value)
 
592
                                return reminderModel.get(i).label
 
593
                        }
204
594
                    } else {
205
 
                        errorText = i18n.tr("End time can't be before start time");
206
 
                        errorPopupDialog.show();
 
595
                        reminderModel.get(0).label
207
596
                    }
208
 
 
209
 
                    error = 0;
210
597
                }
 
598
 
 
599
                onClicked: pageStack.push(Qt.resolvedUrl("EventReminder.qml"),
 
600
                                          {"visualReminder": visualReminder,
 
601
                                              "audibleReminder": audibleReminder,
 
602
                                              "reminderModel": reminderModel,
 
603
                                              "eventTitle": titleEdit.text})
 
604
            }
 
605
 
 
606
            ListItem.ThinDivider {}
 
607
        }
 
608
    }
 
609
    // used to keep the field visible when the keyboard appear or dismiss
 
610
    KeyboardRectangle {
 
611
        id: keyboard
 
612
 
 
613
        onHeightChanged: {
 
614
            if (flickable.activeItem) {
 
615
                flickable.makeMeVisible(flickable.activeItem)
211
616
            }
212
617
        }
213
618
    }
214
619
 
215
620
    QtObject {
216
621
        id: internal
 
622
        property var collectionId;
217
623
 
218
624
        function clearFocus() {
219
625
            Qt.inputMethod.hide()
220
626
            titleEdit.focus = false
221
627
            locationEdit.focus = false
222
 
            personEdit.focus = false
 
628
            startDateTimeInput.clearFocus();
 
629
            endDateTimeInput.clearFocus();
 
630
            messageEdit.focus = false
 
631
        }
 
632
 
 
633
        function isContactAlreadyAdded(contact) {
 
634
            for(var i=0; i < contactList.array.length ; ++i) {
 
635
                var attendee = contactList.array[i];
 
636
                if( attendee.attendeeId === contact.contactId) {
 
637
                    return true;
 
638
                }
 
639
            }
 
640
            return false;
 
641
        }
 
642
 
 
643
        function contactToAttendee(contact) {
 
644
            var attendee = Qt.createQmlObject("import QtOrganizer 5.0; EventAttendee{}", event, "NewEvent.qml");
 
645
            attendee.name = contact.displayLabel.label
 
646
            attendee.emailAddress = contact.email.emailAddress;
 
647
            attendee.attendeeId = contact.contactId;
 
648
            return attendee;
223
649
        }
224
650
    }
225
651
}