[checkmk-commits] Cleaned up old sidebar specific icon render function

Lars Michelsen lm at mathias-kettner.de
Wed Sep 7 08:23:50 CEST 2016


Module: check_mk
Branch: master
Commit: c25b1ed10e7f6cdf6cae94e3f445a882685ffe87
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c25b1ed10e7f6cdf6cae94e3f445a882685ffe87

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Tue Sep  6 17:03:13 2016 +0200

Cleaned up old sidebar specific icon render function

---

 web/htdocs/js/sidebar.js | 57 ++++++++++++++++++++++++++++++------------------
 web/htdocs/sidebar.py    | 24 +++++---------------
 2 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 07745fd..18ad0f6 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -618,29 +618,44 @@ sidebar_restart_time = null;
 // Configures the number of seconds to reload all snapins which request it
 sidebar_update_interval = null;
 
-// Removes a snapin from the sidebar without reloading anything
-function removeSnapin(id, code) {
-  var container = document.getElementById(id).parentNode;
-  var myparent = container.parentNode;
-  myparent.removeChild(container);
-
-  // remove this snapin from the refresh list, if it is contained
-  for (var i in refresh_snapins) {
-      var name    = refresh_snapins[i][0];
-      if (id == "snapin_" + name) {
-          refresh_snapins.splice(i, 1);
-          break;
-      }
-  }
+// Removes the snapin from the current sidebar and informs the server for persistance
+function remove_sidebar_snapin(oLink, url)
+{
+    var container = oLink.parentNode.parentNode.parentNode;
+    var id = container.id.replace("snapin_container_", "");
+
+    call_ajax(url, {
+        handler_data     : "snapin_" + id,
+        response_handler : function (id, _unused) {
+            remove_snapin(id);   
+        },
+        method           : "GET"
+    });
+}
+
 
-  // reload main frame if it is just displaying the "add snapin" page
-  var href = encodeURIComponent(parent.frames[1].location);
-  if (href.indexOf("sidebar_add_snapin.py") > -1)
-      parent.frames[1].location.reload();
+// Removes a snapin from the sidebar without reloading anything
+function remove_snapin(id)
+{
+    var container = document.getElementById(id).parentNode;
+    var myparent = container.parentNode;
+    myparent.removeChild(container);
+
+    // remove this snapin from the refresh list, if it is contained
+    for (var i in refresh_snapins) {
+        var name    = refresh_snapins[i][0];
+        if (id == "snapin_" + name) {
+            refresh_snapins.splice(i, 1);
+            break;
+        }
+    }
 
-  href = null;
-  container = null;
-  myparent = null;
+    // reload main frame if it is currently displaying the "add snapin" page
+    if (parent.frames[1]) {
+        var href = encodeURIComponent(parent.frames[1].location);
+        if (href.indexOf("sidebar_add_snapin.py") > -1)
+            parent.frames[1].location.reload();
+    }
 }
 
 
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index e204f1b..3c527b9 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -107,21 +107,6 @@ def footnotelinks(links):
         html.write(link(text, target))
     end_footnote_links()
 
-def iconbutton(what, url, target="side", handler="", name="", css_class = ""):
-    if target == "side":
-        onclick = "onclick=\"get_url('%s', %s, '%s')\"" % \
-                   (url, handler, name)
-        href = "#"
-        tg = ""
-    else:
-        onclick = ""
-        href = "%scheck_mk/%s" % (defaults.url_prefix, url)
-        tg = "target=%s" % target
-    css_class = css_class and " " + css_class or ""
-    html.write("<a href=\"%s\" %s %s><img class=\"iconbutton%s\" "
-               "align=absmiddle src=\"%scheck_mk/images/button_%s.png\"></a>\n " %
-                  (href, onclick, tg, css_class, defaults.url_prefix, what))
-
 def nagioscgilink(text, target):
     html.write("<li class=sidebar><a target=\"main\" class=link href=\"%snagios/cgi-bin/%s\">%s</a></li>" % \
             (defaults.url_prefix, target, html.attrencode(text)))
@@ -337,14 +322,15 @@ def render_snapin(name, state):
     if config.may("general.configure_sidebar"):
         # Icon for mini/maximizing
         html.write('<div class="minisnapin">')
-        iconbutton(minimaxi + "snapin", None,
-                   "side", "toggle_sidebar_snapin(this, '%s')" % toggle_url, 'snapin_'+name)
+        html.icon_button(url=None, help=_("Toggle this snapin"), icon="%ssnapin" % minimaxi,
+                         onclick="toggle_sidebar_snapin(this, '%s')" % toggle_url)
         html.write('</div>')
 
         # Button for closing (removing) a snapin
         html.write('<div class="closesnapin">')
-        iconbutton("closesnapin", "sidebar_openclose.py?name=%s&state=off" % name,
-                   "side", "removeSnapin", 'snapin_'+name)
+        close_url = "sidebar_openclose.py?name=%s&state=off" % name
+        html.icon_button(url=None, help=_("Remove this snapin"), icon="closesnapin",
+                         onclick="remove_sidebar_snapin(this, '%s')" % close_url)
         html.write('</div>')
 
     # The heading. A click on the heading mini/maximizes the snapin



More information about the checkmk-commits mailing list