<%-- /** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ --%> <%@ include file="/init.jsp" %> <% String activeView = ParamUtil.getString(request, "activeView", sessionClicksDefaultView); long date = ParamUtil.getLong(request, "date", System.currentTimeMillis()); List groupCalendars = Collections.emptyList(); if (groupCalendarResource != null) { groupCalendars = CalendarServiceUtil.search(themeDisplay.getCompanyId(), null, new long[] {groupCalendarResource.getCalendarResourceId()}, null, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator)null); } List userCalendars = Collections.emptyList(); if (userCalendarResource != null) { userCalendars = CalendarServiceUtil.search(themeDisplay.getCompanyId(), null, new long[] {userCalendarResource.getCalendarResourceId()}, null, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator)null); } List otherCalendars = new ArrayList(); long[] calendarIds = StringUtil.split(SessionClicks.get(request, "calendar-portlet-other-calendars", StringPool.BLANK), 0L); for (long calendarId : calendarIds) { Calendar calendar = CalendarServiceUtil.fetchCalendar(calendarId); if (calendar != null) { CalendarResource calendarResource = calendar.getCalendarResource(); if (calendarResource.isActive()) { otherCalendars.add(calendar); } } } Calendar defaultCalendar = null; for (Calendar groupCalendar : groupCalendars) { if (groupCalendar.isDefaultCalendar()) { defaultCalendar = groupCalendar; } } if (defaultCalendar == null) { for (Calendar userCalendar : userCalendars) { if (userCalendar.isDefaultCalendar()) { defaultCalendar = userCalendar; } } } JSONArray groupCalendarsJSONArray = CalendarUtil.toCalendarsJSONArray(themeDisplay, groupCalendars); JSONArray userCalendarsJSONArray = CalendarUtil.toCalendarsJSONArray(themeDisplay, userCalendars); JSONArray otherCalendarsJSONArray = CalendarUtil.toCalendarsJSONArray(themeDisplay, otherCalendars); boolean columnOptionsVisible = GetterUtil.getBoolean(SessionClicks.get(request, "calendar-portlet-column-options-visible", "true")); %>
" type="text" />
" id="columnTogglerIcon">
<%@ include file="/view_calendar_menus.jspf" %> Liferay.CalendarUtil.USER_CLASS_NAME_ID = <%= PortalUtil.getClassNameId(User.class) %>; Liferay.CalendarUtil.DEFAULT_USER_CALENDAR_ID = <%= defaultCalendar.getCalendarId() %>; var syncCalendarsMap = function() { var calendarLists = []; calendarLists.push(window.myCalendarList); calendarLists.push(window.otherCalendarList); calendarLists.push(window.siteCalendarList); Liferay.CalendarUtil.syncCalendarsMap(calendarLists); } window.syncCalendarsMap = syncCalendarsMap; window.calendarLists = {}; window.myCalendarList = new Liferay.CalendarList( { after: { calendarsChange: syncCalendarsMap, 'scheduler-calendar:visibleChange': function(event) { syncCalendarsMap(); refreshVisibleCalendarRenderingRules(); } }, boundingBox: '#myCalendarList', <% updateCalendarsJSONArray(request, userCalendarsJSONArray); %> calendars: <%= userCalendarsJSONArray %>, scheduler: scheduler, simpleMenu: window.calendarsMenu, visible: <%= themeDisplay.isSignedIn() %> } ).render(); window.calendarLists['<%= userCalendarResource.getCalendarResourceId() %>'] = window.myCalendarList; window.otherCalendarList = new Liferay.CalendarList( { after: { calendarsChange: function(event) { syncCalendarsMap(); scheduler.load(); var calendarIds = A.Array.invoke(event.newVal, 'get', 'calendarId'); Liferay.Store('calendar-portlet-other-calendars', calendarIds.join()); }, 'scheduler-calendar:visibleChange': function(event) { syncCalendarsMap(); refreshVisibleCalendarRenderingRules(); } }, boundingBox: '#otherCalendarList', <% updateCalendarsJSONArray(request, otherCalendarsJSONArray); %> calendars: <%= otherCalendarsJSONArray %>, scheduler: scheduler, simpleMenu: window.calendarsMenu } ).render(); window.siteCalendarList = new Liferay.CalendarList( { after: { calendarsChange: syncCalendarsMap, 'scheduler-calendar:visibleChange': function(event) { syncCalendarsMap(); refreshVisibleCalendarRenderingRules(); } }, boundingBox: '#siteCalendarList', <% updateCalendarsJSONArray(request, groupCalendarsJSONArray); %> calendars: <%= groupCalendarsJSONArray %>, scheduler: scheduler, simpleMenu: window.calendarsMenu } ).render(); window.calendarLists['<%= groupCalendarResource.getCalendarResourceId() %>'] = window.siteCalendarList; syncCalendarsMap(); A.each( Liferay.CalendarUtil.availableCalendars, function(item, index) { item.on( { 'visibleChange': function(event) { var instance = this; var calendar = event.currentTarget; Liferay.Store('calendar-portlet-calendar-' + calendar.get('calendarId') + '-visible', event.newVal); } } ); } ); window.toggler = new A.TogglerDelegate( { animated: true, container: '#calendarListContainer', content: '.calendar-portlet-calendar-list', header: '.calendar-portlet-list-header' } ); var addOtherCalendarInput = A.one('#addOtherCalendar'); Liferay.CalendarUtil.createCalendarsAutoComplete( '<%= calendarResourcesURL %>', addOtherCalendarInput, function(event) { window.otherCalendarList.add(event.result.raw); refreshVisibleCalendarRenderingRules(); addOtherCalendarInput.val(''); } ); A.one('#columnToggler').on( 'click', function(event) { var columnGrid = A.one('#columnGrid'); var columnOptions = A.one('#columnOptions'); var columnTogglerIcon = A.one('#columnTogglerIcon'); Liferay.Store('calendar-portlet-column-options-visible', columnOptions.hasClass('hide')); columnGrid.toggleClass('span9').toggleClass('span12'); columnOptions.toggleClass('hide'); columnTogglerIcon.toggleClass('icon-caret-left').toggleClass('icon-caret-right'); } ); var DateMath = A.DataType.DateMath; window.refreshMiniCalendarSelectedDates = function() { miniCalendar._clearSelection(); var activeView = scheduler.get('activeView'); var viewDate = scheduler.get('viewDate'); var viewName = activeView.get('name'); var total = 1; if (viewName == 'month') { total = A.Date.daysInMonth(viewDate); } else if (viewName == 'week') { total = 7; } var selectedDates = Liferay.CalendarUtil.getDatesList(viewDate, total); miniCalendar.selectDates(selectedDates); miniCalendar.set('date', viewDate); }; window.refreshVisibleCalendarRenderingRules = function() { var miniCalendarStartDate = DateMath.subtract(DateMath.toMidnight(window.miniCalendar.get('date')), DateMath.WEEK, 1); var miniCalendarEndDate = DateMath.add(DateMath.add(miniCalendarStartDate, DateMath.MONTH, 1), DateMath.WEEK, 1); miniCalendarEndDate.setHours(23, 59, 59, 999); Liferay.CalendarUtil.getCalendarRenderingRules( A.Object.keys(Liferay.CalendarUtil.visibleCalendars), Liferay.CalendarUtil.toUTC(miniCalendarStartDate), Liferay.CalendarUtil.toUTC(miniCalendarEndDate), 'busy', function(rulesDefinition) { window.miniCalendar.set( 'customRenderer', { filterFunction: function(date, node, rules) { node.addClass('lfr-busy-day'); var selectedDates = this._getSelectedDatesList(); DateMath.toMidnight(date); var selected = (selectedDates.length > 0) && A.Date.isInRange(date, selectedDates[0], selectedDates[selectedDates.length - 1]); if (A.DataType.DateMath.isToday(date)) { node.addClass('lfr-current-day'); } node.toggleClass('yui3-calendar-day-selected', selected); }, rules: rulesDefinition } ); } ); }; window.miniCalendar = new A.Calendar( { after: { dateChange: refreshVisibleCalendarRenderingRules, dateClick: function(event) { scheduler.setAttrs( { activeView: dayView, date: event.date } ); } }, date: new Date(<%= String.valueOf(date) %>), locale: 'en', 'strings.first_weekday': <%= weekStartsOn %> } ).render('#miniCalendarContainer'); scheduler.after( ['*:add', '*:change', '*:load', '*:remove', '*:reset'], A.debounce(refreshVisibleCalendarRenderingRules, 100) ); scheduler.after( ['activeViewChange', 'dateChange'], refreshMiniCalendarSelectedDates ); refreshVisibleCalendarRenderingRules(); refreshMiniCalendarSelectedDates(); scheduler.load(); <%! protected void updateCalendarsJSONArray(HttpServletRequest request, JSONArray calendarsJSONArray) { for (int i = 0; i < calendarsJSONArray.length(); i++) { JSONObject jsonObject = calendarsJSONArray.getJSONObject(i); long calendarId = jsonObject.getLong("calendarId"); jsonObject.put("color", GetterUtil.getString(SessionClicks.get(request, "calendar-portlet-calendar-" + calendarId + "-color", jsonObject.getString("color")))); jsonObject.put("visible", GetterUtil.getBoolean(SessionClicks.get(request, "calendar-portlet-calendar-" + calendarId + "-visible", "true"))); } } %>