/*!
* @copyright@
*/
sap.ui.define([ './library' ],
function(library) {
"use strict";
/**
* NumericContent renderer.
* @namespace
*/
var NumericContentRenderer = {};
/**
* 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
*/
NumericContentRenderer.render = function(oRm, oControl) {
var sValue = oControl.getValue();
var sIndicator = oControl.getIndicator();
var sScale = oControl.getScale();
var sState = oControl.getState();
var bIndicator = library.DeviationIndicator.None !== sIndicator && sValue !== "";
var bWithMargin = oControl.getWithMargin();
var sWithoutMargin;
if (bWithMargin) {
sWithoutMargin = "";
} else {
sWithoutMargin = "WithoutMargin";
}
if (oControl.getFormatterValue()) {
var oFormattedValue = oControl._parseFormattedValue(sValue);
sScale = oFormattedValue.scale;
sValue = oFormattedValue.value;
}
var bScale = sScale && sValue;
oRm.write("
");
oRm.write("
");
if (bWithMargin) {
this._renderScaleAndIndicator(oRm, oControl, bIndicator, bScale, sWithoutMargin, sIndicator, sScale);
this._renderValue(oRm, oControl, sWithoutMargin, sValue);
} else {
this._renderValue(oRm, oControl, sWithoutMargin, sValue);
this._renderScaleAndIndicator(oRm, oControl, bIndicator, bScale, sWithoutMargin, sIndicator, sScale);
}
oRm.write("
");
oRm.write("
");
};
/**
* Adds missing style attributes to the icon due to a different property initialization order in Internet Explorer
* in comparison to Chrome.
*
* @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
* @param {sap.ui.core.Icon} oIcon the icon inside the control
* @param {String} sNumericContentFontClass font class of related NumericContent
* @private
*/
NumericContentRenderer._prepareAndRenderIcon = function (oRm, oControl, oIcon, sNumericContentFontClass) {
if (oIcon) {
var sState,
oLoadState = library.LoadState,
sCurrentState = oControl.getState();
//remove state classes from icon and only add the current state's class
for (sState in oLoadState) {
if (oLoadState.hasOwnProperty(sState) && sState !== sCurrentState) {
oIcon.removeStyleClass(sState);
} else if (oLoadState.hasOwnProperty(sState) && sState === sCurrentState) {
oIcon.addStyleClass(sState);
}
}
oIcon.addStyleClass("sapMNCIconImage");
//adjust top margin depending on the NumericContent font size
oIcon.removeStyleClass("sapMNCIconImageMediumTopMargin");
oIcon.removeStyleClass("sapMNCIconImageSmallTopMargin");
if (sNumericContentFontClass === "sapMNCMediumFontSize") {
oIcon.addStyleClass("sapMNCIconImageMediumTopMargin");
} else if (sNumericContentFontClass === "sapMNCSmallFontSize") {
oIcon.addStyleClass("sapMNCIconImageSmallTopMargin");
}
oRm.renderControl(oIcon);
}
};
/**
* Renders the HTML for the ScaleInd of the given control, using the provided {@link sap.ui.core.RenderManager}.
*
* @private
* @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 whose title should be rendered
* @param {boolean} isIndicator
* @param {boolean} isScale
* @param {String} withoutMargin
* @param {String} textIndicator
* @param {String} textScale
*/
NumericContentRenderer._renderScaleAndIndicator = function(oRm, oControl, isIndicator, isScale, withoutMargin, textIndicator, textScale) {
if (isIndicator || isScale) {
var sState = oControl.getState();
var sColor = oControl.getValueColor();
oRm.write("");
oRm.write("
");
if (isScale) {
oRm.write("
");
oRm.writeEscaped(textScale);
oRm.write("
");
}
oRm.write("
");
}
};
/**
* Renders the HTML for the ScaleInd of the given control, using the provided {@link sap.ui.core.RenderManager}.
*
* @private
* @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 whose title should be rendered
* @param {String} withoutMargin
* @param {String} value
*/
NumericContentRenderer._renderValue = function(oRm, oControl, withoutMargin, value) {
var sEmptyValue;
if (oControl.getNullifyValue()) {
sEmptyValue = "0";
} else {
sEmptyValue = "";
}
oRm.write("");
var oMaxDigitsData = oControl._getMaxDigitsData();
oRm.write("
");
this._prepareAndRenderIcon(oRm, oControl, oControl._oIcon, oMaxDigitsData.fontClass);
var iChar = oControl.getTruncateValueTo() || oMaxDigitsData.maxLength;
oRm.write("");
//Control shows only iChar characters. If the last shown character is decimal separator - show only first N-1 characters. So "144.5" is shown like "144" and not like "144.".
if (value.length >= iChar && (value[iChar - 1] === "." || value[iChar - 1] === ",")) {
oRm.writeEscaped(value.substring(0, iChar - 1));
} else {
oRm.writeEscaped(value ? value.substring(0, iChar) : sEmptyValue);
}
oRm.write("");
oRm.write("
");
oRm.write("
");
};
return NumericContentRenderer;
}, /* bExport= */true);