Module: check_mk
Branch: master
Commit: b48cc5f2fb47b8bae23808a682a96cc0082c6fa3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b48cc5f2fb47b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 21 10:08:37 2018 +0100
Moved backup logic to dedicated module
Change-Id: If3c379f17e338f2609e7b24627c881dd2fd92121
---
cmk/gui/backup.py | 4 +-
web/htdocs/js/checkmk.js | 89 ----------------------------------
web/htdocs/js/index.js | 2 +
web/htdocs/js/modules/backup.js | 103 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 107 insertions(+), 91 deletions(-)
diff --git a/cmk/gui/backup.py b/cmk/gui/backup.py
index e89facb..5a80059 100644
--- a/cmk/gui/backup.py
+++ b/cmk/gui/backup.py
@@ -821,8 +821,8 @@ class PageAbstractBackupJobState(object):
html.open_div(id_="job_details")
self.show_job_details()
html.close_div()
- html.javascript("refresh_job_details('%s', '%s', %s)" %
(self._update_url(), self._ident,
- "true" if
is_site() else "false"))
+ html.javascript("cmk.backup.refresh_job_details('%s', '%s',
%s)" %
+ (self._update_url(), self._ident, "true" if is_site()
else "false"))
def _update_url(self):
return "ajax_backup_job_state.py?job=%s" % self._ident
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 6e6b487..8ed7c5e 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -2379,92 +2379,3 @@ function hover_menu_in_screen(hoverMenu, hoverSpacer)
return true;
}
-
-//#.
-//# .-Backup-------------------------------------------------------------.
-//# | ____ _ |
-//# | | __ ) __ _ ___| | ___ _ _ __ |
-//# | | _ \ / _` |/ __| |/ / | | | '_ \ |
-//# | | |_) | (_| | (__| <| |_| | |_) | |
-//# | |____/ \__,_|\___|_|\_\\__,_| .__/ |
-//# | |_| |
-//# +--------------------------------------------------------------------+
-//# | |
-//# '--------------------------------------------------------------------'
-
-function refresh_job_details(url, ident, is_site)
-{
- setTimeout(function() {
- do_job_detail_refresh(url, ident, is_site);
- }, 1000);
-}
-
-function do_job_detail_refresh(url, ident, is_site)
-{
- call_ajax(url, {
- method : "GET",
- post_data : "job=" + encodeURIComponent(ident),
- response_handler : handle_job_detail_response,
- error_handler : handle_job_detail_error,
- handler_data : {
- "url" : url,
- "ident" : ident,
- "is_site" : is_site,
- }
- });
-}
-
-function handle_job_detail_response(handler_data, response_body)
-{
- // when a message was shown and now not anymore, assume the job has finished
- var had_message = document.getElementById("job_detail_msg") ? true :
false;
-
- var container = document.getElementById("job_details");
- container.innerHTML = response_body;
-
- if (!had_message) {
- refresh_job_details(handler_data["url"],
handler_data["ident"], handler_data["is_site"]);
- }
- else {
- cmk.utils.reload_sidebar();
- window.location.reload();
- }
-}
-
-function handle_job_detail_error(handler_data, status_code, error_msg)
-{
- hide_job_detail_msg();
-
- if (status_code == 0)
- return; // ajax request aborted. Stop refresh.
-
- var container = document.getElementById("job_details");
-
- var msg = document.createElement("div");
- container.insertBefore(msg, container.children[0]);
- msg.setAttribute("id", "job_detail_msg");
- msg.className = "message";
-
- var txt = "Could not update the job details.";
- if (handler_data.is_site)
- txt += " The site will be started again after the restore.";
- else
- txt += " Maybe the device is currently being rebooted.";
-
- txt += "<br>Will continue trying to refresh the job details.";
-
- txt += "<br><br>HTTP status code: "+status_code;
- if (error_msg)
- txt += ", Error: "+error_msg;
-
- msg.innerHTML = txt;
-
- refresh_job_details(handler_data["url"], handler_data["ident"],
handler_data["is_site"]);
-}
-
-function hide_job_detail_msg()
-{
- var msg = document.getElementById("job_detail_msg");
- if (msg)
- msg.parentNode.removeChild(msg);
-}
diff --git a/web/htdocs/js/index.js b/web/htdocs/js/index.js
index 8fe5d44..83a4402 100644
--- a/web/htdocs/js/index.js
+++ b/web/htdocs/js/index.js
@@ -38,6 +38,7 @@ import * as availability from "availability";
import * as sla from "sla";
import * as bi from "bi";
import * as crash_reporting from "crash_reporting";
+import * as backup from "backup";
import * as dashboard from "dashboard";
require("script-loader!./checkmk.js");
@@ -72,6 +73,7 @@ export default {
sla: sla,
bi: bi,
crash_reporting: crash_reporting,
+ backup: backup,
dashboard: dashboard
},
// TODO: Compatibility for not yet modularized JS code
diff --git a/web/htdocs/js/modules/backup.js b/web/htdocs/js/modules/backup.js
new file mode 100644
index 0000000..7f730f2
--- /dev/null
+++ b/web/htdocs/js/modules/backup.js
@@ -0,0 +1,103 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+// +------------------------------------------------------------------+
+//
+// This file is part of Check_MK.
+// The official homepage is at
http://mathias-kettner.de/check_mk.
+//
+// check_mk is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation in version 2. check_mk is distributed
+// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+// PARTICULAR PURPOSE. See the GNU General Public License for more de-
+// ails. You should have received a copy of the GNU General Public
+// License along with GNU Make; see the file COPYING. If not, write
+// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+import * as utils from "utils";
+import * as ajax from "ajax";
+
+export function refresh_job_details(url, ident, is_site)
+{
+ setTimeout(function() {
+ do_job_detail_refresh(url, ident, is_site);
+ }, 1000);
+}
+
+function do_job_detail_refresh(url, ident, is_site)
+{
+ ajax.call_ajax(url, {
+ method : "GET",
+ post_data : "job=" + encodeURIComponent(ident),
+ response_handler : handle_job_detail_response,
+ error_handler : handle_job_detail_error,
+ handler_data : {
+ "url" : url,
+ "ident" : ident,
+ "is_site" : is_site,
+ }
+ });
+}
+
+function handle_job_detail_response(handler_data, response_body)
+{
+ // when a message was shown and now not anymore, assume the job has finished
+ var had_message = document.getElementById("job_detail_msg") ? true :
false;
+
+ var container = document.getElementById("job_details");
+ container.innerHTML = response_body;
+
+ if (!had_message) {
+ refresh_job_details(handler_data["url"],
handler_data["ident"], handler_data["is_site"]);
+ }
+ else {
+ utils.reload_sidebar();
+ window.location.reload();
+ }
+}
+
+function handle_job_detail_error(handler_data, status_code, error_msg)
+{
+ hide_job_detail_msg();
+
+ if (status_code == 0)
+ return; // ajax request aborted. Stop refresh.
+
+ var container = document.getElementById("job_details");
+
+ var msg = document.createElement("div");
+ container.insertBefore(msg, container.children[0]);
+ msg.setAttribute("id", "job_detail_msg");
+ msg.className = "message";
+
+ var txt = "Could not update the job details.";
+ if (handler_data.is_site)
+ txt += " The site will be started again after the restore.";
+ else
+ txt += " Maybe the device is currently being rebooted.";
+
+ txt += "<br>Will continue trying to refresh the job details.";
+
+ txt += "<br><br>HTTP status code: "+status_code;
+ if (error_msg)
+ txt += ", Error: "+error_msg;
+
+ msg.innerHTML = txt;
+
+ refresh_job_details(handler_data["url"], handler_data["ident"],
handler_data["is_site"]);
+}
+
+function hide_job_detail_msg()
+{
+ var msg = document.getElementById("job_detail_msg");
+ if (msg)
+ msg.parentNode.removeChild(msg);
+}