feature #3748: Refactor panels

This commit is contained in:
Daniel Molina committed 2015-04-17 16:46:12 +02:00
1 parent 74ae4912a3
commit 95cc47570f
7 files changed
+146 -57

No files matched your search

+78 -42
View File
@@ -424,6 +424,82 @@ define(function(require) {
}*/
}
var _showElement = function(tabName, infoAction, elementId) {
showTab(tabName);
var context = $('#' + tabName);
$(".resource-id", context).html(elementId);
$(".resource-info-header", context).text("");
_popDialogLoading(context);
Sunstone.runAction(infoAction, elementId);
//enable action buttons
$('.top_button, .list_button', context).attr('disabled', false);
}
var _popDialog = function(content, context){
$(".right-info", context).html(content);
context.foundation();
}
var _popDialogLoading = function(context){
$(".right-list", context).hide();
$(".right-form", context).hide();
$(".right-info", context).show();
$(".only-right-list", context).hide();
$(".only-right-form", context).hide();
$(".only-right-info", context).show();
var loading = '<div style="margin-top: 20px; text-align: center; width: 100%"><img src="images/pbar.gif" alt="loading..." /></div>';
_popDialog(loading, context);
}
var _insertPanels = function(tabName, info) {
var panelName = tabName + '-panels';
var activaTab = $("dd.active a", $("#" + panelName));
if (activaTab) {
var activaTabHref = activaTab.attr('href');
}
var dlTabs = $('<div id="' + panelName + '" class="bordered-tabs">\
<dl class="tabs right-info-tabs text-center" data-tab>\
</dl>\
<div class="tabs-content"></div>\
</div>\
</div>');
console.log(tabName)
console.log(SunstoneCfg)
var tabs = SunstoneCfg['tabs'][tabName].panels;
var tab = null;
var active = false;
for (panelTabName in tabs) {
if (Config.isTabPanelEnabled(tabName, panelTabName) == false) {
continue;
}
tab = tabs[panelTabName];
var dd = $('<dd><a href="#' + panelTabName + '">' + (tab.icon ? '<i class="fa ' + tab.icon + '"></i><br>' : '') + tab.title + '</a></dd>').appendTo($('dl', dlTabs));
var li = $('<div id="' + panelTabName + '" class="content">' + tab.content(info) + '</div>').appendTo($('.tabs-content', dlTabs));
if (activaTabHref) {
if (activaTabHref == "#" + panelTabName) {
dd.addClass('active');
li.addClass('active');
}
} else {
if (!active) {
dd.addClass('active');
li.addClass('active');
active = true;
}
}
}
_popDialog(dlTabs, $("#" + tabName));
}
//Runs a predefined action. Wraps the calls to opennebula.js and
//can be use to run action depending on conditions and notify them
//if desired. Returns 1 if some problem has been detected: i.e
@@ -546,48 +622,8 @@ define(function(require) {
},
//Makes an info panel content pop up in the screen.
"popUpInfoPanel" : function(panelName, selectedTab) {
var activaTab = $("dd.active a", $("#" + panelName));
if (activaTab) {
var activaTabHref = activaTab.attr('href');
}
var dlTabs = $('<div id="' + panelName + '" class="bordered-tabs">\
<dl class="tabs right-info-tabs text-center" data-tab>\
</dl>\
<div class="tabs-content"></div>\
</div>\
</div>');
var tabs = SunstoneCfg["info_panels"][panelName];
var tab = null;
var active = false;
for (panelTabName in tabs) {
if (Config.isTabPanelEnabled(selectedTab, panelTabName) == false) {
continue;
}
tab = tabs[panelTabName];
var dd = $('<dd><a href="#' + panelTabName + '">' + (tab.icon ? '<i class="fa ' + tab.icon + '"></i><br>' : '') + tab.title + '</a></dd>').appendTo($('dl', dlTabs));
var li = $('<div id="' + panelTabName + '" class="content">' + tab.content + '</div>').appendTo($('.tabs-content', dlTabs));
if (activaTabHref) {
if (activaTabHref == "#" + panelTabName) {
dd.addClass('active');
li.addClass('active');
}
} else {
if (!active) {
dd.addClass('active');
li.addClass('active');
active = true;
}
}
}
popDialog(dlTabs, $("#" + selectedTab));
},
"showElement" : _showElement,
"insertPanels" : _insertPanels,
// Replaces a tab from an info panel. Refreshes the DOM if wanted.
"updateInfoPanelTab" : function(panelName, panelTabId, panelTabObj, refresh) {
+3 -1
View File
@@ -3,6 +3,7 @@ define(function(require) {
var Buttons = require('./zones-tab/buttons');
var Actions = require('./zones-tab/actions');
var DataTable = require('./zones-tab/datatable');
var Panels = require('./zones-tab/panels');
var zonesTab = {
title: Locale.tr("Zones"),
@@ -11,9 +12,10 @@ define(function(require) {
parentTab: "infra-tab",
listHeader: '<i class="fa fa-fw fa-files-o"></i>&emsp;' + Locale.tr("Zones"),
infoHeader: '<i class="fa fa-fw fa-files-o"></i>&emsp;' + Locale.tr("Zone"),
subheader: '<span/> <small></small>&emsp;',
subheader: '',
buttons: Buttons,
actions: Actions,
panels: Panels,
dataTable: DataTable
};
@@ -36,9 +36,9 @@ define(function(require) {
callback: function(request, response) {
// TODO var tab = dataTable_zones.parents(".tab");
if (Sunstone.rightInfoVisible(tab)) {
if (Sunstone.rightInfoVisible($('#zones-tab'))) {
// individual view
// TODO updateZoneInfo(request, response);
Sunstone.insertPanels('zones-tab', response);
}
// datatable row
@@ -0,0 +1,7 @@
define(function(require){
var InfoPanel = require('./panels/info');
return {
'zone_info_tab': InfoPanel
}
});
@@ -0,0 +1,21 @@
define(function(require){
var TemplateInfo = require('hbs!./info/content');
var Locale = require('utils/locale');
var _generateHTML = function(info) {
return TemplateInfo(info);
}
var _initialize = function(info) {
}
var infoPanel = {
title : Locale.tr("Info"),
icon: "fa-info-circle",
content : _generateHTML,
initialize: _initialize
}
return infoPanel;
});
@@ -0,0 +1,24 @@
<div class="row">
<div class="large-6 columns">
<table id="info_zone_table" class="dataTable extended_table">
<thead>
<tr>
<th colspan="3">{{tr "Information"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="key_td">{{tr "ID"}}</td>
<td class="value_td" colspan="2">{{ZONE.ID}}</td>
</tr>
{{! TODO insert_rename_tr('zones-tab', "Zone", ID, NAME)}}
</tbody>
</table>
</div>
<div class="large-6 columns"></div>
</div>
<div class="row">
<div class="large-9 columns">
{{! TODO insert_extended_template_table(zone_template, "Zone", ID, tr("Attributes"))}}
</div>
</div>
+11 -12
View File
@@ -1,6 +1,7 @@
define(function(require) {
require('foundation-datatables');
var TemplateEmptyTable = require('hbs!./tab-datatable/empty-table')
var TemplateEmptyTable = require('hbs!./tab-datatable/empty-table');
var Sunstone = require('sunstone');
var SPINNER = '<img src="images/ajax-loader.gif" alt="retrieving" class="loading_img"/>';
@@ -16,12 +17,10 @@ define(function(require) {
//Shows run a custom action when clicking on rows.
var _infoListener = function(dataTable, info_action, target_tab) {
$('tbody tr', dataTable).off("click");
$('tbody tr', dataTable).on("click", function(e) {
if ($(e.target).is('input') ||
$(e.target).is('select') ||
$(e.target).is('option')) return true;
dataTable.on("click", 'tbody tr', function(e) {
if ($(e.target).is('input') ||$(e.target).is('select') || $(e.target).is('option')) {
return true;
}
var aData = dataTable.fnGetData(this);
if (!aData) return true;
@@ -34,10 +33,10 @@ define(function(require) {
$('.check_item', this).trigger('click');
} else {
if (!target_tab) {
target_tab = activeTab;
target_tab = $(dataTable).parents(".tab").attr("id");
}
showElement(target_tab, info_action, id);
console.log(target_tab)
Sunstone.showElement(target_tab, info_action, id);
};
} else {
$('.check_item', this).trigger('click');
@@ -146,7 +145,7 @@ define(function(require) {
$(this).parents('tr').children().removeClass('markrowchecked');
}
recountCheckboxes(datatable, context);
_recountCheckboxes(datatable, context);
});
}
@@ -259,7 +258,7 @@ define(function(require) {
var position = dataTable.fnGetPosition(tr);
dataTable.fnUpdate(element, position, undefined, false);
$('input.check_item', tr).attr('checked', checked_val);
recountCheckboxes(dataTable);
_recountCheckboxes(dataTable);
}
}