Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
var AppCalendar = function() {
2
 
3
    return {
4
        //main function to initiate the module
5
        init: function() {
6
            this.initCalendar();
7
        },
8
 
9
        initCalendar: function() {
10
 
11
            if (!jQuery().fullCalendar) {
12
                return;
13
            }
14
 
15
            var date = new Date();
16
            var d = date.getDate();
17
            var m = date.getMonth();
18
            var y = date.getFullYear();
19
 
20
            var h = {};
21
 
22
            if (App.isRTL()) {
23
                if ($('#calendar').parents(".portlet").width() <= 720) {
24
                    $('#calendar').addClass("mobile");
25
                    h = {
26
                        right: 'title, prev, next',
27
                        center: '',
28
                        left: 'agendaDay, agendaWeek, month, today'
29
                    };
30
                } else {
31
                    $('#calendar').removeClass("mobile");
32
                    h = {
33
                        right: 'title',
34
                        center: '',
35
                        left: 'agendaDay, agendaWeek, month, today, prev,next'
36
                    };
37
                }
38
            } else {
39
                if ($('#calendar').parents(".portlet").width() <= 720) {
40
                    $('#calendar').addClass("mobile");
41
                    h = {
42
                        left: 'title, prev, next',
43
                        center: '',
44
                        right: 'today,month,agendaWeek,agendaDay'
45
                    };
46
                } else {
47
                    $('#calendar').removeClass("mobile");
48
                    h = {
49
                        left: 'title',
50
                        center: '',
51
                        right: 'prev,next,today,month,agendaWeek,agendaDay'
52
                    };
53
                }
54
            }
55
 
56
            var initDrag = function(el) {
57
                // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
58
                // it doesn't need to have a start or end
59
                var eventObject = {
60
                    title: $.trim(el.text()) // use the element's text as the event title
61
                };
62
                // store the Event Object in the DOM element so we can get to it later
63
                el.data('eventObject', eventObject);
64
                // make the event draggable using jQuery UI
65
                el.draggable({
66
                    zIndex: 999,
67
                    revert: true, // will cause the event to go back to its
68
                    revertDuration: 0 //  original position after the drag
69
                });
70
            };
71
 
72
            var addEvent = function(title) {
73
                title = title.length === 0 ? "Untitled Event" : title;
74
                var html = $('<div class="external-event label label-default">' + title + '</div>');
75
                jQuery('#event_box').append(html);
76
                initDrag(html);
77
            };
78
 
79
            $('#external-events div.external-event').each(function() {
80
                initDrag($(this));
81
            });
82
 
83
            $('#event_add').unbind('click').click(function() {
84
                var title = $('#event_title').val();
85
                addEvent(title);
86
            });
87
 
88
            //predefined events
89
            $('#event_box').html("");
90
            addEvent("My Event 1");
91
            addEvent("My Event 2");
92
            addEvent("My Event 3");
93
            addEvent("My Event 4");
94
            addEvent("My Event 5");
95
            addEvent("My Event 6");
96
 
97
            $('#calendar').fullCalendar('destroy'); // destroy the calendar
98
            $('#calendar').fullCalendar({ //re-initialize the calendar
99
                header: h,
100
                defaultView: 'month', // change default view with available options from http://arshaw.com/fullcalendar/docs/views/Available_Views/ 
101
                slotMinutes: 15,
102
                editable: true,
103
                droppable: true, // this allows things to be dropped onto the calendar !!!
104
                drop: function(date, allDay) { // this function is called when something is dropped
105
 
106
                    // retrieve the dropped element's stored Event Object
107
                    var originalEventObject = $(this).data('eventObject');
108
                    // we need to copy it, so that multiple events don't have a reference to the same object
109
                    var copiedEventObject = $.extend({}, originalEventObject);
110
 
111
                    // assign it the date that was reported
112
                    copiedEventObject.start = date;
113
                    copiedEventObject.allDay = allDay;
114
                    copiedEventObject.className = $(this).attr("data-class");
115
 
116
                    // render the event on the calendar
117
                    // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
118
                    $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
119
 
120
                    // is the "remove after drop" checkbox checked?
121
                    if ($('#drop-remove').is(':checked')) {
122
                        // if so, remove the element from the "Draggable Events" list
123
                        $(this).remove();
124
                    }
125
                },
126
                events: [{
127
                    title: 'All Day Event',
128
                    start: new Date(y, m, 1),
129
                    backgroundColor: App.getBrandColor('yellow')
130
                }, {
131
                    title: 'Long Event',
132
                    start: new Date(y, m, d - 5),
133
                    end: new Date(y, m, d - 2),
134
                    backgroundColor: App.getBrandColor('green')
135
                }, {
136
                    title: 'Repeating Event',
137
                    start: new Date(y, m, d - 3, 16, 0),
138
                    allDay: false,
139
                    backgroundColor: App.getBrandColor('red')
140
                }, {
141
                    title: 'Repeating Event',
142
                    start: new Date(y, m, d + 4, 16, 0),
143
                    allDay: false,
144
                    backgroundColor: App.getBrandColor('green')
145
                }, {
146
                    title: 'Meeting',
147
                    start: new Date(y, m, d, 10, 30),
148
                    allDay: false,
149
                }, {
150
                    title: 'Lunch',
151
                    start: new Date(y, m, d, 12, 0),
152
                    end: new Date(y, m, d, 14, 0),
153
                    backgroundColor: App.getBrandColor('grey'),
154
                    allDay: false,
155
                }, {
156
                    title: 'Birthday Party',
157
                    start: new Date(y, m, d + 1, 19, 0),
158
                    end: new Date(y, m, d + 1, 22, 30),
159
                    backgroundColor: App.getBrandColor('purple'),
160
                    allDay: false,
161
                }, {
162
                    title: 'Click for Google',
163
                    start: new Date(y, m, 28),
164
                    end: new Date(y, m, 29),
165
                    backgroundColor: App.getBrandColor('yellow'),
166
                    url: 'http://google.com/',
167
                }]
168
            });
169
 
170
        }
171
 
172
    };
173
 
174
}();
175
 
176
jQuery(document).ready(function() {    
177
   AppCalendar.init();
178
});