Back to index

plone3  3.1.7
commands.py
Go to the documentation of this file.
00001 from kss.core.selectors import Selector, CssSelector, HtmlIdSelector
00002 from kss.core.selectors import ParentNodeSelector, SameNodeSelector
00003 from kss.core.kssview import CommandSet
00004 from kss.core.deprecated import deprecated, deprecated_warning
00005 from kss.core.plugins.core.interfaces import IKSSCoreCommands
00006 from zope.interface import implements
00007 
00008 class KSSCoreCommands(CommandSet):
00009     implements(IKSSCoreCommands)
00010 
00011     def getSelector(self, type, selector):
00012         'Get a selector of a given type'
00013         return Selector(type, selector)
00014 
00015     def getCssSelector(self, selector):
00016         return CssSelector(selector)
00017             
00018     def getHtmlIdSelector(self, selector):
00019         return HtmlIdSelector(selector)
00020 
00021     def getSameNodeSelector(self):
00022         return SameNodeSelector()
00023 
00024     def getParentNodeSelector(self, selector):
00025         return ParentNodeSelector(selector)
00026 
00027     # XXX the list is not full: maybe complete them?
00028     
00029     def replaceInnerHTML(self, selector, new_value, withKssSetup='True'):
00030         """ see interfaces.py """
00031         command = self.commands.addCommand('replaceInnerHTML', selector)
00032         data = command.addHtmlParam('html', new_value)
00033         data = command.addParam('withKssSetup', withKssSetup)
00034 
00035     def replaceHTML(self, selector, new_value, withKssSetup='True'):
00036         """ see interfaces.py """
00037         command = self.commands.addCommand('replaceHTML', selector)
00038         data = command.addHtmlParam('html', new_value)
00039         data = command.addParam('withKssSetup', withKssSetup)
00040     
00041     def setAttribute(self, selector, name, value):
00042         """ see interfaces.py """
00043         command = self.commands.addCommand('setAttribute', selector)
00044         data = command.addParam('name', name)
00045         data = command.addParam('value', value)
00046 
00047     def setKssAttribute(self, selector, name, value):
00048         """ see interfaces.py """
00049         command = self.commands.addCommand('setKssAttribute', selector)
00050         data = command.addParam('name', name)
00051         data = command.addParam('value', value)
00052 
00053     def setStyle(self, selector, name, value):
00054         """ see interfaces.py """
00055         command = self.commands.addCommand('setStyle', selector)
00056         data = command.addParam('name', name)
00057         data = command.addParam('value', value)
00058     
00059     def insertHTMLAfter(self, selector, new_value, withKssSetup='True'):
00060         """ see interfaces.py """
00061         command = self.commands.addCommand('insertHTMLAfter', selector)
00062         data = command.addHtmlParam('html', new_value)
00063         data = command.addParam('withKssSetup', withKssSetup)
00064 
00065     def insertHTMLAsFirstChild(self, selector, new_value, withKssSetup='True'):
00066         """ see interfaces.py """
00067         command = self.commands.addCommand('insertHTMLAsFirstChild', selector)
00068         data = command.addHtmlParam('html', new_value)
00069         data = command.addParam('withKssSetup', withKssSetup)
00070 
00071     def insertHTMLAsLastChild(self, selector, new_value, withKssSetup='True'):
00072         """ see interfaces.py """
00073         command = self.commands.addCommand('insertHTMLAsLastChild', selector)
00074         data = command.addHtmlParam('html', new_value)
00075         data = command.addParam('withKssSetup', withKssSetup)
00076 
00077     def insertHTMLBefore(self, selector, new_value, withKssSetup='True'):
00078         """ see interfaces.py """
00079         command = self.commands.addCommand('insertHTMLBefore', selector)
00080         data = command.addHtmlParam('html', new_value)
00081         data = command.addParam('withKssSetup', withKssSetup)
00082 
00083     def clearChildNodes(self, selector):
00084         """ see interfaces.py """
00085         command = self.commands.addCommand('clearChildNodes', selector)
00086     
00087     def deleteNode(self, selector):
00088         """ see interfaces.py """
00089         command = self.commands.addCommand('deleteNode', selector)
00090 
00091     def deleteNodeAfter(self, selector):
00092         """ see interfaces.py """
00093         command = self.commands.addCommand('deleteNodeAfter', selector)
00094 
00095     def deleteNodeBefore(self, selector):
00096         """ see interfaces.py """
00097         command = self.commands.addCommand('deleteNodeBefore', selector)
00098 
00099     def copyChildNodesFrom(self, selector, id):
00100         """ see interfaces.py """
00101         command = self.commands.addCommand('copyChildNodesFrom', selector)
00102         data = command.addParam('html_id', id)
00103 
00104     def moveNodeAfter(self, selector, id):
00105         """ see interfaces.py """
00106         command = self.commands.addCommand('moveNodeAfter', selector)
00107         data = command.addParam('html_id', id)
00108 
00109     def moveNodeBefore(self, selector, id):
00110         """ see interfaces.py """
00111         command = self.commands.addCommand('moveNodeBefore', selector)
00112         data = command.addParam('html_id', id)
00113 
00114     def copyChildNodesTo(self, selector, id):
00115         """ see interfaces.py """
00116         command = self.commands.addCommand('copyChildNodesTo', selector)
00117         data = command.addParam('html_id', id)
00118 
00119     def setStateVar(self, varname, value):
00120         """ see interfaces.py """
00121         command = self.commands.addCommand('setStateVar')
00122         command.addParam('varname', varname)
00123         command.addParam('value', value)
00124 
00125     def continueEvent(self, name, allnodes=False, **kw):
00126         """ see interfaces.py """
00127         command = self.commands.addCommand('continueEvent')
00128         command.addParam('name', name)
00129         command.addParam('allnodes', allnodes and 'true' or 'false')
00130         for key, value in kw.iteritems():
00131             command.addParam(key, value)
00132 
00133     def toggleClass(self, selector, *arg, **kw):
00134     ##def toggleClass(self, selector, value):
00135         """ see interfaces.py """
00136         # BBB 4 months, until 2007-10-18
00137         value = BBB_classParms('toggleClass', *arg, **kw)
00138 
00139         command = self.commands.addCommand('toggleClass', selector)
00140         data = command.addParam('value', value)
00141 
00142     def addClass(self, selector, *arg, **kw):
00143     ##def addClass(self, selector, name):
00144         """ see interfaces.py """
00145         # BBB 4 months, until 2007-10-18
00146         value = BBB_classParms('addClass', *arg, **kw)
00147 
00148         command = self.commands.addCommand('addClass', selector)
00149         data = command.addParam('value', value)
00150 
00151     def removeClass(self, selector, *arg, **kw):
00152     ##def removeClass(self, selector, name):
00153         """ see interfaces.py """
00154         # BBB 4 months, until 2007-10-18
00155         value = BBB_classParms('removeClass', *arg, **kw)
00156 
00157         command = self.commands.addCommand('removeClass', selector)
00158         data = command.addParam('value', value)
00159 
00160     def focus(self, selector):
00161         """ see interfaces.py """
00162         command = self.commands.addCommand('focus', selector)
00163 
00164     # XXX Deprecated ones
00165 
00166     # BBB until 2007-10-18
00167     def moveChildrenTo(self, selector, id):
00168         """ see interfaces.py """
00169         self.copyChildrenTo(selector, id)
00170         self.clearChildren(selector)
00171     moveChildrenTo = deprecated(moveChildrenTo, 'No more supported, use a sequence of copyChildrenTo and clearChildren')
00172 
00173     # BBB until 2007-10-18
00174     setHtmlAsChild = deprecated(replaceInnerHTML, 'use replaceInnerHTML instead')
00175     addAfter = deprecated(insertHTMLAfter, 'use insertHTMLAfter instead')
00176     clearChildren = deprecated(clearChildNodes, 'use clearChildNodes instead')
00177     removeNode = deprecated(deleteNode, 'use deleteNode instead')
00178     removeNextSibling = deprecated(deleteNodeAfter, 'use deleteNodeAfter instead')
00179     removePreviousSibling = deprecated(deleteNodeBefore, 'use deleteNodeBefore instead')
00180     copyChildrenFrom = deprecated(copyChildNodesFrom, 'use copyChildNodesFrom instead')
00181     copyChildrenTo = deprecated(copyChildNodesTo, 'use copyChildNodesTo instead')
00182     setStatevar = deprecated(setStateVar, 'use setStateVar (capital V) instead')
00183 
00184     # BBB 4 month, until 2007-10-18
00185     addClassName = deprecated(addClass, 'use addClass instead')
00186     removeClassName = deprecated(removeClass, 'use removeClass instead')
00187 
00188 # BBB 4 month, until 2007-10-18
00189 def BBB_classParms(commandname, value=None, classname=None, name=None):
00190     if classname:
00191         deprecated_warning(('Deprecated the "classname" parameter in the "%s" command, ' +
00192                            'use "name" instead.') % (commandname ,))
00193         if not value:
00194             value = classname
00195     if name:
00196         deprecated_warning(('Deprecated the "name" parameter in the "%s" command, ' +
00197                            'use "name" instead.') % (commandname ,))
00198         if not value:
00199             value = name
00200     if not value:
00201         raise Exception, 'Parameter "value" is mandatory in command "%s"' % (commandname, )
00202     return value
00203 
00204     # end deprecated