Module: check_mk
Branch: master
Commit: 5b9b2ab76ff915d86e9b174de4db745f2e9904e4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5b9b2ab76ff915…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 21 10:08:34 2018 +0100
Moved help toggle to dedicated module
Change-Id: Iaf6eae77afe6a5a283af083c2238fcee56ba8116
---
cmk/gui/htmllib.py | 4 +--
web/htdocs/js/checkmk.js | 60 -------------------------------
web/htdocs/js/index.js | 2 ++
web/htdocs/js/modules/help.js | 84 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 88 insertions(+), 62 deletions(-)
diff --git a/cmk/gui/htmllib.py b/cmk/gui/htmllib.py
index a9bf1b1..d3bf147 100644
--- a/cmk/gui/htmllib.py
+++ b/cmk/gui/htmllib.py
@@ -1834,7 +1834,7 @@ class html(HTMLGenerator):
_("Toggle context help texts"),
"help",
id_="helpbutton",
- onclick="toggle_help()",
+ onclick="cmk.help.toggle()",
style="display:none",
cssclass=cssclass)
self.open_a(href="https://mathias-kettner.com",
class_="head_logo")
@@ -1903,7 +1903,7 @@ class html(HTMLGenerator):
def body_end(self):
if self.have_help:
- self.javascript("enable_help();")
+ self.javascript("cmk.help.enable();")
if self.final_javascript_code:
self.javascript(self.final_javascript_code)
self.javascript("cmk.visibility_detection.initialize();")
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 75b9248..b032bd7 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1808,66 +1808,6 @@ function vs_update_color_picker(varprefix, hex, update_picker) {
vs_color_pickers[varprefix].setHex(hex);
}
-//#.
-//# .-Help Toggle--------------------------------------------------------.
-//# | _ _ _ _____ _ |
-//# | | | | | ___| |_ __ |_ _|__ __ _ __ _| | ___ |
-//# | | |_| |/ _ \ | '_ \ | |/ _ \ / _` |/ _` | |/ _ \ |
-//# | | _ | __/ | |_) | | | (_) | (_| | (_| | | __/ |
-//# | |_| |_|\___|_| .__/ |_|\___/ \__, |\__, |_|\___| |
-//# | |_| |___/ |___/ |
-//# +--------------------------------------------------------------------+
-//# | |
-//# '--------------------------------------------------------------------'
-
-function enable_help()
-{
- var help = document.getElementById('helpbutton');
- help.style.display = "inline-block";
-}
-
-function toggle_help()
-{
- var help = document.getElementById('helpbutton');
- if (has_class(help, "active")) {
- remove_class(help, "active");
- add_class(help, "passive");
- switch_help(false);
- } else {
- add_class(help, "active");
- remove_class(help, "passive");
- switch_help(true);
- }
-}
-
-function switch_help(how)
-{
- // recursive scan for all div class=help elements
- var helpdivs = document.getElementsByClassName('help');
- for (var i=0; i<helpdivs.length; i++) {
- helpdivs[i].style.display = how ? "block" : "none";
- }
-
- // small hack for wato ruleset lists, toggle the "float" and
"nofloat"
- // classes on those objects to make the layout possible
- var rulesetdivs = document.getElementsByClassName('ruleset');
- for (var i = 0; i < rulesetdivs.length; i++) {
- if (how) {
- if (has_class(rulesetdivs[i], 'float')) {
- remove_class(rulesetdivs[i], 'float');
- add_class(rulesetdivs[i], 'nofloat');
- }
- } else {
- if (has_class(rulesetdivs[i], 'nofloat')) {
- remove_class(rulesetdivs[i], 'nofloat');
- add_class(rulesetdivs[i], 'float');
- }
- }
- }
-
- get_url("ajax_switch_help.py?enabled=" + (how ? "yes" :
""));
-}
-
/* Switch filter, commands and painter options */
function view_toggle_form(button, form_id) {
var display = "none";
diff --git a/web/htdocs/js/index.js b/web/htdocs/js/index.js
index fcaf3c2..578456b 100644
--- a/web/htdocs/js/index.js
+++ b/web/htdocs/js/index.js
@@ -33,6 +33,7 @@ import * as async_progress from "async_progress";
import * as activation from "activation";
import * as selection from "selection";
import * as element_dragging from "element_dragging";
+import * as help from "help";
import * as dashboard from "dashboard";
require("script-loader!./checkmk.js");
@@ -62,6 +63,7 @@ export default {
activation: activation,
selection: selection,
element_dragging: element_dragging,
+ help: help,
dashboard: dashboard
},
// TODO: Compatibility for not yet modularized JS code
diff --git a/web/htdocs/js/modules/help.js b/web/htdocs/js/modules/help.js
new file mode 100644
index 0000000..69f3eb9
--- /dev/null
+++ b/web/htdocs/js/modules/help.js
@@ -0,0 +1,84 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+// +------------------------------------------------------------------+
+//
+// This file is part of Check_MK.
+// The official homepage is at
http://mathias-kettner.de/check_mk.
+//
+// check_mk is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation in version 2. check_mk is distributed
+// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+// PARTICULAR PURPOSE. See the GNU General Public License for more de-
+// ails. You should have received a copy of the GNU General Public
+// License along with GNU Make; see the file COPYING. If not, write
+// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+import * as utils from "utils";
+import * as ajax from "ajax";
+
+//# .-Help Toggle--------------------------------------------------------.
+//# | _ _ _ _____ _ |
+//# | | | | | ___| |_ __ |_ _|__ __ _ __ _| | ___ |
+//# | | |_| |/ _ \ | '_ \ | |/ _ \ / _` |/ _` | |/ _ \ |
+//# | | _ | __/ | |_) | | | (_) | (_| | (_| | | __/ |
+//# | |_| |_|\___|_| .__/ |_|\___/ \__, |\__, |_|\___| |
+//# | |_| |___/ |___/ |
+//# '--------------------------------------------------------------------'
+
+export function enable()
+{
+ var help = document.getElementById("helpbutton");
+ help.style.display = "inline-block";
+}
+
+export function toggle()
+{
+ var help = document.getElementById("helpbutton");
+ if (utils.has_class(help, "active")) {
+ utils.remove_class(help, "active");
+ utils.add_class(help, "passive");
+ switch_help(false);
+ } else {
+ utils.add_class(help, "active");
+ utils.remove_class(help, "passive");
+ switch_help(true);
+ }
+}
+
+function switch_help(how)
+{
+ // recursive scan for all div class=help elements
+ var helpdivs = document.getElementsByClassName("help");
+ var i;
+ for (i=0; i<helpdivs.length; i++) {
+ helpdivs[i].style.display = how ? "block" : "none";
+ }
+
+ // small hack for wato ruleset lists, toggle the "float" and
"nofloat"
+ // classes on those objects to make the layout possible
+ var rulesetdivs = document.getElementsByClassName("ruleset");
+ for (i = 0; i < rulesetdivs.length; i++) {
+ if (how) {
+ if (utils.has_class(rulesetdivs[i], "float")) {
+ utils.remove_class(rulesetdivs[i], "float");
+ utils.add_class(rulesetdivs[i], "nofloat");
+ }
+ } else {
+ if (utils.has_class(rulesetdivs[i], "nofloat")) {
+ utils.remove_class(rulesetdivs[i], "nofloat");
+ utils.add_class(rulesetdivs[i], "float");
+ }
+ }
+ }
+
+ ajax.get_url("ajax_switch_help.py?enabled=" + (how ? "yes" :
""));
+}