Module: check_mk
Branch: master
Commit: 6119f4104d9fc5618fe7dbf26d85c3960a11b9a9
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6119f4104d9fc5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 1 10:24:22 2011 +0200
The progress dialog now supports a optional URL to redirect to when nothing has been found
---
web/htdocs/js/wato.js | 37 +++++++++++++++++++++++++++----------
web/htdocs/wato.py | 11 +++++++----
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index 1779d93..7e3d447 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -83,8 +83,17 @@ var progress_items = null;
var failed_items = null;
// Number of total items to handle
var progress_total_num = 0;
+// Contains the total number of items which have been successfully processed
+// This is e.g. used to decide if the dialog needs to redirect to end_url
+// or to the term_url
+var progress_found = 0;
+// The fields which signal that something has been successfully processed.
+// this is used together with progress_found to find out the correct redirect url
+var progress_success_stats = [];
// The URL to redirect to after finish/abort button pressed
var progress_end_url = '';
+// The URL to redirect to after finish/abort button pressed when nothing found
+var progress_term_url = '';
// The text to show in the progress bar after finished processing
var progress_fin_txt = '';
// Is set to true while one request is waiting for a response
@@ -180,10 +189,14 @@ function progress_finished() {
function progress_end() {
// Mark as ended to catch currently running requests
progress_ended = true;
- location.href = progress_end_url;
+ if(progress_found > 0)
+ location.href = progress_end_url;
+ else
+ location.href = progress_term_url;
}
function clear_progress_stats() {
+ progress_found = 0
for(var i = 1; i < 100; i++) {
var o = document.getElementById('progress_stat' + (i - 1));
if (o) {
@@ -199,6 +212,8 @@ function update_progress_stats(header) {
for(var i = 1; i < header.length; i++) {
var o = document.getElementById('progress_stat' + (i - 1));
if (o) {
+ if(progress_success_stats.indexOf(i) !== -1)
+ progress_found += parseInt(header[i]);
o.innerHTML = parseInt(o.innerHTML) + parseInt(header[i]);
o = null;
}
@@ -237,17 +252,19 @@ function progress_clean_log() {
log = null;
}
-function progress_scheduler(mode, url_prefix, timeout, items, end_url, finished_txt) {
+function progress_scheduler(mode, url_prefix, timeout, items, end_url, success_stats, term_url, finished_txt) {
// Initialize
if (progress_items === null) {
- progress_items = items;
- failed_items = Array();
- progress_total_num = items.length;
- progress_end_url = end_url;
- progress_fin_txt = finished_txt;
- progress_mode = mode;
- progress_url = url_prefix;
- progress_timeout = timeout;
+ progress_items = items;
+ failed_items = Array();
+ progress_total_num = items.length;
+ progress_end_url = end_url;
+ progress_term_url = term_url;
+ progress_success_stats = success_stats;
+ progress_fin_txt = finished_txt;
+ progress_mode = mode;
+ progress_url = url_prefix;
+ progress_timeout = timeout;
}
// Escape the loop when ended
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index a308f82..ad30896 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2200,7 +2200,9 @@ def render_folder_path(the_folder = 0, the_file = 0, link_to_last = False):
# | buttons for aborting and pausing. |
# +----------------------------------------------------------------------+
-def interactive_progress(items, title, stats, finishvars, timewait):
+def interactive_progress(items, title, stats, finishvars, timewait, success_stats = [], termvars = []):
+ if not termvars:
+ termvars = finishvars;
html.write("<center>")
html.write("<table class=progress>")
html.write("<tr><th colspan=2>%s</th></tr>" % title)
@@ -2227,13 +2229,14 @@ def interactive_progress(items, title, stats, finishvars, timewait):
html.write("</td></tr>")
html.write("</table>")
html.write("</center>")
- json_items = '[ %s ]' % ','.join([ "'" + h + "'" for h in items ])
+ json_items = '[ %s ]' % ','.join([ "'" + h + "'" for h in items ])
+ success_stats = '[ %s ]' % ','.join(success_stats)
# Remove all sel_* variables. We do not need them for our ajax-calls.
# They are just needed for the Abort/Finish links. Those must be converted
# to POST.
base_url = html.makeuri([], remove_prefix = "sel_")
- html.javascript(('progress_scheduler("%s", "%s", 50, %s, "%s", "' + _("FINISHED.") + '");') %
- (html.var('mode'), base_url, json_items, html.makeuri(finishvars)))
+ html.javascript(('progress_scheduler("%s", "%s", 50, %s, "%s", %s, "%s", "' + _("FINISHED.") + '");') %
+ (html.var('mode'), base_url, json_items, html.makeuri(finishvars), success_stats, html.makeuri(termvars),))
# +----------------------------------------------------------------------+
# | _ _ _ _ _ _ |