UNPKG

@openui5/sap.m

Version:

OpenUI5 UI Library sap.m

1,895 lines (1,621 loc) 75 kB
/*! * OpenUI5 * (c) Copyright 2009-2023 SAP SE or an SAP affiliate company. * Licensed under the Apache License, Version 2.0 - see LICENSE.txt. */ // Provides control sap.m.VariantManagement. sap.ui.define([ "sap/ui/model/json/JSONModel", "sap/ui/model/base/ManagedObjectModel", "sap/ui/model/Filter", "sap/ui/model/FilterOperator", 'sap/ui/base/ManagedObjectObserver', "sap/ui/Device", "sap/ui/core/InvisibleText", "sap/ui/core/Control", "sap/ui/core/Icon", "sap/ui/core/Item", "sap/ui/layout/HorizontalLayout", "sap/ui/layout/Grid", "sap/m/SearchField", "sap/m/RadioButton", "sap/m/ColumnListItem", "sap/m/Column", "sap/m/Text", "sap/m/Bar", "sap/m/Table", "sap/m/Page", "sap/m/Toolbar", "sap/m/ToolbarSpacer", "sap/m/Button", "sap/m/CheckBox", "sap/m/Dialog", "sap/m/Input", "sap/m/Label", "sap/m/Title", "sap/m/ResponsivePopover", "sap/m/SelectList", "sap/m/ObjectIdentifier", "sap/m/OverflowToolbar", "sap/m/OverflowToolbarLayoutData", "sap/m/VBox", 'sap/m/HBox', "sap/ui/events/KeyCodes", 'sap/base/Log', "sap/ui/core/library", "sap/m/library" ], function( JSONModel, ManagedObjectModel, Filter, FilterOperator, ManagedObjectObserver, Device, InvisibleText, Control, Icon, Item, HorizontalLayout, Grid, SearchField, RadioButton, ColumnListItem, Column, Text, Bar, Table, Page, Toolbar, ToolbarSpacer, Button, CheckBox, Dialog, Input, Label, Title, ResponsivePopover, SelectList, ObjectIdentifier, OverflowToolbar, OverflowToolbarLayoutData, VBox, HBox, KeyCodes, Log, coreLibrary, mobileLibrary ) { "use strict"; // shortcut for sap.m.OverflowToolbarPriority var OverflowToolbarPriority = mobileLibrary.OverflowToolbarPriority; // shortcut for sap.m.ButtonType var ButtonType = mobileLibrary.ButtonType; // shortcut for sap.m.FlexAlignItems var FlexAlignItems = mobileLibrary.FlexAlignItems; // shortcut for sap.m.PlacementType var PlacementType = mobileLibrary.PlacementType; // shortcut for sap.m.PopinDisplay var PopinDisplay = mobileLibrary.PopinDisplay; // shortcut for sap.m.ScreenSize var ScreenSize = mobileLibrary.ScreenSize; var ListKeyboardMode = mobileLibrary.ListKeyboardMode; // shortcut for sap.ui.core.ValueState var ValueState = coreLibrary.ValueState; // shortcut for sap.ui.core.TextAlign var TextAlign = coreLibrary.TextAlign; // shortcut for sap.ui.core.TitleLevel var TitleLevel = coreLibrary.TitleLevel; /** * Constructor for a new <code>VariantManagement</code>. * @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 Can be used to manage variants. You can use this control in most controls that are enabled for <i>key user adaptation</i>.<br> * <b>Note: </b>On the user interface, variants are generally referred to as "views". * @extends sap.ui.core.Control * @constructor * @experimental As of version 1.103 * @private * @ui5-restricted sap.ui.fl, sap.ui.rta, sap.ui.comp * @since 1.103 * @alias sap.m.VariantManagement */ var VariantManagement = Control.extend("sap.m.VariantManagement", /** @lends sap.m.VariantManagement.prototype */ { metadata: { interfaces: [ "sap.ui.core.IShrinkable", "sap.m.IOverflowToolbarContent", "sap.m.IToolbarInteractiveControl" ], library: "sap.m", designtime: "sap/m/designtime/VariantManagement.designtime", properties: { /** * Indicates that default of variants is supported */ supportDefault: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates that favorite handling is supported */ supportFavorites: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates that apply automatically functionality is supported */ supportApplyAutomatically: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates that public functionality is supported */ supportPublic: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates that contexts functionality is supported */ supportContexts: { type: "boolean", group: "Misc", defaultValue: false }, /** * Identifies the currently selected item */ selectedKey: { type: "string", group: "Misc", defaultValue: "" }, /** * Identifies the defaulted item */ defaultKey: { type: "string", group: "Misc", defaultValue: "" }, /** * Controls the visibility of the 'SaveAs' button */ showSaveAs: { type: "boolean", group: "Misc", defaultValue: true }, /** * If set to <code>false</code> neither 'Save As' nor 'Save' buttons on the 'My Views' dialog are visible. */ creationAllowed: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates that the control is in edit state. If set to <code>false</code>, the footer of the <i>Views</i> list will be hidden. */ showFooter: { type: "boolean", group: "Misc", defaultValue: true }, /** * Indicates the visible and selected item. */ modified: { type: "boolean", group: "Misc", defaultValue: false }, /** * Indicates the title in the 'My Views' popover. */ popoverTitle: { type: "string", group: "Misc", defaultValue: "" }, /** * Indicates that the control is in error state. If set to <code>true</code>, an error message will be displayed whenever the variant is * opened. */ inErrorState: { type: "boolean", group: "Misc", defaultValue: false }, /** * Determines the behavior for Apply Automatically if the standard variant is marked as the default variant. * */ executeOnSelectionForStandardDefault: { type: "boolean", group: "Misc", defaultValue: false }, /** * Defines the Apply Automatically text for the standard variant in the Manage Views dialog if the application controls this behavior. */ displayTextForExecuteOnSelectionForStandardVariant: { type: "string", group: "Misc", defaultValue: "" }, /** * Semantic level of the header. * For more information, see {@link sap.m.Title#setLevel}. */ level: { type: "sap.ui.core.TitleLevel", group: "Appearance", defaultValue: TitleLevel.Auto }, /** * Defines the style of the title. * For more information, see {@link sap.m.Title#setTitleStyle}. * * @since 1.109 */ titleStyle: { type: "sap.ui.core.TitleLevel", group: "Appearance", defaultValue: TitleLevel.Auto }, /** * Sets the maximum width of the control. * * @since 1.109 */ maxWidth: { type: "sap.ui.core.CSSSize", group: "Dimension", defaultValue: "100%" }, /** * Defines the behavior, when the same list item is selected * If set to <code>false</code> the <code>select</code> event will be omitted. */ _selectStategyForSameItem: { type: "boolean", group: "Misc", defaultValue: true, visibility: "hidden" } }, defaultAggregation: "items", aggregations: { /** * Items displayed by the <code>VariantManagement</code> control. */ items: { type: "sap.m.VariantItem", multiple: true, singularName: "item" } }, events: { /** * This event is fired when the <i>Save View</i> dialog or the <i>Save As</i> dialog is closed with the save button. */ save: { parameters: { /** * Variant title */ name: { type: "string" }, /** * Indicates if an existing variant is overwritten or if a new variant is created. */ overwrite: { type: "boolean" }, /** * Variant key */ key: { type: "string" }, /** * <i>Apply Automatically</i> indicator */ execute: { type: "boolean" }, /** * The default variant indicator */ def: { type: "boolean" }, /** * Indicates the check box state for 'Public'. */ 'public': { type: "boolean" }, /** * Indicates the check box state for 'Create Tile'. * <br>Note:</br>This event parameter is used only internally. */ tile: { type: "boolean" } } }, /** * This event is fired when users presses the cancel button inside <i>Save As</i> dialog. */ cancel: {}, /** * This event is fired when users presses the cancel button inside <i>Manage Views</i> dialog. */ manageCancel: {}, /** * This event is fired when users apply changes to variants in the <i>Manage Views</i> dialog. */ manage: { parameters: { /** * List of changed variants. Each entry contains a 'key' - the variant key and a 'name' - the new title of the variant */ renamed: { type: "object[]" }, /** * List of deleted variant keys */ deleted: { type: "string[]" }, /** * List of variant keys and the associated Execute on Selection indicator */ exe: { type: "object[]" }, /** * List of variant keys and the associated favorite indicator */ fav: { type: "object[]" }, /** * The default variant key */ def: { type: "string" } } }, /** * This event is fired when a new variant is selected. */ select: { parameters: { /** * Variant key */ key: { type: "string" } } } } }, /** * Renders the HTML for the given control, using the provided {@link sap.ui.core.RenderManager}. * @param {sap.ui.core.RenderManager} oRm - <code>RenderManager</code> that can be used for writing to the render output buffer * @param {sap.ui.core.Control} oControl - Object representation of the control that should be rendered */ renderer: { apiVersion: 2, render: function(oRm, oControl) { oRm.openStart("div", oControl) .style("max-width", oControl.getMaxWidth()) .class("sapMVarMngmt") .openEnd(); oRm.renderControl(oControl.oVariantLayout); oRm.close("div"); } } }); VariantManagement.INNER_MODEL_NAME = "$sapMInnerVariants"; VariantManagement.MAX_NAME_LEN = 100; VariantManagement.COLUMN_FAV_IDX = 0; VariantManagement.COLUMN_NAME_IDX = 1; VariantManagement.COLUMN_DEFAULT_IDX = 3; /* * Constructs and initializes the <code>VariantManagement</code> control. */ VariantManagement.prototype.init = function() { this._oRb = sap.ui.getCore().getLibraryResourceBundle("sap.m"); this._oManagedObjectModel = new ManagedObjectModel(this); this.setModel(this._oManagedObjectModel, "$mVariants"); this._oObserver = new ManagedObjectObserver(this._observeChanges.bind(this)); this._oObserver.observe(this, { aggregations: [ "items" ] }); }; VariantManagement.prototype._observeChanges = function(oChanges) { var oVariantItem; if (oChanges.type === "aggregation") { if (oChanges.name === "items") { oVariantItem = oChanges.child; switch (oChanges.mutation) { case "insert": if (!this._oObserver.isObserved(oVariantItem, {properties: ["title"]})) { this._oObserver.observe(oVariantItem, {properties: ["title"]}); } if (this.getSelectedKey() === oVariantItem.getKey()) { this.refreshTitle(); } break; case "remove": if (this._oObserver.isObserved(oVariantItem, {properties: ["title"]})) { this._oObserver.unobserve(oVariantItem, {properties: ["title"]}); } break; default: Log.error("operation " + oChanges.mutation + " not yet implemented"); } } } else if (oChanges.type === "property") { if (oChanges.object.isA && oChanges.object.isA("sap.m.VariantItem")) { oVariantItem = oChanges.object; if (oVariantItem) { if (this.getSelectedKey() === oVariantItem.getKey()) { this.refreshTitle(); } } } } }; VariantManagement.prototype.applySettings = function(mSettings, oScope) { Control.prototype.applySettings.apply(this, arguments); this._createInnerModel(); this._initializeControl(); }; VariantManagement.prototype.setShowFooter = function(bValue) { this.setProperty("showFooter", bValue); return this; }; VariantManagement.prototype.setDefaultKey = function(sValue) { this.setProperty("defaultKey", sValue); return this; }; VariantManagement.prototype.setPopoverTitle = function(sValue) { this.setProperty("popoverTitle", sValue); return this; }; VariantManagement.prototype._initializeControl = function() { if (this.oVariantInvisibleText) { return; } this.oVariantInvisibleText = new InvisibleText(); this.oVariantText = new Title(this.getId() + "-text", { text: { path: '/selectedKey', model: "$mVariants", formatter: function(sKey) { var sText = ""; if (sKey) { sText = this.getSelectedVariantText(sKey); this._setInvisibleText(sText, this.getModified()); } return sText; }.bind(this) }, level: { path: '/level', model: "$mVariants" }, titleStyle: { path: '/titleStyle', model: "$mVariants" } }); this.oVariantText.addStyleClass("sapMVarMngmtClickable"); this.oVariantText.addStyleClass("sapMVarMngmtTitle"); var oVariantModifiedText = new Text(this.getId() + "-modified", { text: "*", visible: { path: "/modified", model: "$mVariants", formatter: function(bValue) { var sKey = this.getSelectedKey(); if (sKey) { this._setInvisibleText(this.getSelectedVariantText(sKey), bValue); } return ((bValue === null) || (bValue === undefined)) ? false : bValue; }.bind(this) } }); oVariantModifiedText.setVisible(false); oVariantModifiedText.addStyleClass("sapMVarMngmtModified"); oVariantModifiedText.addStyleClass("sapMVarMngmtClickable"); this.oVariantPopoverTrigger = new Button(this.getId() + "-trigger", { icon: "sap-icon://slim-arrow-down", type: ButtonType.Transparent, tooltip: this._oRb.getText("VARIANT_MANAGEMENT_TRIGGER_TT"), enabled: { path: "/isDesignMode", model: VariantManagement.INNER_MODEL_NAME, formatter: function(bValue) { return !bValue; } } }); this.oVariantPopoverTrigger.addAriaLabelledBy(this.oVariantInvisibleText); this.oVariantPopoverTrigger.addStyleClass("sapMVarMngmtClickable"); this.oVariantLayout = new HorizontalLayout({ content: [ this.oVariantText, oVariantModifiedText, this.oVariantPopoverTrigger ] }); this.oVariantLayout.addStyleClass("sapMVarMngmtLayout"); this.oVariantLayout.addStyleClass("sapMVarMngmtLayoutModifiedHidden"); oVariantModifiedText.setVisible(false); this.oVariantModifiedText = oVariantModifiedText; this.oVariantInvisibleText.toStatic(); this.addDependent(this.oVariantLayout); }; /** * Required by the {@link sap.m.IOverflowToolbarContent} interface. * Registers invalidations event which is fired when width of the control is changed. * * @protected * @returns {{canOverflow: boolean, invalidationEvents: string[]}} Configuration information for the <code>sap.m.IOverflowToolbarContent</code> interface */ VariantManagement.prototype.getOverflowToolbarConfig = function() { return { canOverflow: false, invalidationEvents: ["save", "manage", "select"] }; }; /** * Returns the title control of the <code>VariantManagement</code>. This is used in the key user scenario. * @protected * @returns {sap.m.Title} Title part of the <code>VariantManagement</code> control. */ VariantManagement.prototype.getTitle = function() { return this.oVariantText; }; VariantManagement.prototype.refreshTitle = function() { if (this.oVariantText) { this.oVariantText.getBinding("text").refresh(true); } }; VariantManagement.prototype._setInvisibleText = function(sText, bFlag) { var sInvisibleTextKey; if (sText) { if (bFlag) { sInvisibleTextKey = "VARIANT_MANAGEMENT_SEL_VARIANT_MOD"; this.oVariantLayout.removeStyleClass("sapMVarMngmtLayoutModifiedHidden"); } else { sInvisibleTextKey = "VARIANT_MANAGEMENT_SEL_VARIANT"; this.oVariantLayout.addStyleClass("sapMVarMngmtLayoutModifiedHidden"); } this.oVariantInvisibleText.setText(this._oRb.getText(sInvisibleTextKey, [sText])); } }; VariantManagement.prototype._createInnerModel = function() { var oModel = new JSONModel({ showCreateTile: false, isDesignMode: false }); this.setModel(oModel, VariantManagement.INNER_MODEL_NAME); }; VariantManagement.prototype._getShowCreateTile = function() { return this._getInnerModelProperty("/showCreateTile"); }; VariantManagement.prototype._setShowCreateTile = function(bValue) { this._setInnerModelProperty("/showCreateTile", bValue); }; VariantManagement.prototype.getDesignMode = function() { return this._getInnerModelProperty("/isDesignMode"); }; VariantManagement.prototype.setDesignMode = function(bValue) { this._setInnerModelProperty("/isDesignMode", bValue); }; VariantManagement.prototype._setInnerModelProperty = function(sPropertyPath, vValue) { var oInnerModel = this.getModel(VariantManagement.INNER_MODEL_NAME); if (oInnerModel) { oInnerModel.setProperty(sPropertyPath, vValue); } }; VariantManagement.prototype._getInnerModelProperty = function(sPropertyPath) { var oInnerModel = this.getModel(VariantManagement.INNER_MODEL_NAME); if (oInnerModel) { return oInnerModel.getProperty(sPropertyPath); } return null; }; /** * Gets all the variants * @private * @returns {array} Of variants */ VariantManagement.prototype._getItems = function() { return this.getItems(); }; VariantManagement.prototype.getSelectedVariantText = function(sKey) { var oItem = this._getItemByKey(sKey); if (oItem) { return oItem.getTitle(); } return ""; }; VariantManagement.prototype.getStandardVariantKey = function() { var aItems = this._getItems(); if (aItems && aItems[0]) { return aItems[0].getKey(); } return null; }; VariantManagement.prototype._clearDeletedItems = function() { this._aDeletedItems = []; }; VariantManagement.prototype._addDeletedItem = function(oItem) { var sKey = oItem.getKey(); if (this._aDeletedItems.indexOf(sKey) < 0) { this._aDeletedItems.push(sKey); } }; VariantManagement.prototype._getDeletedItems = function() { return this._aDeletedItems; }; VariantManagement.prototype._clearRenamedItems = function() { this._aRenamedItems = []; }; VariantManagement.prototype._addRenamedItem = function(oItem) { var sKey = oItem.getKey(); if (this._aRenamedItems.indexOf(sKey) < 0) { this._aRenamedItems.push(sKey); } }; VariantManagement.prototype._removeRenamedItem = function(oItem) { var sKey = oItem.getKey(); var nIdx = this._aRenamedItems.indexOf(sKey); if ( nIdx >= 0) { this._aRenamedItems.splice(nIdx, 1); } }; VariantManagement.prototype._getRenamedItems = function() { return this._aRenamedItems; }; VariantManagement.prototype._getItemByKey = function(sKey) { var oItem = null; var aItems = this._getItems(); if (aItems) { aItems.some(function(oEntry) { if (oEntry.getKey() === sKey) { oItem = oEntry; } return (oItem !== null); }); } return oItem; }; VariantManagement.prototype._obtainControl = function(oEvent) { if (oEvent && oEvent.target && oEvent.target.id) { var sId = oEvent.target.id; var nPos = sId.indexOf("-inner"); if (nPos > 0) { sId = sId.substring(0, nPos); } return sap.ui.getCore().byId(sId); } return null; }; // clickable area VariantManagement.prototype.handleOpenCloseVariantPopover = function(oEvent) { if (!this.bPopoverOpen) { this._oCtrlRef = this._obtainControl(oEvent); this._openVariantList(); } else if (this.oVariantPopOver && this.oVariantPopOver.isOpen()) { this.oVariantPopOver.close(); } else if (this.getInErrorState() && this.oErrorVariantPopOver && this.oErrorVariantPopOver.isOpen()) { this.oErrorVariantPopOver.close(); } }; VariantManagement.prototype.getFocusDomRef = function() { return this.oVariantPopoverTrigger.getFocusDomRef(); }; VariantManagement.prototype.onclick = function(oEvent) { if (this.getDesignMode()) { return; } if (this.oVariantPopoverTrigger && !this.bPopoverOpen) { this.oVariantPopoverTrigger.focus(); } this.handleOpenCloseVariantPopover(oEvent); }; VariantManagement.prototype.onkeyup = function(oEvent) { if (oEvent.which === KeyCodes.F4 || oEvent.which === KeyCodes.SPACE || oEvent.altKey === true && oEvent.which === KeyCodes.ARROW_UP || oEvent.altKey === true && oEvent.which === KeyCodes.ARROW_DOWN) { this._oCtrlRef = this._obtainControl(oEvent); this._openVariantList(); } }; VariantManagement.prototype.onAfterRendering = function() { if (this.oVariantText) { this.oVariantText.$().off("mouseover").on("mouseover", function() { this.oVariantPopoverTrigger.addStyleClass("sapMVarMngmtTriggerBtnHover"); }.bind(this)); this.oVariantText.$().off("mouseout").on("mouseout", function() { this.oVariantPopoverTrigger.removeStyleClass("sapMVarMngmtTriggerBtnHover"); }.bind(this)); } }; // ERROR LIST VariantManagement.prototype._openInErrorState = function() { var oVBox; if (!this.oErrorVariantPopOver) { oVBox = new VBox({ fitContainer: true, alignItems: FlexAlignItems.Center, items: [ new Icon({ size: "4rem", color: "lightgray", src: "sap-icon://message-error" }), new Title({ titleStyle: TitleLevel.H2, text: this._oRb.getText("VARIANT_MANAGEMENT_ERROR_TEXT1") }), new Text({ textAlign: TextAlign.Center, text: this._oRb.getText("VARIANT_MANAGEMENT_ERROR_TEXT2") }) ] }); oVBox.addStyleClass("sapMVarMngmtErrorPopover"); this.oErrorVariantPopOver = new ResponsivePopover(this.getId() + "-errorpopover", { title: { path: "/popoverTitle", model: "$mVariants" }, contentWidth: "400px", placement: PlacementType.VerticalPreferredBottom, content: [ new Page(this.getId() + "-errorselpage", { showSubHeader: false, showNavButton: false, showHeader: false, content: [ oVBox ] }) ], afterOpen: function() { this.bPopoverOpen = true; }.bind(this), afterClose: function() { if (this.bPopoverOpen) { setTimeout(function() { this.bPopoverOpen = false; }.bind(this), 200); } }.bind(this), contentHeight: "300px" }); this.oErrorVariantPopOver.attachBrowserEvent("keyup", function(e) { if (e.which === 32) { // UP this.oErrorVariantPopOver.close(); } }.bind(this)); } if (this.bPopoverOpen) { return; } this.oErrorVariantPopOver.openBy(this.oVariantLayout); }; // My Views List VariantManagement.prototype._createVariantList = function() { if (this.oVariantPopOver) { return; } this.oVariantManageBtn = new Button(this.getId() + "-manage", { text: this._oRb.getText("VARIANT_MANAGEMENT_MANAGE"), enabled: true, press: function() { this._openManagementDialog(); }.bind(this), layoutData: new OverflowToolbarLayoutData({ priority: OverflowToolbarPriority.Low }) }); this.oVariantSaveBtn = new Button(this.getId() + "-mainsave", { text: this._oRb.getText("VARIANT_MANAGEMENT_SAVE"), press: function() { this._handleVariantSave(); }.bind(this), visible: { parts: [{ path: '$mVariants>/creationAllowed' },{ path: '$mVariants>/modified' },{ path: '$mVariants>/selectedKey' } ], formatter: function(bCreationAllowed, bModified, sSelectedKey) { var bItemChangeable = false; var oItem = this._getItemByKey(sSelectedKey); if (oItem) { bItemChangeable = oItem.getChangeable(); } return bCreationAllowed && bModified && bItemChangeable; }.bind(this) }, type: ButtonType.Emphasized, layoutData: new OverflowToolbarLayoutData({ priority: OverflowToolbarPriority.Low }) }); this.oVariantSaveAsBtn = new Button(this.getId() + "-saveas", { text: this._oRb.getText("VARIANT_MANAGEMENT_SAVEAS"), press: function() { this._openSaveAsDialog(); }.bind(this), layoutData: new OverflowToolbarLayoutData({ priority: OverflowToolbarPriority.Low }), visible: { parts: [{ path: '$mVariants>/creationAllowed' },{ path: '$mVariants>/showSaveAs' }], formatter: function(bCreationAllowed, bShowSaveAs) { return bCreationAllowed && bShowSaveAs; } } }); this.oVariantList = new SelectList(this.getId() + "-list", { selectedKey: { path: "/selectedKey", model: "$mVariants" }, itemPress: function(oEvent) { var sSelectionKey = null; if (oEvent && oEvent.getParameters()) { var oItemPressed = oEvent.getParameters().item; if (oItemPressed) { sSelectionKey = oItemPressed.getKey(); } } if (sSelectionKey) { var bTriggerForSameItem = this.getProperty("_selectStategyForSameItem"); if (bTriggerForSameItem || (!bTriggerForSameItem && (this.getSelectedKey() !== sSelectionKey))) { this.setSelectedKey(sSelectionKey); this.fireSelect({ key: sSelectionKey }); } this.oVariantPopOver.close(); } }.bind(this) }); this.oVariantList.setNoDataText(this._oRb.getText("VARIANT_MANAGEMENT_NODATA")); var oItemTemplate = new Item({ key: "{$mVariants>key}", text: "{$mVariants>title}" }); this.oVariantList.bindAggregation("items", { path: "/items", model: "$mVariants", template: oItemTemplate }); this._oSearchField = new SearchField(this.getId() + "-search"); this._oSearchField.attachLiveChange(function(oEvent) { this._triggerSearch(oEvent, this.oVariantList); }.bind(this)); this.oVariantSelectionPage = new Page(this.getId() + "-selpage", { subHeader: new Toolbar({ content: [ this._oSearchField ] }), content: [ this.oVariantList ], footer: new OverflowToolbar({ content: [ new ToolbarSpacer(this.getId() + "-spacer"), this.oVariantSaveBtn, this.oVariantSaveAsBtn, this.oVariantManageBtn ] }), showNavButton: false, showHeader: false }); this.oVariantSelectionPage.bindProperty("showFooter", { path: "/showFooter", model: "$mVariants" }); this.oVariantPopOver = new ResponsivePopover(this.getId() + "-popover", { title: { path: "/popoverTitle", model: "$mVariants" }, titleAlignment: "Auto", contentWidth: "400px", placement: PlacementType.VerticalPreferredBottom, content: [ this.oVariantSelectionPage ], afterOpen: function() { this.bPopoverOpen = true; }.bind(this), afterClose: function() { if (this.bPopoverOpen) { setTimeout(function() { this.bPopoverOpen = false; }.bind(this), 200); } }.bind(this), contentHeight: "300px" }); this.oVariantPopOver.addStyleClass("sapMVarMngmtPopover"); if (this.oVariantLayout.$().closest(".sapUiSizeCompact").length > 0) { this.oVariantPopOver.addStyleClass("sapUiSizeCompact"); } this.addDependent(this.oVariantPopOver); this.oVariantPopOver.isPopupAdaptationAllowed = function() { return false; }; // this.oVariantList.getBinding("items").filter(this._getFilters()); }; VariantManagement.prototype._determineEmphasizedFooterButton = function() { if (this.oVariantSaveBtn.getVisible()) { this.oVariantSaveBtn.setType(ButtonType.Emphasized); this.oVariantSaveAsBtn.setType(ButtonType.Default); } else { this.oVariantSaveAsBtn.setType(ButtonType.Emphasized); } }; VariantManagement.prototype.setModified = function(bValue) { this.setProperty("modified", bValue); return this; }; VariantManagement.prototype._openVariantList = function() { if (this.getInErrorState()) { this._openInErrorState(); return; } if (this.bPopoverOpen) { return; } this._createVariantList(); this._oSearchField.setValue(""); this.oVariantList.getBinding("items").filter(this._getFilters()); this.oVariantSelectionPage.setShowSubHeader(this.oVariantList.getItems().length > 9); this._determineEmphasizedFooterButton(); var oSelectedItem = this.oVariantList.getSelectedItem(); if (oSelectedItem) { this.oVariantPopOver.setInitialFocus(oSelectedItem.getId()); } var oControlRef = this._oCtrlRef ? this._oCtrlRef : this.oVariantLayout; this._oCtrlRef = null; this.oVariantPopOver.openBy(oControlRef); }; VariantManagement.prototype._triggerSearch = function(oEvent, oVariantList) { if (!oEvent) { return; } var parameters = oEvent.getParameters(); if (!parameters) { return; } var sValue = parameters.newValue ? parameters.newValue : ""; var oFilter = new Filter({ path: "title", operator: FilterOperator.Contains, value1: sValue }); oVariantList.getBinding("items").filter(this._getFilters(oFilter)); }; // Save View dialog VariantManagement.prototype._createSaveAsDialog = function() { if (!this.oSaveAsDialog) { this.oInputName = new Input(this.getId() + "-name", { liveChange: function() { this._checkVariantNameConstraints(this.oInputName); }.bind(this) }); var oLabelName = new Label(this.getId() + "-namelabel", { text: this._oRb.getText("VARIANT_MANAGEMENT_NAME") }); oLabelName.setLabelFor(this.oInputName); oLabelName.addStyleClass("sapMVarMngmtSaveDialogLabel"); this.oDefault = new CheckBox(this.getId() + "-default", { text: this._oRb.getText("VARIANT_MANAGEMENT_SETASDEFAULT"), visible: { path: "/supportDefault", model: "$mVariants" }, select: function(oEvent) { if (this._sStyleClass) { if (oEvent.getParameter("selected")) { var mContexts = this._getContextInfoChanges(); if (this._isRestricted(mContexts)) { this.oDefault.setValueState(ValueState.Error); this.oDefault.setValueStateText(this._oRb.getText("VARIANT_MANAGEMENT_NO_DEFAULT_ON_RESTRICTED_VIEWS")); this.oDefault.focus(); } else { this.oDefault.setValueState(ValueState.None); this.oDefault.setValueStateText(""); } } else if (this.oDefault.getValueState() != ValueState.None){ this.oDefault.setValueState(ValueState.None); this.oDefault.setValueStateText(""); } } }.bind(this), width: "100%" }); this.oPublic = new CheckBox(this.getId() + "-public", { text: this._oRb.getText("VARIANT_MANAGEMENT_SETASPUBLIC"), visible: { path: "/supportPublic", model: "$mVariants" }, width: "100%" }); this.oExecuteOnSelect = new CheckBox(this.getId() + "-execute", { text: this._oRb.getText("VARIANT_MANAGEMENT_EXECUTEONSELECT"), visible: { path: "/supportApplyAutomatically", model: "$mVariants" }, width: "100%" }); this.oCreateTile = new CheckBox(this.getId() + "-tile", { text: this._oRb.getText("VARIANT_MANAGEMENT_CREATETILE"), enabled: true, visible: { path: "/showCreateTile", model: VariantManagement.INNER_MODEL_NAME }, width: "100%" }); this.oSaveSave = new Button(this.getId() + "-variantsave", { text: this._oRb.getText("VARIANT_MANAGEMENT_SAVE"), type: ButtonType.Emphasized, press: function() { if (!this._bSaveOngoing) { this._checkVariantNameConstraints(this.oInputName); if (this.oInputName.getValueState() === "Error") { this.oInputName.focus(); return; } this._bSaveOngoing = true; this._bSaveCanceled = false; var bReturn = this._handleVariantSaveAs(this.oInputName.getValue()); if (!bReturn) { this._bSaveOngoing = false; } } }.bind(this), enabled: true }); var oSaveAsDialogOptionsGrid = new Grid({ defaultSpan: "L12 M12 S12" }); oSaveAsDialogOptionsGrid.addContent(this.oDefault); oSaveAsDialogOptionsGrid.addContent(this.oPublic); oSaveAsDialogOptionsGrid.addContent(this.oExecuteOnSelect); oSaveAsDialogOptionsGrid.addContent(this.oCreateTile); this.oSaveAsDialog = new Dialog(this.getId() + "-savedialog", { title: this._oRb.getText("VARIANT_MANAGEMENT_SAVEDIALOG"), afterClose: function() { this._bSaveOngoing = false; if (this._sStyleClass) { this.setSupportPublic(this._bShowPublic); this.oSaveAsDialog.removeStyleClass(this._sStyleClass); if (this._oRolesComponentContainer) { this.oSaveAsDialog.removeContent(this._oRolesComponentContainer); } this._sStyleClass = undefined; this._oRolesComponentContainer = null; } }.bind(this), beginButton: this.oSaveSave, endButton: new Button(this.getId() + "-variantcancel", { text: this._oRb.getText("VARIANT_MANAGEMENT_CANCEL"), press: this._cancelPressed.bind(this) }), content: [ oLabelName, this.oInputName, oSaveAsDialogOptionsGrid ], stretch: Device.system.phone }); this.oSaveAsDialog.isPopupAdaptationAllowed = function() { return false; }; this.oSaveAsDialog.addStyleClass("sapUiContentPadding"); this.oSaveAsDialog.addStyleClass("sapMVarMngmtSaveDialog"); if (this.oVariantLayout.$().closest(".sapUiSizeCompact").length > 0) { this.oSaveAsDialog.addStyleClass("sapUiSizeCompact"); } this.addDependent(this.oSaveAsDialog); } }; VariantManagement.prototype._cancelPressed = function() { this._bSaveCanceled = true; this.fireCancel(); this.oSaveAsDialog.close(); }; VariantManagement.prototype._getSelectedContexts = function() { return this._oRolesComponentContainer.getComponentInstance().getSelectedContexts(); }; VariantManagement.prototype._setSelectedContexts = function(mContexts) { if (!mContexts || (Object.keys(mContexts).length === 0)) { mContexts = { role: []}; } this._oRolesComponentContainer.getComponentInstance().setSelectedContexts(mContexts); }; VariantManagement.prototype._isInErrorContexts = function() { return this._oRolesComponentContainer.getComponentInstance().hasErrorsAndShowErrorMessage(); }; VariantManagement.prototype._isRestricted = function(mContexts) { if (!mContexts) { mContexts = { role: []}; } return (mContexts.role && mContexts.role.length > 0); }; VariantManagement.prototype._determineRolesSpecificText = function(oItem, oTextControl) { if (oTextControl) { oTextControl.setText(this._oRb.getText((this._isRestricted(oItem.getContexts())) ? "VARIANT_MANAGEMENT_VISIBILITY_RESTRICTED" : "VARIANT_MANAGEMENT_VISIBILITY_NON_RESTRICTED")); } }; VariantManagement.prototype._checkAndAddRolesContainerToManageDialog = function() { if (this._oRolesComponentContainer && this._oRolesDialog) { var oRolesComponentContainer = null; this._oRolesDialog.getContent().some(function(oContent) { if (oContent === this._oRolesComponentContainer) { oRolesComponentContainer = oContent; return true; } return false; }.bind(this)); if (!oRolesComponentContainer) { this._oRolesDialog.addContent(this._oRolesComponentContainer); } } }; VariantManagement.prototype._createRolesDialog = function() { if (!this._oRolesDialog) { this._oRolesDialog = new Dialog(this.getId() + "-roledialog", { draggable: true, resizable: true, contentWidth: "40%", title: this._oRb.getText("VARIANT_MANAGEMENT_SELECTROLES_DIALOG"), beginButton: new Button(this.getId() + "-rolesave", { text: this._oRb.getText("VARIANT_MANAGEMENT_SAVE"), type: ButtonType.Emphasized, press: function() { if (!this._checkAndCreateContextInfoChanges(this._oCurrentContextsKey, this._oTextControl)) { return; } this._oRolesDialog.close(); }.bind(this) }), endButton: new Button(this.getId() + "-rolecancel", { text: this._oRb.getText("VARIANT_MANAGEMENT_CANCEL"), press: function() { this._oRolesDialog.close(); }.bind(this) }), content: [this._oRolesComponentContainer], stretch: Device.system.phone }); this._oRolesDialog.setParent(this); this._oRolesDialog.addStyleClass("sapUiContentPadding"); this._oRolesDialog.addStyleClass(this._sStyleClass); this._oRolesDialog.isPopupAdaptationAllowed = function() { return false; }; } this._checkAndAddRolesContainerToManageDialog(); }; VariantManagement.prototype._openRolesDialog = function(oItem, oTextControl) { this._createRolesDialog(); this._oCurrentContextsKey = oItem.getKey(); this._oTextControl = oTextControl; this._setSelectedContexts(oItem.getContexts()); this._oRolesDialog.open(); }; VariantManagement.prototype._checkAndCreateContextInfoChanges = function(sKey, oTextControl) { if (sKey) { if (this._oRolesComponentContainer) { try { if (!this._isInErrorContexts()) { var mContexts = this._getSelectedContexts(); var oItem = this._getItemByKey(sKey); if (oItem) { oItem.setContexts(mContexts); this._determineRolesSpecificText(oItem, oTextControl); this._checkDefaultEnabled(oItem); } } else { return false; } } catch (ex) { return false; } } return true; } return false; }; VariantManagement.prototype._checkAndAddRolesContainerToSaveAsDialog = function() { if (this._oRolesComponentContainer && this.oSaveAsDialog) { var oRolesComponentContainer = null; this.oSaveAsDialog.getContent().some(function(oContent) { if (oContent === this._oRolesComponentContainer) { oRolesComponentContainer = oContent; return true; } return false; }.bind(this)); this._setSelectedContexts({ role: []}); if (!oRolesComponentContainer) { this.oSaveAsDialog.addContent(this._oRolesComponentContainer); } } }; /** * Opens the <i>Save As</i> dialog. * @param {string} sStyleClassName - style-class to be used * @param {object} oRolesComponentContainer - component for roles handling */ VariantManagement.prototype.openSaveAsDialog = function (sStyleClassName, oRolesComponentContainer) { this._openSaveAsDialog(true); this.oSaveAsDialog.addStyleClass(sStyleClassName); this._sStyleClass = sStyleClassName; // indicates that dialog is running in key user scenario this._bShowPublic = this.getSupportPublic(); this.setSupportPublic(false); if (oRolesComponentContainer) { Promise.all([oRolesComponentContainer]).then(function(vArgs) { this._oRolesComponentContainer = vArgs[0]; this.setSupportContexts(!!this._oRolesComponentContainer ); this._checkAndAddRolesContainerToSaveAsDialog(); this.oSaveAsDialog.open(); }.bind(this)); } else { this.oSaveAsDialog.open(); } }; VariantManagement.prototype._openSaveAsDialog = function(bDoNotOpen) { this._createSaveAsDialog(); this.setSupportContexts(false); this.oInputName.setValue(this.getSelectedVariantText(this.getSelectedKey())); this.oInputName.setEnabled(true); this.oInputName.setValueState(ValueState.None); this.oInputName.setValueStateText(null); this.oDefault.setEnabled(true); this.oDefault.setSelected(false); if (this.oDefault.getValueState() !== ValueState.None) { this.oDefault.setValueState(ValueState.None); this.oDefault.setValueStateText(""); } this.oPublic.setSelected(false); this.oExecuteOnSelect.setSelected(false); this.oCreateTile.setSelected(false); if (this.oVariantPopOver) { this.oVariantPopOver.close(); } if (!bDoNotOpen) { this.oSaveAsDialog.open(); } }; VariantManagement.prototype._handleVariantSaveAs = function(sNewVariantName) { var sKey = null; var sName = sNewVariantName.trim(); if (sName === "") { this.oInputName.setValueState(ValueState.Error); this.oInputName.setValueStateText(this._oRb.getText("VARIANT_MANAGEMENT_ERROR_EMPTY")); return false; } var mContexts = this._getContextInfoChanges(); var bIsRestricted = this._isRestricted(mContexts); if (bIsRestricted && this.oDefault.getSelected()) { this.oDefault.setValueState(ValueState.Error); this.oDefault.setValueStateText(this._oRb.getText("VARIANT_MANAGEMENT_NO_DEFAULT_ON_RESTRICTED_VIEWS")); this.oDefault.focus(); return false; } else if (!bIsRestricted){ var bWasInErrorState = this.oDefault.getValueState() !== ValueState.None; this.oDefault.setValueState(ValueState.None); this.oDefault.setValueStateText(""); if (bWasInErrorState){ return false; // otherwise the error state is still visible on the UI and the Save completes... } } if (this.oSaveAsDialog) { this.oSaveAsDialog.close(); } var oObj = { key: sKey, name: sName, overwrite: false, def: this.oDefault.getSelected(), execute: this.oExecuteOnSelect.getSelected(), "public": this.getSupportPublic() ? this.oPublic.getSelected() : undefined, contexts: mContexts }; if (this._getShowCreateTile() && this.oCreateTile) { oObj.tile = this.oCreateTile.getSelected(); } this.fireSave(oObj); return true; }; VariantManagement.prototype._getContextInfoChanges = function() { if (this._oRolesComponentContainer) { try { if (!this._isInErrorContexts()) { return this._getSelectedContexts(); } } catch (ex) { return undefined; } } return undefined; }; VariantManagement.prototype._handleVariantSave = function() { var oItem = this._getItemByKey(this.getSelectedKey()); var bDefault = false; if (this.getDefaultKey() === oItem.getKey()) { bDefault = true; } if (this.oVariantPopOver) { this.oVariantPopOver.close(); } this.fireSave({ name: oItem.getTitle(), overwrite: true, key: oItem.getKey(), def: bDefault }); }; // Manage Views dialog VariantManagement.prototype.destroyManageDialog = function() { if (this.oManagementDialog) { this.oManagementDialog.destroy(); this.oManagementDialog = undefined; } }; /** * Opens the <i>Manage Views</i> dialog. * @param {boolean} bCreateAlways - Indicates that if this is set to <code>true</code>, the former dialog will be destroyed before a new one is created * @param {string} sStyleClass - style-class to be used * @param {object} oRolesComponentContainer - component for roles handling */ VariantManagement.prototype.openManagementDialog = function(bCreateAlways, sStyleClass, oRolesComponentContainer) { if (bCreateAlways && this.oManagementDialog) { this.oManagementDialog.destroy(); this.oManagementDialog = undefined; } if (sStyleClass) { this._sStyleClass = sStyleClass; this._bShowPublic = this.getSupportPublic(); this.setSupportPublic(false); this.setSupportContexts(false); } if (oRolesComponentContainer) { Promise.all([oRolesComponentContainer]).then(function(vArgs) { this._oRolesComponentContainer = vArgs[0]; this.setSupportContexts(!!this._oRolesComponentContainer); this._openManagementDialog(); if (this._sStyleClass) { this.oManagementDialog.addStyleClass(this._sStyleClass); } }.bind(this)); } else { this._openManagementDialog(); if (this._sStyleClass) { this.oManagementDialog.addStyleClass(this._sStyleClass); } } }; VariantManagement.prototype._triggerSearchInManageDialog = function(oEvent, oManagementTable) { if (!oEvent) { return; } var parameters = oEvent.getParameters(); if (!parameters) { return; } var sValue; if (parameters.query) { sValue = parameters.query; } else { sValue = parameters.newValue ? parameters.newValue : ""; } this._triggerSearchInManageDialogByValue(sValue, oManagementTable); }; VariantManagement.prototype._triggerSearchInManageDialogByValue = function(sValue, oManagementTable) { var aFilters = [ this._getVisibleFilter(), new Filter({ filters: [ new Filter({ path: "title", operator: FilterOperator.Contains, value1: sValue }), new Filter({ path: "author", operator: FilterOperator.Contains, value1: sValue }) ], and: false }) ]; oManagementTable.getBinding("items").filter(aFilters); this._bDeleteOccured = true; }; VariantManagement.prototype.getManageDialog = function() { return this.oManagementDialog; }; VariantManagement.prototype._createManagementDialog = function() { if (!this.oManagementDialog || this.oManagementDialog.bIsDestroyed) { this.oManagementTable = new Table(this.getId() + "-managementTable", { contextualWidth: "Auto", fixedLayout: false, growing: true, keyboardMode: ListKeyboardMode.Edit, columns: [ new Column({ header: new InvisibleText({ text: this._oRb.getText("VARIANT_MANAGEMENT_FAVORITE_COLUMN") }), width: "3rem", visible: { path: "/supportFavorites", model: "$mVariants" } }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_NAME") }), width: "16rem" }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_VARIANTTYPE"), wrappingType: "Hyphenated" }), visible: { path: "/supportPublic", model: "$mVariants" }, demandPopin: true, popinDisplay: PopinDisplay.Inline, minScreenWidth: ScreenSize.Tablet }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_DEFAULT"), wrappingType: "Hyphenated" }), hAlign: TextAlign.Center, demandPopin: true, popinDisplay: PopinDisplay.Block, minScreenWidth: ScreenSize.Tablet, visible: { path: "/supportDefault", model: "$mVariants" } }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_EXECUTEONSELECT"), wrappingType: "Hyphenated" }), hAlign: this.getDisplayTextForExecuteOnSelectionForStandardVariant() ? TextAlign.Begin : TextAlign.Center, demandPopin: true, popinDisplay: PopinDisplay.Block, minScreenWidth: ScreenSize.Tablet, visible: { path: "/supportApplyAutomatically", model: "$mVariants" } }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_VISIBILITY"), wrappingType: "Hyphenated" }), width: "8rem", demandPopin: true, popinDisplay: PopinDisplay.Inline, minScreenWidth: ScreenSize.Tablet, visible: { path: "/supportContexts", model: "$mVariants" } }), new Column({ header: new Text({ text: this._oRb.getText("VARIANT_MANAGEMENT_AUTHOR") }), demandPopin: true, popinDisplay: PopinDisplay.Block, minScreenWidth: ScreenSize.Tablet }), new Column({ header: new InvisibleText({ text: this._oRb.getText("VARIANT_MANAGEMENT_ACTION_COLUMN") }), hAlign: TextAlign.Center }), new Column({ visible: false }) ] }); this.oManagementSave = new Button(this.getId() + "-managementsave", { text: this._oRb.getText("VARIANT_MANAGEMENT_SAVE"), enabled: true, type: ButtonType.Emphasized, press: function() { this._handleManageSavePressed(); //this.oManagementDialog.close(); }.bind(this) }); this.oManagementCancel = new Button(this.getId() + "-managementcancel", { text: this._oRb.getText("VARIANT_MANAGEMENT_CANCEL"), press: function() { this._resumeManagementTableBinding(); this._handleManageCancelPressed(); if (this.oManagementDialog) { // can be deleted during manageCancel event this.oManagementDialog.close(); } }.bind(this) }); this.oManagementDialog = new Dialog(this.getId() + "-managementdialog", { contentWidth: "64%", resizable: true, draggable: true, title: this._oRb.getText("VARIANT_MANAGEMENT_MANAGEDIALOG"), beginButton: this.oManagementSave, endButton: this.oManagementCancel, afterClose: function() { if (this._sStyleClass) { this.setSupportPublic(this._bShowPublic, true); this.oManagementDialog.removeStyleClass(this._sStyleClass); this._sStyleClass = undefined; this._oRolesComponentContainer = null; } }.bind(this), content: [ this.oManagementTable ], stretch: Device.system.phone }); // add marker this.oManagementDialog.isPopupAdaptationAllowed = function() { return false; }; this._oSearchFieldOnMgmtDialog = new SearchField(); this._oSearchFieldOnMgmtDialog.attachLiveChange(function(oEvent) { this._triggerSearchInManageDialog(oEvent, this.oManagementTable); }.bind(this)); this._oSearchFieldOnMgmtDialog.attachSearch(function(oEvent) { this._triggerSearchInManageDialog(oEvent, this.oManagementTable); }.bind(this)); var oSubHeader = new Bar(this.getId() + "-mgmHeaderSearch", { contentMiddle: [ this._oSearchFieldOnMgmtDialog ] }); this.oManagementDialog.setSubHeader(oSubHeader); this.oManagementDialog.setInitialFocus(this._oSearchFieldOnMgmtDialog); if (this.oVariantLayout.$().closest(".sapUiSizeCompact").length > 0) { this.oManagementDialog.addStyleClass("sapUiSizeCompact"); }