/*!
* 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.
*/
// Provides default renderer for control sap.f.Card
sap.ui.define(["sap/f/library", "sap/base/security/encodeXML", "sap/ui/core/IconPool"],
function (library, encodeXML, IconPool) {
"use strict";
var mSizes = {
"1x1": {
icon: true
},
"2x1": {
icon: false,
title: true,
subtitle: true
},
"4x1": {
icon: true,
title: true,
subtitle: true,
status: true
},
"2x2": {
icon: true,
title: true,
subtitle: true,
status: false
},
"*x*": {
icon: true,
title: true,
subtitle: true,
status: true,
content: true
}
};
/**
* Card
renderer.
* @author SAP SE
* @namespace
*/
var CardRenderer = {};
/**
* 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} oCard an object representation of the control that should be rendered
*/
CardRenderer.render = function (oRm, oCard) {
//start
var mSizeSettings = CardRenderer.getSizeSettings(oCard),
vRaster = oCard.getRaster(),
iHorizontalSize = oCard.getHorizontalSize(),
iVerticalSize = oCard.getVerticalSize();
oRm.write("");
//header
CardRenderer.renderHeaderSection(oRm, oCard, mSizeSettings);
//content
if (mSizeSettings.content) {
oRm.write("");
CardRenderer.renderContentSection(oRm, oCard);
}
//end
oRm.write("");
};
/*
* renders the header of the card
*/
CardRenderer.renderHeaderSection = function (oRm, oCard, mSizeSettings) {
oRm.write("");
};
/*
* renders the icon of the card
*/
CardRenderer.renderHeaderIcon = function (oRm, oCard) {
var sIcon = oCard.getIcon(),
vIconInfo = IconPool.getIconInfo(oCard.getIcon(), undefined, "mixed"),
bIconInfo = false,
sColor = oCard.getIconColor() || oCard.getColor(),
sIconBackgroundColor = oCard.getIconBackgroundColor();
if (vIconInfo instanceof Promise) {
// if the icon info is still being loaded,
// an invalidation is triggered after the icon info is available
vIconInfo.then(oCard.invalidate.bind(oCard));
} else if (vIconInfo) {
// render icon info in renderer
bIconInfo = true;
}
if (sColor) {
oRm.addStyle("color", sColor);
}
if (sIconBackgroundColor) {
oRm.addStyle("background-color", sIconBackgroundColor);
}
oRm.write("");
oRm.write("");
};
/*
* renders the content of the card
*/
CardRenderer.renderContentSection = function (oRm, oCard) {
oRm.write("");
oRm.renderControl(oCard.getAggregation("_content"));
oRm.write("");
};
/*
* renders the content of the card
*/
CardRenderer.getSizeSettings = function (oCard) {
var iVertical = oCard.getVerticalSize(),
iHorizontal = oCard.getHorizontalSize(),
mSettings = mSizes[iHorizontal + "x" + iVertical] || mSizes["*x*"];
mSettings.vertical = iVertical;
mSettings.horizontal = iHorizontal;
return mSettings;
};
return CardRenderer;
}, /* bExport= */ true);