Esempio n. 1
0
    def getJsScript(self,
                    url,
                    data,
                    success,
                    dataType='json',
                    jsDataKey=None,
                    isPyData=True,
                    js_func=None,
                    profile=None):
        """
    Description:
    ------------
    Load a JavaScript file from the server using a GET HTTP request, then execute it.

    Related Pages:

      https//api.jquery.com/jQuery.getScript/

    Attributes:
    ----------
    :param url:
    :param data:
    :param success:
    :param dataType:
    :param jsDataKey:
    :param isPyData:
    :param js_func:
    """
        success = JsUtils.jsConvertFncs(success, toStr=True, profile=profile)
        data = JsUtils.jsConvert(data, jsDataKey, isPyData, js_func)
        return Jsjqxhr(
            "jQuery.getScript('%s', {data: JSON.stringify(%s)}, function(data, textStatus, jqxhr) {%s}, '%s')"
            % (url, data, success, dataType))
Esempio n. 2
0
    def getJSON(self,
                url,
                data,
                success,
                dataType='json',
                jsDataKey=None,
                isPyData=True,
                js_func=None,
                profile=None):
        """
    Description:
    ------------
    Load JSON-encoded data from the server using a GET HTTP request.

    Related Pages:

      https//api.jquery.com/jQuery.getJSON/#jQuery-getJSON-url-data-success

    Attributes:
    ----------
    """
        success = JsUtils.jsConvertFncs(success, toStr=True, profile=profile)
        data = JsUtils.jsConvert(data, jsDataKey, isPyData, js_func)
        return Jsjqxhr(
            "jQuery.getJSON('%s', {data: JSON.stringify(%s)}, function(data) {%s}, '%s')"
            % (url, data, success, dataType))
Esempio n. 3
0
  def removeItem(self, data, key: Union[str, primitives.JsDataModel] = None, is_py_data: bool = False,
                 js_funcs: Union[list, str] = None):
    """
    Description:
    ------------
    Syntax for REMOVING ALL saved data from sessionStorage.

    The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

    Usage::

      jsObj.sessionStorage.removeItem("lastname")

    Related Pages:

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

    Attributes:
    ----------
    :param data:
    :param key:
    :param bool is_py_data:
    :param Union[list, str] js_funcs:
    """
    data = JsUtils.jsConvert(data, key, is_py_data, js_funcs)
    return JsFncs.JsFunction("sessionStorage.removeItem(%s)" % data)
Esempio n. 4
0
    def get(self, jsData=None, jsDataKey=None, isPyData=True, jsFnc=None):
        """

    :return:
    """
        if jsData is None:
            return Js.JsJson().parse("decodeURIComponent(document.cookies)",
                                     isPyData=False)

        jsData = JsUtils.jsConvert(jsData, jsDataKey, isPyData, jsFnc)
        return Js.JsJson().parse("decodeURIComponent(document.cookies)['%s']" %
                                 jsData,
                                 isPyData=False)
Esempio n. 5
0
  def getJSON(self, url, jsData, success, dataType='json', jsDataKey=None, isPyData=True, jsFnc=None):
    """
    Load JSON-encoded data from the server using a GET HTTP request.

    Related Pages:

      https//api.jquery.com/jQuery.getJSON/#jQuery-getJSON-url-data-success

    :return:
    """
    success = JsUtils.jsConvertFncs(success)
    jsData = JsUtils.jsConvert(jsData, jsDataKey, isPyData, jsFnc)
    return Jsjqxhr("jQuery.getJSON('%s', {data: JSON.stringify(%s)}, function(data) {%s}, '%s')" % (url, jsData, ";".join(success), dataType))
Esempio n. 6
0
    def set(self, jsKey, jsData, jsDataKey=None, isPyData=True, jsFnc=None):
        """

    Related Pages:

      https//www.w3schools.com/js/js_cookies.asp

    :return:
    """
        jsData = JsUtils.jsConvert(jsData, jsDataKey, isPyData, jsFnc)
        if self.src._context.get('cookies') is None:
            self.src._context['cookies'] = True
            return "document.cookies = {'%s': %s}" % (jsKey, jsData)

        return "document.cookies['%s'] = %s" % (jsKey, jsData)
Esempio n. 7
0
    def splice(self, i, j, jsData, jsFnc=None):
        """
    The splice() method can be used to add new items to an array
    With clever parameter setting, you can use splice() to remove elements without leaving "holes" in the array

    Example

    Documentation:
    https://www.w3schools.com/js/js_array_methods.asp

    :param i: Required. An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array
    :param j: Optional. The number of items to be removed. If set to 0, no items will be removed
    :param jsData: Optional. The new item(s) to be added to the array

    :return: A new Array, containing the removed items (if any)
    """
        jsData = JsUtils.jsConvert(jsData, jsFnc)
        return JsArray("%s.splice(%s, %s, %s)" % (self.varId, i, j, jsData))
Esempio n. 8
0
  def set(self, key: str, data, data_key: str = None, python_data=True, js_funcs: Optional[Union[list, str]] = None):
    """
    Description:
    ------------

    Related Pages:

      https//www.w3schools.com/js/js_cookies.asp

    Attributes:
    ----------
    :param key:
    :param data:
    :param data_key:
    :param python_data:
    :param Optional[Union[list, str]] js_funcs: The Javascript functions.
    """
    data = JsUtils.jsConvert(data, data_key, python_data, js_funcs)
    if self.page._context.get('cookies') is None:
      self.page._context['cookies'] = True
      return "document.cookies = {'%s': %s}" % (key, data)

    return "document.cookies['%s'] = %s" % (key, data)