Kimchi is currently not able to configure and open help pages of any
plugin tab. This patch fixes this problem and removes the HELP button
if any Kimchi tab or plugin tab do not have a help configured properly
for the language being used.
(eg. if plugins/<tab_html>/help/<lang>/<tab_html>.html does not exist,
then the help button is disabled).
A help page for a plugin tab follow same Kimchi system:
- html help file should have the same name of plugin html tab file;
- html files should be placed in plugin's " ui/pages/help/<LANG> "
path;
- plugin should add following lines to <PLUGIN_NAME>.conf:
* [/help]
* tools.staticdir.on = True
* tools.nocache.on = True
* tools.staticdir.dir = '<HELP PAGE DIRECTORY>'
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.main.js | 53 +++++++++++++++++++++++++++++++++++-------------
1 file changed, 39 insertions(+), 14 deletions(-)
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index a8ae42a..1424827 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -38,11 +38,14 @@ kimchi.main = function() {
var path = tab['path'];
var mode = tab['mode'];
if (mode != 'none') {
+ var helpPath = kimchi.checkHelpFile(path);
+ var disableHelp = (helpPath.length == 0 ? "disableHelp" :
helpPath);
tabsHtml.push(
'<li>',
- '<a class="item" href="', path,
'">',
+ '<a class="item ', disableHelp,'"
href="', path, '">',
title,
'</a>',
+ '<input id="helpPathId"
name="helpPath" value="' + helpPath + '"
type="hidden"/>',
'</li>'
);
}
@@ -161,7 +164,15 @@ kimchi.main = function() {
$('#nav-menu a').removeClass('current');
$(tab).addClass('current');
$(tab).focus();
-
+ // Disable Help button according to selected tab
+ if ($(tab).hasClass("disableHelp")) {
+ $('#btn-help').css('cursor', "not-allowed");
+ $('#btn-help').off("click");
+ }
+ else {
+ $('#btn-help').css('cursor', "pointer");
+ $('#btn-help').on("click", kimchi.openHelp);
+ }
// Load page content.
loadPage(url);
};
@@ -261,7 +272,7 @@ kimchi.main = function() {
});
// Set handler for help button
- $('#btn-help').on('click', kimchi.getHelp);
+ $('#btn-help').on('click', kimchi.openHelp);
// Set handler to peers drop down
$('#peers').on('click', function() {
@@ -328,15 +339,29 @@ kimchi.main = function() {
});
};
-kimchi.getHelp = function(e) {
- var url = window.location.hash;
- var lang = kimchi.lang.get();
- url = url.replace("#tabs", "/help/" + lang);
- if (url == "/help" + lang)
- url = url + "/index.html"
- else
- url = url + ".html";
-
- window.open(url, "Kimchi Help");
- e.preventDefault();
+
+kimchi.checkHelpFile = function(path) {
+ var lang = kimchi.lang.get();
+ var url = ""
+ // Find help page path according to tab name
+ if (/^tabs/.test(path))
+ url = path.replace("tabs", "/help/" + lang);
+ else if (/^plugins/.test(path))
+ url = path.slice(0, path.lastIndexOf('/')) + "/help/" + lang +
path.slice(path.lastIndexOf('/'));
+ // Checking if help page exist.
+ $.ajax({
+ url: url,
+ async: false,
+ error: function() { url = ""; },
+ success: function() { }
+ });
+ return url;
+};
+
+
+kimchi.openHelp = function(e) {
+ var tab = $('#nav-menu a.current');
+ var url = $(tab).parent().find("input[name='helpPath']").val();
+ window.open(url, "Kimchi Help");
+ e.preventDefault();
};
--
1.9.3