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

« back to all changes in this revision

Viewing changes to NewEvent.qml

  • Committer: Kunal Parmar
  • Date: 2014-01-18 03:06:49 UTC
  • mfrom: (182 ubuntu-calendar-app)
  • mto: This revision was merged to the branch mainline in revision 186.
  • Revision ID: pkunal.parmar@gmail.com-20140118030649-ziqq655e89lqc3id
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
Page {
10
10
    id: root
11
 
 
12
11
    property var date: new Date();
 
12
 
 
13
    property var event:null;
 
14
 
13
15
    property var startDate;
14
16
    property var endDate;
15
17
    property int optionSelectorWidth: frequencyLabel.width > remindLabel.width ? frequencyLabel.width : remindLabel.width
16
18
 
17
19
    property alias scrollY: flickable.contentY
 
20
    property bool isEdit: false
18
21
 
19
22
    Component.onCompleted: {
 
23
 
 
24
        pageStack.header.visible = true;
 
25
 
20
26
        // If startDate is setted by argument we have to not change it
21
27
        if (typeof(startDate) === 'undefined')
22
28
            startDate = new Date(date)
26
32
            endDate = new Date(date)
27
33
            endDate.setMinutes( endDate.getMinutes() + 10)
28
34
        }
29
 
 
30
35
        internal.eventModel = GlobalModel.gloablModel();
31
36
 
 
37
        if(event === null){
 
38
            isEdit =false;
 
39
            addEvent();
 
40
        }
 
41
        else{
 
42
            isEdit = true;
 
43
            editEvent(event);
 
44
        }
 
45
    }
 
46
    //Data for Add events
 
47
    function addEvent() {
 
48
        event = Qt.createQmlObject("import QtOrganizer 5.0; Event { }", Qt.application,"NewEvent.qml");
 
49
        startDate = new Date(date)
 
50
        endDate = new Date(date)
 
51
        endDate.setMinutes( endDate.getMinutes() + 10)
 
52
 
32
53
        startTime.text = Qt.formatDateTime(startDate, "dd MMM yyyy hh:mm");
33
54
        endTime.text = Qt.formatDateTime(endDate, "dd MMM yyyy hh:mm");
34
55
    }
35
 
 
 
56
    //Editing Event
 
57
    function editEvent(e) {
 
58
        startDate =new Date(e.startDateTime);
 
59
        endDate = new Date(e.endDateTime);
 
60
        startTime.text = Qt.formatDateTime(e.startDateTime, "dd MMM yyyy hh:mm");
 
61
        endTime.text = Qt.formatDateTime(e.endDateTime, "dd MMM yyyy hh:mm");
 
62
        if(e.displayLabel)
 
63
            titleEdit.text = e.displayLabel;
 
64
        if(e.location)
 
65
            locationEdit.text = e.location;
 
66
        if( e.description ) {
 
67
            messageEdit.text = e.description;
 
68
        }
 
69
        if(e.attendees){
 
70
            for( var j = 0 ; j < e.attendees.length ; ++j ) {
 
71
                personEdit.text += e.attendees[j].name;
 
72
                if(j!== e.attendees.length-1)
 
73
                    personEdit.text += ",";
 
74
            }
 
75
        }
 
76
    }
 
77
    //Save the new or Existing event
36
78
    function saveToQtPim() {
37
 
 
38
79
        internal.clearFocus()
39
 
 
40
80
        if ( startDate >= endDate ) {
41
81
            PopupUtils.open(errorDlgComponent,root,{"text":i18n.tr("End time can't be before start time")});
42
82
        } else {
43
 
 
44
 
            var event = Qt.createQmlObject("import QtOrganizer 5.0; Event { }", Qt.application,"NewEvent.qml");
45
 
 
46
83
            event.startDateTime = startDate;
47
84
            event.endDateTime = endDate;
48
85
            event.displayLabel = titleEdit.text;
49
86
            event.description = messageEdit.text;
50
 
 
51
87
            event.location = locationEdit.text
52
 
 
 
88
            event.attendees = []; // if Edit remove all attendes & add them again if any
53
89
            if( personEdit.text != "") {
54
90
                var attendee = Qt.createQmlObject("import QtOrganizer 5.0; EventAttendee{}", Qt.application, "NewEvent.qml");
55
91
                attendee.name = personEdit.text;
56
 
                attendee.emailAddress = "none@nowhere.com";
57
92
                event.setDetail(attendee);
58
93
            }
59
 
 
60
94
            internal.eventModel.saveItem(event);
61
95
            pageStack.pop();
62
96
        }
65
99
    width: parent.width
66
100
    height: parent.height
67
101
 
68
 
    title: i18n.tr("New Event")
 
102
    title: isEdit ? i18n.tr("Edit Event"):i18n.tr("New Event")
69
103
 
70
104
    tools: ToolbarItems {
71
105
        //keeping toolbar always open
107
141
            }
108
142
        }
109
143
    }
110
 
 
111
144
    Component {
112
145
        id: timePicker
113
146
        TimePicker {
194
227
                    }
195
228
                }
196
229
            }
197
 
 
198
230
            NewEventEntryField{
199
231
                id: titleEdit
200
232
                width: parent.width