Beispiel #1
0
    def __urlStringFromDict__(parameterDict):
        params = []
        for key, value in parameterDict.iteritems():
            if type(value) in (list, set, tuple):
                for instance in value:
                    params.append("%s=%s" % (key, urllib.quote(interpretAsString(instance))))
            else:
                params.append("%s=%s" % (key, urllib.quote(interpretAsString(value))))

        return "&".join(params)
Beispiel #2
0
    def __urlStringFromDict__(parameterDict):
        params = []
        for key, value in parameterDict.iteritems():
            if type(value) in (list, set, tuple):
                for instance in value:
                    params.append(
                        "%s=%s" %
                        (key, urllib.quote(interpretAsString(instance))))
            else:
                params.append("%s=%s" %
                              (key, urllib.quote(interpretAsString(value))))

        return "&".join(params)
Beispiel #3
0
    def startTag(self):
        """
            Returns the elements html start tag,
                for example '<span class="whateverclass">'
        """
        if not self._tagName:
            return u''

        nativeAttributes = (('name', self.fullName()),
                            ('id', self.fullId()),
                            ('class', self._classes),
                            ('style', self._style),)
        startTag = "<" + self._tagName + " "

        attributes = nativeAttributes
        if self._attributes is not None:
            attributes = chain(attributes, self.attributes.iteritems())
        for key, value in attributes:
            value = interpretAsString(value)
            if value:
                if value == '_BLANK_':
                    value = ""

                if value == '_EMPTY_':
                    startTag += key + " "
                else:
                    startTag += key + '="' + value.replace('"', '&quot;') + '" '

        if self._tagSelfCloses:
            startTag += '/'
        else:
            startTag = startTag[:-1]
        startTag += '>'

        return unicode(startTag)
Beispiel #4
0
    def startTag(self):
        """
            Returns the elements html start tag,
                for example '<span class="whateverclass">'
        """
        if not self.tagName:
            return u''

        self.attributes['name'] = self.fullName()
        self.attributes['id'] = self.fullId()
        self.attributes['class'] = self.classes
        self.attributes['style'] = self.style
        startTag = "<" + self.tagName + " "
        for key, value in self.attributes.iteritems():
            value = interpretAsString(value)
            if value:
                if value == '<BLANK>':
                    value = ""

                if value == '<EMPTY>':
                    startTag += key + " "
                else:
                    startTag += key + '="' + value.replace('"', '&quot;') + '" '

        if self.tagSelfCloses:
            startTag += '/'
        else:
            startTag = startTag[:-1]
        startTag += '>'

        return unicode(startTag)
Beispiel #5
0
    def startTag(self):
        """
            Returns the elements html start tag,
                for example '<span class="whateverclass">'
        """
        if not self.tagName:
            return u''

        self.attributes['name'] = self.fullName()
        self.attributes['id'] = self.fullId()
        self.attributes['class'] = self.classes
        self.attributes['style'] = self.style
        startTag = "<" + self.tagName + " "
        for key, value in self.attributes.iteritems():
            value = interpretAsString(value)
            if value:
                if value == '<BLANK>':
                    value = ""

                if value == '<EMPTY>':
                    startTag += key + " "
                else:
                    startTag += key + '="' + value.replace('"',
                                                           '&quot;') + '" '

        if self.tagSelfCloses:
            startTag += '/'
        else:
            startTag = startTag[:-1]
        startTag += '>'

        return unicode(startTag)
Beispiel #6
0
 def update(self, silent=True, parameters=None, instanceId=None, timeout=0):
     """
         Returns the javascript that will update this control
     """
     if parameters == None:
         parameters = {}
     return "ajaxUpdate('%s', %s, '%s', %d);" % (
         self.jsId(instanceId), interpretAsString(silent),
         self.__urlStringFromDict__(parameters), timeout)
Beispiel #7
0
 def submit(self, silent=False, parameters=None, instanceId=None, timeout=0):
     """
         Returns the javascript that will submit this control
     """
     if parameters == None:
         parameters = {}
     return "ajaxSubmit('%s', %s, '%s', %d);" % (self.jsId(instanceId),
                                             interpretAsString(silent),
                                             self.__urlStringFromDict__(parameters), timeout)
Beispiel #8
0
    def addOption(self, key, value=None, displayKeys=True):
        """
            Adds options based on a key-value dictionary
        """
        newOption = Option()
        if not value:
            value = key

        key = interpretAsString(key)
        value = interpretAsString(value)
        if displayKeys:
            newOption.setValue(value)
            newOption.setText(key)
        else:
            newOption.setValue(key)
            newOption.setText(value)

        newOption.connect('selected', None, self, 'emit', 'selectionChanged')
        return self.addChildElement(newOption)
Beispiel #9
0
    def addOption(self, key, value=None, displayKeys=True):
        """
            Adds options based on a key-value dictionary
        """
        newOption = Option()
        if not value:
            value = key

        key = interpretAsString(key)
        value = interpretAsString(value)
        if displayKeys:
            newOption.setValue(value)
            newOption.setText(key)
        else:
            newOption.setValue(key)
            newOption.setText(value)

        newOption.connect('selected', None, self, 'emit', 'selectionChanged')
        return self.addChildElement(newOption)
Beispiel #10
0
    def jsFunctionAsString(self, jsFunction):
        """
            Creates and returns a jsFunction implementation based on a pased in python function representation
        """
        methodName = jsFunction.__name__
        attributes = list(jsFunction.func_code.co_varnames)
        attributes.reverse()

        if jsFunction.func_defaults:
            methodDefaults = list(jsFunction.func_defaults)
        else:
            methodDefaults = []

        methodDefaults.reverse()

        defaults = {}
        for index, default in enumerate(methodDefaults):
            if type(default) in types.StringTypes:
                default = "'" + default + "'"
            else:
                default = interpretAsString(default)
            defaults[attributes[index]] = default

        attributeValues = {}
        for attribute in attributes:
            if defaults.get(attribute, None) == None:
                attributeValues[attribute] = None

        attributes.reverse()
        script = ["\nfunction %s(%s)" % (methodName, ', '.join(attributes))]
        script.append("{")
        for var, default in defaults.iteritems():
            script.append("\tif(%s == null) var %s = %s;" %
                          (var, var, default))

        for var in attributes:
            if var.startswith("element"):
                script.append('\tvar %s = JUGetElement(%s);' % (var, var))
        script.append(interpretAsString(jsFunction(**attributeValues)))
        script.append("}\n")

        return "\n".join(script)
Beispiel #11
0
    def content(self, formatted=False, *args, **kwargs):
        """
            Overrides the base content method to return the javascript associated with the scriptcontainer
        """
        scriptContent = ";".join([interpretAsString(script) for script in self.scripts()])

        for objectType in self.usedObjects:
            for function in objectType.jsFunctions:
                scriptContent += self.jsFunctionAsString(getattr(objectType, function))

        return scriptContent
Beispiel #12
0
 def setValue(self, value):
     """
         Selects a child select option
     """
     strValue = interpretAsString(value)
     for obj in self.childElements:
         if strValue and ((obj.fullId() == strValue) or (str(obj.value()) == strValue) or
                          (obj._textNode.text() == strValue)):
             obj.select()
         else:
             obj.unselect()
Beispiel #13
0
    def jsFunctionAsString(self, jsFunction):
        """
            Creates and returns a jsFunction implementation based on a pased in python function representation
        """
        methodName = jsFunction.__name__
        attributes = list(jsFunction.func_code.co_varnames)
        attributes.reverse()

        if jsFunction.func_defaults:
            methodDefaults = list(jsFunction.func_defaults)
        else:
            methodDefaults = []

        methodDefaults.reverse()

        defaults = {}
        for index, default in enumerate(methodDefaults):
            if type(default) in types.StringTypes:
                default = "'" + default + "'"
            else:
                default = interpretAsString(default)
            defaults[attributes[index]] = default

        attributeValues = {}
        for attribute in attributes:
            if defaults.get(attribute, None) == None:
                attributeValues[attribute] = None

        attributes.reverse()
        script = ["\nfunction %s(%s)" % (methodName, ", ".join(attributes))]
        script.append("{")
        for var, default in defaults.iteritems():
            script.append("\tif(%s == null) var %s = %s;" % (var, var, default))

        for var in attributes:
            if var.startswith("element"):
                script.append("\tvar %s = JUGetElement(%s);" % (var, var))
        script.append(interpretAsString(jsFunction(**attributeValues)))
        script.append("}\n")

        return "\n".join(script)
Beispiel #14
0
 def setValue(self, value):
     """
         Selects a child select option
     """
     strValue = interpretAsString(value)
     for obj in self.childElements:
         if strValue and ((obj.fullId() == strValue) or
                          (str(obj.value()) == strValue) or
                          (obj.textBeforeChildren == strValue)):
             obj.select()
         else:
             obj.unselect()
Beispiel #15
0
 def updateControls(controls, silent=True, parameters=None, timeout=0):
     """
         Returns the javascript to update a list of controls
     """
     if parameters == None:
         parameters = {}
     for index, control in enumerate(controls):
         if isinstance(control, Base.WebElement):
             controls[index] = control.jsId()
     return "ajaxUpdate(%s, %s, '%s', %d);" % (str(controls),
                                             interpretAsString(silent),
                                             AjaxController.__urlStringFromDict__(parameters), timeout)
Beispiel #16
0
 def updateControls(controls, silent=True, parameters=None, timeout=0):
     """
         Returns the javascript to update a list of controls
     """
     if parameters == None:
         parameters = {}
     for index, control in enumerate(controls):
         if isinstance(control, Base.WebElement):
             controls[index] = control.jsId()
     return "ajaxUpdate(%s, %s, '%s', %d);" % (
         str(controls), interpretAsString(silent),
         AjaxController.__urlStringFromDict__(parameters), timeout)
Beispiel #17
0
    def content(self, variableDict=None, formatted=False):
        """
            Overrides the base content method to return the javascript associated with the scriptcontainer
        """
        scriptContent = ""
        for script in self.scripts():
            scriptContent += interpretAsString(script) + "\n"

        for objectType in self.usedObjects:
            for function in objectType.jsFunctions:
                scriptContent += self.jsFunctionAsString(getattr(objectType, function))

        return scriptContent
Beispiel #18
0
    def content(self, variableDict=None, formatted=False):
        """
            Overrides the base content method to return the javascript associated with the scriptcontainer
        """
        scriptContent = ""
        for script in self.scripts():
            scriptContent += interpretAsString(script) + "\n"

        for objectType in self.usedObjects:
            for function in objectType.jsFunctions:
                scriptContent += self.jsFunctionAsString(
                    getattr(objectType, function))

        return scriptContent
Beispiel #19
0
    def addOption(self, key, value=None, displayKeys=True):
        """
            Adds a new option that can be selected
        """
        newOption = Buttons.Link()
        newOption.setDestination("#Link")
        if not self.options:
            newOption.addClass('selected')
        if not value:
            value = key

        key = interpretAsString(key)
        value = interpretAsString(value)
        if displayKeys:
            newOption.name = value
            newOption.setText(key)
        else:
            newOption.name = key
            newOption.setText(value)

        newOption.addJavascriptEvent('onclick', 'selectUnrolledOption(this);')

        self.options.append(newOption)
        return self.addChildElement(newOption)
Beispiel #20
0
    def addOption(self, key, value=None, displayKeys=True):
        """
            Adds a new option that can be selected
        """
        newOption = Buttons.Link()
        newOption.setDestination("#Link")
        if not self.options:
            newOption.addClass('selected')
        if not value:
            value = key

        key = interpretAsString(key)
        value = interpretAsString(value)
        if displayKeys:
            newOption.name = value
            newOption.setText(key)
        else:
            newOption.name = key
            newOption.setText(value)

        newOption.addJavascriptEvent('onclick', 'selectUnrolledOption(this);')

        self.options.append(newOption)
        return self.addChildElement(newOption)
Beispiel #21
0
 def jsAddFilter(self, filterType, toggledOn):
     """
         Return the javascript to add a filter to the filter list clientside
     """
     return "javascriptAddFilter(this, '" + filterType + "', " + \
                                 interpretAsString(toggledOn) + ");"
Beispiel #22
0
 def do(self, silent=True, parameters=None, instanceId=None):
     if parameters == None:
         parameters = {}
     return "ajaxDo('%s', %s, '%s');" % (
         self.jsId(instanceId), interpretAsString(silent),
         self.__urlStringFromDict__(parameters))
Beispiel #23
0
 def javascriptEvent(self, event):
     """
         Returns the action associated with a particular client-side event:
             event - the name of the client side event
     """
     return interpretAsString(self.attributes.get(event, None))
Beispiel #24
0
 def do(self, silent=True, parameters=None, instanceId=None):
     if parameters == None:
         parameters = {}
     return "ajaxDo('%s', %s, '%s');" % (self.jsId(instanceId),
                                         interpretAsString(silent),
                                         self.__urlStringFromDict__(parameters))
Beispiel #25
0
 def jsAddFilter(self, filterType, toggledOn):
     """
         Return the javascript to add a filter to the filter list clientside
     """
     return "javascriptAddFilter(this, '" + filterType + "', " + interpretAsString(toggledOn) + ");"
Beispiel #26
0
 def javascriptEvent(self, event):
     """
         Returns the action associated with a particular client-side event:
             event - the name of the client side event
     """
     return interpretAsString(self.attributes.get(event, None))