Esempio n. 1
0
    def toString(self, explicit: bool = True):
        """
    Description:
    ------------
    Converts an Object to a string, and returns the result

    Usage::

      jsObj.objects.get("MyObject").toString()

    Related Pages:

      https://www.w3schools.com/JS/js_number_methods.asp

    Attributes:
    ----------
    :param bool explicit: Optional, default True. Parameter to force the String conversion on the Js side

    :return: A Javascript String
    """
        from epyk.core.js.primitives import JsString

        if not explicit:
            return JsString.JsString("%s" % self.varId, is_py_data=False)

        return JsString.JsString("%s.toString()" % self.varId,
                                 is_py_data=False)
Esempio n. 2
0
    def href(self,
             href: Union[str, primitives.JsDataModel] = None,
             secured: bool = False):
        """
    Description:
    ------------
    The href property sets or returns the entire URL of the current component.

    Usage::

      page.js.location.href("https://www.w3schools.com/howto/howto_js_fullscreen.asp")

    Related Pages:

      https://www.w3schools.com/jsref/prop_loc_href.asp

    Attributes:
    ----------
    :param Union[str, primitives.JsDataModel] href: Optional. Set the href property.
    :param bool secured: Optional.

    :return: A String, representing the entire URL of the page, including the protocol (like http://).
    """
        if href is None:
            return JsString.JsString("location.href", is_py_data=False)

        if not hasattr(href, 'toStr') and href.startswith("www."):
            href = r"http:\\%s" % href if not secured else r"https:\\%s" % href
        return JsObject.JsObject("location.href = %s" %
                                 JsUtils.jsConvertData(href, None))
Esempio n. 3
0
    def formatMoney(self, jsObj, decPlaces=0, countryCode='UK'):
        """
    Description:
    ------------
    Wrapper function

    Related Pages:

      https://en.wikipedia.org/wiki/Decimal_separator
    https://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html

    Attributes:
    ----------
    :param jsObj: The base Javascript Python object
    :param decPlaces: The number of decimal
    """
        thouSeparator, decSeparator = (
            ",", ".") if countryCode.upper() in ["UK", 'US'] else (" ", ".")
        jsObj.extendProto(self,
                          "formatMoney",
                          '''
      var n = this, decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces, decSeparator = decSeparator == undefined ? "." : decSeparator,
      thouSeparator = thouSeparator == undefined ? "," : thouSeparator, sign = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
      j = (j = i.length) > 3 ? j % 3 : 0;
      return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
      ''',
                          pmts=["decPlaces", "thouSeparator", "decSeparator"])
        from epyk.core.js.primitives import JsString
        return JsString.JsString(
            "%s.formatMoney(%s, '%s', '%s')" %
            (self.varId, decPlaces, thouSeparator, decSeparator),
            isPyData=False)
Esempio n. 4
0
    def join(self, sep: Union[primitives.JsDataModel, str]):
        """
    Description:
    -----------
    The join() method joins the elements of an array into a string, and returns the string.

    Usage::

      page.js.array(varName="newUrl").join("&")

    Related Pages:

      https://www.w3schools.com/jsref/jsref_join.asp

    Attributes:
    ----------
    :param Union[primitives.JsDataModel, str] sep: Optional. The separator to be used. If omitted, the elements are
    separated with a comma.
    :return: A String, representing the array values, separated by the specified separator.
    """
        from epyk.core.js.primitives import JsString

        sep = JsUtils.jsConvertData(sep, None)
        return JsString.JsString(
            "%s.join(%s)" % (self.varId, JsUtils.jsConvertData(sep, None)),
            is_py_data=False)
Esempio n. 5
0
 def var(self):
   """
   Description:
   ------------
   Property to return the variable name as a valid pyJs object
   """
   return JsString.JsString(self.varId, isPyData=False)
Esempio n. 6
0
    def mail(self, mails: List[str], subject: str, body: str):
        """
    Description:
    ------------
    The mailto link when clicked opens users default email program or software.
    A new email page is created with "To" field containing the address of the name specified on the link by default.

    Usage::

      page.js.location.mail(["*****@*****.**"], "This is a test", "This is the email's content")

    Related Pages:

      http://www.tutorialspark.com/html5/HTML5_email_mailto.php

    Attributes:
    ----------
    :param list[str] mails: The email addresses.
    :param str subject: The email's subject.
    :param str body: The email's content.

    :return: THe Javascript string.
    """
        if isinstance(mails, list):
            mails = ";".join(mails)
        return self.href(
            JsString.JsString(
                "'mailto:%s?subject=%s&body='+ encodeURIComponent('%s')" %
                (mails, subject, body),
                is_py_data=False))
Esempio n. 7
0
    def metaKey(self):
        """
    The metaKey property returns a Boolean value that indicates whether or not the "META" key was pressed when a key event was triggered.

    https://www.w3schools.com/jsref/event_metakey.asp
    """
        return JsString.JsString("event.metaKey", isPyData=False)
Esempio n. 8
0
    def href(self, href=None, secured=False):
        """
    Description:
    ------------
    The href property sets or returns the entire URL of the current p

    Usage::

      rptObj.js.location.href("https://www.w3schools.com/howto/howto_js_fullscreen.asp")

    Related Pages:

      https://www.w3schools.com/jsref/prop_loc_href.asp

    Attributes:
    ----------
    :param href: Set the href property

    :return: A String, representing the entire URL of the page, including the protocol (like http://)
    """
        if href is None:
            return JsString.JsString("location.href", isPyData=False)

        if not hasattr(href, 'toStr') and href.startswith("www."):
            href = r"http:\\%s" % href if not secured else r"https:\\%s" % href
        return JsObject.JsObject("location.href = %s" %
                                 JsUtils.jsConvertData(href, None))
Esempio n. 9
0
    def text(self):
        """
    Description:
    -----------

    """
        return JsString.JsString("%s.getData('text')" % self.varId,
                                 isPyData=False)
Esempio n. 10
0
 def text(self):
     """
 Description:
 -----------
 Get text data from a datatransfer object.
 """
     return JsString.JsString("%s.getData('text')" % self.varId,
                              is_py_data=False)
Esempio n. 11
0
    def getData(self, format="text"):
        """
    Description:
    -----------

    :param format:
    """
        return JsString.JsString("%s.getData(%s)" % (self.varId, format),
                                 isPyData=False)
Esempio n. 12
0
    def platform(self):
        """
    The platform property returns the browser platform (operating system)

    Related Pages:

      https://www.w3schools.com/js/js_window_navigator.asp
    """
        return JsString.JsString("navigator.platform", isPyData=False)
Esempio n. 13
0
    def appVersion(self):
        """
    The appVersion property returns version information about the browser

    Related Pages:

      https://www.w3schools.com/js/js_window_navigator.asp
    """
        return JsString.JsString("navigator.appVersion", isPyData=False)
Esempio n. 14
0
    def product(self):
        """
    The product property returns the product name of the browser engine

    Related Pages:

      https://www.w3schools.com/js/js_window_navigator.asp
    """
        return JsString.JsString("navigator.product", isPyData=False)
Esempio n. 15
0
    def appName(self):
        """
    The appName property returns the application name of the browser

    Related Pages:

      https://www.w3schools.com/js/js_window_navigator.asp
    """
        return JsString.JsString("navigator.appName", isPyData=False)
Esempio n. 16
0
    def userAgent(self):
        """
    The userAgent property returns the user-agent header sent by the browser to the server

    Related Pages:

      https://www.w3schools.com/js/js_window_navigator.asp

    """
        return JsString.JsString("navigator.userAgent", isPyData=False)
Esempio n. 17
0
    def currentMonthName(self):
        """
    Description:
    ------------
    Calendar month in plain english. E.x. January

    :return:
    """
        return JsString.JsString("%s.currentYear" % self._src.js.varName,
                                 report=self._report)
Esempio n. 18
0
    def language(self):
        """
    The language property returns the language version of the browser.

    Related Pages:

      https://www.w3schools.com/jsref/prop_nav_language.asp

    :return:
    """
        return JsString.JsString("navigator.language", isPyData=False)
Esempio n. 19
0
    def preventDefault(self):
        """
    Description:
    ------------
    Cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur

    Related Pages:

      https://www.w3schools.com/jsref/event_preventdefault.asp
    """
        return JsString.JsString("event.preventDefault()", isPyData=False)
Esempio n. 20
0
    def timeStamp(self):
        """
    Description:
    ------------
    Returns the time (in milliseconds relative to the epoch) at which the event was created

    Related Pages:

      https://www.w3schools.com/jsref/event_timestamp.asp
    """
        return JsString.JsString("event.timeStamp", isPyData=False)
Esempio n. 21
0
    def rootMargin(self):
        """
    Description:
    ------------
    The IntersectionObserver interface's read-only rootMargin property is a string with syntax similar to that of the CSS margin property.

    Related Pages:

      https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin
    """
        return JsString.JsString("%s.rootMargin", isPyData=False)
Esempio n. 22
0
    def target(self):
        """
    Description:
    ------------
    Returns the element that triggered the event

    Related Pages:

      https://www.w3schools.com/jsref/event_target.asp
    """
        return JsString.JsString("event.target")
Esempio n. 23
0
    def defaultPrevented(self):
        """
    Description:
    ------------
    The defaultPrevented event property checks whether the preventDefault() method was called for the event.

    Related Pages:

      https://www.w3schools.com/jsref/event_defaultprevented.asp
    """
        return JsString.JsString("event.defaultPrevented", isPyData=False)
Esempio n. 24
0
    def metaKey(self):
        """
    Description:
    ------------
    The metaKey property returns a Boolean value that indicates whether or not the "META" key was pressed when a touch event was triggered.

    Related Pages:

      https://www.w3schools.com/jsref/event_touch_metakey.asp
    """
        return JsString.JsString("event.metaKey", isPyData=False)
Esempio n. 25
0
    def cancelBubble(self):
        """
    Description:
    ------------
    The cancelBubble() method prevents the event-flow from bubbling up to parent elements.

    Related Pages:

      https://www.w3schools.com/jsref/event_cancelbubble.asp
    """
        return JsString.JsString("event.cancelBubble = true")
Esempio n. 26
0
    def code(self):
        """
    Description:
    ------------
    The code property returns the key that triggered the event.

    Related Pages:

      https://www.w3schools.com/jsref/event_key_code.asp
    """
        return JsString.JsString("event.code", isPyData=False)
Esempio n. 27
0
    def keyCode(self):
        """
    Description:
    ------------
    The keyCode property returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.

    Related Pages:

      https://www.w3schools.com/jsref/event_key_keycode.asp
    """
        return JsString.JsString("event.keyCode", isPyData=False)
Esempio n. 28
0
    def key(self):
        """
    Description:
    ------------
    The getModifierState() method returns true if the specified modifier key was pressed, or activated.

    Related Pages:

      https://www.w3schools.com/jsref/event_key_key.asp
    """
        return JsString.JsString("event.key", isPyData=False)
Esempio n. 29
0
    def toString(self, explicit=True):
        """
    Converts a Object to a string, and returns the result

    Example
    jsObj.objects.get("MyObject").toString()

    Documentation
    https://www.w3schools.com/JS/js_number_methods.asp

    :param explicit: Optional, default True. Parameter to force the String conversion on the Js side

    :return: A Javascript String
    """
        from epyk.core.js.primitives import JsString

        if not explicit:
            return JsString.JsString("%s" % self.varId, isPyData=False)

        return JsString.JsString("%s.toString()" % self.varId, isPyData=False)
Esempio n. 30
0
    def stopPropagation(self):
        """
    Description:
    ------------
    Prevents further propagation of an event during event flow

    Related Pages:

      https://www.w3schools.com/jsref/event_stoppropagation.asp
    """
        return JsString.JsString("event.stopPropagation()", isPyData=False)