Module: check_mk
Branch: master
Commit: cd19f96e78337ea1c78d7f0078786bfd82a79c1e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cd19f96e78337e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Jan 31 14:11:50 2016 +0100
popup_trigger can now call code on close
---
web/htdocs/htmllib.py | 7 ++++---
web/htdocs/js/checkmk.js | 13 ++++++++++---
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 5cf7c3d..81d76dc 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1032,14 +1032,15 @@ class html(GUITester):
else:
self.status_icons[img] = tooltip
- def render_popup_trigger(self, content, ident, what=None, data=None, url_vars=None,
style=None, menu_content=None, cssclass=None):
+ def render_popup_trigger(self, content, ident, what=None, data=None, url_vars=None,
style=None, menu_content=None, cssclass=None, onclose=None):
style = style and (' style="%s"' % style) or ""
src = '<div class="popup_trigger%s"
id="popup_trigger_%s"%s>\n' % (cssclass and (" " + cssclass) or
"", ident, style)
- onclick = 'toggle_popup(event, this, \'%s\', %s, %s, %s, %s)' %
\
+ onclick = 'toggle_popup(event, this, \'%s\', %s, %s, %s, %s, %s)'
% \
(ident, what and "'"+what+"'" or
'null',
data and self.attrencode(json.dumps(data)) or 'null',
url_vars and
"'"+self.urlencode_vars(url_vars)+"'" or 'null',
- menu_content and
"'"+self.attrencode(menu_content)+"'" or 'null')
+ menu_content and
"'"+self.attrencode(menu_content)+"'" or 'null',
+ onclose and "'%s'" %
onclose.replace("'", "\\'") or 'null')
src += '<a class="popup_trigger"
href="javascript:void(0)" onclick="%s">\n' % onclick
src += content
src += '</a>'
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 6ec57f5..1106ba4 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -2439,6 +2439,9 @@ function close_popup()
menu = null;
}
popup_id = null;
+
+ if (on_popup_close)
+ eval(on_popup_close);
}
// Registerd as click handler on the page while the popup menu is opened
@@ -2466,9 +2469,12 @@ function handle_popup_close(event) {
// The static content of the menu is given in the "menu_content"
parameter.
// data: json data which can be used by actions in popup menus
// url_vars: vars are added to ajax_popup_*.py calls for rendering the popup menu
-function toggle_popup(event, trigger_obj, ident, what, data, url_vars, menu_content)
+var on_popup_close = null;
+function toggle_popup(event, trigger_obj, ident, what, data, url_vars, menu_content,
onclose)
{
- if(!event)
+ on_popup_close = onclose;
+
+ if (!event)
event = window.event;
var container = trigger_obj.parentNode;
@@ -2476,7 +2482,8 @@ function toggle_popup(event, trigger_obj, ident, what, data,
url_vars, menu_cont
if (popup_id === ident) {
close_popup();
return; // same icon clicked: just close the menu
- } else {
+ }
+ else {
close_popup();
}
}