Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / cmk / gui / display_options.py
blob9ade0ec9b32898a17c179303494b2cd1dca33337
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | copyright mathias kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # this file is part of check_mk.
14 # the official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the gnu general public license as published by
18 # the free software foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but without any warranty; with-
20 # out even the implied warranty of merchantability or fitness for a
21 # particular purpose. see the gnu general public license for more de-
22 # tails. you should have received a copy of the gnu general public
23 # license along with gnu make; see the file copying. if not, write
24 # to the free software foundation, inc., 51 franklin st, fifth floor,
25 # boston, ma 02110-1301 usa.
27 from cmk.gui.globals import html
30 # .--Display Opts.-------------------------------------------------------.
31 # | ____ _ _ ___ _ |
32 # | | _ \(_)___ _ __ | | __ _ _ _ / _ \ _ __ | |_ ___ |
33 # | | | | | / __| '_ \| |/ _` | | | | | | | | '_ \| __/ __| |
34 # | | |_| | \__ \ |_) | | (_| | |_| | | |_| | |_) | |_\__ \_ |
35 # | |____/|_|___/ .__/|_|\__,_|\__, | \___/| .__/ \__|___(_) |
36 # | |_| |___/ |_| |
37 # +----------------------------------------------------------------------+
38 # | Display options are flags that control which elements of a view |
39 # | should be displayed (buttons, sorting, etc.). They can be specified |
40 # | via the URL variable display_options. |
41 # | An upper-case char means enabled, lower-case means disabled. |
42 # '----------------------------------------------------------------------'
45 class DisplayOptions(object):
46 H = "H" # The HTML header and body-tag (containing the tags <HTML> and <BODY>)
47 T = "T" # The title line showing the header and the logged in user
48 B = "B" # The blue context buttons that link to other views
49 F = "F" # The button for using filters
50 C = "C" # The button for using commands and all icons for commands (e.g. the reschedule icon)
51 O = "O" # The view options number of columns and refresh
52 D = "D" # The Display button, which contains column specific formatting settings
53 E = "E" # The button for editing the view
54 Z = "Z" # The footer line, where refresh: 30s is being displayed
55 R = "R" # The auto-refreshing in general (browser reload)
56 S = "S" # The playing of alarm sounds (on critical and warning services)
57 U = "U" # Load persisted user row selections
58 I = "I" # All hyperlinks pointing to other views
59 X = "X" # All other hyperlinks (pointing to external applications like PNP, WATO or others)
60 M = "M" # If this option is not set, then all hyperlinks are targeted to the HTML frame
61 # with the name main. This is useful when using views as elements in the dashboard.
62 L = "L" # The column title links in multisite views
63 W = "W" # The limit and livestatus error message in views
64 N = "N" # Switching to inline display mode when disabled
65 # (e.g. no padding round page)
67 @classmethod
68 def all_on(cls):
69 opts = ""
70 for k in sorted(cls.__dict__.keys()):
71 if len(k) == 1:
72 opts += k
73 return opts
75 @classmethod
76 def all_off(cls):
77 return cls.all_on().lower()
79 def __init__(self):
80 super(DisplayOptions, self).__init__()
81 self.options = self.all_off()
82 self.title_options = None
84 def load_from_html(self):
85 # Parse display options and
86 if html.output_format == "html":
87 options = html.request.var("display_options", "")
88 else:
89 options = display_options.all_off()
91 # Remember the display options in the object for later linking etc.
92 self.options = self._merge_with_defaults(options)
94 # This is needed for letting only the data table reload. The problem is that
95 # the data table is re-fetched via javascript call using special display_options
96 # but these special display_options must not be used in links etc. So we use
97 # a special var _display_options for defining the display_options for rendering
98 # the data table to be reloaded. The contents of "display_options" are used for
99 # linking to other views.
100 if html.request.has_var('_display_options'):
101 self.options = self._merge_with_defaults(html.request.var("_display_options", ""))
103 # But there is one special case: The sorter links! These links need to know
104 # about the provided display_option parameter. The links could use
105 # "display_options.options" but this contains the implicit options which should
106 # not be added to the URLs. So the real parameters need to be preserved for
107 # this case.
108 self.title_options = html.request.var("display_options")
110 # If display option 'M' is set, then all links are targetet to the 'main'
111 # frame. Also the display options are removed since the view in the main
112 # frame should be displayed in standard mode.
113 if self.disabled(self.M):
114 html.set_link_target("main")
115 html.request.del_var("display_options")
117 # If all display_options are upper case assume all not given values default
118 # to lower-case. Vice versa when all display_options are lower case.
119 # When the display_options are mixed case assume all unset options to be enabled
120 def _merge_with_defaults(self, opts):
121 do_defaults = self.all_off() if opts.isupper() else self.all_on()
122 for c in do_defaults:
123 if c.lower() not in opts.lower():
124 opts += c
125 return opts
127 def enabled(self, opt):
128 return opt in self.options
130 def disabled(self, opt):
131 return opt not in self.options
134 display_options = DisplayOptions()