/*!
* 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.ListBase.
sap.ui.define([
"sap/ui/events/KeyCodes",
"sap/ui/Device",
"sap/ui/core/Control",
"sap/ui/core/InvisibleText",
"sap/ui/core/LabelEnablement",
"sap/ui/core/delegate/ItemNavigation",
"./library",
"./InstanceManager",
"./GrowingEnablement",
"./GroupHeaderListItem",
"./ListItemBase",
"./ListBaseRenderer",
"sap/base/strings/capitalize",
"sap/ui/thirdparty/jquery",
"sap/base/Log",
"sap/ui/dom/jquery/control", // jQuery Plugin "control"
"sap/ui/dom/jquery/Selectors", // jQuery custom selectors ":sapTabbable"
"sap/ui/dom/jquery/Aria" // jQuery Plugin "addAriaLabelledBy", "removeAriaLabelledBy"
],
function(
KeyCodes,
Device,
Control,
InvisibleText,
LabelEnablement,
ItemNavigation,
library,
InstanceManager,
GrowingEnablement,
GroupHeaderListItem,
ListItemBase,
ListBaseRenderer,
capitalize,
jQuery,
Log
) {
"use strict";
// shortcut for sap.m.ListType
var ListItemType = library.ListType;
// shortcut for sap.m.ListKeyboardMode
var ListKeyboardMode = library.ListKeyboardMode;
// shortcut for sap.m.ListGrowingDirection
var ListGrowingDirection = library.ListGrowingDirection;
// shortcut for sap.m.SwipeDirection
var SwipeDirection = library.SwipeDirection;
// shortcut for sap.m.ListSeparators
var ListSeparators = library.ListSeparators;
// shortcut for sap.m.ListMode
var ListMode = library.ListMode;
// shortcut for sap.m.ListHeaderDesign
var ListHeaderDesign = library.ListHeaderDesign;
// shortcut for sap.m.Sticky
var Sticky = library.Sticky;
/**
* Constructor for a new ListBase.
*
* @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 sap.m.ListBase
control provides a base functionality of the sap.m.List
and sap.m.Table
controls. Selection, deletion, unread states and inset style are also maintained in sap.m.ListBase
.
*
* See section "{@link topic:295e44b2d0144318bcb7bdd56bfa5189 List, List Item, and Table}"
* in the documentation for an introduction to subclasses of sap.m.ListBase
control.
*
* Note: The ListBase including all contained items may be completely re-rendered when the data of a bound model is changed. Due to the limited hardware resources of mobile devices this can lead to longer delays for lists that contain many items. As such the usage of a list is not recommended for these use cases.
* @extends sap.ui.core.Control
*
* @author SAP SE
* @version 1.60.23
*
* @constructor
* @public
* @since 1.16
* @alias sap.m.ListBase
* @ui5-metamodel This control/element also will be described in the UI5 (legacy) designtime metamodel
*/
var ListBase = Control.extend("sap.m.ListBase", /** @lends sap.m.ListBase.prototype */ { metadata : {
library : "sap.m",
dnd : true,
properties : {
/**
* Defines the indentation of the container. Setting it to true
indents the list.
*/
inset : {type : "boolean", group : "Appearance", defaultValue : false},
/**
* Defines the header text that appears in the control.
* Note: If headerToolbar
aggregation is set, then this property is ignored.
*/
headerText : {type : "string", group : "Misc", defaultValue : null},
/**
* Defines the header style of the control. Possible values are Standard
and Plain
.
* @since 1.14
* @deprecated Since version 1.16. No longer has any functionality.
*/
headerDesign : {type : "sap.m.ListHeaderDesign", group : "Appearance", defaultValue : ListHeaderDesign.Standard, deprecated: true},
/**
* Defines the footer text that appears in the control.
*/
footerText : {type : "string", group : "Misc", defaultValue : null},
/**
* Defines the mode of the control (e.g. None
, SingleSelect
, MultiSelect
, Delete
).
*/
mode : {type : "sap.m.ListMode", group : "Behavior", defaultValue : ListMode.None},
/**
* Sets the width of the control.
*/
width : {type : "sap.ui.core.CSSSize", group : "Dimension", defaultValue : "100%"},
/**
* Defines whether the items are selectable by clicking on the item itself (true
) rather than having to set the selection control first.
* Note: The SingleSelectMaster
mode also provides this functionality by default.
*/
includeItemInSelection : {type : "boolean", group : "Behavior", defaultValue : false},
/**
* Activates the unread indicator for all items, if set to true
.
*/
showUnread : {type : "boolean", group : "Misc", defaultValue : false},
/**
* This text is displayed when the control contains no items.
*/
noDataText : {type : "string", group : "Misc", defaultValue : null},
/**
* Defines whether or not the text specified in the noDataText
property is displayed.
*/
showNoData : {type : "boolean", group : "Misc", defaultValue : true},
/**
* When this property is set to true
, the control will automatically display a busy indicator when it detects that data is being loaded. This busy indicator blocks the interaction with the items until data loading is finished.
* By default, the busy indicator will be shown after one second. This behavior can be customized by setting the busyIndicatorDelay
property.
* @since 1.20.2
*/
enableBusyIndicator : {type : "boolean", group : "Behavior", defaultValue : true},
/**
* Defines if animations will be shown while switching between modes.
*/
modeAnimationOn : {type : "boolean", group : "Misc", defaultValue : true},
/**
* Defines which item separator style will be used.
*/
showSeparators : {type : "sap.m.ListSeparators", group : "Appearance", defaultValue : ListSeparators.All},
/**
* Defines the direction of the swipe movement (e.g LeftToRight, RightToLeft, Both) to display the control defined in the swipeContent
aggregation.
*/
swipeDirection : {type : "sap.m.SwipeDirection", group : "Misc", defaultValue : SwipeDirection.Both},
/**
* If set to true
, enables the growing feature of the control to load more items by requesting from the model.
* Note:: This feature only works when an items
aggregation is bound. Growing must not be used together with two-way binding.
* @since 1.16.0
*/
growing : {type : "boolean", group : "Behavior", defaultValue : false},
/**
* Defines the number of items to be requested from the model for each grow.
* This property can only be used if the growing
property is set to true
.
* @since 1.16.0
*/
growingThreshold : {type : "int", group : "Misc", defaultValue : 20},
/**
* Defines the text displayed on the growing button. The default is a translated text ("More") coming from the message bundle.
* This property can only be used if the growing
property is set to true
.
* @since 1.16.0
*/
growingTriggerText : {type : "string", group : "Appearance", defaultValue : null},
/**
* If set to true, the user can scroll down/up to load more items. Otherwise a growing button is displayed at the bottom/top of the control.
* Note: This property can only be used if the growing
property is set to true
and only if there is one instance of sap.m.List
or sap.m.Table
inside the scrollable scroll container (e.g sap.m.Page
).
* @since 1.16.0
*/
growingScrollToLoad : {type : "boolean", group : "Behavior", defaultValue : false},
/**
* Defines the direction of the growing feature.
* If set to Downwards
the user has to scroll down to load more items or the growing button is displayed at the bottom.
* If set to Upwards
the user has to scroll up to load more items or the growing button is displayed at the top.
* @since 1.40.0
*/
growingDirection : {type : "sap.m.ListGrowingDirection", group : "Behavior", defaultValue : ListGrowingDirection.Downwards},
/**
* If set to true, this control remembers and retains the selection of the items after a binding update has been performed (e.g. sorting, filtering).
* Note: This feature works only if two-way data binding for the selected
property of the item is not used. It also needs to be turned off if the binding context of the item does not always point to the same entry in the model, for example, if the order of the data in the JSONModel
is changed.
* @since 1.16.6
*/
rememberSelections : {type : "boolean", group : "Behavior", defaultValue : true},
/**
* Defines keyboard handling behavior of the control.
* @since 1.38.0
*/
keyboardMode : {type : "sap.m.ListKeyboardMode", group : "Behavior", defaultValue : ListKeyboardMode.Navigation},
/**
* Defines the section of the control that remains fixed at the top of the page during vertical scrolling as long as the control is in the viewport.
*
* Note: Enabling sticky column headers in List controls will not have any effect.
*
* There is limited browser support.
* Browsers that do not support this feature are listed below:
*
sap.ui.layout.Grid
control,
* the sticky elements of the control are not fixed at the top of the viewport. The control behaves in a similar way when placed within the sap.m.ObjectPage
control.sap.m.Table
control, setting focus on the column headers will let the table scroll to the top.headerText
property.
* @since 1.16
*/
headerToolbar : {type : "sap.m.Toolbar", multiple : false},
/**
* A toolbar that is placed below the header to show extra information to the user.
* @since 1.16
*/
infoToolbar : {type : "sap.m.Toolbar", multiple : false},
/**
* Defines the context menu of the items.
*
* @since 1.54
*/
contextMenu : {type : "sap.ui.core.IContextMenu", multiple : false}
},
associations: {
/**
* Association to controls / ids which label this control (see WAI-ARIA attribute aria-labelledby).
* @since 1.28.0
*/
ariaLabelledBy: { type: "sap.ui.core.Control", multiple: true, singularName: "ariaLabelledBy" }
},
events : {
/**
* Fires when selection is changed via user interaction. In MultiSelect
mode, this event is also fired on deselection.
* @deprecated Since version 1.16.
* Use the selectionChange
event instead.
*/
select : {deprecated: true,
parameters : {
/**
* The item which fired the select event.
*/
listItem : {type : "sap.m.ListItemBase"}
}
},
/**
* Fires when selection is changed via user interaction inside the control.
* @since 1.16
*/
selectionChange : {
parameters : {
/**
* The item whose selection has changed. In MultiSelect
mode, only the up-most selected item is returned. This parameter can be used for single-selection modes.
*/
listItem : {type : "sap.m.ListItemBase"},
/**
* Array of items whose selection has changed. This parameter can be used for MultiSelect
mode.
*/
listItems : {type : "sap.m.ListItemBase[]"},
/**
* Indicates whether the listItem
parameter is selected or not.
*/
selected : {type : "boolean"},
/**
* Indicates whether the select all action is triggered or not.
*/
selectAll : {type : "boolean"}
}
},
/**
* Fires when delete icon is pressed by user.
*/
"delete" : {
parameters : {
/**
* The item which fired the delete event.
*/
listItem : {type : "sap.m.ListItemBase"}
}
},
/**
* Fires after us"r's swipe action and before the swipeContent
is shown. On the swipe
event handler, swipeContent
can be changed according to the swiped item.
* Calling the preventDefault
method of the event cancels the swipe action.
*/
swipe : {allowPreventDefault : true,
parameters : {
/**
* The item which fired the swipe.
*/
listItem : {type : "sap.m.ListItemBase"},
/**
* Aggregated swipeContent
control that is shown on the right hand side of the item.
*/
swipeContent : {type : "sap.ui.core.Control"},
/**
* Holds which control caused the swipe event within the item.
*/
srcControl : {type : "sap.ui.core.Control"}
}
},
/**
* Fires before the new growing chunk is requested from the model.
* @since 1.16
* @deprecated Since version 1.16.3.
* Instead, use updateStarted
event with listening changeReason
.
*/
growingStarted : {deprecated: true,
parameters : {
/**
* Actual number of items.
*/
actual : {type : "int"},
/**
* Total number of items.
*/
total : {type : "int"}
}
},
/**
* Fires after the new growing chunk has been fetched from the model and processed by the control.
* @since 1.16
* @deprecated Since version 1.16.3.
* Instead, use "updateFinished" event.
*/
growingFinished : {deprecated: true,
parameters : {
/**
* Actual number of items.
*/
actual : {type : "int"},
/**
* Total number of items.
*/
total : {type : "int"}
}
},
/**
* Fires before items
binding is updated (e.g. sorting, filtering)
*
* Note: Event handler should not invalidate the control.
* @since 1.16.3
*/
updateStarted : {
parameters : {
/**
* The reason of the update, e.g. Binding, Filter, Sort, Growing, Change, Refresh, Context.
*/
reason : {type : "string"},
/**
* Actual number of items.
*/
actual : {type : "int"},
/**
* The total count of bound items. This can be used if the growing
property is set to true
.
*/
total : {type : "int"}
}
},
/**
* Fires after items
binding is updated and processed by the control.
* @since 1.16.3
*/
updateFinished : {
parameters : {
/**
* The reason of the update, e.g. Binding, Filter, Sort, Growing, Change, Refresh, Context.
*/
reason : {type : "string"},
/**
* Actual number of items.
*/
actual : {type : "int"},
/**
* The total count of bound items. This can be used if the growing
property is set to true
.
*/
total : {type : "int"}
}
},
/**
* Fires when an item is pressed unless the item's type
property is Inactive
.
* @since 1.20
*/
itemPress : {
parameters : {
/**
* The item which fired the pressed event.
*/
listItem : {type : "sap.m.ListItemBase"},
/**
* The control which caused the press event within the container.
*/
srcControl : {type : "sap.ui.core.Control"}
}
},
/**
* Fired when the context menu is opened.
* When the context menu is opened, the binding context of the item is set to the given contextMenu
.
* @since 1.54
*/
beforeOpenContextMenu : {
allowPreventDefault : true,
parameters : {
/**
* Item in which the context menu was opened.
*/
listItem : {type : "sap.m.ListItemBase"}
}
}
},
designtime: "sap/m/designtime/ListBase.designtime"
}});
// announce accessibility details at the initial focus
ListBase.prototype.bAnnounceDetails = true;
ListBase.getInvisibleText = function() {
return this.oInvisibleText || (this.oInvisibleText = new InvisibleText().toStatic());
};
// class name for the navigation items
ListBase.prototype.sNavItemClass = "sapMLIB";
ListBase.prototype.init = function() {
this._aNavSections = [];
this._aSelectedPaths = [];
this._iItemNeedsHighlight = 0;
this.data("sap-ui-fastnavgroup", "true", true); // Define group for F6 handling
};
ListBase.prototype.onBeforeRendering = function() {
this._bRendering = true;
this._bActiveItem = false;
this._aNavSections = [];
this._removeSwipeContent();
};
ListBase.prototype.onAfterRendering = function() {
this._bRendering = false;
this._sLastMode = this.getMode();
// invalidate item navigation for desktop
if (Device.system.desktop) {
this._bItemNavigationInvalidated = true;
}
};
ListBase.prototype.exit = function () {
this._oSelectedItem = null;
this._aNavSections = [];
this._aSelectedPaths = [];
this._destroyGrowingDelegate();
this._destroyItemNavigation();
};
// this gets called only with oData Model when first load or filter/sort
ListBase.prototype.refreshItems = function(sReason) {
if (this._oGrowingDelegate) {
// inform growing delegate to handle
this._oGrowingDelegate.refreshItems(sReason);
} else {
// if data multiple time requested during the ongoing request
// UI5 cancels the previous requests then we should fire updateStarted once
if (!this._bReceivingData) {
// handle update started event
this._updateStarted(sReason);
this._bReceivingData = true;
}
// for flat list get all data
this.refreshAggregation("items");
}
};
// this gets called via JSON and OData model when binding is updated
// if there is no data this should get called anyway
// TODO: if there is a network error this will not get called
// but we need to turn back to initial state
ListBase.prototype.updateItems = function(sReason) {
if (this._oGrowingDelegate) {
// inform growing delegate to handle
this._oGrowingDelegate.updateItems(sReason);
} else {
if (this._bReceivingData) {
// if we are receiving the data this should be oDataModel
// updateStarted is already handled before on refreshItems
// here items binding is updated because data is came from server
// so we can convert the flag for the next request
this._bReceivingData = false;
} else {
// if data is not requested this should be JSON Model
// data is already in memory and will not be requested
// so we do not need to change the flag
// this._bReceivingData should be always false
this._updateStarted(sReason);
}
// for flat list update items aggregation
this.updateAggregation("items");
// items binding are updated
this._updateFinished();
}
};
ListBase.prototype.setBindingContext = function(oContext, sModelName) {
var sItemsModelName = (this.getBindingInfo("items") || {}).model;
if (sItemsModelName === sModelName) {
this._resetItemsBinding();
}
return Control.prototype.setBindingContext.apply(this, arguments);
};
ListBase.prototype._bindAggregation = function(sName, oBindingInfo) {
function addBindingListener(oBindingInfo, sEventName, fHandler) {
oBindingInfo.events = oBindingInfo.events || {};
if (!oBindingInfo.events[sEventName]) {
oBindingInfo.events[sEventName] = fHandler;
} else {
// Wrap the event handler of the other party to add our handler.
var fOriginalHandler = oBindingInfo.events[sEventName];
oBindingInfo.events[sEventName] = function() {
fHandler.apply(this, arguments);
fOriginalHandler.apply(this, arguments);
};
}
}
if (sName === "items") {
this._resetItemsBinding();
addBindingListener(oBindingInfo, "dataRequested", this._onBindingDataRequestedListener.bind(this));
addBindingListener(oBindingInfo, "dataReceived", this._onBindingDataReceivedListener.bind(this));
}
Control.prototype._bindAggregation.call(this, sName, oBindingInfo);
};
ListBase.prototype._onBindingDataRequestedListener = function(oEvent) {
this._showBusyIndicator();
if (this._dataReceivedHandlerId != null) {
clearTimeout(this._dataReceivedHandlerId);
delete this._dataReceivedHandlerId;
}
};
ListBase.prototype._onBindingDataReceivedListener = function(oEvent) {
if (this._dataReceivedHandlerId != null) {
clearTimeout(this._dataReceivedHandlerId);
delete this._dataReceivedHandlerId;
}
// The list will be set to busy when a request is sent, and set to not busy when a response is received.
// Under certain conditions it can happen that there are multiple requests in the request queue of the binding, which will be processed
// sequentially. In this case the busy indicator will be shown and hidden multiple times (flickering) until all requests have been
// processed. With this timer we avoid the flickering, as the list will only be set to not busy after all requests have been processed.
this._dataReceivedHandlerId = setTimeout(function() {
this._hideBusyIndicator();
delete this._dataReceivedHandlerId;
}.bind(this), 0);
};
ListBase.prototype.destroyItems = function(bSuppressInvalidate) {
// check whether we have items to destroy or not
if (!this.getItems(true).length) {
return this;
}
// clean up the selection
this._oSelectedItem = null;
// suppress the synchronous DOM removal of the aggregation destroy
this.destroyAggregation("items", "KeepDom");
// invalidate to update the DOM on the next tick of the RenderManager
if (!bSuppressInvalidate) {
this.invalidate();
}
return this;
};
ListBase.prototype.removeAllItems = function(sAggregationName) {
this._oSelectedItem = null;
return this.removeAllAggregation("items");
};
ListBase.prototype.removeItem = function(vItem) {
var oItem = this.removeAggregation("items", vItem);
if (oItem && oItem === this._oSelectedItem) {
this._oSelectedItem = null;
}
return oItem;
};
ListBase.prototype.getItems = function(bReadOnly) {
if (bReadOnly) {
return this.mAggregations["items"] || [];
}
return this.getAggregation("items", []);
};
ListBase.prototype.getId = function(sSuffix) {
var sId = this.sId;
return sSuffix ? sId + "-" + sSuffix : sId;
};
ListBase.prototype.setGrowing = function(bGrowing) {
bGrowing = !!bGrowing;
if (this.getGrowing() != bGrowing) {
this.setProperty("growing", bGrowing, !bGrowing);
if (bGrowing) {
this._oGrowingDelegate = new GrowingEnablement(this);
} else if (this._oGrowingDelegate) {
this._oGrowingDelegate.destroy();
this._oGrowingDelegate = null;
}
}
return this;
};
ListBase.prototype.setGrowingThreshold = function(iThreshold) {
return this.setProperty("growingThreshold", iThreshold, true);
};
ListBase.prototype.setEnableBusyIndicator = function(bEnable) {
this.setProperty("enableBusyIndicator", bEnable, true);
if (!this.getEnableBusyIndicator()) {
this._hideBusyIndicator();
}
return this;
};
ListBase.prototype.setNoDataText = function(sNoDataText) {
this.setProperty("noDataText", sNoDataText, true);
this.$("nodata-text").text(this.getNoDataText());
return this;
};
ListBase.prototype.getNoDataText = function(bCheckBusy) {
// check busy state
if (bCheckBusy && this._bBusy) {
return "";
}
// return no data text from resource bundle when there is no custom
var sNoDataText = this.getProperty("noDataText");
sNoDataText = sNoDataText || sap.ui.getCore().getLibraryResourceBundle("sap.m").getText("LIST_NO_DATA");
return sNoDataText;
};
/**
* Returns selected list item. When no item is selected, "null" is returned. When "multi-selection" is enabled and multiple items are selected, only the up-most selected item is returned.
*
* @type sap.m.ListItemBase
* @public
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.getSelectedItem = function() {
var aItems = this.getItems(true);
for (var i = 0; i < aItems.length; i++) {
if (aItems[i].getSelected()) {
return aItems[i];
}
}
return null;
};
/**
* Selects or deselects the given list item.
*
* @param {sap.m.ListItemBase} oListItem
* The list item whose selection to be changed. This parameter is mandatory.
* @param {boolean} bSelect
* Sets selected status of the list item. Default value is true.
* @type sap.m.ListBase
* @public
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.setSelectedItem = function(oListItem, bSelect, bFireEvent) {
if (this.indexOfItem(oListItem) < 0) {
Log.warning("setSelectedItem is called without valid ListItem parameter on " + this);
return;
}
if (this._bSelectionMode) {
oListItem.setSelected((bSelect === undefined) ? true : !!bSelect);
bFireEvent && this._fireSelectionChangeEvent([oListItem]);
}
};
/**
* Returns an array containing the selected list items. If no items are selected, an empty array is returned.
*
* @type sap.m.ListItemBase[]
* @public
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.getSelectedItems = function() {
return this.getItems(true).filter(function(oItem) {
return oItem.getSelected();
});
};
/**
* Sets a list item to be selected by id. In single mode the method removes the previous selection.
*
* @param {string} sId
* The id of the list item whose selection to be changed.
* @param {boolean} bSelect
* Sets selected status of the list item. Default value is true.
* @type sap.m.ListBase
* @public
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.setSelectedItemById = function(sId, bSelect) {
var oListItem = sap.ui.getCore().byId(sId);
return this.setSelectedItem(oListItem, bSelect);
};
/**
* Returns the binding contexts of the selected items.
* Note: This method returns an empty array if no databinding is used.
*
* @param {boolean} bAll
* Set true to include even invisible selected items(e.g. the selections from the previous filters).
* Note: In single selection modes, only the last selected item's binding context is returned in array.
* @type object[]
* @public
* @since 1.18.6
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.getSelectedContexts = function(bAll) {
var oBindingInfo = this.getBindingInfo("items"),
sModelName = (oBindingInfo || {}).model,
oModel = this.getModel(sModelName);
// only deal with binding case
if (!oBindingInfo || !oModel) {
return [];
}
// return binding contexts from all selection paths
if (bAll && this.getRememberSelections()) {
return this._aSelectedPaths.map(function(sPath) {
return oModel.getContext(sPath);
});
}
// return binding context of current selected items
return this.getSelectedItems().map(function(oItem) {
return oItem.getBindingContext(sModelName);
});
};
/**
* Removes visible selections of the current selection mode.
*
* @param {boolean} bAll
* Since version 1.16.3. This control keeps old selections after filter or sorting. Set this parameter "true" to remove all selections.
* @type sap.m.ListBase
* @public
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.removeSelections = function(bAll, bFireEvent, bDetectBinding) {
var aChangedListItems = [];
this._oSelectedItem = null;
bAll && (this._aSelectedPaths = []);
this.getItems(true).forEach(function(oItem) {
if (!oItem.getSelected()) {
return;
}
// if the selected property is two-way bound then we do not need to update the selection
if (bDetectBinding && oItem.isSelectedBoundTwoWay()) {
return;
}
oItem.setSelected(false, true);
aChangedListItems.push(oItem);
!bAll && this._updateSelectedPaths(oItem);
}, this);
if (bFireEvent && aChangedListItems.length) {
this._fireSelectionChangeEvent(aChangedListItems);
}
return this;
};
/**
* Select all items in "MultiSelection" mode.
*
* @type sap.m.ListBase
* @public
* @since 1.16
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.selectAll = function (bFireEvent) {
if (this.getMode() != "MultiSelect") {
return this;
}
var aChangedListItems = [];
this.getItems(true).forEach(function(oItem) {
if (!oItem.getSelected()) {
oItem.setSelected(true, true);
aChangedListItems.push(oItem);
this._updateSelectedPaths(oItem);
}
}, this);
if (bFireEvent && aChangedListItems.length) {
this._fireSelectionChangeEvent(aChangedListItems, bFireEvent);
}
return this;
};
/**
* Returns the last list mode, the mode that is rendered
* This can be used to detect mode changes during rendering
*
* @protected
*/
ListBase.prototype.getLastMode = function(sMode) {
return this._sLastMode;
};
ListBase.prototype.setMode = function(sMode) {
sMode = this.validateProperty("mode", sMode);
var sOldMode = this.getMode();
if (sOldMode == sMode) {
return this;
}
// determine the selection mode
this._bSelectionMode = sMode.indexOf("Select") > -1;
// remove selections if mode is not a selection mode
if (!this._bSelectionMode) {
this.removeSelections(true);
} else {
// update selection status of items
var aSelecteds = this.getSelectedItems();
if (aSelecteds.length > 1) {
// remove selection if there are more than one item is selected
this.removeSelections(true);
} else if (sOldMode === ListMode.MultiSelect) {
// if old mode is multi select then we need to remember selected item
// in case of new item selection right after setMode call
this._oSelectedItem = aSelecteds[0];
}
}
// update property with invalidate
return this.setProperty("mode", sMode);
};
/**
* Returns growing information as object with "actual" and "total" keys.
* Note: This function returns "null" if "growing" feature is disabled.
*
* @type object
* @public
* @since 1.16
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
*/
ListBase.prototype.getGrowingInfo = function() {
return this._oGrowingDelegate ? this._oGrowingDelegate.getInfo() : null;
};
ListBase.prototype.setRememberSelections = function(bRemember) {
this.setProperty("rememberSelections", bRemember, true);
!this.getRememberSelections() && (this._aSelectedPaths = []);
return this;
};
/*
* Sets internal remembered selected context paths.
* This method can be called to reset remembered selection
* and does not change selection of the items until binding update.
*
* @param {String[]} aSelectedPaths valid binding context path array
* @since 1.26
* @protected
*/
ListBase.prototype.setSelectedContextPaths = function(aSelectedPaths) {
this._aSelectedPaths = aSelectedPaths || [];
};
/*
* Returns internal remembered selected context paths as a copy if rememberSelections is set to true,
* else returns the binding context path for the current selected items.
*
* @return {String[]} selected items binding context path
* @since 1.26
* @protected
*/
ListBase.prototype.getSelectedContextPaths = function(bAll) {
// return this selectedPaths if rememberSelections is true
if (!bAll || (bAll && this.getRememberSelections())) {
return this._aSelectedPaths.slice(0);
}
// return the binding context path of current selected items
return this.getSelectedItems().map(function(oItem) {
return oItem.getBindingContextPath();
});
};
/* Determines whether all selectable items are selected or not
* @protected
*/
ListBase.prototype.isAllSelectableSelected = function() {
if (this.getMode() != ListMode.MultiSelect) {
return false;
}
var aItems = this.getItems(true),
iSelectedItemCount = this.getSelectedItems().length,
iSelectableItemCount = aItems.filter(function(oItem) {
return oItem.isSelectable();
}).length;
return (aItems.length > 0) && (iSelectedItemCount == iSelectableItemCount);
};
/*
* Returns only visible items
* @protected
*/
ListBase.prototype.getVisibleItems = function() {
return this.getItems(true).filter(function(oItem) {
return oItem.getVisible();
});
};
// return whether list has active item or not
ListBase.prototype.getActiveItem = function() {
return this._bActiveItem;
};
// this gets called when items DOM is changed
ListBase.prototype.onItemDOMUpdate = function(oListItem) {
if (!this._bRendering && this.bOutput) {
this._startItemNavigation(true);
}
};
// this gets called when items active state is changed
ListBase.prototype.onItemActiveChange = function(oListItem, bActive) {
this._bActiveItem = bActive;
};
// this gets called when item type column requirement is changed
ListBase.prototype.onItemHighlightChange = function(oItem, bNeedsHighlight) {
this._iItemNeedsHighlight += (bNeedsHighlight ? 1 : -1);
// update highlight visibility
if (this._iItemNeedsHighlight == 1 && bNeedsHighlight) {
this.$("listUl").addClass("sapMListHighlight");
} else if (this._iItemNeedsHighlight == 0) {
this.$("listUl").removeClass("sapMListHighlight");
}
};
// this gets called when selected property of the ListItem is changed
ListBase.prototype.onItemSelectedChange = function(oListItem, bSelected) {
if (this.getMode() == ListMode.MultiSelect) {
this._updateSelectedPaths(oListItem, bSelected);
return;
}
if (bSelected) {
this._aSelectedPaths = [];
this._oSelectedItem && this._oSelectedItem.setSelected(false, true);
this._oSelectedItem = oListItem;
} else if (this._oSelectedItem === oListItem) {
this._oSelectedItem = null;
}
// update selection path for the list item
this._updateSelectedPaths(oListItem, bSelected);
};
/*
* Returns items container DOM reference
* @protected
*/
ListBase.prototype.getItemsContainerDomRef = function() {
return this.getDomRef("listUl");
};
ListBase.prototype.checkGrowingFromScratch = function() {};
/*
* This hook method gets called if growing feature is enabled and before new page loaded
* @protected
*/
ListBase.prototype.onBeforePageLoaded = function(oGrowingInfo, sChangeReason) {
this._fireUpdateStarted(sChangeReason, oGrowingInfo);
this.fireGrowingStarted(oGrowingInfo);
};
/*
* This hook method get called if growing feature is enabled and after page loaded
* @protected
*/
ListBase.prototype.onAfterPageLoaded = function(oGrowingInfo, sChangeReason) {
this._fireUpdateFinished(oGrowingInfo);
this.fireGrowingFinished(oGrowingInfo);
};
/*
* Adds navigation section that we can be navigate with alt + down/up
* @protected
*/
ListBase.prototype.addNavSection = function(sId) {
this._aNavSections.push(sId);
return sId;
};
/*
* Returns the max items count.
* If aggregation items is bound the count will be the length of the binding
* otherwise the length of the list items aggregation will be returned
* @protected
*/
ListBase.prototype.getMaxItemsCount = function() {
var oBinding = this.getBinding("items");
if (oBinding && oBinding.getLength) {
return oBinding.getLength() || 0;
}
return this.getItems(true).length;
};
/*
* This hook method is called from renderer to determine whether items should render or not
* @protected
*/
ListBase.prototype.shouldRenderItems = function() {
return true;
};
// when new items binding we should turn back to initial state
ListBase.prototype._resetItemsBinding = function() {
if (this.isBound("items")) {
this._bUpdating = false;
this._bReceivingData = false;
this.removeSelections(true, false, true);
this._oGrowingDelegate && this._oGrowingDelegate.reset();
this._hideBusyIndicator();
/* reset focused position */
if (this._oItemNavigation) {
this._oItemNavigation.iFocusedIndex = -1;
}
}
};
// called before update started via sorting/filtering/growing etc.
ListBase.prototype._updateStarted = function(sReason) {
// if data receiving/update is not started or ongoing
if (!this._bReceivingData && !this._bUpdating) {
this._bUpdating = true;
this._fireUpdateStarted(sReason);
}
};
// fire updateStarted event with update reason and actual/total info
ListBase.prototype._fireUpdateStarted = function(sReason, oInfo) {
this._sUpdateReason = capitalize(sReason || "Refresh");
this.fireUpdateStarted({
reason : this._sUpdateReason,
actual : oInfo ? oInfo.actual : this.getItems(true).length,
total : oInfo ? oInfo.total : this.getMaxItemsCount()
});
};
// event listener for theme changed
ListBase.prototype.onThemeChanged = function() {
if (this._oGrowingDelegate) {
this._oGrowingDelegate._updateTrigger();
}
};
// called on after rendering to finalize item update finished
ListBase.prototype._updateFinished = function() {
// check if data receiving/update is finished
if (!this._bReceivingData && this._bUpdating) {
this._fireUpdateFinished();
this._bUpdating = false;
}
};
// fire updateFinished event delayed to make sure rendering phase is done
ListBase.prototype._fireUpdateFinished = function(oInfo) {
this._hideBusyIndicator();
setTimeout(function() {
this._bItemNavigationInvalidated = true;
this.fireUpdateFinished({
reason : this._sUpdateReason,
actual : oInfo ? oInfo.actual : this.getItems(true).length,
total : oInfo ? oInfo.total : this.getMaxItemsCount()
});
}.bind(this), 0);
};
ListBase.prototype._showBusyIndicator = function() {
if (this.getEnableBusyIndicator() && !this.getBusy() && !this._bBusy) {
// set the busy state
this._bBusy = true;
// TODO: would be great to have an event when busy indicator visually seen
this._sBusyTimer = setTimeout(function() {
// clean no data text
this.$("nodata-text").text("");
}.bind(this), this.getBusyIndicatorDelay());
// set busy property
this.setBusy(true, "listUl");
}
};
ListBase.prototype._hideBusyIndicator = function() {
if (this._bBusy) {
// revert busy state
this._bBusy = false;
this.setBusy(false, "listUl");
clearTimeout(this._sBusyTimer);
// revert no data texts when necessary
if (!this.getItems(true).length) {
this.$("nodata-text").text(this.getNoDataText());
}
}
};
ListBase.prototype.onItemBindingContextSet = function(oItem) {
// determine whether selection remember is necessary or not
if (!this._bSelectionMode || !this.getRememberSelections() || !this.isBound("items")) {
return;
}
// if selected property two-way bound then we do not need to update the selection
if (oItem.isSelectedBoundTwoWay()) {
return;
}
// update the item selection
var sPath = oItem.getBindingContextPath();
if (sPath) {
var bSelected = (this._aSelectedPaths.indexOf(sPath) > -1);
oItem.setSelected(bSelected);
}
};
ListBase.prototype.onItemInserted = function(oItem, bSelectedDelayed) {
if (bSelectedDelayed) {
// item was already selected before inserted to the list
this.onItemSelectedChange(oItem, true);
}
if (!this._bSelectionMode ||
!this._aSelectedPaths.length ||
!this.getRememberSelections() ||
!this.isBound("items") ||
oItem.isSelectedBoundTwoWay() ||
oItem.getSelected()) {
return;
}
// retain item selection
var sPath = oItem.getBindingContextPath();
if (sPath && this._aSelectedPaths.indexOf(sPath) > -1) {
oItem.setSelected(true);
}
};
// this gets called from item when selection is changed via checkbox/radiobutton/press event
ListBase.prototype.onItemSelect = function(oListItem, bSelected) {
if (this.getMode() == ListMode.MultiSelect) {
this._fireSelectionChangeEvent([oListItem]);
} else if (this._bSelectionMode && bSelected) {
this._fireSelectionChangeEvent([oListItem]);
}
};
// Fire selectionChange event and support old select event API
ListBase.prototype._fireSelectionChangeEvent = function(aListItems, bSelectAll) {
var oListItem = aListItems && aListItems[0];
if (!oListItem) {
return;
}
// fire event
this.fireSelectionChange({
listItem : oListItem,
listItems : aListItems,
selected : oListItem.getSelected(),
selectAll: !!bSelectAll
});
// support old API
this.fireSelect({
listItem : oListItem
});
};
// this gets called from item when delete is triggered via delete button
ListBase.prototype.onItemDelete = function(oListItem) {
this.fireDelete({
listItem : oListItem
});
};
// this gets called from item when item is pressed(enter/tap/click)
ListBase.prototype.onItemPress = function(oListItem, oSrcControl) {
// do not fire press event for inactive type
if (oListItem.getType() == ListItemType.Inactive) {
return;
}
// fire event async
setTimeout(function() {
this.fireItemPress({
listItem : oListItem,
srcControl : oSrcControl
});
}.bind(this), 0);
};
// insert or remove given item's path from selection array
ListBase.prototype._updateSelectedPaths = function(oItem, bSelect) {
if (!this.getRememberSelections() || !this.isBound("items")) {
return;
}
var sPath = oItem.getBindingContextPath();
if (!sPath) {
return;
}
bSelect = (bSelect === undefined) ? oItem.getSelected() : bSelect;
var iIndex = this._aSelectedPaths.indexOf(sPath);
if (bSelect) {
iIndex < 0 && this._aSelectedPaths.push(sPath);
} else {
iIndex > -1 && this._aSelectedPaths.splice(iIndex, 1);
}
};
ListBase.prototype._destroyGrowingDelegate = function() {
if (this._oGrowingDelegate) {
this._oGrowingDelegate.destroy();
this._oGrowingDelegate = null;
}
};
ListBase.prototype._destroyItemNavigation = function() {
if (this._oItemNavigation) {
this.removeEventDelegate(this._oItemNavigation);
this._oItemNavigation.destroy();
this._oItemNavigation = null;
}
};
/**
* After swipe content is shown on the right hand side of the list item
* we will block the touch events and this method defines this touch blocker area.
* It must be always child/ren of the area because we will listen parent's touch events
*
* @private
*/
ListBase.prototype._getTouchBlocker = function() {
return this.$().children();
};
ListBase.prototype._getSwipeContainer = function() {
return this._$swipeContainer || (
this._$swipeContainer = jQuery("