tools, frontends (xmlui): add Widget.setInternalCallback:
- to add UI callback not communication with the bridge
- a list of predefined actions can be used to copy, move, select values
- extra data can be passed within the 'internal_data' element
TODO: frontend side operation to retrieve the data from node to data structure should be generic
This commit is contained in:
parent
35d66de820
commit
38eb876e94
1 changed files with 141 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ from wokkel import data_form
|
|||
from twisted.words.xish import domish
|
||||
from sat.core import exceptions
|
||||
|
||||
|
||||
"""This library help manage XML used in SàT (parameters, registration, etc) """
|
||||
|
||||
SAT_FORM_PREFIX = "SAT_FORM_"
|
||||
|
|
@ -299,6 +300,26 @@ class FieldBackElement(Element):
|
|||
self.elem.setAttribute('name', name)
|
||||
|
||||
|
||||
class InternalFieldElement(Element):
|
||||
""" Used by internal callbacks to indicate which fields are manipulated """
|
||||
type = 'internal_field'
|
||||
|
||||
def __init__(self, parent, name):
|
||||
super(InternalFieldElement, self).__init__(parent.xmlui, parent)
|
||||
self.elem.setAttribute('name', name)
|
||||
|
||||
|
||||
class InternalDataElement(Element):
|
||||
""" Used by internal callbacks to retrieve extra data """
|
||||
type = 'internal_data'
|
||||
|
||||
def __init__(self, parent, children):
|
||||
super(InternalDataElement, self).__init__(parent.xmlui, parent)
|
||||
assert(isinstance(children, list))
|
||||
for child in children:
|
||||
self.elem.childNodes.append(child)
|
||||
|
||||
|
||||
class OptionElement(Element):
|
||||
"""" Used by ListWidget to specify options """
|
||||
type = 'option'
|
||||
|
|
@ -510,6 +531,32 @@ class Widget(Element):
|
|||
self.elem.setAttribute('name', name)
|
||||
self.elem.setAttribute('type', self.type)
|
||||
|
||||
def setInternalCallback(self, callback, fields, data_elts=None):
|
||||
"""Set an internal UI callback when the widget value is changed.
|
||||
|
||||
The internal callbacks are NO callback ids, they are strings from
|
||||
a predefined set of actions that are running in the scope of XMLUI.
|
||||
|
||||
@param callback (string): a value from:
|
||||
- 'copy': process the widgets given in 'fields' two by two, by
|
||||
copying the values of one widget to the other. Target widgets
|
||||
of type List do not accept the empty value.
|
||||
- 'move': same than copy but moves the values if the source widget
|
||||
is not a List.
|
||||
- 'groups_of_contact': process the widgets two by two, assume A is
|
||||
is a list of JID and B a list of groups, select in B the groups
|
||||
to which the JID selected in A belongs.
|
||||
- more operation to be added when necessary...
|
||||
@param fields (list): a list of widget names (string)
|
||||
@param data_elts (list[Element]): extra data elements
|
||||
"""
|
||||
self.elem.setAttribute('internal_callback', callback)
|
||||
if fields:
|
||||
for field in fields:
|
||||
InternalFieldElement(self, field)
|
||||
if data_elts:
|
||||
InternalDataElement(self, data_elts)
|
||||
|
||||
|
||||
class InputWidget(Widget):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue