From fd64d27fa0b3e0821b3f0f3eb8bc8dc74b88818c Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 17 Feb 2016 17:14:23 +0100 Subject: [PATCH] Bug #4332: Show datatable when clicking in a label from a detailed view --- .../app/tabs/provision-tab/templates/list.js | 7 +++- src/sunstone/public/app/utils/labels/utils.js | 41 ++++++++++++++----- .../public/app/utils/tab-datatable.js | 4 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/sunstone/public/app/tabs/provision-tab/templates/list.js b/src/sunstone/public/app/tabs/provision-tab/templates/list.js index 9d6b65e535..19d501dee0 100644 --- a/src/sunstone/public/app/tabs/provision-tab/templates/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/templates/list.js @@ -94,7 +94,12 @@ define(function(require) { datatable.fnAddData(item_list); LabelsUtils.clearLabelsFilter(datatable, TEMPLATE_LABELS_COLUMN); var context = $('.labels-dropdown', datatable.closest('.content')); - LabelsUtils.insertLabelsMenu(context, datatable, TEMPLATE_LABELS_COLUMN, "VMTEMPLATE.TEMPLATE.LABELS"); + LabelsUtils.insertLabelsMenu({ + 'context': context, + 'dataTable': datatable, + 'labelsColumn': TEMPLATE_LABELS_COLUMN, + 'labelsPath': 'VMTEMPLATE.TEMPLATE.LABELS' + }); } }, error: Notifier.onError diff --git a/src/sunstone/public/app/utils/labels/utils.js b/src/sunstone/public/app/utils/labels/utils.js index 35e863610b..4f56dc9b04 100644 --- a/src/sunstone/public/app/utils/labels/utils.js +++ b/src/sunstone/public/app/utils/labels/utils.js @@ -39,10 +39,26 @@ define(function(require) { /* FUNCTION DEFINITIONS */ - /* - Add labels tree to the left menu + /** + * Add labels tree to the left menu + * @param {Object} opts - Options + * @param {string} opts.tabName - Tab Name to retrieve the rest of the opts + * @param {jQuery Object} [opts.context] - jQuery object to insert the menu, if not + * provided the link of the tab in the left menu will be used + * @param {DataTable} [opts.dataTable] - Datatable to apply the filter, if not + * provided the one defined in the Sunstone tab will be used + * @param {Number} [opts.labelsColumn] - Column of the labels in the datatable, + * if not provided the one defined in the Sunstone tab datatable + * will be used + * @param {string} [opts.labelsPath] - Path of the labels attr, this value will be + * used if the datatable uses aData object instead of an array with the values */ - function _insertLabelsMenu(context, dataTable, labelsColumn, labelsPath) { + function _insertLabelsMenu(opts) { + var context = opts.context || $('#li_' + opts.tabName); + var dataTable = opts.dataTable || Sunstone.getDataTable(opts.tabName).dataTable; + var labelsColumn = opts.labelsColumn || Sunstone.getDataTable(opts.tabName).labelsColumn; + var labelsPath = opts.labelsPath; + var labels = _getLabels(dataTable, labelsColumn, labelsPath); $('.labels-tree', context).remove(); context.append(Tree.html(_makeTree(labels), true)); @@ -53,6 +69,10 @@ define(function(require) { */ context.off('click', '.one-label'); context.on('click', '.one-label', function() { + if (opts.tabName) { + Sunstone.showTab(opts.tabName); + } + var regExp = []; var label = $(this).attr('one-label-full-name'); regExp.push('^' + label + '$'); @@ -94,7 +114,7 @@ define(function(require) { var selectedItems = tabTable.elements(); $.each(selectedItems, function(index, resourceId) { - labelsStr = _getLabel(dataTable, labelsColumn, resourceId); + labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId); if (labelsStr != '') { $.each(labelsStr.split(','), function(){ if (labelsIndexed[this]) { @@ -159,7 +179,7 @@ define(function(require) { var labelsArray, labelIndex; var selectedItems = tabTable.elements(); $.each(selectedItems, function(index, resourceId) { - labelsStr = _getLabel(dataTable, labelsColumn, resourceId); + labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId); if (labelsStr != '') { labelsArray = labelsStr.split(',') } else { @@ -190,7 +210,7 @@ define(function(require) { var labelsArray, labelIndex; var selectedItems = tabTable.elements(); $.each(selectedItems, function(index, resourceId) { - labelsStr = _getLabel(dataTable, labelsColumn, resourceId); + labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId); if (labelsStr != '') { labelsArray = labelsStr.split(',') } else { @@ -233,7 +253,7 @@ define(function(require) { } - _insertLabelsMenu($('#li_' + tabName), tabTable.dataTable, tabTable.labelsColumn); + _insertLabelsMenu({'tabName': tabName}); _insertLabelsDropdown(tabName); }, error: Notifier.onError @@ -333,10 +353,9 @@ define(function(require) { return _deserializeLabels(labels.join(',')); } - function _getLabel(dataTable, labelsColumn, resourceId) { - var tab = dataTable.parents(".tab") - if (Sunstone.rightInfoVisible(tab)) { - var element = Sunstone.getElementRightInfo(tab.attr('id')); + function _getLabel(tabName, dataTable, labelsColumn, resourceId) { + if (Sunstone.rightInfoVisible($('#' + tabName))) { + var element = Sunstone.getElementRightInfo(tabName); if (element && element.TEMPLATE) { return element.TEMPLATE[LABELS_ATTR]||''; } else { diff --git a/src/sunstone/public/app/utils/tab-datatable.js b/src/sunstone/public/app/utils/tab-datatable.js index af39be65d9..8da8d2a864 100644 --- a/src/sunstone/public/app/utils/tab-datatable.js +++ b/src/sunstone/public/app/utils/tab-datatable.js @@ -485,9 +485,7 @@ define(function(require) { } if (that.labelsColumn) { - var dataTable = that.dataTable; - var labelsColumn = that.labelsColumn; - LabelsUtils.insertLabelsMenu($('#li_' + that.tabId), dataTable, labelsColumn); + LabelsUtils.insertLabelsMenu({'tabName': that.tabId}); LabelsUtils.insertLabelsDropdown(that.tabId); }