Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

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