On 09/30/2014 03:37 PM, Rodrigo Trujillo wrote:
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, 40 insertions(+), 13 deletions(-)
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index a3305e9..3210dd9 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -49,11 +49,16 @@ kimchi.main = function() {
var path = tab['path'];
var mode = tab['mode'];
if (mode != 'none') {
+ var helpPath = kimchi.checkHelpFile(path);
+ var disableHelp = ""
+ if (helpPath == "disableHelp")
+ disableHelp = helpPath;
disabledHelp = "disableHelp" ? helpPath.lenght() == 0 : ""
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>'
);
}
@@ -172,7 +177,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);
};
@@ -265,7 +278,7 @@ kimchi.main = function() {
event.preventDefault();
});
- $('#btn-help').on('click', kimchi.getHelp);
+ $('#btn-help').on('click', kimchi.openHelp);
};
var initUI = function() {
@@ -307,15 +320,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 = "disableHelp"; },
Return an empty string in that case.
url = "";
So the function does what it is supposed to do without joining 2
different meanings.
+ 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();
};