Module: check_mk
Branch: master
Commit: ed725c75a62f294a8cb050a70100986c276e922c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ed725c75a62f29…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 10 15:01:47 2015 +0200
Cleaned up multisite popup menu data structures a bit
---
web/htdocs/htmllib.py | 16 ++++++++--------
web/htdocs/js/checkmk.js | 6 +++---
web/htdocs/valuespec.py | 8 ++++----
web/htdocs/visuals.py | 6 +-----
web/plugins/icons/builtin.py | 2 +-
5 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index ebd1663..635b70e 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -45,7 +45,7 @@
# input to str or unicode must happen as early as possible,
# directly when reading from file or URL.
-import time, os, pwd, urllib, random, re, __builtin__
+import time, os, pwd, urllib, random, re, __builtin__, json
from lib import *
# Python 2.3 does not have 'set' in normal namespace.
@@ -981,18 +981,20 @@ class html:
else:
self.status_icons[img] = tooltip
- def render_popup_trigger(self, content, ident, what, data=None, params=None):
+ def render_popup_trigger(self, content, ident, what, data=None, url_vars=None):
src = '<div class="popup_trigger">\n'
onclick = 'toggle_popup(event, this, \'%s\', \'%s\', %s,
%s)' % \
- (ident, what, data or 'null', params and
"'"+params+"'" or 'null')
+ (ident, what,
+ data and self.attrencode(json.dumps(data)) or 'null',
+ url_vars and
"'"+self.urlencode_vars(url_vars)+"'" or 'null')
src += '<a class="popup_trigger"
href="javascript:void(0)" onclick="%s">\n' % onclick
src += content
src += '</a>\n'
src += '</div>\n'
return src
- def popup_trigger(self, content, ident, what, data=None, params=None):
- self.write(self.render_popup_trigger(content, ident, what, data, params))
+ def popup_trigger(self, content, ident, what, data=None, url_vars=None):
+ self.write(self.render_popup_trigger(content, ident, what, data, url_vars))
def write_status_icons(self):
self.write('<a target="_top" href="%s"><img
class=statusicon src="images/status_frameurl.png"
title="%s"></a>\n' % \
@@ -1019,9 +1021,7 @@ class html:
self.popup_trigger(
'<img class=statusicon src="images/icon_menu.png"
title="%s">\n' % _("Add this view to..."),
- 'add_visual', 'add_visual', data='[\'%s\',
%s, {\'name\': \'%s\'}]' %
- (mode_name,
self.attrencode(repr(encoded_vars)),
-
self.attrencode(self.var('view_name'))))
+ 'add_visual', 'add_visual', data=[mode_name,
encoded_vars, {'name': self.var('view_name')}])
for img, tooltip in self.status_icons.items():
if type(tooltip) == tuple:
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index fd8392a..64436ff 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -2409,9 +2409,9 @@ function handle_popup_close(event) {
close_popup();
}
-function toggle_popup(event, trigger_obj, ident, what, data, params)
+function toggle_popup(event, trigger_obj, ident, what, data, url_vars)
{
- var params = typeof(params) === "undefined" ? '' :
'?'+params;
+ var url_vars = typeof(url_vars) === "undefined" ? '' :
'?'+url_vars;
if(!event)
event = window.event;
@@ -2447,7 +2447,7 @@ function toggle_popup(event, trigger_obj, ident, what, data,
params)
//if (ident in popup_contents)
// menu.innerHTML = popup_contents[ident];
//else
- get_url('ajax_popup_'+what+'.py'+params,
handle_render_popup_contents, [ident, event]);
+ get_url('ajax_popup_'+what+'.py'+url_vars,
handle_render_popup_contents, [ident, event]);
}
function handle_render_popup_contents(data, response_text)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 49743ea..89d6363 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -3329,10 +3329,10 @@ class IconSelector(ValueSpec):
else:
content = _('Select an Icon')
html.popup_trigger(content, varprefix+'_icon_selector',
'icon_selector',
- params=html.urlencode_vars([('value', value),
- ('varprefix', varprefix),
- ('allow_empty', self._allow_empty and
'1' or '0'),
- ('back', html.makeuri([]))]))
+ params=[('value', value),
+ ('varprefix', varprefix),
+ ('allow_empty', self._allow_empty and
'1' or '0'),
+ ('back', html.makeuri([]))])
def render_popup_input(self, varprefix, value):
html.write('<div class="icons">')
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index e497645..7b9a7d8 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1407,12 +1407,8 @@ def ajax_add_visual():
# type of the visual to add (e.g. view)
element_type = html.var("type")
- # Context and params are | separated lists of : separated triples
- # of name, datatype and value. Datatype is int or string
extra_data = []
for what in [ 'context', 'params' ]:
- value = html.var(what)
- if value:
- extra_data.append(json.loads(value))
+ extra_data.append(json.loads(html.var(what)))
handler(visual_name, element_type, *extra_data)
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 2e10c19..86e22ce 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -86,7 +86,7 @@ def paint_action_menu(what, row, tags, host_custom_vars):
return html.render_popup_trigger(
html.render_icon('menu', _('Open the action menu')),
- 'action_menu', 'action_menu',
params=html.urlencode_vars(url_vars))
+ 'action_menu', 'action_menu', url_vars=url_vars)
multisite_icons_and_actions['action_menu'] = {
'columns': [],