Tab.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. 'use strict';
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['./PageCollectionView', 'jquery', '../../../../lib/@waca/core-client/js/core-client/utils/BidiUtil', '../../../../app/nls/StringResources', '../../../../lib/@waca/core-client/js/core-client/utils/dom-utils', '../../../../lib/@waca/core-client/js/core-client/utils/Deferred', '../../../../app/ui/dnd/DnDHelper', '../../../../app/ui/dialogs/GenericViewDialog', '../../../views/LayoutPickerView', '../../../../lib/@waca/core-client/js/core-client/utils/EventHelper'], function (BaseClass, $, BidiUtil, stringResources, utils, Deferred, DnDHelper, Dialog, TemplatePickerView) {
  9. var Tab = null;
  10. Tab = BaseClass.extend({
  11. init: function init(options) {
  12. var _this = this;
  13. Tab.inherited('init', this, arguments);
  14. options = options || {};
  15. this._getLabelId = this.consumeView._getLabelId.bind(this.consumeView);
  16. this.specializeConsumeView(['showView', 'renderContent', '_attachView', 'onAddClick', 'onReorder', '_handleKeydown', 'showToolbar', 'deleteView', 'updateViewLabel', 'editViewTitle']);
  17. this.services = options.services;
  18. this.config = options.config;
  19. this.layoutsPath = options.layoutsPath;
  20. this.templateListing = options.templateListing;
  21. this.whenIsReadyDfd = new Deferred();
  22. this.backgroundChangeHandle = this.model.on('change:css', function () {
  23. return _this.consumeView.tabWidget.updateTheme();
  24. });
  25. this.dashboardApi = options.dashboardApi;
  26. this._attachedHandles = {};
  27. this._icons = this.dashboardApi.getFeature('Icons');
  28. },
  29. renderContent: function renderContent() {
  30. var _this2 = this;
  31. return this.overridden.renderContent().then(function () {
  32. _this2.consumeView.tabWidget.setState({ addable: true, deleteable: _this2.allowTabDeletion(), draggable: true });
  33. if (_this2.model.items && _this2.model.items.length) {
  34. _this2.model.items.forEach(function (item) {
  35. return _this2._attachView(item);
  36. });
  37. }
  38. _this2._initializeDnd();
  39. });
  40. },
  41. whenIsReady: function whenIsReady() {
  42. return this.whenIsReadyDfd.promise;
  43. },
  44. destroy: function destroy() {
  45. // Remove the registered dropZonez
  46. if (this._tabStripDropZone) {
  47. this._tabStripDropZone.remove();
  48. }
  49. if (this._tabDropHandler) {
  50. this._tabDropHandler.deregister();
  51. this._tabDropHandler = null;
  52. }
  53. if (this.backgroundChangeHandle) {
  54. this.backgroundChangeHandle.remove();
  55. }
  56. if (this.toolbar && this.toolbar.remove) {
  57. this.toolbar.remove();
  58. }
  59. this.toolbar = null;
  60. this.model.items.forEach(this._detachView.bind(this));
  61. this.consumeView.updateState({ addable: false, deleteable: false, draggable: false });
  62. Tab.inherited('destroy', this, arguments);
  63. },
  64. _initializeDnd: function _initializeDnd() {
  65. this._dndManager = this.dashboardApi.getFeature('DashboardDnd.internal');
  66. this.setupGlobalDropZone();
  67. this.whenIsReadyDfd.resolve();
  68. },
  69. _attachView: function _attachView(pageModel) {
  70. var _this3 = this;
  71. this.services.getSvcSync('TranslationService').registerView({ view: this, model: pageModel });
  72. this._attachedHandles[pageModel.id] = pageModel.on('change:title', this.onTabLabelChange.bind(this, pageModel), this);
  73. this._attachedHandles[pageModel.id] = pageModel.on('change:tabTextColor', function (options) {
  74. return _this3.consumeView.tabWidget.updateTheme(options);
  75. });
  76. this._attachedHandles[pageModel.id] = pageModel.on('change:tabSelectedLineColor', function (options) {
  77. return _this3.consumeView.tabWidget.updateTheme(options);
  78. });
  79. this._attachedHandles[pageModel.id] = pageModel.on('change:tabBackgroundColor', function (options) {
  80. return _this3.consumeView.tabWidget.updateTheme(options);
  81. });
  82. this._attachedHandles[pageModel.id] = pageModel.on('change:tabIconColor', function (options) {
  83. return _this3.consumeView.tabWidget.updateTheme(options);
  84. });
  85. this._attachedHandles[pageModel.id] = pageModel.on('change:tabIcon', function (options) {
  86. return _this3.onTabIconChange(pageModel, options);
  87. });
  88. },
  89. _detachView: function _detachView(pageModel) {
  90. if (this._attachedHandles[pageModel.id]) {
  91. this._attachedHandles[pageModel.id].remove();
  92. delete this._attachedHandles[pageModel.id];
  93. }
  94. },
  95. addTranslationIcon: function addTranslationIcon(multilingualAttributesInfo) {
  96. var pageModel = multilingualAttributesInfo && multilingualAttributesInfo[0].propertyParentModel;
  97. if (this.model.get('hideTab')) {
  98. return 0;
  99. } else {
  100. return this.consumeView.tabWidget.updateTranslationIcon(pageModel, true);
  101. }
  102. },
  103. removeTranslationIcon: function removeTranslationIcon(multilingualAttributesInfo) {
  104. var pageModel = multilingualAttributesInfo && multilingualAttributesInfo[0].propertyParentModel;
  105. return this.consumeView.tabWidget.updateTranslationIcon(pageModel, false);
  106. },
  107. _handleKeydown: function _handleKeydown(pageModel, evt, node) {
  108. var keyCode = evt.keyCode;
  109. if (this._shouldShowToolbar(evt, keyCode)) {
  110. this.showToolbar(pageModel, node);
  111. evt.preventDefault();
  112. return false; //Signal to the browser that it should prevent the default behavior of opening the context menu
  113. } else {
  114. this.overridden._handleKeydown(pageModel, evt, node);
  115. }
  116. },
  117. // Shift + F10 key - show contextual toolbar
  118. _shouldShowToolbar: function _shouldShowToolbar(evt, keyCode) {
  119. return evt.shiftKey && keyCode === 121;
  120. },
  121. /**
  122. * Move the view to the location before the provided id.
  123. * @param pageModel
  124. * @param beforeId
  125. */
  126. moveViewBefore: function moveViewBefore(pageModel, beforeId) {
  127. // Avoid a model update when it is not needed
  128. if (pageModel.id !== beforeId && pageModel.getNextSiblingId() !== beforeId) {
  129. pageModel.updateModel({ updateArray: [{
  130. id: pageModel.id,
  131. parentId: pageModel.getParent().id,
  132. insertBefore: beforeId
  133. }] });
  134. }
  135. },
  136. showView: function showView(viewModel) {
  137. if (this.isToolbarShown) {
  138. this.hideToolbar();
  139. }
  140. //call consume view's showView
  141. this.overridden.showView(viewModel);
  142. },
  143. showToolbar: function showToolbar(viewModel, node) {
  144. if (!this.isToolbarShown) {
  145. this.isToolbarShown = true;
  146. this.toolbar.clearItems();
  147. var items = this._toolbarItems(viewModel);
  148. this.toolbar.addItems(items);
  149. this.toolbar.setSelectionContext($(node));
  150. this.toolbar.show();
  151. } else {
  152. this.hideToolbar();
  153. }
  154. },
  155. hideToolbar: function hideToolbar() {
  156. this.isToolbarShown = false;
  157. return this.toolbar.hide();
  158. },
  159. _toolbarItems: function _toolbarItems(viewModel) {
  160. var items = [];
  161. /*
  162. * By UX design order of icons matters:
  163. * 1. edit
  164. * 2. duplicate
  165. * 3. delete (if more then one tab exists)
  166. * 4. change template
  167. */
  168. items.push({
  169. icon: this._icons.getIcon('edit').id,
  170. label: stringResources.get('toolbarActionEditTitle'),
  171. name: 'rename',
  172. type: 'Button',
  173. action: this.editViewTitle.bind(this, viewModel)
  174. });
  175. items.push({
  176. icon: this._icons.getIcon('dashboard-duplicate').id,
  177. label: stringResources.get('duplicate'),
  178. name: 'duplicate',
  179. type: 'Button',
  180. action: this.duplicateTab.bind(this, viewModel.id)
  181. });
  182. if (this.config.changeTabTemplate !== 'disabled') {
  183. items.push({
  184. icon: this._icons.getIcon('template').id,
  185. label: stringResources.get('changeTemplate'),
  186. name: 'changeTemplate',
  187. type: 'Button',
  188. disabled: viewModel.templateName === 'NoTemplate',
  189. action: this.selectTemplate.bind(this, viewModel.id)
  190. });
  191. }
  192. return items;
  193. },
  194. /**
  195. * Called when a new tab is added.
  196. *
  197. * @param n - tab content node
  198. * @param insertBefore - content node to insert before, null if we're creating a new tab, and a string when we're dragging tabs around
  199. * @param model - model of the page being added
  200. */
  201. add: function add(layoutView, insertBefore) {
  202. var _this4 = this;
  203. var model = layoutView.model;
  204. var tabs = this.consumeView.tabWidget.state.tabs;
  205. var layoutIndex = void 0,
  206. isNew = true;
  207. for (var i = 0; i < tabs.length; i++) {
  208. if (this.consumeView._getModelIdFromPanel(tabs[i].props.id) === model.id) {
  209. isNew = false;
  210. layoutIndex = i;
  211. break;
  212. }
  213. }
  214. if (!isNew) {
  215. // This is a re-order. See if we need to update the state.
  216. if (!(insertBefore === null && layoutIndex === tabs.length - 1 || tabs[layoutIndex + 1] && this.consumeView._getModelIdFromPanel(tabs[layoutIndex + 1].props.id) === insertBefore)) {
  217. var updatedTabs = [];
  218. tabs.forEach(function (tab) {
  219. if (_this4.consumeView._getModelIdFromPanel(tab.props.id) === insertBefore) {
  220. updatedTabs.push(tabs[layoutIndex]);
  221. updatedTabs.push(tab);
  222. } else if (_this4.consumeView._getModelIdFromPanel(tab.props.id) !== model.id) {
  223. updatedTabs.push(tab);
  224. }
  225. });
  226. if (insertBefore === null) {
  227. updatedTabs.push(tabs[layoutIndex]);
  228. }
  229. this.consumeView.tabWidget.setState({ tabs: updatedTabs });
  230. }
  231. var $tabContent = this.$el.find('#' + this._getViewId(model));
  232. $tabContent.append(layoutView.domNode);
  233. } else {
  234. var _$tabContent = $(this.htmlTemplate.replaceLayoutValues(this.htmlTemplate.getItemTemplate('tab', '', model), this.model));
  235. _$tabContent.append(layoutView.domNode);
  236. this.$el.find('.tabPageHolder').append(_$tabContent);
  237. var _updatedTabs = [];
  238. var newTab = this.consumeView._createTabPanel(model, _$tabContent, this.consumeView._getColorProperties());
  239. if (insertBefore) {
  240. tabs.forEach(function (tab) {
  241. if (_this4.consumeView._getModelIdFromPanel(tab.props.id) === insertBefore) {
  242. _updatedTabs.push(newTab);
  243. }
  244. _updatedTabs.push(tab);
  245. });
  246. } else {
  247. _updatedTabs = tabs.slice();
  248. _updatedTabs.push(newTab);
  249. }
  250. this.consumeView.tabWidget.setState({ tabs: _updatedTabs });
  251. this.consumeView.canvas.selectContent([model.id]);
  252. // Attach the tab behavior (e.g. events)
  253. this.overridden._attachView(model);
  254. this._attachView(model);
  255. }
  256. if (this.consumeView.tabWidget.state.deleteable === false && this.allowTabDeletion()) {
  257. this.consumeView.tabWidget.setState({ deleteable: true });
  258. }
  259. },
  260. allowTabDeletion: function allowTabDeletion() {
  261. return this.model.items.length > 1;
  262. },
  263. _getDefaultViewLabel: function _getDefaultViewLabel() {
  264. var tabLength = this.model.items.length;
  265. for (var i = 1; i < tabLength + 1; i++) {
  266. var isAvailable = true;
  267. for (var j = 0; j < tabLength; j++) {
  268. if (this.model.items[j].get('title') === stringResources.get('defaultTabTitle', { index: i })) {
  269. isAvailable = false;
  270. break;
  271. }
  272. }
  273. if (isAvailable) {
  274. return stringResources.get('defaultTabTitle', { index: i });
  275. }
  276. }
  277. return stringResources.get('defaultTabTitle', { index: tabLength + 1 });
  278. },
  279. onAddClick: function onAddClick() {
  280. return this._invokeLifeCycleHandlers('tabs.onPressNew', {
  281. $el: this.$el
  282. }).then(function () {
  283. //default behavior goes in here.
  284. this._openTemplateSelectDialog(); //TODO this needs to be triggered via a lifecycle handler!
  285. }.bind(this));
  286. },
  287. onReorder: function onReorder(tabsList, newIndex, tabId) {
  288. var beforeId = null;
  289. if (newIndex + 1 < tabsList.length) {
  290. beforeId = this.consumeView._getModelIdFromPanel(tabsList[newIndex + 1].props.id);
  291. }
  292. var movedId = this.consumeView._getModelIdFromPanel(tabId);
  293. this.moveViewBefore(this.model.findModel(movedId), beforeId);
  294. this.consumeView.eventRouter.trigger('properties:refreshPane');
  295. },
  296. onTabLabelChange: function onTabLabelChange(pageModel) {
  297. this.consumeView.tabWidget.updateTabLabel(pageModel);
  298. var pageIndex = this.model.items.findIndex(function (item) {
  299. return item.id === pageModel.id;
  300. });
  301. var propertyName = 'tabIndividualStylingLink' + pageIndex;
  302. var updatePayload = {
  303. propertyName: propertyName,
  304. subPropertyName: 'r_' + propertyName + '0',
  305. value: pageModel.get('title')
  306. };
  307. this.consumeView.eventRouter.trigger('properties:setValue', updatePayload);
  308. this.consumeView.eventRouter.trigger('properties:setChildValue', {
  309. propertyName: 'title',
  310. value: pageModel.get('title'),
  311. contentId: pageModel.id
  312. });
  313. },
  314. onTabIconChange: function onTabIconChange(pageModel, options) {
  315. this.consumeView.tabWidget.updateTabIcon(pageModel);
  316. if (options && options.sender === 'UndoRedoController') {
  317. var content = this.consumeView.canvas.getContent(pageModel.id);
  318. this.consumeView.eventRouter.trigger('properties:refreshChild', { content: content });
  319. this.consumeView.eventRouter.trigger('properties:refreshPane');
  320. }
  321. },
  322. setupGlobalDropZone: function setupGlobalDropZone() {
  323. var _this5 = this;
  324. if (this._tabStripDropZone) {
  325. this._tabStripDropZone.remove();
  326. }
  327. this._tabStripDropZone = this._dndManager.addDropTarget($(this.consumeView.tabWidget.tabListNode), '[role=tab]', {
  328. accepts: function accepts(dragObject) {
  329. if (dragObject.type === 'widget') {
  330. return true;
  331. }
  332. return false;
  333. },
  334. onDragEnter: function onDragEnter(dragObject, node) {
  335. var tabPanel = _this5.consumeView._getPanelFromNode(node);
  336. var hoverColor = tabPanel.props.hoverColor;
  337. $(node).css('background-color', hoverColor);
  338. },
  339. onDragLeave: function onDragLeave(dragObject, node) {
  340. var tabPanel = _this5.consumeView._getPanelFromNode(node);
  341. var backgroundColor = tabPanel.props.backgroundColor;
  342. $(node).css('background-color', backgroundColor);
  343. },
  344. onDrop: function onDrop(dragObject, node) {
  345. var tabPanel = _this5.consumeView._getPanelFromNode(node);
  346. if (dragObject.type === 'widget' && tabPanel) {
  347. var id = _this5.consumeView._getModelIdFromPanel(tabPanel.props.id);
  348. DnDHelper.handleWidgetDrop(_this5.consumeView.canvas, id, dragObject);
  349. }
  350. },
  351. info: function info(node) {
  352. var tabPanel = _this5.consumeView._getPanelFromNode(node);
  353. if (tabPanel) {
  354. return {
  355. containerId: _this5.consumeView._getModelIdFromPanel(tabPanel.props.id)
  356. };
  357. }
  358. return {};
  359. },
  360. type: 'dropOnTab'
  361. });
  362. if (!this._tabDropHandler) {
  363. this._tabDropHandler = this._dndManager.registerDropHandler({
  364. accepts: function accepts(dragPayload, dropPayload) {
  365. return dragPayload.type.match(/content\..*/) && dropPayload.type === 'dropOnTab';
  366. },
  367. onDrop: function onDrop(dragPayload, dropPayload) {
  368. if (dropPayload.info.containerId) {
  369. var content = _extends({}, dragPayload.data, {
  370. containerId: dropPayload.info.containerId
  371. });
  372. _this5.consumeView.canvas.addContent(content);
  373. }
  374. }
  375. });
  376. }
  377. },
  378. updateViewLabel: function updateViewLabel(pageModel, sText) {
  379. var content = this.consumeView.canvas.getContent(pageModel.id);
  380. content.setPropertyValue('title', sText);
  381. },
  382. duplicateTab: function duplicateTab(sViewId) {
  383. this.model.boardModel.duplicateLayout(sViewId);
  384. },
  385. deleteView: function deleteView(sViewId) {
  386. this.consumeView.canvas.removeContent(sViewId);
  387. this.services.getSvcSync('TranslationService').deregisterView(sViewId);
  388. },
  389. selectTemplate: function selectTemplate(sViewId) {
  390. this._openTemplateSelectDialog(sViewId, true);
  391. },
  392. /**
  393. * Private method that creates the template selection dialog options
  394. * It gets the excluded tab templates list from the perspective collection and adds the default exclusion NoTemplate to the list
  395. * Returns template selection dialog options
  396. */
  397. _templateSelectDialogViewOptions: function _templateSelectDialogViewOptions() {
  398. var excludedTabTemplates = this.dashboardApi.getCanvas().getPropertyValue('excludedTemplates');
  399. excludedTabTemplates.push('NoTemplate');
  400. var dialogElement = document.createElement('div');
  401. dialogElement.classList.add('templatePickerDialog');
  402. return {
  403. el: dialogElement,
  404. templateListing: this.templateListing,
  405. layoutsPath: this.layoutsPath,
  406. disableHeaderSection: true,
  407. action: function action() {},
  408. // Freeform no longer is diplayed as an template option - replaced by the 'absolute' dashboard property
  409. excludeTemplates: excludedTabTemplates
  410. };
  411. },
  412. /**
  413. * @param viewId string a model id for the view (of the tab) to update
  414. * @param forEdit boolean true if opening the template select dialog for editing; undefined/false for new
  415. */
  416. _openTemplateSelectDialog: function _openTemplateSelectDialog(viewId, forEdit) {
  417. var _this6 = this;
  418. var templateSelectDialog = void 0;
  419. var templateView = void 0;
  420. var action = void 0;
  421. var viewOptions = this._templateSelectDialogViewOptions();
  422. if (!forEdit) {
  423. action = function action(_ref) {
  424. var layout = _ref.layout;
  425. _this6._addBoardLayout(layout);
  426. _this6._setDefaultLayoutPositioning();
  427. _this6.lastSelectedTemplate = layout.templateName;
  428. templateSelectDialog.hide();
  429. };
  430. } else if (forEdit === true) {
  431. /*
  432. * When we are editing we need to use a slightly different action
  433. */
  434. action = function action(_ref2) {
  435. var layout = _ref2.layout;
  436. _this6._updateTemplateDropZones(viewId, layout);
  437. _this6.lastSelectedTemplate = layout.templateName;
  438. templateSelectDialog.hide();
  439. };
  440. }
  441. viewOptions.action = function () {
  442. return templateView.getSelectedLayoutSpec().then(action);
  443. };
  444. templateSelectDialog = new Dialog({
  445. title: stringResources.get('selectTemplateLabel'),
  446. viewClass: TemplatePickerView,
  447. viewOptions: viewOptions,
  448. okCallback: viewOptions.action,
  449. buttons: [{
  450. text: stringResources.get('dlg_create'),
  451. handler: viewOptions.action,
  452. type: 'primary'
  453. }, 'cancel'],
  454. showCloseX: true,
  455. width: '850px'
  456. });
  457. templateView = templateSelectDialog.view;
  458. templateView.setNavigationTemplate('tab');
  459. var selectedTemplate = this.lastSelectedTemplate || this.model.items.length > 0 && this.model.items[0].templateName || 'NoTemplate';
  460. templateView.selectLayout(selectedTemplate);
  461. templateSelectDialog.open();
  462. },
  463. _setDefaultLayoutPositioning: function _setDefaultLayoutPositioning() {
  464. var defaultLayoutPositioning = this.model.getValueFromSelfOrParent('layoutPositioning') || 'relative';
  465. var layouts = this.model.findDescendantsWithType('genericPage');
  466. for (var _iterator = layouts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  467. var _ref3;
  468. if (_isArray) {
  469. if (_i >= _iterator.length) break;
  470. _ref3 = _iterator[_i++];
  471. } else {
  472. _i = _iterator.next();
  473. if (_i.done) break;
  474. _ref3 = _i.value;
  475. }
  476. var layout = _ref3;
  477. layout.layoutPositioning = defaultLayoutPositioning;
  478. }
  479. },
  480. editViewTitle: function editViewTitle(viewModel) {
  481. var _this7 = this;
  482. this.hideToolbar().then(function () {
  483. _this7.consumeView.tabWidget.editTabLabel(true, viewModel);
  484. });
  485. },
  486. _addBoardLayout: function _addBoardLayout(layout) {
  487. layout = layout || { type: 'absolute' };
  488. layout.title = this._getDefaultViewLabel();
  489. layout.localizedProps = ['title'];
  490. var content = {
  491. spec: layout,
  492. containerId: this.model.id
  493. };
  494. this.consumeView.canvas.addContent(content);
  495. },
  496. /**
  497. * Private method to handle updating the drop zones in dashboards
  498. * After the user selects a template we update the layout drop zones
  499. *
  500. * @param viewId string The model id of the dashboard tab the user is updating
  501. * @param layout object The user selected layout to update/change the template to
  502. */
  503. _updateTemplateDropZones: function _updateTemplateDropZones(viewId, layout) {
  504. this.model.boardModel.updateLayoutDropZones({
  505. id: viewId,
  506. model: layout
  507. });
  508. },
  509. /**
  510. * Called when a view is removed
  511. *
  512. * @param node
  513. */
  514. removeChild: function removeChild(layoutView) {
  515. var _this8 = this;
  516. if (!layoutView) {
  517. return;
  518. }
  519. // detach model event listener added by the current parent
  520. layoutView.model.off('change:title');
  521. var model = layoutView.model;
  522. var tabs = this.consumeView.tabWidget.state.tabs;
  523. var isPresent = false;
  524. var updatedTabs = [],
  525. index = void 0;
  526. tabs.forEach(function (tab, i) {
  527. if (_this8.consumeView._getModelIdFromPanel(tab.props.id) === model.id) {
  528. isPresent = true;
  529. index = i;
  530. } else {
  531. updatedTabs.push(tab);
  532. }
  533. });
  534. if (isPresent) {
  535. var stateUpdate = {
  536. tabs: updatedTabs
  537. };
  538. if (this.consumeView._getViewId(model) === this.consumeView._currentViewId) {
  539. //We are deleting the selected tab. We need to select a new one.
  540. var selectedIndex = Math.max(index - 1, 0);
  541. stateUpdate.selectedTab = this.consumeView._getPanelId(this.model.items[selectedIndex].id);
  542. }
  543. this.consumeView.tabWidget.setState(stateUpdate);
  544. }
  545. //Remove the dom node
  546. var parentSelector = '#' + layoutView.domNode.parentNode.id;
  547. $(parentSelector).remove();
  548. Tab.inherited('removeChild', this, arguments);
  549. if (this.consumeView.tabWidget.state.deleteable === true && !this.allowTabDeletion()) {
  550. this.consumeView.tabWidget.setState({ deleteable: false });
  551. }
  552. },
  553. _invokeLifeCycleHandlers: function _invokeLifeCycleHandlers(name, payload) {
  554. return this.services.getSvc('.LifeCycleManager').then(function (LifeCycleManager) {
  555. return LifeCycleManager.invokeLifeCycleHandlers(name, payload);
  556. });
  557. }
  558. });
  559. return Tab;
  560. });
  561. //# sourceMappingURL=Tab.js.map