/*! * UI development toolkit for HTML5 (OpenUI5) * (c) Copyright 2009-2018 SAP SE or an SAP affiliate company. * Licensed under the Apache License, Version 2.0 - see LICENSE.txt. */ sap.ui.define(['sap/ui/core/date/UniversalDate', 'sap/ui/core/InvisibleText', 'sap/ui/unified/library'], function (UniversalDate, InvisibleText, unifiedLibrary) { "use strict"; // shortcut for sap.ui.unified.CalendarDayType var CalendarDayType = unifiedLibrary.CalendarDayType; // shortcut for sap.ui.unified.CalendarAppointmentVisualization var CalendarAppointmentVisualization = unifiedLibrary.CalendarAppointmentVisualization; /** * OnePersonGrid renderer. * @namespace */ var OnePersonGridRenderer = {}; /** * Renders the HTML for the given control, using the provided {@link sap.ui.core.RenderManager}. * * @param {sap.ui.core.RenderManager} oRm The RenderManager that can be used for writing to the render output buffer * @param {sap.ui.core.Control} oControl An object representation of the control that should be rendered */ OnePersonGridRenderer.render = function (oRm, oControl) { oRm.write(""); oRm.renderControl(oControl.getAggregation("_columnHeaders")); this.renderBlockersContainer(oRm, oControl); oRm.write(""); this.renderRowHeaders(oRm, oControl); this.renderNowMarker(oRm, oControl); this.renderColumns(oRm, oControl); oRm.write(""); // END .sapMOnePersonGridContent oRm.write(""); // END .sapMOnePersonGrid }; OnePersonGridRenderer.renderBlockersContainer = function (oRm, oControl) { var iColumns = oControl._getColumns(), iMaxLevel = oControl._getBlockersToRender().iMaxlevel, oStartDate = oControl.getStartDate(); oRm.write(""); oRm.write(""); for (var i = 0; i < iColumns; i++) { var oColumnDate = new UniversalDate(oStartDate.getFullYear(), oStartDate.getMonth(), oStartDate.getDate() + i), sDate = oControl._formatDayAsString(oColumnDate); oRm.write(""); oRm.write(""); // END .sapMOnePersonColumn } this.renderBlockers(oRm, oControl); oRm.write(""); // END .sapMOnePersonColumns oRm.write(""); // END .sapMOnePersonGridBlockers }; OnePersonGridRenderer.renderBlockers = function (oRm, oControl) { var that = this, oBlockersList = oControl._getBlockersToRender().oBlockersList; oRm.write(""); oBlockersList.getIterator().forEach(function (oBlocker) { that.renderBlockerAppointment(oRm, oControl, oBlocker); }); oRm.write(""); // END .sapMOnePersonBlockers }; OnePersonGridRenderer.renderBlockerAppointment = function(oRm, oControl, oBlockerNode) { var iGridStart = oControl._getDayPart(oControl.getStartDate()).getTime(), oBlocker = oBlockerNode.getData(), iBlockerStart = oControl._getDayPart(oBlocker.getStartDate()).getTime(), iBlockerEnd = oControl._getDayPart(oBlocker.getEndDate()).getTime(), iStartDayDiff = oControl._calculateDaysDifference(iGridStart, iBlockerStart), iEndDayDiff = oControl._calculateDaysDifference(iGridStart, iBlockerEnd), iColumns = oControl._getColumns(), bFilled = oControl.getAppointmentsVisualization() === CalendarAppointmentVisualization.Filled, iRowHeight = oControl._getBlockerRowHeight(), iBlockerLevel = oBlockerNode.level, iBlockerWidth = oBlockerNode.width, sTooltip = oBlocker.getTooltip_AsString(), sType = oBlocker.getType(), sColor = oBlocker.getColor(), sTitle = oBlocker.getTitle(), sText = oBlocker.getText(), sIcon = oBlocker.getIcon(), sId = oBlocker.getId(), mAccProps = {labelledby: {value: InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT") + " " + sId + "-Descr", append: true}}, aAriaLabels = oControl.getAriaLabelledBy(), iLeftPosition = iStartDayDiff * (100 / iColumns), iRightPosition = (iColumns - iEndDayDiff - 1) * (100 / iColumns), bIsRTL = sap.ui.getCore().getConfiguration().getRTL(); if (aAriaLabels.length > 0) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + aAriaLabels.join(" "); } if (sTitle) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + sId + "-Title"; } if (sText) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + sId + "-Text"; } if (oBlocker.getSelected()) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT_SELECTED"); } if (oBlocker.getTentative()) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT_TENTATIVE"); } oRm.write(""); oRm.write(""); // div element // extra content DIV to make some styling possible oRm.write(""); // div element if (iLeftPosition < 0) { oRm.writeIcon("sap-icon://arrow-left", null, { title: null }); } if (sIcon) { var aClasses = ["sapUiCalendarAppIcon"]; var mAttributes = {}; mAttributes["id"] = sId + "-Icon"; mAttributes["title"] = null; oRm.writeIcon(sIcon, aClasses, mAttributes); } if (sTitle) { oRm.write(""); // span element oRm.writeEscaped(sTitle, true); oRm.write(""); } if (iRightPosition < 0) { oRm.writeIcon("sap-icon://arrow-right", null, { title: null }); } oRm.write(""); oRm.write(""); oRm.write(""); }; OnePersonGridRenderer.renderRowHeaders = function (oRm, oControl) { var iStartHour = oControl._getVisibleStartHour(), iEndHour = oControl._getVisibleEndHour(), oStartDate = oControl._getUniversalCurrentDate(), oHoursFormat = oControl._getHoursFormat(), oAMPMFormat = oControl._getAMPMFormat(); oRm.write(""); for (var i = iStartHour; i <= iEndHour; i++) { oStartDate.setHours(i); oRm.write(""); oRm.write(oHoursFormat.format(oStartDate)); // TODO: use second param true when convert all dates to UTC if (oControl._hasAMPM()) { oRm.write(""); oRm.write(" " + oAMPMFormat.format(oStartDate)); // TODO: use second param true when convert all dates to UTC oRm.write(""); } oRm.write(""); // END .sapMOnePersonRowHeader } oRm.write(""); // END .sapMOnePersonRowHeaders }; OnePersonGridRenderer.renderColumns = function (oRm, oControl) { var iColumns = oControl._getColumns(), oStartDate = oControl.getStartDate(), oAppointmentsToRender = oControl._getAppointmentsToRender(); oRm.write(""); for (var i = 0; i < iColumns; i++) { var oColumnDate = new UniversalDate(oStartDate.getFullYear(), oStartDate.getMonth(), oStartDate.getDate() + i), sDate = oControl._formatDayAsString(oColumnDate); oRm.write(""); this.renderRows(oRm, oControl); this.renderAppointments(oRm, oControl, oAppointmentsToRender[sDate], oColumnDate); oRm.write(""); // END .sapMOnePersonColumn } oRm.write(""); // END .sapMOnePersonColumns }; OnePersonGridRenderer.renderRows = function (oRm, oControl) { var iStartHour = oControl._getVisibleStartHour(), iEndHour = oControl._getVisibleEndHour(); for (var i = iStartHour; i <= iEndHour; i++) { oRm.write(""); oRm.write(""); // END .sapMOnePersonRow } }; OnePersonGridRenderer.renderAppointments = function (oRm, oControl, oAppointmentsByDate, oColumnDate) { var that = this; if (oAppointmentsByDate) { oRm.write(""); oAppointmentsByDate.oAppointmentsList.getIterator().forEach(function (oAppointmentNode) { var iMaxLevel = oAppointmentsByDate.iMaxLevel, iLevel = oAppointmentNode.level, iWidth = oAppointmentNode.width, oAppointment = oAppointmentNode.getData(); that.renderAppointment(oRm, oControl, iMaxLevel, iLevel, iWidth, oAppointment, oColumnDate); }); oRm.write(""); } }; OnePersonGridRenderer.renderAppointment = function(oRm, oControl, iMaxLevel, iAppointmentLevel, iAppointmentWidth, oAppointment, oColumnDate) { var bFilled = oControl.getAppointmentsVisualization() === CalendarAppointmentVisualization.Filled, iRowHeight = oControl._getRowHeight(), oColumnStartDateAndHour = new UniversalDate(oColumnDate.getFullYear(), oColumnDate.getMonth(), oColumnDate.getDate(), oControl._getVisibleStartHour()), oColumnEndDateAndHour = new UniversalDate(oColumnDate.getFullYear(), oColumnDate.getMonth(), oColumnDate.getDate(), oControl._getVisibleEndHour(), 59, 59), oAppStartDate = oAppointment.getStartDate(), oAppEndDate = oAppointment.getEndDate(), sTooltip = oAppointment.getTooltip_AsString(), sType = oAppointment.getType(), sColor = oAppointment.getColor(), sTitle = oAppointment.getTitle(), sText = oAppointment.getText(), sIcon = oAppointment.getIcon(), sId = oAppointment.getId(), mAccProps = {labelledby: {value: InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT") + " " + sId + "-Descr", append: true}}, aAriaLabels = oControl.getAriaLabelledBy(), bAppStartIsOutsideVisibleStartHour = oColumnStartDateAndHour.getTime() > oAppStartDate.getTime(), bAppEndIsOutsideVisibleEndHour = oColumnEndDateAndHour.getTime() < oAppEndDate.getTime(), iAppTop = bAppStartIsOutsideVisibleStartHour ? 0 : oControl._calculateTopPosition(oAppStartDate), iAppBottom = bAppEndIsOutsideVisibleEndHour ? 0 : oControl._calculateBottomPosition(oAppEndDate), iAppChunkWidth = 100 / (iMaxLevel + 1); if (aAriaLabels.length > 0) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + aAriaLabels.join(" "); } if (sTitle) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + sId + "-Title"; } if (sText) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + sId + "-Text"; } if (oAppointment.getSelected()) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT_SELECTED"); } if (oAppointment.getTentative()) { mAccProps["labelledby"].value = mAccProps["labelledby"].value + " " + InvisibleText.getStaticId("sap.ui.unified", "APPOINTMENT_TENTATIVE"); } oRm.write(""); oRm.write(""); // div element // extra content DIV to make some styling possible oRm.write(""); // div element if (sIcon) { var aClasses = ["sapUiCalendarAppIcon"]; var mAttributes = {}; mAttributes["id"] = sId + "-Icon"; mAttributes["title"] = null; oRm.writeIcon(sIcon, aClasses, mAttributes); } if (sTitle) { oRm.write(""); // span element oRm.writeEscaped(sTitle, true); oRm.write(""); } if (sText) { oRm.write(""); // span element oRm.writeEscaped(sText, true); oRm.write(""); } // ARIA information about start and end // var sAriaText = oRow._oRb.getText("CALENDAR_START_TIME") + ": " + oRow._oFormatAria.format(oAppointment.getStartDate()); // sAriaText = sAriaText + "; " + oRow._oRb.getText("CALENDAR_END_TIME") + ": " + oRow._oFormatAria.format(oAppointment.getEndDate()); // if (sTooltip) { // sAriaText = sAriaText + "; " + sTooltip; // } // if (sType && sType != CalendarDayType.None) { // // sAriaText = sAriaText + "; " + this.getAriaTextForType(sType, aTypes); // } // oRm.write("" + sAriaText + ""); oRm.write(""); // this.renderResizeHandle(oRm, oRow, oAppointment); oRm.write(""); oRm.write(""); }; OnePersonGridRenderer.renderNowMarker = function (oRm, oControl) { var oDate = oControl._getUniversalCurrentDate(); oRm.write(""); oRm.write(""); oRm.write(oControl._formatTimeAsString(oDate)); oRm.write(""); // END .sapMOnePersonNowMarkerText oRm.write(""); // END .sapMOnePersonNowMarker }; return OnePersonGridRenderer; }, true /* bExport */);