Exemplo n.º 1
0
 def display_review_tree(self, root_node=True):
     global href_counter
     href_counter = href_counter + 1
     self.href = "item" + str(href_counter)
     has_branches = len(self.branches.elements) > 0
     output = ""
     if root_node:
         output += "<div class=\"just-padding\">"
     if root_node and has_branches:
         output += "<div class=\"list-group list-group-root\">"
     if has_branches:
         output += "<a href=\"#" + self.href + "\" class=\"list-group-item list-group-item-action\" data-toggle=\"collapse\">"
         output += "<i class=\"fa fa-caret-right\"></i>"
     else:
         output += "<div class=\"list-group-item list-group-item-action\">"
     output += self.text
     output += "<p>"
     output += action_button_html(url_action('edit_node',
                                             node=self.instanceName),
                                  label="Edit",
                                  icon="pencil-alt",
                                  color="light",
                                  size="sm")
     if not root_node:
         output += action_button_html(url_action('delete_node',
                                                 node=self.instanceName),
                                      label="Delete",
                                      icon="trash",
                                      color="danger",
                                      size="sm")
     output += action_button_html(url_action('add_subnode',
                                             node=self.instanceName),
                                  label="Add SubNode",
                                  icon="plus",
                                  color="primary",
                                  size="sm")
     output += "</p>"
     if has_branches:
         output += "</a>"
     else:
         output += "</div>"
     if has_branches:
         output += "<div class=\"list-group collapse\" id=\"" + self.href + "\">"
         for b in self.branches:
             output += b.display_review_tree(False)
         output += "</div>"
     if root_node and has_branches:
         output += "</div>"
     if root_node:
         output += "</div>"
     return output
def section_links(nav):
  """Returns a list of clickable navigation links without animation."""
  sections = nav.get_sections()
  section_link = []
  for section in sections:
    for key in section:
      section_link.append('[' + section[key] + '](' + url_action(key) + ')' )

  return section_link    
def get_language_list_item(language, link=True):
  """ Given an ordered tuple, returns a link to the current interview with lang=language code and the link title
    given in the first part of the tuple."""
  li_start = '<li class="list-inline-item">'
  li_end = '</li>'
  
  if link:
    iurl = url_action('change_language', lang = language[1])
    return li_start + '<a target="_self" href="' + iurl + '">' + language[0] + '</a>' + li_end
  else:
    return li_start + language[0] + li_end     
def button_field(buttons):
    """Create a button field, like image buttons but can be used in a question/subquestion. The buttons
  all visit a URL.
  Expects a list of dictionaries, with each dictionary having these keys:
  {
    'label': the label displayed with the link
    'icon': the font-awesome icon, or static image to display in the button
    'new_window': Boolean, optional, controls whether link opens in same/different tab
    'url': the URL the link will visit. Conflicts with action -- this takes precedence
    'action': paramater passed to url_action to generate a Docassemble action URL. Conflicts with url -- url overrides action
  }
  """

    opening = '<fieldset class="da-field-buttons"><legend class="sr-only">Press one of the following buttons:</legend><div>'
    close = "</div></fieldset>"

    html = opening

    for button in buttons:
        # TODO: fix parent CSS so we don't need to hardcode margin
        html += '<a style="margin: .3em;" class="btn btn-da btn-light btn-da btn-da-custom" '
        # Set the target of the link
        if button.get('new_window') is True or button.get('new_window',
                                                          None) is None:
            target = ''
        elif button.get('new_window') is False:
            target = 'target="_self" '
        else:
            target = 'target="' + str(button.get('new_window')) + '" '
        html += target
        if button.get('url'):
            html += 'href="' + button.get('url', '') + '"'
        elif button.get('action'):
            html += 'href="' + url_action(button.get('action', '')) + '"'
        else:
            html += 'href="' + '' + '"'  # This won't make sense, but we can still show a button
        # Close anchor
        html += '>'
        # TODO: fix parent CSS so we don't need to hardcode vertical-align
        html += '<span style="vertical-align: middle; display: inline-block;"><div>'
        if isinstance(button.get('icon'), str):
            icon = re.sub(r'^(fa[a-z])-fa-', r'\1 fa-', button.get('icon'))
            if not re.search(r'^fa[a-z] fa-', icon):
                icon = 'fas fa-' + icon
            icon = '<i class="' + icon + '"></i> '
        else:
            icon = ''
        html += icon + '</div>' + button.get('label', '') + '</span></a>'
    html += close

    return html