~pkunal-parmar/ubuntu-calendar-app/Minor-Performance

12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
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;
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
11
    property alias errorText: errorPopupDialog.text;
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
12
    property var startDate: new Date()
13
    property var endDate: new Date()
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
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 {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
27
                objectName: "newEventName"
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
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
41
            width: parent.width
42
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
                }
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
64
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
65
                Component {
66
                    id: timePicker
67
                    TimePicker {
68
                    }
69
                }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
70
71
                Item {
72
                    id: timeContainer
73
                    width: parent.width
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
74
                    height: startTimeItem.height
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
75
76
                    ListItem.Empty {
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
77
                        id: startTimeItem
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
78
                        anchors.left: timeContainer.left
79
                        width: units.gu(12)
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
80
                        Button {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
81
                            objectName: "startTimeInput"
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
82
                            id: startTimeButton
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
83
                            text: Qt.formatDateTime(startDate,"hh:mm")
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
84
                            anchors {
85
                                fill: parent
86
                                margins: units.gu(1)
87
                            }
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
88
                            onClicked: {
88.1.1 by Olivier Tilloy
Dismiss the OSK when a text field looses focus.
89
                                internal.clearFocus()
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
90
                                var popupObj = PopupUtils.open(timePicker);
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
91
                                popupObj.accepted.connect(function(startHour, startMinute) {
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
92
                                    var newDate = startDate;
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
93
                                    newDate.setHours(startHour, startMinute);
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
94
                                    startDate = newDate;
95
                                })
96
                            }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
97
                        }
98
                    }
99
56.1.1 by Riccardo Padovani
Fixed #1193090
100
                    Label {
101
                        id: endTimeLabel
102
                        text: i18n.tr("to");
103
                        anchors {
104
                            horizontalCenter: parent.horizontalCenter;
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
105
                            verticalCenter: startTimeItem.verticalCenter;
56.1.1 by Riccardo Padovani
Fixed #1193090
106
                        }
107
                    }
108
109
                   ListItem.Empty {
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
110
                        id: endTimeItem
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
111
                        highlightWhenPressed: false
112
                        anchors.right: timeContainer.right
113
                        width: units.gu(12)
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
114
                        Button {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
115
                            objectName: "endTimeInput"
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
116
                            id: endTimeButton
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
117
                            text: Qt.formatDateTime(endDate,"hh:mm")
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
118
                            anchors {
119
                                fill: parent
120
                                margins: units.gu(1)
121
                            }
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
122
                            onClicked: {
88.1.1 by Olivier Tilloy
Dismiss the OSK when a text field looses focus.
123
                                internal.clearFocus()
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
124
                                var popupObj = PopupUtils.open(timePicker);
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
125
                                popupObj.accepted.connect(function(endHour, endMinute) {
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
126
                                    var newDate = endDate;
56.1.8 by Riccardo Padovani
Fixed some bugs. Modified save function
127
                                    newDate.setHours(endHour, endMinute);
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
128
                                    endDate = newDate;
129
                                })
130
                            }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
131
                        }
132
                    }
133
                }
134
            }
135
        }
136
93.1.1 by Olivier Tilloy
Reduce the height of the "new event" popup so that the OSK doesn’t partially hide the save button.
137
        ListItem.Header { text: i18n.tr("Location & People") }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
138
        ListItem.Empty {
139
            highlightWhenPressed: false
140
            TextField {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
141
                objectName: "eventLocationInput"
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
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 {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
154
                objectName: "eventPeopleInput"
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
155
                id: personEdit
156
                placeholderText: i18n.tr("Invite People")
157
                anchors {
158
                    fill: parent
159
                    margins: units.gu(1)
160
                }
161
            }
162
        }
163
80.1.1 by Kunal Parmar
Changed ListItem.SingleControl to ListItem.Empty in NewEvent.qml
164
        ListItem.Empty {
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
165
            highlightWhenPressed: false
56.1.3 by Riccardo Padovani
Added pop-up error
166
            Dialog {
167
                id: errorPopupDialog
168
                title: i18n.tr("Error")
56.1.4 by Riccardo Padovani
Implemented DatePicker. Thanks to Michael Zanetti
169
                text: ""
56.1.3 by Riccardo Padovani
Added pop-up error
170
                Button {
171
                    text: i18n.tr("Ok")
172
                    onClicked: PopupUtils.close(errorPopupDialog)
173
                }
174
            }
80.1.1 by Kunal Parmar
Changed ListItem.SingleControl to ListItem.Empty in NewEvent.qml
175
            Button {
33.1.7 by Omer Akram
add autopilot test for NewEvent dialog
176
                objectName: "eventSaveButton"
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
177
                text: i18n.tr("Save")
178
                anchors {
179
                    fill: parent
180
                    margins: units.gu(1)
181
                }
182
69.1.15 by Kunal Parmar
reverting unwanted changes in NewEvent.qml
183
                onClicked: {
88.1.1 by Olivier Tilloy
Dismiss the OSK when a text field looses focus.
184
                    internal.clearFocus()
185
69.1.12 by Kunal Parmar
scrolling changed
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);
204
                    } else {
205
                        errorText = i18n.tr("End time can't be before start time");
206
                        errorPopupDialog.show();
207
                    }
208
209
                    error = 0;
210
                }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
211
            }
212
        }
213
    }
88.1.1 by Olivier Tilloy
Dismiss the OSK when a text field looses focus.
214
215
    QtObject {
216
        id: internal
217
218
        function clearFocus() {
219
            Qt.inputMethod.hide()
220
            titleEdit.focus = false
221
            locationEdit.focus = false
222
            personEdit.focus = false
223
        }
224
    }
12.1.3 by Frank Mertens
Added the NewEvent component from the EventAPI_EventView branch
225
}