Module: check_mk
Branch: master
Commit: 5e5fd16bef4dfa326460edfe9f10212784b22b1e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5e5fd16bef4dfa…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 11 10:49:23 2015 +0200
Improved error handling when experiencing problems during "add to visual"
---
web/htdocs/dashboard.py | 2 +-
web/htdocs/js/checkmk.js | 28 +++++++++++++++++++++-------
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 78c23bf..e85bd67 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -1201,4 +1201,4 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context,
params):
# Directly go to the dashboard in edit mode. We send the URL as an answer
# to the AJAX request
- html.write('dashboard.py?name=' + dashboard_name + '&edit=1')
+ html.write('OK dashboard.py?name=' + dashboard_name + '&edit=1')
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index f40120a..8b81c92 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -412,6 +412,7 @@ function call_ajax(url, args)
{
args = merge_args({
add_ajax_id : true,
+ plain_error : false,
response_handler : null,
error_handler : null,
handler_data : null,
@@ -431,6 +432,11 @@ function call_ajax(url, args)
url += "_ajaxid="+Math.floor(Date.parse(new Date()) / 1000);
}
+ if (args.plain_error) {
+ url += url.indexOf('\?') !== -1 ? "&" : "?";
+ url += "_plain_error=1";
+ }
+
try {
AJAX.open(args.method, url, !args.sync);
} catch (e) {
@@ -2488,18 +2494,26 @@ function add_to_visual(visual_type, visual_name)
{
close_popup();
- response = get_url_sync('ajax_add_visual.py?visual_type=' + visual_type
- + '&visual_name=' + visual_name
- + '&type=' + popup_data[0]
- + '&context=' +
encodeURIComponent(JSON.stringify(popup_data[1]))
- + '¶ms=' +
encodeURIComponent(JSON.stringify(popup_data[2])));
+ var AJAX = call_ajax('ajax_add_visual.py?visual_type=' + visual_type
+ + '&visual_name=' + visual_name
+ + '&type=' + popup_data[0]
+ + '&context=' +
encodeURIComponent(JSON.stringify(popup_data[1]))
+ + '¶ms=' +
encodeURIComponent(JSON.stringify(popup_data[2])), {
+ sync: true,
+ plain_error : true
+ })
+ var response = AJAX.responseText;
popup_data = null;
// After adding a dashlet, go to the choosen dashboard
- if (response)
- window.location.href = response;
+ if (response.substr(0, 2) == "OK") {
+ window.location.href = response.substr(3);
+ } else {
+ alert("Failed to add element: "+response);
+ }
}
+// FIXME: Adapt error handling which has been addded to add_to_visual() in the meantime
function pagetype_add_to_container(page_type, page_name)
{
var element_type = popup_data[0]; // e.g. 'pnpgraph'