function getColorAttendee(keyColor){ var colors = ['#3b7847', '#98993d' , '#130aff' , '#d95a0d', '#d9990d', '#8cd90d', '#0dd9b9', '#123456', '#000000', '#5f04c3', '#c3043a', '#faa26b', '#cee4d1', '#adadad', '#707070']; return colors[keyColor % 15] ; } function updateMap(data){ var start_date = $(".new-event-win.active .start-date").val(); var end_date = $(".new-event-win.active .end-date").val(); var start_time = $(".new-event-win.active .start-time").val(); var end_time = $(".new-event-win.active .end-time").val(); var isAllDay = $('.new-event-win.active input[name="allDay"]').is(':checked'); var formatString = (isAllDay)? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; var startDate = Date.parseExact( isAllDay ? start_date+ " 00:00": start_date + " " + $.trim(start_time) , formatString ); var endDate = Date.parseExact( isAllDay ? end_date+ " 00:00": end_date + " " + $.trim(end_time) , formatString ); var event = $("#new_event_map").fullCalendar('clientEvents', 'map')[0]; if(!!event){ event.start = startDate; event.end = endDate; event.allDay = isAllDay; $("#new_event_map").fullCalendar( 'updateEvent', event ) } } function disponibily(objEvent, path, attendees){ var formatString = (objEvent.allDay)? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; var startDate = Date.parseExact( objEvent.allDay ? objEvent.startDate+ " 00:00": objEvent.startDate + " " + $.trim(objEvent.startHour) , formatString ); var endDate = Date.parseExact( objEvent.allDay ? objEvent.endDate+ " 00:00": objEvent.endDate + " " + $.trim(objEvent.endHour) , formatString ); var mapHtml = DataLayer.render( path+'templates/availability_map.ejs', {}); $("#calendar_addevent_details7").html(mapHtml); $("#new_event_map").fullCalendar(DataLayer.merge({ height : 300, timeFormat: { agenda: 'HH:mm{ - HH:mm}', '': 'HH:mm{ - HH:mm} }' }, axisFormat: User.preferences.hourFormat, firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart], editable: false, selectable: true, selectHelper: false, droppable: false, allDayText: 'Dia todo', buttonText: { today: 'hoje' }, titleFormat: { month: 'MMMM yyyy', week: "dd[ yyyy] { 'a'[ MMM] dd 'de' MMMM '-' yyyy}", day: 'dddd, dd MMM , yyyy' }, columnFormat:{ month: 'ddd', week: 'ddd dd/MM', day: 'dddd dd/MM' }, select: function( start, end, allDay, event, view ){ var event2 = $("#new_event_map").fullCalendar('clientEvents', 'map')[0]; event2.start = start; event2.end = end; event2.allDay = allDay; $("#new_event_map").fullCalendar( 'updateEvent', event2 ); $('[name="startDate"]').val(start.toString("dd/MM/yyyy")); $('[name="endDate"]').val(end.toString("dd/MM/yyyy")); if(!allDay){ $('[name="allDay"]').attr("checked", false); UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); $('[name="startHour"]').val(start.toString("HH:mm")); if(end){ $('[name="endHour"]').val(end.toString("HH:mm")); } }else{ $('[name="allDay"]').attr("checked", true); UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden'); } }, events: [ { id : 'map', title: 'Disponibilidade', start: startDate, end: endDate, editable : true, allDay : (objEvent.allDay ? true : false), className : "map-event", backgroundColor : "transparent !important" } ], eventDrop : function(event,dayDelta,minuteDelta,allDay,revertFunc){ if(event.allDay){ $('[name="allDay"]').attr("checked", true); UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden'); $('[name="startDate"]').val(event.start.toString("dd/MM/yyyy")); if(event.end) $('[name="endDate"]').val(event.end.toString("dd/MM/yyyy")); else $('[name="endDate"]').val(event.start.toString("dd/MM/yyyy")); return; }else{ $('[name="allDay"]').attr("checked", false); UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); } $('[name="startHour"]').val(event.start.toString("HH:mm")); $('[name="startDate"]').val(event.start.toString("dd/MM/yyyy")); if(event.end){ $('[name="endHour"]').val(event.end.toString("HH:mm")); $('[name="endDate"]').val(event.end.toString("dd/MM/yyyy")); }else $('[name="endDate"]').val(event.start.toString("dd/MM/yyyy")); }, eventResize: function(event,dayDelta,minuteDelta,revertFunc) { if(event.end){ $('[name="endHour"]').val(event.end.toString("HH:mm")); $('[name="endDate"]').val(event.end.toString("dd/MM/yyyy")); }else $('[name="endDate"]').val(event.start.toString("dd/MM/yyyy")); }, defaultView : "agendaWeek" }, dateCalendar)); var eventSource = new Array(); var updateMapView = function(){ updateMap(); var view = $("#new_event_map").fullCalendar('getView'); var map = {}; $("#new_event_map").fullCalendar( 'removeEventSource', eventSource ); eventSource = new Array(); map = {startTime : view.start.getTime(), endTime : view.end.getTime(), attendees: {}, timezone: (objEvent.timezone || User.preferences.timezone)}; map.attendees[User.me.id] = {id : User.me.id, name : User.me.name}; var count = 0; for (var idAttendee in attendees){ if(attendees[idAttendee]){ map.attendees[idAttendee] = {id : idAttendee, name : attendees[idAttendee], color: getColorAttendee(count)}; count++; } } map_events = DataLayer.dispatch("mapDisponibility", map, false, false); for(var map_attende in map_events){ for(var event_by_attende in map_events[map_attende]){ eventSource.push( { id : "map_busy_events", title : map.attendees[map_attende].name, start: new Date(parseInt(map_events[map_attende][event_by_attende].startTime)), end: new Date(parseInt(map_events[map_attende][event_by_attende].endTime)), editable : false, allDay : !!parseInt(map_events[map_attende][event_by_attende].allDay), backgroundColor : map.attendees[map_attende].color + " !important", borderColor : map.attendees[map_attende].color + " !important" }); } } if(eventSource.length) $("#new_event_map").fullCalendar( 'addEventSource', eventSource ); }; $('[href="#calendar_addevent_details7"]').click(function(eventData, eventObject){ $("#new_event_map").fullCalendar( 'gotoDate', Date.parseExact($('[name="startDate"]').val() + " " + $.trim($('[name="startHour"]').val()), formatString) , formatString); //if(eventObject == undefined) updateMapView(); }); $("#new_event_map").find(".fc-button-prev, .fc-button-next, .fc-button-today").click(function(){ updateMapView(); }); }