Ejemplo n.º 1
0
def _get_jquery_for_component(component):
    if isinstance(component, _anvil.Button):
        return _S(_js.get_dom_node(component).firstElementChild)
    elif isinstance(component, _anvil.FileLoader):
        return _S(_js.get_dom_node(component)).find('form')
    else:
        return _S(_js.get_dom_node(component))
Ejemplo n.º 2
0
def _get_jquery_for_component(component):
    if isinstance(component, _anvil.Button):
        return _S(_js.get_dom_node(component).firstElementChild)
    elif isinstance(component, _anvil.FileLoader):
        return _S(_js.get_dom_node(component)).find("form")
    elif isinstance(component, (_anvil.CheckBox, _anvil.RadioButton)):
        return _S(_js.get_dom_node(component)).find("input")
    else:
        return _S(_js.get_dom_node(component))
Ejemplo n.º 3
0
def setup_editor_component(component, cancel, onRendered):
    closed = {}
    def blur_cancel(e):
        # hack for datepicker
        relatedTarget = getattr(e, 'relatedTarget', None)
        if not e.target.parentElement.classList.contains('anvil-datepicker') or (relatedTarget and relatedTarget.tagName != 'SELECT'):
          if closed:
            return
          closed['x'] = True
          cancel()

    el = get_dom_node(component)
    el.addEventListener('blur', blur_cancel, True)
    el.style.padding = '8px'
    def close_editor(**event_args):
        if closed:
          return
        else:
          closed['x'] = True
        cancel()
        component.remove_from_parent()

    component.set_event_handler('x-close-editor', close_editor)
    
    def set_focus(*args):
        to_focus = el.querySelector(':not(div)')
        to_focus = to_focus or el
        to_focus.focus()
    onRendered(set_focus)
    return el
Ejemplo n.º 4
0
 def __init__(self, track_colour, indicator_colour, **properties):
     self.indicator_dom_node = get_dom_node(self.indicator_panel)
     self.role = "progress-track"
     self.indicator_panel.role = "progress-indicator"
     self.background = track_colour
     self.indicator_panel.background = indicator_colour
     self.init_components(**properties)
Ejemplo n.º 5
0
    def __init__(self, **properties):
        # Set Form properties and Data Bindings.
        self._init = False

        self._dom_node = _js.get_dom_node(self)
        _S_dom_node = _S(self._dom_node)
        self._el = _S_dom_node.find("select")

        _S_dom_node.html("").append(self._el)
        # remove all the script tags before they load into the dom

        self._values = {}
        self._invalid = []
        # Any code you write here will run when the form opens
        self._props = props = _defaults | properties
        props["items"] = props["items"] or []
        selected = props.pop("selected", ())

        self.init_components(**props)

        self._el.selectpicker()
        self._el.on("changed.bs.select", self.change)
        self._el.on("shown.bs.select", self._opened)
        self._el.on("hidden.bs.select", self._closed)
        self.set_event_handler("x-popover-init", self._mk_popover)
        if selected:
            self.selected = selected
        self._user_selected_all(False)
        menu = self._el.data("selectpicker")["$menu"]
        menu.find(".bs-actionsbox").on("click", self._user_selected_all)
        self._init = True
Ejemplo n.º 6
0
 def loadComponentCell(cell, formatterParams, onRendered):
     formatterParams = formatterParams or {}
     if is_template:
         component = formatter(item={**cell.getData()}, **formatterParams)
     else:
         component = formatter(**formatterParams)
     self.add_component(component) # make sure we have a parent
     return get_dom_node(component)
Ejemplo n.º 7
0
 def loadFunctionCell(cell, formatterParams, onRendered):
     formatterParams = formatterParams or {}
     row = dict(cell.getData())
     cell_component_or_str = formatter(row, **formatterParams)
     if isinstance(cell_component_or_str, str):
         return cell_component_or_str
     elif isinstance(cell_component_or_str, Component):
         self.add_component(cell_component_or_str)
         return get_dom_node(cell_component_or_str)
     else:
         # oops hope for the best
         return cell_component_or_str
Ejemplo n.º 8
0
    def __init__(self, track_colour, indicator_colour, **properties):
        dom_node = get_dom_node(self)
        dom_node.style.setProperty("background-color", indicator_colour)

        indicator_id = _get_dom_node_id(self.indicator_panel)
        css = f"""
#{indicator_id}:before {{
  background-color: {track_colour}
}}
"""
        _html_injector.css(css)
        self.role = "progress-track"
        self.indicator_panel.role = "indeterminate-progress-indicator"
        self.indicator_panel.background = indicator_colour
        self.init_components(**properties)
Ejemplo n.º 9
0
def _set_pagination_handlers(data_grid, handler):
    grid_dom = _js.get_dom_node(data_grid)
    for name in ["first", "last", "previous", "next"]:
        btn = grid_dom.querySelector(f".{name}-page")
        # use True so that we capture this event before the anvil click event
        btn.addEventListener("click", _prevent_disabled, True)
        btn.addEventListener(
            "click",
            _wrap_js_event(
                _partial(
                    handler,
                    sender=data_grid,
                    button=name,
                    event_name="pagination_click",
                )),
        )