diff --git a/src/sunstone/public/app/tabs/templates-tab.js b/src/sunstone/public/app/tabs/templates-tab.js index 0327a5702f..42c37594c2 100644 --- a/src/sunstone/public/app/tabs/templates-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab.js @@ -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 = [ diff --git a/src/sunstone/public/app/tabs/templates-tab/panels/template.js b/src/sunstone/public/app/tabs/templates-tab/panels/template.js new file mode 100644 index 0000000000..7813c1e877 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/panels/template.js @@ -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) { + } +}); diff --git a/src/sunstone/public/app/tabs/templates-tab/panels/template/html.hbs b/src/sunstone/public/app/tabs/templates-tab/panels/template/html.hbs new file mode 100644 index 0000000000..7a4f3e29ae --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/panels/template/html.hbs @@ -0,0 +1,5 @@ +
+
+ {{{prettyTemplateHTML}}}
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/templates-tab/panels/template/panelId.js b/src/sunstone/public/app/tabs/templates-tab/panels/template/panelId.js new file mode 100644 index 0000000000..7c5a7ebf5b --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/panels/template/panelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'template_template_tab'; +}); \ No newline at end of file diff --git a/src/sunstone/public/app/utils/humanize.js b/src/sunstone/public/app/utils/humanize.js index d5c36efa98..2d2225d061 100644 --- a/src/sunstone/public/app/utils/humanize.js +++ b/src/sunstone/public/app/utils/humanize.js @@ -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 += '\ + ' + + field + + '\ + \ + \ + '; + //attributes rows + //empty row - prettyprint - empty row + str += _prettyPrintJSON(value, padding + 25, "normal", "0", 1); + } else { + str += '\ + ' + + field + + '\ + ' + + value + + '\ + '; + }; + + return str; + } })