1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

Bug #4332: Show datatable when clicking in a label from a detailed view

This commit is contained in:
Daniel Molina 2016-02-17 17:14:23 +01:00
parent 27f5df9162
commit fd64d27fa0
3 changed files with 37 additions and 15 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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);
}