1 | $(document).ready(function() { |
---|
2 | |
---|
3 | refresh_calendars(); |
---|
4 | $tabs = $('#tabs').tabs({ |
---|
5 | add: function( event, ui ) { |
---|
6 | Calendar.lastView = $tabs.tabs('option' ,'selected'); |
---|
7 | $('#tabs .events-list-win.active').removeClass('active'); |
---|
8 | $tabs.tabs('select', '#' + ui.panel.id); |
---|
9 | }, |
---|
10 | remove: function( event, ui ) { |
---|
11 | $tabs.tabs('select', Calendar.lastView); |
---|
12 | }, |
---|
13 | show: function( event, ui ){ |
---|
14 | delete Calendar.currentViewKey; |
---|
15 | $('#calendar').fullCalendar('refetchEvents'); |
---|
16 | } |
---|
17 | }) |
---|
18 | .tabs('option', 'tabTemplate', "<li><a href='#{href}'>#{label}</a><span class='ui-icon ui-icon-close'>Remove Tab</span></li>" ); |
---|
19 | |
---|
20 | /** |
---|
21 | * Make a button to close the tab |
---|
22 | */ |
---|
23 | $tabs.find( "span.ui-icon-close" ).live( "click", function() { |
---|
24 | var index = $( "li", $tabs ).index( $( this ).parent() ); |
---|
25 | if($tabs.tabs('option' ,'selected') == index){ |
---|
26 | if($tabs.tabs("length") == 2 && Calendar.lastView != 1) |
---|
27 | $tabs.tabs( "select", 0); |
---|
28 | $tabs.tabs( "select", Calendar.lastView); |
---|
29 | } |
---|
30 | if($tabs.tabs('option' ,'selected') == 0 || $tabs.tabs('option' ,'selected') == 1) |
---|
31 | Calendar.lastView = $tabs.tabs('option' ,'selected'); |
---|
32 | if(index != -1) |
---|
33 | $tabs.tabs( "remove", index ); |
---|
34 | |
---|
35 | |
---|
36 | }); |
---|
37 | $('.button.config-menu').button({ |
---|
38 | icons: { |
---|
39 | primary: "ui-icon-gear", |
---|
40 | secondary: "ui-icon-triangle-1-s" |
---|
41 | }, |
---|
42 | text: false |
---|
43 | }); |
---|
44 | $('.button.add').button({ |
---|
45 | icons: { |
---|
46 | secondary: "ui-icon-plus" |
---|
47 | } |
---|
48 | }) |
---|
49 | |
---|
50 | var miniCalendar = $('.block-vertical-toolbox .mini-calendar').datepicker({ |
---|
51 | dateFormat: 'yy-m-d', |
---|
52 | //dateFormat: 'DD, d MM, yy', |
---|
53 | //inline: true, |
---|
54 | firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart], |
---|
55 | onSelect: function(dateText, inst) |
---|
56 | { |
---|
57 | $tabs.tabs("select", "#calendar"); |
---|
58 | var toDate = $('.block-vertical-toolbox .mini-calendar').datepicker("getDate").toString('yyyy-MM-dd').split('-'); |
---|
59 | $('#calendar').fullCalendar('gotoDate', toDate[0], parseInt(toDate[1]-1), toDate[2] ); |
---|
60 | $('#calendar').fullCalendar( 'changeView', 'agendaDay' ); |
---|
61 | } |
---|
62 | }) |
---|
63 | .find('.ui-icon-circle-triangle-e').removeClass('ui-icon-circle-triangle-e').addClass('ui-icon-triangle-1-e').end() |
---|
64 | .find('.ui-icon-circle-triangle-w').removeClass('ui-icon-circle-triangle-w').addClass('ui-icon-triangle-1-w'); |
---|
65 | |
---|
66 | //Onclick do mês |
---|
67 | $('.ui-datepicker-title .ui-datepicker-month').live('click',function(){ |
---|
68 | $tabs.tabs("select", "#calendar"); |
---|
69 | $('#calendar').fullCalendar('gotoDate',$(this).siblings('span').html(), Date.getMonthNumberFromName($(this).html() == 'Março' ? 'Mar' : $(this).html()),'01'); |
---|
70 | $('#calendar').fullCalendar( 'changeView', 'month'); |
---|
71 | }); |
---|
72 | //Onclick do ano |
---|
73 | $('.ui-datepicker-title .ui-datepicker-year').live('click',function(){ |
---|
74 | $tabs.tabs("select", "#calendar"); |
---|
75 | $('#calendar').fullCalendar('gotoDate',$(this).html(), '0', '01'); |
---|
76 | $('.fc-button-year').click(); |
---|
77 | }); |
---|
78 | |
---|
79 | //Onclick em um dia do calendário anual |
---|
80 | $( ".fc-day-number" ).live( "click", function() { |
---|
81 | |
---|
82 | var date = $(this).parents('[class*="fc-day-"]').attr('class').match(/fc-day-(\d{4})-(\d{2})-(\d{2})/); |
---|
83 | |
---|
84 | if (date) date.shift(); |
---|
85 | else return false; |
---|
86 | |
---|
87 | $('#calendar').fullCalendar('gotoDate',date[0],date[1]-1,date[2]); |
---|
88 | $('#calendar').fullCalendar( 'changeView', 'agendaDay' ); |
---|
89 | }); |
---|
90 | |
---|
91 | $('.main-search input.search').keydown(function(event){ |
---|
92 | if(event.keyCode == 13) { |
---|
93 | Encoder.EncodeType = "entity"; |
---|
94 | //$(this).val($(this).val()); |
---|
95 | |
---|
96 | add_events_list($(this).val()); |
---|
97 | $(this).val(''); |
---|
98 | } |
---|
99 | }); |
---|
100 | |
---|
101 | $('.block-horizontal-toolbox .main-config-menu').menu({ |
---|
102 | content: $('.main-config-menu-content').html(), |
---|
103 | positionOpts: { |
---|
104 | posX: 'left', |
---|
105 | posY: 'bottom', |
---|
106 | offsetX: -140, |
---|
107 | offsetY: 0, |
---|
108 | directionH: 'right', |
---|
109 | directionV: 'down', |
---|
110 | detectH: true, // do horizontal collision detection |
---|
111 | detectV: true, // do vertical collision detection |
---|
112 | linkToFront: false |
---|
113 | }, |
---|
114 | flyOut: true, |
---|
115 | showSpeed: 100, |
---|
116 | crumbDefaultText: '>' |
---|
117 | }); |
---|
118 | |
---|
119 | $('#trash').droppable({ |
---|
120 | drop: function(event, ui){ |
---|
121 | // calendar.fullCalendar( 'removeEvents', ui.draggable.attr('event-id') ); |
---|
122 | DataLayer.remove( "event", ui.draggable.attr('event-id') ); |
---|
123 | $(this).switchClass('empty','full'); |
---|
124 | }, |
---|
125 | tolerance: "touch" |
---|
126 | }); |
---|
127 | |
---|
128 | /* initialize the calendar |
---|
129 | -----------------------------------------------------------------*/ |
---|
130 | $(".button.add.add-event").click(function(event){ |
---|
131 | var startEvent = new Date(); |
---|
132 | if(startEvent.toString('mm') < 30) |
---|
133 | startEvent.add({minutes: (30 - parseInt(startEvent.toString('mm')))}); |
---|
134 | else |
---|
135 | startEvent.add({hours: 1, minutes: '-'+startEvent.toString('mm')}); |
---|
136 | var endEvent = function(date){ |
---|
137 | if(!!User.preferences.defaultCalendar){ |
---|
138 | return parseInt(date.getTime()) + |
---|
139 | ( !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? |
---|
140 | (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) : |
---|
141 | (User.preferences.defaultDuration * 60000) |
---|
142 | ); |
---|
143 | }else |
---|
144 | return parseInt(date.getTime()) + (User.preferences.defaultDuration * 60000); |
---|
145 | }; |
---|
146 | |
---|
147 | eventDetails({ |
---|
148 | startTime: startEvent.getTime(), |
---|
149 | endTime: endEvent(startEvent) |
---|
150 | }, true ); |
---|
151 | }); |
---|
152 | |
---|
153 | var calendar = $('#calendar').fullCalendar(DataLayer.merge({ |
---|
154 | |
---|
155 | defaultView: User.preferences.defaultCalView, |
---|
156 | timeFormat: User.preferences.hourFormat, |
---|
157 | axisFormat: User.preferences.hourFormat, |
---|
158 | eventSources: Calendar.sources, |
---|
159 | |
---|
160 | header: { |
---|
161 | left: 'prev,next today,basicWeek,basicDay', |
---|
162 | center: 'title', |
---|
163 | right: 'agendaDay,agendaWeek,month,year' |
---|
164 | }, |
---|
165 | firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart], |
---|
166 | editable: true, |
---|
167 | selectable: true, |
---|
168 | selectHelper: true, |
---|
169 | droppable: true, // this allows things to be dropped onto the calendar !!! |
---|
170 | timeFormat: { |
---|
171 | agenda: 'HH:mm{ - HH:mm}', |
---|
172 | '': 'HH:mm{ - HH:mm} }' |
---|
173 | }, |
---|
174 | titleFormat: { |
---|
175 | month: 'MMMM yyyy', |
---|
176 | week: "dd[ yyyy] { 'a'[ MMM] dd 'de' MMMM '-' yyyy}", |
---|
177 | day: 'dddd, dd MMM , yyyy' |
---|
178 | }, |
---|
179 | columnFormat:{ |
---|
180 | month: 'ddd', |
---|
181 | week: 'ddd dd/MM', |
---|
182 | day: 'dddd dd/MM' |
---|
183 | }, |
---|
184 | |
---|
185 | allDayText: 'Dia todo', |
---|
186 | buttonText: { |
---|
187 | today: 'hoje', |
---|
188 | month: 'mês', |
---|
189 | week: 'semana', |
---|
190 | day: 'dia', |
---|
191 | year: 'ano' |
---|
192 | }, |
---|
193 | /* |
---|
194 | eventRender: function( event, element, view ){ |
---|
195 | $(element).attr( 'event-id', event.id ); |
---|
196 | }, |
---|
197 | */ |
---|
198 | select: function( start, end, allDay, event, view ){ |
---|
199 | eventDetails( { 'start': start, |
---|
200 | 'end': end, |
---|
201 | 'allDay': allDay } ); |
---|
202 | }, |
---|
203 | |
---|
204 | eventDrop: function( event ){ |
---|
205 | DataLayer.put( "schedulable:calendar", event ); |
---|
206 | |
---|
207 | event.editable = false; |
---|
208 | event.className = "blocked-event"; |
---|
209 | calendar.fullCalendar( 'updateEvent', event ); |
---|
210 | }, |
---|
211 | |
---|
212 | eventResize: function( event ){ |
---|
213 | DataLayer.put( "schedulable:calendar", event ); |
---|
214 | |
---|
215 | event.editable = false; |
---|
216 | event.className = "blocked-event"; |
---|
217 | calendar.fullCalendar( 'updateEvent', event ); |
---|
218 | }, |
---|
219 | |
---|
220 | eventClick: function( evt, event, view ){ |
---|
221 | eventDetails( DataLayer.get( "schedulable", evt.id), true); |
---|
222 | } |
---|
223 | }, dateCalendar)); |
---|
224 | |
---|
225 | if($(window).height() < $('body').height()){ |
---|
226 | var hei = $('body').height() - $(window).height(); |
---|
227 | hei = $('#divAppbox').height() - hei; |
---|
228 | $('#divAppbox').css('max-height', hei); |
---|
229 | $('#divAppbox').css('min-height', hei); |
---|
230 | $('body').css('overflow-y','hidden'); |
---|
231 | delete hei; |
---|
232 | } |
---|
233 | |
---|
234 | $(window).resize(function(){ |
---|
235 | $('#divAppbox').css('max-height', $(window).height() - 104); |
---|
236 | $('#divAppbox').css('min-height', $(window).height() - 104); |
---|
237 | $('#divAppbox').css('overflow-x', 'auto'); |
---|
238 | $('#divAppbox').css('overflow-y', 'scroll'); |
---|
239 | }); |
---|
240 | //Todo chamada do metodo que adiciona ao full calendar o botao de listagem de eventos |
---|
241 | //listEvents(); |
---|
242 | }); |
---|