mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
feature #3748: Add template panel
This commit is contained in:
1 parent
6492bae0e6
commit
66e377f8ef
5 files changed
+139
-4
No files matched your search
@@ -13,9 +13,7 @@ define(function(require) {
|
||||
|
||||
var _panels = [
|
||||
require('./templates-tab/panels/info'),
|
||||
//require('./templates-tab/panels/ar'),
|
||||
//require('./templates-tab/panels/leases'),
|
||||
//require('./templates-tab/panels/secgroups')
|
||||
require('./templates-tab/panels/template')
|
||||
];
|
||||
|
||||
/*var _formPanels = [
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
define(function(require) {
|
||||
/*
|
||||
DEPENDENCIES
|
||||
*/
|
||||
|
||||
var Locale = require('utils/locale');
|
||||
var Humanize = require('utils/humanize');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
*/
|
||||
|
||||
var TemplateInfo = require('hbs!./template/html');
|
||||
|
||||
/*
|
||||
CONSTANTS
|
||||
*/
|
||||
|
||||
var TAB_ID = require('../tabId');
|
||||
var PANEL_ID = require('./template/panelId');
|
||||
var RESOURCE = "Template"
|
||||
var XML_ROOT = "VMTEMPLATE"
|
||||
|
||||
/*
|
||||
CONSTRUCTOR
|
||||
*/
|
||||
|
||||
function Panel(info) {
|
||||
this.title = Locale.tr("Template");
|
||||
this.icon = "fa-file-o";
|
||||
|
||||
this.element = info[XML_ROOT];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Panel.PANEL_ID = PANEL_ID;
|
||||
Panel.prototype.html = _html;
|
||||
Panel.prototype.setup = _setup;
|
||||
|
||||
return Panel;
|
||||
|
||||
/*
|
||||
FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
function _html() {
|
||||
var prettyTemplateHTML = Humanize.prettyPrintJSON(this.element.TEMPLATE);
|
||||
|
||||
return TemplateInfo({
|
||||
'element': this.element,
|
||||
'prettyTemplateHTML': prettyTemplateHTML
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<table class="info_table dataTable" style="width:80%">{{{prettyTemplateHTML}}}</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
define(function(require){
|
||||
return 'template_template_tab';
|
||||
});
|
||||
@@ -7,7 +7,8 @@ define(function(require) {
|
||||
'size': _size,
|
||||
'sizeFromMB': _sizeFromMB,
|
||||
'prettyTime': _prettyTime,
|
||||
'prettyTimeAxis': _prettyTimeAxis
|
||||
'prettyTimeAxis': _prettyTimeAxis,
|
||||
'prettyPrintJSON': _prettyPrintJSON
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -104,4 +105,74 @@ define(function(require) {
|
||||
else
|
||||
return hour + ":" + mins;
|
||||
}
|
||||
|
||||
// Returns an HTML string with the json keys and values
|
||||
// Attempts to css format output, giving different values to
|
||||
// margins etc. according to depth level etc.
|
||||
// See example of use in plugins.
|
||||
function _prettyPrintJSON(template_json, padding, weight, border_bottom, padding_top_bottom) {
|
||||
var str = ""
|
||||
if (!template_json) { return "Not defined";}
|
||||
if (!padding) {padding = 10};
|
||||
if (!weight) {weight = "bold";}
|
||||
if (!border_bottom) {border_bottom = "1px solid #efefef";}
|
||||
if (!padding_top_bottom) {padding_top_bottom = 6;}
|
||||
var field = null;
|
||||
|
||||
if (template_json.constructor == Array) {
|
||||
for (field = 0; field < template_json.length; ++field) {
|
||||
str += _prettyPrintRowJSON(field, template_json[field], padding, weight, border_bottom, padding_top_bottom);
|
||||
}
|
||||
} else {
|
||||
for (field in template_json) {
|
||||
str += _prettyPrintRowJSON(field, template_json[field], padding, weight, border_bottom, padding_top_bottom);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function _prettyPrintRowJSON(field, value, padding, weight, border_bottom, padding_top_bottom) {
|
||||
var str = "";
|
||||
|
||||
if (typeof value == 'object') {
|
||||
//name of field row
|
||||
str += '<tr>\
|
||||
<td class="key_td" style=\
|
||||
"padding-left:' + padding + 'px;\
|
||||
font-weight:' + weight + ';\
|
||||
border-bottom:' + border_bottom + ';\
|
||||
padding-top:' + padding_top_bottom + 'px;\
|
||||
padding-bottom:' + padding_top_bottom + 'px;">' +
|
||||
field +
|
||||
'</td>\
|
||||
<td class="value_td" style=\
|
||||
"border-bottom:' + border_bottom + ';\
|
||||
padding-top:' + padding_top_bottom + 'px;\
|
||||
padding-bottom:' + padding_top_bottom + 'px">\
|
||||
</td>\
|
||||
</tr>';
|
||||
//attributes rows
|
||||
//empty row - prettyprint - empty row
|
||||
str += _prettyPrintJSON(value, padding + 25, "normal", "0", 1);
|
||||
} else {
|
||||
str += '<tr>\
|
||||
<td class="key_td" style="\
|
||||
padding-left:' + padding + 'px;\
|
||||
font-weight:' + weight + ';\
|
||||
border-bottom:' + border_bottom + ';\
|
||||
padding-top:' + padding_top_bottom + 'px;\
|
||||
padding-bottom:' + padding_top_bottom + 'px">' +
|
||||
field +
|
||||
'</td>\
|
||||
<td class="value_td" style="\
|
||||
border-bottom:' + border_bottom + ';\
|
||||
padding-top:' + padding_top_bottom + 'px;\
|
||||
padding-bottom:' + padding_top_bottom + 'px">' +
|
||||
value +
|
||||
'</td>\
|
||||
</tr>';
|
||||
};
|
||||
|
||||
return str;
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user