/*! * 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 control sap.m.ObjectAttribute. sap.ui.define([ './library', 'sap/ui/core/Control', 'sap/ui/core/library', 'sap/m/Text', './ObjectAttributeRenderer', "sap/base/Log" ], function(library, Control, coreLibrary, Text, ObjectAttributeRenderer, Log) { "use strict"; // shortcut for sap.ui.core.TextDirection var TextDirection = coreLibrary.TextDirection; /** * Constructor for a new ObjectAttribute. * * @param {string} [sId] ID for the new control, generated automatically if no ID is given * @param {object} [mSettings] Initial settings for the new control * * @class * The ObjectAttribute control displays a text field that can be normal or active. * The ObjectAttribute fires a press event when the user chooses the active text. * * Note: If property active is set to true, only the value of the * text property is styled and acts as a link. In this case the text * property must also be set, as otherwise there will be no link displayed for the user. * @extends sap.ui.core.Control * @version 1.60.23 * * @constructor * @public * @since 1.12 * @alias sap.m.ObjectAttribute * @ui5-metamodel This control/element also will be described in the UI5 (legacy) designtime metamodel */ var ObjectAttribute = Control.extend("sap.m.ObjectAttribute", /** @lends sap.m.ObjectAttribute.prototype */ { metadata : { library : "sap.m", designtime: "sap/m/designtime/ObjectAttribute.designtime", properties : { /** * Defines the ObjectAttribute title. */ title : {type : "string", group : "Misc", defaultValue : null}, /** * Defines the ObjectAttribute text. */ text : {type : "string", group : "Misc", defaultValue : null}, /** * Indicates if the ObjectAttribute text is selectable for the user. * * Note: As of version 1.48, only the value of the text property becomes active (styled and acts like a link) as opposed to both the title and text in the previous versions. If you set this property to true, you have to also set the text property. */ active : {type : "boolean", group : "Misc", defaultValue : null}, /** * Determines the direction of the text, not including the title. * Available options for the text direction are LTR (left-to-right) and RTL (right-to-left). By default the control inherits the text direction from its parent control. */ textDirection : {type : "sap.ui.core.TextDirection", group : "Appearance", defaultValue : TextDirection.Inherit} }, aggregations : { /** * When the aggregation is set, it replaces the text, active and textDirection properties. This also ignores the press event. The provided control is displayed as an active link in case it is a sap.m.Link. * Note: It will only allow sap.m.Text and sap.m.Link controls. */ customContent : {type : "sap.ui.core.Control", multiple : false}, /** * Text control to display title and text property. */ _textControl : {type : "sap.ui.core.Control", multiple : false, visibility : "hidden"} }, events : { /** * Fires when the user clicks on active text. */ press : { parameters : { /** * DOM reference of the ObjectAttribute's text to be used for positioning. */ domRef : {type : "string"} } } } }}); /** * Initializes member variables. * * @private */ ObjectAttribute.prototype.init = function() { this.setAggregation('_textControl', new Text()); }; /** * Delivers text control with updated title, text and maxLines properties. * * @private */ ObjectAttribute.prototype._getUpdatedTextControl = function() { var oAttrAggregation = this.getAggregation('customContent') || this.getAggregation('_textControl'), sTitle = this.getTitle(), sText = this.getAggregation('customContent') ? this.getAggregation('customContent').getText() : this.getText(), sTextDir = this.getTextDirection(), oParent = this.getParent(), bPageRTL = sap.ui.getCore().getConfiguration().getRTL(), iMaxLines = ObjectAttributeRenderer.MAX_LINES.MULTI_LINE, bWrap = true, oppositeDirectionMarker = ''; if (sTextDir === TextDirection.LTR && bPageRTL) { oppositeDirectionMarker = '\u200e'; } if (sTextDir === TextDirection.RTL && !bPageRTL) { oppositeDirectionMarker = '\u200f'; } sText = oppositeDirectionMarker + sText + oppositeDirectionMarker; if (sTitle) { sText = sTitle + ": " + sText; } oAttrAggregation.setProperty('text', sText, true); //if attribute is used inside responsive ObjectHeader or in ObjectListItem - only 1 line if (oParent instanceof sap.m.ObjectListItem) { bWrap = false; iMaxLines = ObjectAttributeRenderer.MAX_LINES.SINGLE_LINE; } this._setControlWrapping(oAttrAggregation, bWrap, iMaxLines); return oAttrAggregation; }; /** * Sets the appropriate property to the customContent aggregation. * * @private */ ObjectAttribute.prototype._setControlWrapping = function(oAttrAggregation, bWrap, iMaxLines) { if (oAttrAggregation.isA("sap.m.Link")) { oAttrAggregation.setProperty('wrapping', bWrap, true); } if (oAttrAggregation.isA("sap.m.Text")) { oAttrAggregation.setProperty('maxLines', iMaxLines, true); } }; /** * @private * @param {object} oEvent The fired event */ ObjectAttribute.prototype.ontap = function(oEvent) { //event should only be fired if the click is on the text (acting like a link) if (this._isSimulatedLink() && (oEvent.target.id === this.getId() + "-text")) { this.firePress({ domRef : this.getDomRef() }); } }; /** * @private * @param {object} oEvent The fired event */ ObjectAttribute.prototype.onsapenter = function(oEvent) { if (this._isSimulatedLink()) { this.firePress({ domRef : this.getDomRef() }); // mark the event that it is handled by the control oEvent.setMarked(); } }; /** * @private * @param {object} oEvent The fired event */ ObjectAttribute.prototype.onsapspace = function(oEvent) { this.onsapenter(oEvent); }; /** * Checks if ObjectAttribute is empty. * * @private * @returns {boolean} true if ObjectAttribute's text is empty or only consists of whitespaces */ ObjectAttribute.prototype._isEmpty = function() { if (this.getAggregation('customContent') && !(this.getAggregation('customContent').isA("sap.m.Link") || this.getAggregation('customContent').isA("sap.m.Text"))) { Log.warning("Only sap.m.Link or sap.m.Text are allowed in \"sap.m.ObjectAttribute.customContent\" aggregation"); return true; } return !(this.getText().trim() || this.getTitle().trim()); }; /** * Called when the control is touched. * @param {object} oEvent The fired event * @private */ ObjectAttribute.prototype.ontouchstart = function(oEvent) { if (this._isSimulatedLink()) { // for control who need to know if they should handle events from the ObjectAttribute control oEvent.originalEvent._sapui_handledByControl = true; } }; /** * Defines to which DOM reference the Popup should be docked. * * @protected * @return {DomNode} The DOM reference that Popup should dock to */ ObjectAttribute.prototype.getPopupAnchorDomRef = function() { return this.getDomRef("text"); }; ObjectAttribute.prototype._isSimulatedLink = function () { return (this.getActive() && this.getText() !== "") && !this.getAggregation('customContent'); }; ObjectAttribute.prototype.setCustomContent = function(oCustomContent) { if (oCustomContent && oCustomContent.isA('sap.m.Link')) { oCustomContent._getTabindex = function() { return "-1"; }; } return this.setAggregation('customContent', oCustomContent); }; /** * Returns whether the control can be clicked so in the renderer appropriate attributes can be set (for example tabindex). * @private */ ObjectAttribute.prototype._isClickable = function() { return (this.getActive() && this.getText() !== "") || ( this.getAggregation('customContent') && this.getAggregation('customContent').isA('sap.m.Link')); }; return ObjectAttribute; });