~timo-jyrinki/ubuntu-calendar-app/use_pickerpanelworkaround_lp1351024

« back to all changes in this revision

Viewing changes to NewEvent.qml

  • Committer: Kunal Parmar
  • Date: 2014-05-19 08:54:41 UTC
  • mfrom: (274 ubuntu-calendar-app)
  • mto: This revision was merged to the branch mainline in revision 354.
  • Revision ID: pkunal.parmar@gmail.com-20140519085441-rw80fn7schao4tqi
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
Page {
12
12
    id: root
13
 
    property var date: new Date();
 
13
    property var date : new Date();
14
14
 
15
15
    property var event:null;
16
16
    property var model;
27
27
        pageStack.header.visible = true;
28
28
 
29
29
        // If startDate is setted by argument we have to not change it
 
30
        //Set the nearest current time.
 
31
        var newDate = new Date();
 
32
        date.setHours(newDate.getHours(), newDate.getMinutes());
30
33
        if (typeof(startDate) === 'undefined')
31
 
            startDate = new Date(date)
 
34
            startDate = new Date(root.roundDate(date))
32
35
 
33
36
        // If endDate is setted by argument we have to not change it
34
37
        if (typeof(endDate) === 'undefined') {
35
 
            endDate = new Date(date)
36
 
            endDate.setMinutes( endDate.getMinutes() + 30)
 
38
            endDate = new Date(root.roundDate(date))
 
39
            endDate.setMinutes(endDate.getMinutes() + 30)
37
40
        }
38
41
 
39
42
        if(event === null){
49
52
    //Data for Add events
50
53
    function addEvent() {
51
54
        event = Qt.createQmlObject("import QtOrganizer 5.0; Event { }", Qt.application,"NewEvent.qml");
52
 
        startDate = new Date(date)
53
 
        endDate = new Date(date)
54
 
        endDate.setMinutes( endDate.getMinutes() + 30)
55
55
 
56
56
        startTime.text = Qt.formatDateTime(startDate, "dd MMM yyyy hh:mm");
57
57
        endTime.text = Qt.formatDateTime(endDate, "dd MMM yyyy hh:mm");
67
67
        if(e.displayLabel) {
68
68
            titleEdit.text = e.displayLabel;
69
69
        }
 
70
 
70
71
        if(e.location) {
71
72
            locationEdit.text = e.location;
72
73
        }
 
74
 
73
75
        if( e.description ) {
74
76
            messageEdit.text = e.description;
75
77
        }
76
 
        if(e.attendees){
77
 
            for( var j = 0 ; j < e.attendees.length ; ++j ) {
78
 
                personEdit.text += e.attendees[j].name;
79
 
                if(j!== e.attendees.length-1)
80
 
                    personEdit.text += ",";
81
 
            }
82
 
        }
83
78
 
84
79
        var index = 0;
85
 
        if(e.recurrence ) {
86
 
            var recurrenceRule = e.recurrence.recurrenceRules;
87
 
            index = ( recurrenceRule.length > 0 ) ? recurrenceRule[0].frequency : 0;
 
80
        if( e.itemType === Type.Event ) {
 
81
            if(e.attendees){
 
82
                for( var j = 0 ; j < e.attendees.length ; ++j ) {
 
83
                    personEdit.text += e.attendees[j].name;
 
84
                    if(j!== e.attendees.length-1)
 
85
                        personEdit.text += ",";
 
86
                }
 
87
            }
 
88
 
 
89
            index = 0;
 
90
            if(e.recurrence ) {
 
91
                var recurrenceRule = e.recurrence.recurrenceRules;
 
92
                index = ( recurrenceRule.length > 0 ) ? recurrenceRule[0].frequency : 0;
 
93
            }
 
94
            recurrenceOption.selectedIndex = index;
88
95
        }
89
 
        recurrenceOption.selectedIndex = index;
90
96
 
91
97
        index = 0;
92
98
        var reminder = e.detail( Detail.VisualReminder);
119
125
            event.description = messageEdit.text;
120
126
            event.location = locationEdit.text
121
127
 
122
 
            event.attendees = []; // if Edit remove all attendes & add them again if any
123
 
            if( personEdit.text != "") {
124
 
                var attendee = Qt.createQmlObject("import QtOrganizer 5.0; EventAttendee{}", event, "NewEvent.qml");
125
 
                attendee.name = personEdit.text;
126
 
                event.setDetail(attendee);
127
 
            }
128
 
 
129
128
            event.allDay = allDayEventCheckbox.checked;
130
129
 
131
 
            var recurrenceRule = Defines.recurrenceValue[ recurrenceOption.selectedIndex ];
132
 
            if( recurrenceRule !== RecurrenceRule.Invalid ) {
133
 
                var rule = Qt.createQmlObject("import QtOrganizer 5.0; RecurrenceRule {}", event.recurrence,"NewEvent.qml");
134
 
                rule.frequency = recurrenceRule;
135
 
                event.recurrence.recurrenceRules = [rule];
 
130
            if( event.itemType === Type.Event ) {
 
131
                event.attendees = []; // if Edit remove all attendes & add them again if any
 
132
                if( personEdit.text != "") {
 
133
                    var attendee = Qt.createQmlObject("import QtOrganizer 5.0; EventAttendee{}", event, "NewEvent.qml");
 
134
                    attendee.name = personEdit.text;
 
135
                    event.setDetail(attendee);
 
136
                }
 
137
 
 
138
                var recurrenceRule = Defines.recurrenceValue[ recurrenceOption.selectedIndex ];
 
139
                if( recurrenceRule !== RecurrenceRule.Invalid ) {
 
140
                    var rule = Qt.createQmlObject("import QtOrganizer 5.0; RecurrenceRule {}", event.recurrence,"NewEvent.qml");
 
141
                    rule.frequency = recurrenceRule;
 
142
                    event.recurrence.recurrenceRules = [rule];
 
143
                }
136
144
            }
137
145
 
138
146
            //remove old reminder value
169
177
        }
170
178
    }
171
179
 
172
 
    // Calucate default hour for start and end time on event
173
 
    function hourForPickerFromDate(date) {
174
 
        if(date.getMinutes() < 30)
175
 
            return date.getHours()
176
 
        return date.getHours() + 1
177
 
    }
178
 
 
179
 
    // Calucate default minute for start and end time on event
180
 
    function minuteForPickerFromDate(date) {
181
 
        if(date.getMinutes() < 30)
182
 
            return 30
183
 
        return 0
 
180
    // Calucate default hour and minute for start and end time on event
 
181
    function roundDate(date) {
 
182
        var tempDate = new Date(date)
 
183
        if(tempDate.getMinutes() < 30)
 
184
            return tempDate.setMinutes(30)
 
185
        tempDate.setMinutes(0)
 
186
        return tempDate.setHours(tempDate.getHours() + 1)
184
187
    }
185
188
 
186
189
    width: parent.width
192
195
        pageStack.pop();
193
196
    }
194
197
 
 
198
    // we use a custom toolbar in this view
195
199
    tools: ToolbarItems {
196
 
        //keeping toolbar always open
197
 
        opened: true
198
200
        locked: true
199
 
 
200
 
        //FIXME: set the icons for toolbar buttons
201
 
        back: ToolbarButton {
202
 
            objectName: "eventCancelButton"
203
 
            action: Action {
204
 
                text: i18n.tr("Cancel");
205
 
                iconSource: Qt.resolvedUrl("cancel.svg");
206
 
                onTriggered: {
207
 
                    pageStack.pop();
208
 
                }
209
 
            }
210
 
        }
211
 
 
212
 
        ToolbarButton {
213
 
            objectName: "eventSaveButton"
214
 
            action: Action {
215
 
                text: i18n.tr("Save");
216
 
                iconSource: Qt.resolvedUrl("save.svg");
217
 
                onTriggered: {
218
 
                    saveToQtPim();
219
 
                }
220
 
            }
221
 
        }
 
201
        opened: false
222
202
    }
223
203
 
224
204
    Component{
239
219
        }
240
220
    }
241
221
 
 
222
    Rectangle {
 
223
        id: availableArea
 
224
 
 
225
        width: parent.width
 
226
        color: "red"
 
227
        opacity: 0.5
 
228
        z: 100
 
229
    }
 
230
 
 
231
 
242
232
    Flickable{
243
233
        id: flickable
 
234
 
 
235
        property var activeItem: null
 
236
 
 
237
        function makeMeVisible(item) {
 
238
            if (!item) {
 
239
                return
 
240
            }
 
241
 
 
242
            activeItem = item
 
243
            var position = flickable.contentItem.mapFromItem(item, 0, 0);
 
244
 
 
245
            // check if the item is already visible
 
246
            var bottomY = flickable.contentY + flickable.height
 
247
            var itemBottom = position.y + item.height
 
248
            if (position.y >= flickable.contentY && itemBottom <= bottomY) {
 
249
                return;
 
250
            }
 
251
 
 
252
            // if it is not, try to scroll and make it visible
 
253
            var targetY = position.y + item.height - flickable.height
 
254
            if (targetY >= 0 && position.y) {
 
255
                flickable.contentY = targetY;
 
256
            } else if (position.y < flickable.contentY) {
 
257
                // if it is hidden at the top, also show it
 
258
                flickable.contentY = position.y;
 
259
            }
 
260
            flickable.returnToBounds()
 
261
        }
 
262
 
244
263
        anchors {
245
264
            top: parent.top
246
265
            topMargin: units.gu(2)
247
 
            bottom: parent.bottom
 
266
            bottom: toolbar.top
248
267
            left: parent.left
249
268
            right: parent.right
250
269
            leftMargin: units.gu(2)
297
316
                            anchors.fill: parent
298
317
                            onClicked: {
299
318
                                internal.clearFocus()
300
 
                                var popupObj = PopupUtils.open(timePicker,root,{"hour": root.hourForPickerFromDate(startDate),"minute":root.minuteForPickerFromDate(startDate)});
 
319
                                var popupObj = PopupUtils.open(timePicker,root,{"hour": startDate.getHours(),"minute":startDate.getMinutes()});
301
320
                                popupObj.accepted.connect(function(startHour, startMinute) {
302
321
                                    var newDate = startDate;
303
322
                                    newDate.setHours(startHour, startMinute);
322
341
                            anchors.fill: parent
323
342
                            onClicked: {
324
343
                                internal.clearFocus()
325
 
                                var popupObj = PopupUtils.open(timePicker,root,{"hour": root.hourForPickerFromDate(endDate),"minute":root.minuteForPickerFromDate(endDate)});
 
344
                                var popupObj = PopupUtils.open(timePicker,root,{"hour": endDate.getHours(),"minute":endDate.getMinutes()});
326
345
                                popupObj.accepted.connect(function(startHour, startMinute) {
327
346
                                    var newDate = endDate;
328
347
                                    newDate.setHours(startHour, startMinute);
414
433
                    TextArea{
415
434
                        id: messageEdit
416
435
                        width: parent.width
 
436
                        color: focus ? "#2C001E" : "#EAD3A8"
 
437
                        // default style
 
438
                        font {
 
439
                            pixelSize: focus ? FontUtils.sizeToPixels("large") : FontUtils.sizeToPixels("medium")
 
440
                        }
417
441
                    }
418
442
                }
419
443
            }
430
454
                width: parent.width
431
455
                title: i18n.tr("Guests")
432
456
                objectName: "eventPeopleInput"
 
457
                visible: event.itemType === Type.Event
433
458
            }
434
459
 
435
460
            Item {
436
461
                width: parent.width
437
462
                height: recurrenceOption.height
 
463
                visible: event.itemType === Type.Event
438
464
                Label{
439
465
                    id: frequencyLabel
440
466
                    text: i18n.tr("This happens");
469
495
        }
470
496
    }
471
497
 
 
498
    EditToolbar {
 
499
        id: toolbar
 
500
        anchors {
 
501
            left: parent.left
 
502
            right: parent.right
 
503
            bottom: parent.bottom
 
504
        }
 
505
        height: units.gu(6)
 
506
        acceptAction: Action {
 
507
            text: i18n.tr("Save")
 
508
            onTriggered: saveToQtPim();
 
509
        }
 
510
        rejectAction: Action {
 
511
            text: i18n.tr("Cancel")
 
512
            onTriggered: pageStack.pop();
 
513
        }
 
514
    }
 
515
 
 
516
    // used to keep the field visible when the keyboard appear or dismiss
 
517
    KeyboardRectangle {
 
518
        id: keyboard
 
519
 
 
520
        onHeightChanged: {
 
521
            if (flickable.activeItem) {
 
522
                flickable.makeMeVisible(flickable.activeItem)
 
523
            }
 
524
        }
 
525
    }
 
526
 
472
527
    QtObject {
473
528
        id: internal
474
529