Skip to content
Permalink
Browse files

First step for new implementation of visuals

  • Loading branch information
MathiasKettner committed Apr 27, 2015
1 parent deca66f commit 2589a36270b5e53581b0cbfb3324f49c830eeef9
@@ -143,6 +143,7 @@ def load():

loaded_with_language = current_language

# TODO: This has been obsoleted by pagetypes.py
def declare_visual_permissions(what, what_plural):
config.declare_permission("general.edit_" + what,
_("Customize %s and use them") % what_plural,
@@ -136,9 +136,14 @@ def omd_mode(self):
omd_mode = 'own'
return (omd_mode, omd_site)

def log(self, msg):
def log(self, *args):
from lib import logger, LOG_NOTICE
logger(LOG_NOTICE, msg)
for arg in args:
if type(arg) in (str, unicode):
text = arg
else:
text = repr(arg)
logger(LOG_NOTICE, text)

def http_redirect(self, url):
self.set_http_header('Location', url)
@@ -311,9 +311,6 @@ def makeuri(self, addvars, remove_prefix=None, filename=None, delvars=None):
else:
return filename

def makeactionuri(self, addvars):
return self.makeuri(addvars + [("_transid", self.get_transid())])

def makeuri_contextless(self, vars, filename=None):
if not filename:
filename = self.myfile + ".py"
@@ -322,6 +319,12 @@ def makeuri_contextless(self, vars, filename=None):
else:
return filename

def makeactionuri(self, addvars, filename=None):
return self.makeuri(addvars + [("_transid", self.get_transid())], filename=filename)

def makeactionuri_contextless(self, addvars, filename=None):
return self.makeuri_contextless(addvars + [("_transid", self.get_transid())], filename=filename)

def image_button(self, varname, title, cssclass = ''):
if not self.mobile:
self.write('<label for="%s" class="image_button">' % self.attrencode(varname))
@@ -35,7 +35,7 @@
import sys, os, pprint
from lib import *
import livestatus
import defaults, config, login, userdb, hooks, visuals, default_permissions
import defaults, config, login, userdb, hooks, visuals, default_permissions, pagetypes

if os.path.exists(os.path.dirname(os.path.abspath(__file__)) + '/reporting.py'):
import reporting
@@ -44,24 +44,30 @@

from html_mod_python import *

# Load page handlers
pagehandlers = {}
pagehandlers_dir = defaults.web_dir + "/plugins/pages"
for fn in os.listdir(pagehandlers_dir):
if fn.endswith(".py"):
execfile(pagehandlers_dir + "/" + fn)

# prepare local-structure within OMD sites
if defaults.omd_root:
local_module_path = defaults.omd_root + "/local/share/check_mk/web/htdocs"
local_locale_path = defaults.omd_root + "/local/share/check_mk/locale"
if local_module_path not in sys.path:
sys.path[0:0] = [ local_module_path, defaults.web_dir + "/htdocs" ]
local_pagehandlers_dir = defaults.omd_root + "/local/share/check_mk/web/plugins/pages"
if os.path.exists(local_pagehandlers_dir):
for fn in os.listdir(local_pagehandlers_dir):
if fn.endswith(".py"):
execfile(local_pagehandlers_dir + "/" + fn)

# Load page handlers
def load_page_handlers():
global pagehandlers
pagehandlers = {}
pagehandlers_dir = defaults.web_dir + "/plugins/pages"
for fn in os.listdir(pagehandlers_dir):
if fn.endswith(".py"):
execfile(pagehandlers_dir + "/" + fn, globals(), globals())

if defaults.omd_root:
local_pagehandlers_dir = defaults.omd_root + "/local/share/check_mk/web/plugins/pages"
if os.path.exists(local_pagehandlers_dir):
for fn in os.listdir(local_pagehandlers_dir):
if fn.endswith(".py"):
execfile(local_pagehandlers_dir + "/" + fn, globals(), globals())

load_page_handlers()


# Call the load_plugins() function in all modules
@@ -137,6 +143,9 @@ def handler(req, fields = None, profiling = True):
# time before the first login for generating auth.php.
load_all_plugins()

# Install page handlers created by the pagetypes.py modules
pagehandlers.update(pagetypes.page_handlers())

# Detect mobile devices
if html.has_var("mobile"):
html.mobile = not not html.var("mobile")
@@ -2464,6 +2464,8 @@ function fix_popup_menu_position(event, menu) {
}
}

// TODO: Remove this function as soon as all visuals have been
// converted to pagetypes.py
function add_to_visual(visual_type, visual_name)
{
close_popup();
@@ -2492,6 +2494,27 @@ function add_to_visual(visual_type, visual_name)
window.location.href = response;
}

function pagetype_add_to_container(page_type, page_name)
{
var element_type = popup_data[0]; // e.g. 'graph'
var create_info = popup_data[1]; // complex JSON struct describing the thing
var create_info_json = JSON.stringify(create_info);

close_popup();

response = get_url_sync('ajax_pagetype_add_element.py'
+ '?page_type=' + page_type
+ '&page_name=' + page_name
+ '&element_type=' + element_type
+ '&create_info=' + encodeURIComponent(create_info_json));
popup_data = null;

// After adding an element, the page type might want us to send to the
// container
if (response)
window.location.href = response;
}

//#.
//# .-HoverMenu----------------------------------------------------------.
//# | _ _ __ __ |

0 comments on commit 2589a36

Please sign in to comment.
You can’t perform that action at this time.