コード例 #1
0
def init_rowselect(view):
    # Don't make rows selectable when no commands can be fired
    # Ignore "C" display option here. Otherwise the rows will not be selectable
    # after view reload.
    if not config.user.may("general.act"):
        return

    selected = weblib.get_rowselection('view-' + view['name'])
    selection_properties = {
        "page_id": "view-%s" % view['name'],
        "selection_id": weblib.selection_id(),
        "selected_rows": selected,
    }
    html.javascript("cmk.selection.init_rowselect(%s);" %
                    (json.dumps(selection_properties)))
コード例 #2
0
ファイル: folders.py プロジェクト: spearheadsys/checkmk
    def _show_hosts(self):
        if not self._folder.has_hosts():
            return

        show_checkboxes = html.request.var('show_checkboxes', '0') == '1'

        hostnames = self._folder.hosts().keys()
        hostnames.sort(key=functools.cmp_to_key(utils.cmp_num_split))
        search_text = html.request.var("search")

        # Helper function for showing bulk actions. This is needed at the bottom
        # of the table of hosts and - if there are more than just a few - also
        # at the top of the table.
        search_shown = False

        # Show table of hosts in this folder
        html.begin_form("hosts", method="POST")
        with table_element("hosts",
                           title=_("Hosts"),
                           searchable=False,
                           omit_empty_columns=True) as table:

            # Remember if that host has a target folder (i.e. was imported with
            # a folder information but not yet moved to that folder). If at least
            # one host has a target folder, then we show an additional bulk action.
            at_least_one_imported = False
            more_than_ten_items = False
            for num, hostname in enumerate(hostnames):
                if search_text and (search_text.lower()
                                    not in hostname.lower()):
                    continue

                host = self._folder.host(hostname)
                effective = host.effective_attributes()

                if effective.get("imported_folder"):
                    at_least_one_imported = True

                if num == 11:
                    more_than_ten_items = True

            # Compute colspan for bulk actions
            colspan = 6
            for attr in host_attribute_registry.attributes():
                if attr.show_in_table():
                    colspan += 1
            if not self._folder.locked_hosts() and config.user.may(
                    "wato.edit_hosts") and config.user.may("wato.move_hosts"):
                colspan += 1
            if show_checkboxes:
                colspan += 1
            if self._folder.is_search_folder():
                colspan += 1

            # Add the bulk action buttons also to the top of the table when this
            # list shows more than 10 rows
            if more_than_ten_items and \
                (config.user.may("wato.edit_hosts") or config.user.may("wato.manage_hosts")):
                self._bulk_actions(table, at_least_one_imported, True, True,
                                   colspan, show_checkboxes)
                search_shown = True

            contact_group_names = load_contact_group_information()

            host_errors = self._folder.host_validation_errors()
            rendered_hosts = []

            # Now loop again over all hosts and display them
            for hostname in hostnames:
                self._show_host_row(rendered_hosts, table, hostname,
                                    search_text, show_checkboxes, colspan,
                                    host_errors, contact_group_names)

            if config.user.may("wato.edit_hosts") or config.user.may(
                    "wato.manage_hosts"):
                self._bulk_actions(table, at_least_one_imported, False,
                                   not search_shown, colspan, show_checkboxes)

        html.hidden_fields()
        html.end_form()

        selected = weblib.get_rowselection('wato-folder-/' +
                                           self._folder.path())

        row_count = len(rendered_hosts)
        headinfo = "%d %s" % (row_count,
                              _("host") if row_count == 1 else _("hosts"))
        html.javascript("cmk.utils.update_header_info(%s);" %
                        json.dumps(headinfo))

        if show_checkboxes:
            selection_properties = {
                "page_id": "wato-folder-%s" % ('/' + self._folder.path()),
                "selection_id": weblib.selection_id(),
                "selected_rows": selected,
            }
            html.javascript('cmk.selection.init_rowselect(%s);' %
                            (json.dumps(selection_properties)))