Exemple #1
0
    def add_type(self, type, item_def, dependencies=None):
        """
    Description:
    ------------

    Attributes:
    ----------
    :param type: String.
    :param item_def: String.
    :param dependencies: List. Optional. The external module dependencies
    """
        if dependencies is not None:
            for d in dependencies:
                if d in Imports.JS_IMPORTS:
                    self._report.jsImports.add(d)
                if d in Imports.CSS_IMPORTS:
                    self._report.cssImport.add(d)
        self.style.css.padding_left = 0
        self.css({"list-style": 'none'})
        self._jsStyles['items_type'] = type
        item_type_name = "%s%s" % (self._prefix, self._jsStyles['items_type'])
        constructors = self._report._props.setdefault("js", {}).setdefault(
            "constructors", {})
        constructors[
            item_type_name] = "function %s(htmlObj, data, options){%s}" % (
                item_type_name, JsHtmlList.JsItemsDef().custom(item_def))
        return self
Exemple #2
0
    def dom(self):
        """
    Description:
    ------------

    :rtype: JsHtmlList.JsItem
    """
        if self._dom is None:
            self._dom = JsHtmlList.JsItem(self, report=self._report)
        return self._dom
Exemple #3
0
    def add_type(self,
                 name: str,
                 item_def: Optional[str] = None,
                 func_name: Optional[str] = None,
                 dependencies: list = None):
        """
    Description:
    ------------
    Add a bespoke item type with it is specific style and components.

    TODO: Create a tutorial to explain how to extend list types.

    Attributes:
    ----------
    :param str name: The reference of this type name in the framework.
    :param Optional[str] item_def: The definition of the items (examples in JsHtmlList.py).
    :param Optional[str] func_name: The external function name used to build the items.
    :param Optional[List[str]] dependencies: Optional. The external module dependencies.
    """
        if dependencies is not None:
            for d in dependencies:
                if d in Imports.JS_IMPORTS:
                    self.page.jsImports.add(d)
                if d in Imports.CSS_IMPORTS:
                    self.page.cssImport.add(d)
        self.style.css.padding_left = 0
        self.css({"list-style": 'none'})
        self.options.items_type = name
        if func_name is not None:
            self.__external_item = True
            item_type_name = "%s%s" % (self.options.prefix,
                                       self.options.items_type)
            self.page.properties.js.add_constructor(
                item_type_name, "function %s(htmlObj, data, options){%s}" %
                (item_type_name, JsHtmlList.JsItemsDef(self).custom(
                    "var item = %s(htmlObj, data, options)" % func_name)))
        else:
            item_type_name = "%s%s" % (self.options.prefix,
                                       self.options.items_type)
            self.page.properties.js.add_constructor(
                item_type_name, "function %s(htmlObj, data, options){%s}" %
                (item_type_name, JsHtmlList.JsItemsDef(self).custom(item_def)))
        return self
Exemple #4
0
  def dom(self) -> JsHtmlList.Tags:
    """
    Description:
    -----------
    The Javascript Dom object.

    :rtype: JsHtmlList.Tags
    """
    if self._dom is None:
      self._dom = JsHtmlList.Tags(self, page=self.page)
    return self._dom
Exemple #5
0
  def dom(self):
    """
    Description:
    -----------
    The Javascript Dom object

    :rtype: JsHtmlList.Tags
    """
    if self._dom is None:
      self._dom = JsHtmlList.Tags(self, report=self._report)
    return self._dom
Exemple #6
0
    def dom(self) -> JsHtmlList.JsItem:
        """
    Description:
    ------------
    Return all the Javascript functions defined for an HTML Component.
    Those functions will use plain javascript by default.

    :rtype: JsHtmlList.JsItem
    """
        if self._dom is None:
            self._dom = JsHtmlList.JsItem(self, page=self.page)
        return self._dom
Exemple #7
0
 def __str__(self):
     item_type_name = "%s%s" % (self.options.prefix,
                                self.options.items_type)
     self.options.style_select = "list_%s_selected" % self.options.items_type
     # add all the shape definitions
     if not self.page.properties.js.has_constructor(
             item_type_name) and not self.__external_item:
         shapes = JsHtmlList.JsItemsDef(self)
         self.page.properties.js.add_constructor(
             item_type_name, "function %s(htmlObj, data, options){%s}" %
             (item_type_name, getattr(shapes, self.options.items_type)(
                 self.page)))
     self.page.properties.js.add_builders(self.refresh())
     return '<ul %s></ul>%s' % (self.get_attrs(
         css_class_names=self.style.get_classes()), self.helper)
Exemple #8
0
 def __str__(self):
     item_type_name = "%s%s" % (self._prefix, self._jsStyles['items_type'])
     constructors = self._report._props.setdefault("js", {}).setdefault(
         "constructors", {})
     if not item_type_name in constructors:
         # add all the shape definitions
         shapes = JsHtmlList.JsItemsDef()
         constructors[
             item_type_name] = "function %s(htmlObj, data, options){%s}" % (
                 item_type_name,
                 getattr(shapes, self._jsStyles['items_type'])(
                     self._report))
     self._report._props.setdefault('js', {}).setdefault(
         "builders", []).append(self.refresh())
     return '<ul %s></ul>' % self.get_attrs(
         pyClassNames=self.style.get_classes())