<%page args="element, widgetstyle" /> <%namespace file="../_helpers.html" import="wireElementEvents"/> <% from splunk.appserver.mrsparkle.lib import eai import splunk.util as util option_map = util.OrderedDict() selected_options = [] fetch_error = False elementName = element.get('elementName') try: caseSensitive = True if 'caseSensitiveMatch' in element and element['caseSensitiveMatch'].lower() == 'true' else False # Ensure that only valid options can be selected option_values = set([ (caseSensitive and option['value'] or option['value'].lower()) for option in element['options'] ]) if elementName in form_defaults and \ isinstance(form_defaults[elementName], (tuple, list)): selected_options = [ val for val in form_defaults[elementName] if (caseSensitive and val or val.lower()) in option_values ] # if only * is among selected elements, assume all elements selected if len(selected_options) == 0 and \ len(form_defaults[elementName]) == 1 and form_defaults[elementName][0] == '*': selected_options = [option.get('label') for option in element["options"]] for option in element["options"]: option_map[option['value']] = option['label'] except eai.EAIFetchError, e: fetch_error = e except splunk.RESTException, e: # Throw a more specific exception if the disk quota has been exceeded. # TODO: Searching for the phrase 'disk space' in the message text is currently how we detect that the exception is related to the disk quota. This is lame. Fix this. msg_txt = e.get_message_text() if e.statusCode == 503 and 'disk space' in msg_txt: raise splunk.QuotaExceededException(msg_txt) raise for selection in selected_options: if selection not in option_map: option_map[selection] = selection option_list = option_map.items() if 'sort' in element: sortMethod = element.get('sort').lower() if sortMethod != 'none': option_list.sort(key=(lambda x: x[1].lower())) available_heading = _("Available %(fields)s") % { 'fields': _(element.get('label', '')) or _(element.get('elementName', ''))} selected_heading = _("Selected %(fields)s") % { 'fields': _(element.get('label', '')) or _(element.get('elementName', ''))} %> ## Note: onChange events are wired up by initAccumulators() in admin.js
% if fetch_error:
${_('Failed to fetch data: ')}${str(fetch_error)|h}
% endif
% if element.get('disabled') is None: ${_('add all')} » % endif

${available_heading|h}

## This ul contains all options that are NOT currently selected
    % for (value, label) in option_list:
  • ${label | h}
  • % endfor
% if element.get('disabled') is None: « ${_('clear all')} % endif

${selected_heading|h}

## This ul contains all options that are ARE currently selected
    % for (value, label) in option_list: % if value in selected_options:
  • ${label | h}
  • % endif % endfor
% if 'exampleText' in element:

${_(element['exampleText']) | extract_help_links }

% endif