IndentedListView.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2014, 2020
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['jquery', 'underscore', '../VisView', '../../../lib/@waca/core-client/js/core-client/utils/dom-utils', '../../../lib/@waca/dashboard-common/dist/utils/ScrollBarUtil', '../../../lib/@waca/core-client/js/core-client/i18n/FormatResources', '../../../util/DashboardFormatter', '../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/utils/EventChainLocal', '../VisEventHandler', './IndentedListEventTarget', '../../../util/EventUtils'], function ($, _, VisView, domUtils, ScrollBarUtil, FormatResources, Formatter, stringResources, EventChainLocal, VisEventHandler, IndentedListEventTarget, EventUtils) {
  13. 'use strict';
  14. var IndentedListView = VisView.extend({
  15. DEFAULT_MAX_WIDTH: 320,
  16. DEFAULT_MAX_HEIGHT: 480,
  17. GROUP_MAX_LENGTH: 100,
  18. DELAYLOADING_THROTTLE: 2000,
  19. ATTRIBUTES: {
  20. COLUMN_CLASS: 'col',
  21. ROW_CLASS: 'row'
  22. },
  23. // Maps related to changing text properties
  24. // Map properties to css style strings
  25. PROPERTY_TO_STYLE: {
  26. 'font-weight': 'bold',
  27. 'font-style': 'italic',
  28. 'text-decoration': 'underline'
  29. },
  30. PROPERTY_MAP: {
  31. listValueColor: 'color',
  32. listValueFontSize: 'font-size',
  33. listValueFontFace: 'font-family',
  34. listValueFontBold: 'font-weight',
  35. listValueFontItalic: 'font-style',
  36. listValueFontUnderline: 'text-decoration',
  37. listValueFontAlign: 'text-align'
  38. },
  39. templateString: '<div role="tree" aria -expanded="true" aria-label="' + _.escape(stringResources.get('srILVTreeLabel')) + '" tabIndex="-1" class="datawidget indentedlist-content userPrimaryFGPaletteColor" data-attach-point="contentNode"></div>',
  40. events: {
  41. 'mousedown .item': 'onDataItemMousedown',
  42. 'touchdown .item': 'onDataItemMousedown',
  43. 'keydown .item': 'onDataItemKeydown',
  44. 'hold .item': 'onDataItemHold',
  45. 'mousedown': 'onMouseDown'
  46. },
  47. initialRender: true,
  48. _groupArrays: [],
  49. _groupCounter: 0,
  50. init: function init() {
  51. IndentedListView.inherited('init', this, arguments);
  52. this._cache = []; /*Holds all items after a render*/
  53. this._groupArrays = []; /*Holds all items after a 3*/
  54. this._groupCounter = 0;
  55. this._focusedNode = null;
  56. this.$el.addClass('dataview indentedlist-view indentedlist-view-initial-max-size');
  57. this.initialRender = true;
  58. var $inner = this.$el.find('.indentedlist-content').first();
  59. this.scrollBarUtil = new ScrollBarUtil($inner, // inner
  60. this.$el // outer
  61. );
  62. this.isMobilePannable = true;
  63. this.content = this.content || this.dashboardApi.getCanvas().getContent(this.ownerWidget.getId());
  64. this._scrollHandlerFn = this.scrollHandler.bind(this);
  65. },
  66. scrollHandler: function scrollHandler(evt) {
  67. var $dom = $(evt.target);
  68. if ($dom.scrollTop() + $dom.innerHeight() >= $dom[0].scrollHeight - 20) {
  69. this._addMore();
  70. }
  71. },
  72. onMouseDown: function onMouseDown(event) {
  73. if (this._isOnScrollBar(event)) {
  74. event.stopPropagation();
  75. }
  76. },
  77. getRenderer: function getRenderer() {
  78. return 'dashboard-analytics/visualizations/renderer/indentedlist/IndentedListRenderer';
  79. },
  80. /**
  81. * Loads and creates the control. Returns a promise which is resolved when the control
  82. * is created and ready to render
  83. */
  84. whenVisControlReady: function whenVisControlReady() {
  85. var _this = this;
  86. var result = void 0;
  87. if (this.visControl) {
  88. result = Promise.resolve(this.visControl);
  89. } else {
  90. result = new Promise(function (resolve, reject) {
  91. try {
  92. require([_this.visModel.getDefinition().control], function (VisControl) {
  93. _this.visControl = new VisControl({
  94. domNode: _this.$el.find('.indentedlist-content')[0]
  95. });
  96. resolve(_this.visControl);
  97. }, reject);
  98. } catch (error) {
  99. reject(error);
  100. }
  101. }).then(function () {
  102. _this.eventHandler = new VisEventHandler({
  103. target: new IndentedListEventTarget({
  104. $el: _this.$el,
  105. visControl: _this.visControl,
  106. visAPI: _this.visModel,
  107. view: _this,
  108. logger: _this.logger
  109. }),
  110. transaction: _this.transactionApi,
  111. logger: _this.logger,
  112. ownerWidget: _this.ownerWidget,
  113. visAPI: _this.visModel,
  114. edgeSelection: true
  115. });
  116. return _this.visControl;
  117. });
  118. }
  119. return result;
  120. },
  121. /*
  122. * Set a list widget's size based on its content in order to set an initial size
  123. */
  124. _clampDefaultDimensions: function _clampDefaultDimensions() {
  125. //indentedlist-view-initial-max-size is applied when a list widget is first created to help determine a reasonable default size.
  126. //It turns off line wrapping. This is to compensate for a browser behaviour which artificially reduces available space to a list widget when it
  127. //is on a templated page outside the main area (see defect 49563).
  128. //This function determines the best default size of a list widget and hard codes it in.
  129. if (this.$el.hasClass('indentedlist-view-initial-max-size')) {
  130. if (this.$el.width() > this.DEFAULT_MAX_WIDTH) {
  131. //Clamp max default width
  132. this.$el.width(this.DEFAULT_MAX_WIDTH);
  133. } else {
  134. //Set width (to compensate for browser artificially shortening width).
  135. this.$el.width(this.$el.width());
  136. }
  137. //Turn line wrapping back on now that the width is set.
  138. this.$el.removeClass('indentedlist-view-initial-max-size');
  139. if (this.$el.height() > this.DEFAULT_MAX_HEIGHT) {
  140. //Clamp max height
  141. this.$el.height(this.DEFAULT_MAX_HEIGHT);
  142. //Set width (to compensate for vertical scroll bar).
  143. var newWidth = this.$el.width() + this._getScrollbarWidth();
  144. this.$el.width(newWidth);
  145. }
  146. }
  147. },
  148. /*
  149. * Clear the clamping performed in _clampDefaultDimensions.
  150. */
  151. _clearDefaultDimensionClamp: function _clearDefaultDimensionClamp() {
  152. this.$el.width('');
  153. this.$el.height('');
  154. },
  155. _getScrollbarWidth: function _getScrollbarWidth() {
  156. var $content = this.$el.find('.datawidget');
  157. var scrollbarWidth = $content.width() - $content[0].scrollWidth;
  158. return scrollbarWidth;
  159. },
  160. /**
  161. * @param {Object} renderInfo - renderInfo passed to all render methods from the render sequence.
  162. * @returns a Promise which is resolved when rendering is complete.
  163. */
  164. render: function render(renderInfo) {
  165. var _this2 = this;
  166. this._cache = [];
  167. this._groupArrays = [];
  168. this._groupCounter = 0;
  169. this._focusedNode = null;
  170. if (!this.isMappingComplete() || this.hasMissingFilters() || this.hasUnavailableMetadataColumns()) {
  171. this.$el.find('.indentedlist-content').empty();
  172. this.resizeToWidget(renderInfo);
  173. this.initialRender = true; // Reset flag to calculate width
  174. this.renderIconView();
  175. return Promise.resolve(this);
  176. }
  177. this.dataItems = renderInfo.useAPI ? renderInfo.data.getResult() : renderInfo.data.getDefaultQueryResult().getQueryResult();
  178. this.onResultsReady(this.dataItems);
  179. this.removeIconView();
  180. this.resizeToWidget(renderInfo);
  181. this.renderSelected();
  182. if (this.initialRender) {
  183. this.initialRender = false;
  184. this.visModel.ownerWidget.whenContainerIsReady.promise.then(function () {
  185. _this2._clampDefaultDimensions();
  186. _this2._clearDefaultDimensionClamp();
  187. });
  188. }
  189. return IndentedListView.inherited('render', this, arguments);
  190. },
  191. remove: function remove() {
  192. this.scrollBarUtil = null;
  193. if (this.eventHandler) {
  194. this.eventHandler.remove();
  195. this.eventHandler = null;
  196. }
  197. if (this._cache) {
  198. this._cache = null;
  199. }
  200. IndentedListView.inherited('remove', this, arguments);
  201. },
  202. getDescription: function getDescription() {
  203. // Append the F12 key instruction to the description
  204. var description = IndentedListView.inherited('getDescription', this, arguments);
  205. return stringResources.get('WidgetLabelWithDescripion', {
  206. label: description,
  207. description: stringResources.get('f12KeyDescription')
  208. });
  209. },
  210. renderIconView: function renderIconView() {
  211. // Remove the size restriction for an indented list's icon view
  212. this.$el.removeClass('indentedlist-view-initial-max-size');
  213. IndentedListView.inherited('renderIconView', this, arguments);
  214. },
  215. /**
  216. * Divide the original array of view HTML markups Strings into multiple arrays
  217. * each array has an maximum length of GROUP_MAX_LENGTH defined in the class
  218. **/
  219. _groupItems: function _groupItems(origArray) {
  220. var lists = _.groupBy(origArray, function (element, index) {
  221. return Math.floor(index / this.GROUP_MAX_LENGTH);
  222. }.bind(this));
  223. return _.toArray(lists); //Added this to convert the returned object to an array.
  224. },
  225. _isEqualLevel: function _isEqualLevel(curTuple, prevTuple) {
  226. var notSame = _.find(curTuple, function (obj, k) {
  227. return prevTuple[k] ? prevTuple[k].value !== obj.value : true;
  228. });
  229. return notSame ? false : true;
  230. },
  231. onResultsReady: function onResultsReady(results) {
  232. var _this3 = this;
  233. var code = [];
  234. var prevRow = null;
  235. var indentationLevel = 0;
  236. var slots = this.content.getFeature('Visualization').getSlots();
  237. var level1Slot = slots.getSlot('level1');
  238. var resultRowSize = results.getRowCount();
  239. var dataItemFormatMap = {};
  240. _.each(level1Slot.getDataItemList(), function (dataItem) {
  241. dataItemFormatMap[dataItem.getId()] = dataItem.getFormat();
  242. });
  243. var _loop = function _loop(rowIndex) {
  244. var row = [];
  245. _.each(level1Slot.getDataItemList(), function (dataItemAPI, colIndex) {
  246. var v = [],
  247. t = {};
  248. /*By current design, indented list currently does not support stacked data items per data slot
  249. *Therefore there will be only one tuple part for one dataItem
  250. */
  251. var dataItem = results.getValue(rowIndex, colIndex)[0];
  252. var dataItemLabel = dataItem.label;
  253. if (dataItemAPI) {
  254. v.push(Formatter.format(dataItemLabel, dataItemFormatMap[dataItemAPI.getId()]));
  255. t[dataItemAPI.getColumnId()] = dataItem;
  256. }
  257. row.push({
  258. tuple: t,
  259. value: v.join(FormatResources.getListSeparatorSymbol() + ' '),
  260. rowId: rowIndex,
  261. colId: colIndex
  262. });
  263. });
  264. var tuple = {};
  265. var startLevel = 0;
  266. if (prevRow) {
  267. while (startLevel < row.length && _this3._isEqualLevel(row[startLevel].tuple, prevRow[startLevel].tuple)) {
  268. _.extend(tuple, row[startLevel].tuple);
  269. startLevel++;
  270. }
  271. }
  272. if (startLevel < row.length) {
  273. if (prevRow && startLevel !== prevRow.length - 1) {
  274. levels = prevRow.length - startLevel - 1;
  275. for (i = 0; i < levels; i++) {
  276. indentationLevel--;
  277. code.push('</div>');
  278. }
  279. }
  280. for (colIdx = startLevel; colIdx < row.length; colIdx++) {
  281. if (colIdx > 0 && colIdx !== startLevel) {
  282. indentationLevel++;
  283. code.push('<div class="indentGroup" role="group" depth=' + indentationLevel + '>');
  284. }
  285. _.extend(tuple, row[colIdx].tuple);
  286. //Store Element Metadata only
  287. code.push({
  288. // ensure the clone, so that the child tuple doesn't overwrite the parent tuple
  289. 'tuple': _.clone(tuple),
  290. 'colIdx': colIdx,
  291. 'rowValue': row[colIdx].value,
  292. 'iLevel': indentationLevel,
  293. 'rowId': row[colIdx].rowId,
  294. 'colId': row[colIdx].colId
  295. });
  296. }
  297. }
  298. prevRow = row;
  299. };
  300. for (var rowIndex = 0; rowIndex < resultRowSize; rowIndex++) {
  301. var levels;
  302. var i;
  303. var colIdx;
  304. _loop(rowIndex);
  305. }
  306. for (var k = 0; k < indentationLevel; k++) {
  307. code.push('</div>');
  308. }
  309. if (this.el) {
  310. var $listContent = this.$el.find('.indentedlist-content');
  311. var $scrollInner = $listContent.first();
  312. $scrollInner.off('scroll', this._scrollHandlerFn);
  313. if (code.length <= this.DELAYLOADING_THROTTLE) {
  314. this._convertListObjectsToHTML(code);
  315. $listContent.html(code.join(''));
  316. } else {
  317. $scrollInner.on('scroll', this._scrollHandlerFn);
  318. this._cache = code;
  319. this._addMore(true);
  320. }
  321. }
  322. },
  323. /**
  324. * Append more HTML markups to the existing view
  325. * @param {boolean} isNewRender, true, add first group only
  326. **/
  327. _addMore: function _addMore(isNewRender) {
  328. var currentArray = [];
  329. this._groupArrays = this._groupItems(this._cache);
  330. //Add only first group for a rerender
  331. if (isNewRender) {
  332. currentArray = this._groupArrays[0];
  333. } else {
  334. //Add one more group
  335. if (this._groupArrays.length > this._groupCounter) {
  336. var nEndPos = this._groupCounter * this.GROUP_MAX_LENGTH + this._groupArrays[this._groupCounter].length;
  337. currentArray = this._cache.slice(0, nEndPos);
  338. } else {
  339. return;
  340. }
  341. }
  342. this._convertListObjectsToHTML(currentArray);
  343. var nLen = currentArray.length;
  344. var sLastEle = currentArray[nLen - 1];
  345. if (sLastEle !== '</div>') {
  346. var $LastEle = $(sLastEle);
  347. var sDepth = $LastEle.attr('depth');
  348. if (sDepth === '2') {
  349. currentArray.push('</div></div>');
  350. } else if (sDepth === '1') {
  351. currentArray.push('</div>');
  352. }
  353. } else {
  354. var s2ndLastEle = currentArray[nLen - 2];
  355. if (s2ndLastEle !== '</div>') {
  356. var $2ndLastEle = $(s2ndLastEle);
  357. if ($2ndLastEle.attr('depth') === '2') {
  358. currentArray.push('</div>');
  359. }
  360. }
  361. }
  362. this.$el.find('.indentedlist-content').empty();
  363. this.$el.find('.indentedlist-content').html(currentArray.join(''));
  364. this._groupCounter++;
  365. this.renderSelected();
  366. },
  367. /*@param {Array} objects*/
  368. _convertListObjectsToHTML: function _convertListObjectsToHTML(objects) {
  369. var oCurElement;
  370. var styleString = this._constructStyleString(this.visModel);
  371. for (var i = 0; i < objects.length; i++) {
  372. oCurElement = objects[i];
  373. if (oCurElement && oCurElement.rowValue) {
  374. oCurElement.style = styleString;
  375. objects[i] = this.renderItem(oCurElement);
  376. }
  377. }
  378. },
  379. _constructStyleString: function _constructStyleString(visModel) {
  380. var styleString = 'style="';
  381. var propertyToStyle = this.PROPERTY_TO_STYLE;
  382. _.each(this.PROPERTY_MAP, function (styleName, propertyName) {
  383. var propertyValue = visModel.getPropertyValue(propertyName);
  384. if (propertyValue) {
  385. if (propertyToStyle[styleName]) {
  386. propertyValue = propertyToStyle[styleName];
  387. }
  388. styleString = styleString + styleName + ':' + propertyValue + ';';
  389. }
  390. });
  391. styleString += '"';
  392. return styleString;
  393. },
  394. _getTextAlignmentStyle: function _getTextAlignmentStyle() {
  395. var textAlignment = this.visModel.getPropertyValue('listValueFontAlign');
  396. var textAlignmentStr = '';
  397. if (textAlignment) {
  398. textAlignmentStr = 'style="text-align:' + textAlignment + ';"';
  399. }
  400. return textAlignmentStr;
  401. },
  402. renderItem: function renderItem(item) {
  403. var tuple, level, label, indentationLevel, colId, rowId, styleString;
  404. if (item) {
  405. tuple = item.tuple;
  406. level = item.colIdx;
  407. label = item.rowValue;
  408. indentationLevel = item.iLevel;
  409. colId = item.colId;
  410. rowId = item.rowId;
  411. styleString = item.style;
  412. }
  413. if (!label) {
  414. return;
  415. }
  416. var arrowClass = level > 0 ? 'arrow wfg_shape_arrow_right' : 'no-arrow';
  417. var textAlignment = this._getTextAlignmentStyle();
  418. return ['<div class="item" ' + textAlignment + ' role="treeitem" tabindex="-1" aria-label="', _.escape(label), '" data-tuple="', encodeURIComponent(JSON.stringify(tuple)), '" depth="', indentationLevel, '" ', this.ATTRIBUTES.ROW_CLASS, '="', rowId, '" ', this.ATTRIBUTES.COLUMN_CLASS, '="', colId, '" >', '<span class="' + arrowClass + '"></span>',
  419. // (edge case) Truncate labels to 500 characters. Limit of 500 already used in modelling/DataPreviewView.js
  420. // Browsers can have issues displaying really huge strings (100,000+ characters). See bug 8461.
  421. '<span ' + styleString + ' >', _.escape(label.substr(0, 500)), '</span>', '</div>'].join('');
  422. },
  423. /**
  424. * Process the rendered items in the list and highlight any selected ones.
  425. * Each entry in the list has a data-tuple attribute.
  426. */
  427. renderSelected: function renderSelected() /*renderInfo*/{
  428. var selections = this.getController();
  429. if (selections) {
  430. var items = $(this.el).find('.item');
  431. _.each(items, function (item) {
  432. var tuple = null;
  433. $(item).removeClass('selected');
  434. try {
  435. var decodedTuple = decodeURIComponent(item.getAttribute('data-tuple'));
  436. tuple = JSON.parse(decodedTuple);
  437. } catch (err) {
  438. if (this.logger) {
  439. this.logger.warn('Unable to parse the string into a JSON object in the indented list.', decodedTuple);
  440. }
  441. }
  442. if (this.isSubsetOfTupleSelected(tuple, selections)) {
  443. $(item).addClass('selected');
  444. }
  445. }.bind(this));
  446. }
  447. },
  448. renderFocused: function renderFocused(bShow) {
  449. //Clear first
  450. $(this.el).find('.item.focused').removeClass('focused');
  451. if (bShow && ($(this._focusedNode).hasClass('selected') || $(this._focusedNode).is(':focus'))) {
  452. $(this._focusedNode).addClass('focused');
  453. } else {
  454. $(this._focusedNode).blur();
  455. this._focusedNode = null;
  456. }
  457. },
  458. /**
  459. * @returns true if a subset of this tuple is selected.
  460. * A tuple is a list of columnId/value pairs stored as the "data-tuple" attribute
  461. * for row rendered in the list {"5":"Canada", "2":"Backpacks"}
  462. *
  463. * A subset is selected if:
  464. * 1) the last entry in the tuple (in field order) is selected
  465. * 2) preceding entries either have selections that match the tuple column/value
  466. * OR have NO selections for their columns
  467. */
  468. isSubsetOfTupleSelected: function isSubsetOfTupleSelected(tuple, selections) {
  469. if (!tuple || !selections) {
  470. return false;
  471. }
  472. var lastInTupleSelected = false;
  473. var tupleKeys = _.keys(tuple);
  474. for (var i = 0; i < tupleKeys.length; ++i) {
  475. var columnId = tupleKeys[i];
  476. if (tuple[columnId] !== undefined) {
  477. if (selections.isItemSelected(columnId) && !selections.isValueSelected(columnId, EventUtils.toDeprecatedPayload(tuple[columnId]))) {
  478. return false;
  479. }
  480. lastInTupleSelected = selections.isValueSelected(columnId, EventUtils.toDeprecatedPayload(tuple[columnId]));
  481. }
  482. }
  483. return lastInTupleSelected;
  484. },
  485. /**
  486. * Initiate a select from this widget....called from the click/touch handler.
  487. * @param wasSelected The current node was previously selected
  488. * @param tuple The set of column/value pairs representing this row
  489. * eg: data-tuple="{ '5': {u: 'Canada'}, '3': {u: '2001'} }"
  490. * @param clearFirst Prior to selecting the new value, clear old values.
  491. * NOTE: the wasSelected switch takes precedence over this switch.
  492. * If the user clicks a selected item it should simply remove that item from the selection
  493. * not clear everything.
  494. */
  495. doSelect: function doSelect(wasSelected, tuple, clearFirst) {
  496. this.getController().select({
  497. itemIds: _.keys(tuple),
  498. tuple: _.values(tuple),
  499. command: wasSelected ? 'remove' : 'update',
  500. slotsToClear: clearFirst && !wasSelected ? this.visualization.getSlots().getMappedSlotList() : [],
  501. edgeSelect: true //IndentedList selects tuples as edgeSelections not dataPoints.
  502. });
  503. },
  504. /**
  505. * Handle Click and Touch events
  506. */
  507. onDataItemClick: function onDataItemClick(ev) {
  508. // Ignore the click if it was handled by a hold event
  509. if (this._isHandledByHold) {
  510. this._isHandledByHold = false;
  511. return;
  512. }
  513. // do selection - only clear the selection list if not multi-select (ctrl key on windows/linux, command key on Mac)
  514. this._touchOrClickSelection(ev, !(ev.ctrlKey || ev.metaKey));
  515. },
  516. onDataItemHold: function onDataItemHold(ev) {
  517. // do multi-select
  518. this._touchOrClickSelection(ev, false);
  519. this._isHandledByHold = true;
  520. },
  521. onDataItemMousedown: function onDataItemMousedown(ev) {
  522. if (ev.ctrlKey || ev.metaKey) {
  523. var eventChainLocal = new EventChainLocal(ev);
  524. eventChainLocal.setProperty('preventWidgetDeselect', true);
  525. }
  526. },
  527. /**
  528. * Function to get the dom element from the event and perform the selection.
  529. * @param ev Event object
  530. * @param bClearList Boolean flag to clear the previous selection or not
  531. * @return null
  532. * @private
  533. */
  534. _touchOrClickSelection: function _touchOrClickSelection(ev, bClearList) {
  535. var el = domUtils.getAncestorOfClass(ev.target, 'item');
  536. if (el) {
  537. this._focusedNode = el;
  538. var tuple = JSON.parse(_.unescape(el.getAttribute('data-tuple')));
  539. this.doSelect($(el).hasClass('selected'), tuple, bClearList);
  540. }
  541. },
  542. /**
  543. * Handle the on container entered event
  544. * Sets up keyboard navigation inside the list
  545. */
  546. onEnterContainer: function onEnterContainer() {
  547. // get list items and through and set tabindex
  548. var oItems = $(this.el).find('.item');
  549. // place focus on the first item
  550. if (oItems.length > 0) {
  551. if (this._focusedNode) {
  552. this._focusedNode.focus();
  553. } else {
  554. oItems[0].focus();
  555. }
  556. }
  557. },
  558. /**
  559. * Handle keyboard events
  560. * @param event - keyboard event object
  561. */
  562. onDataItemKeydown: function onDataItemKeydown(event) {
  563. // process various keyboard events
  564. switch (event.keyCode) {
  565. case 37:
  566. case 38:
  567. this._moveFocusUp();
  568. break;
  569. case 39:
  570. case 40:
  571. this._moveFocusDown();
  572. break;
  573. case 32:
  574. case 13:
  575. // pass to the click handler for item selection
  576. this.onDataItemClick(event);
  577. // prevent widget move/resize/etc when clicked on item.
  578. event.stopPropagation();
  579. break;
  580. default:
  581. return;
  582. }
  583. event.preventDefault();
  584. },
  585. /**
  586. * Returns the index of list item that has focus
  587. * @return integer
  588. * @private
  589. */
  590. _getFocusedItemIndex: function _getFocusedItemIndex() {
  591. var oItems = $(this.el).find('.item');
  592. var iFocusIndex = 0;
  593. for (var i = 0; i < oItems.length; i++) {
  594. if ($(oItems[i]).is(':focus')) {
  595. iFocusIndex = i;
  596. break;
  597. }
  598. }
  599. return iFocusIndex;
  600. },
  601. /**
  602. * Sets the focus on the list item that is rendered above the currently focussed item (stops at top)
  603. * @private
  604. */
  605. _moveFocusUp: function _moveFocusUp() {
  606. // get current index
  607. var iFocusIndex = this._getFocusedItemIndex();
  608. // set focus on item
  609. this._setItemFocus(Math.max(iFocusIndex - 1, 0));
  610. },
  611. /**
  612. * Sets the focus on the list item that is rendered below the currently focussed item (stops at bottom)
  613. * @private
  614. */
  615. _moveFocusDown: function _moveFocusDown() {
  616. // get current index
  617. var iFocusIndex = this._getFocusedItemIndex();
  618. // set focus on item
  619. this._setItemFocus(Math.min(iFocusIndex + 1, $(this.el).find('.item').length - 1));
  620. },
  621. /**
  622. * Sets the focus on the list item at the given index
  623. * @param iIndex: List item index to set focus
  624. * @private
  625. */
  626. _setItemFocus: function _setItemFocus(iIndex) {
  627. $(this.el).find('.item')[iIndex].focus();
  628. },
  629. /**
  630. * Indented List view overwrites the default animation in order to avoid it fading in/out when
  631. * applying filters.
  632. */
  633. //@Override
  634. animate: function animate() {
  635. this.visModel.renderCompleteBeforeAnimation(); // Rendering is complete, no animation yet
  636. },
  637. _isOnScrollBar: function _isOnScrollBar(event) {
  638. return this.scrollBarUtil.isOnScrollBar(event);
  639. }
  640. });
  641. return IndentedListView;
  642. });
  643. //# sourceMappingURL=IndentedListView.js.map