Mercurial > libervia-web
diff browser_side/xmlui.py @ 299:e4f586fc6101
server and browser side: updated callback system to follow core changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 02:00:30 +0100 |
parents | fe83837d3491 |
children | bfbd9d6eb901 |
line wrap: on
line diff
--- a/browser_side/xmlui.py Tue Dec 17 01:47:01 2013 +0100 +++ b/browser_side/xmlui.py Tue Dec 24 02:00:30 2013 +0100 @@ -101,26 +101,28 @@ elif node_type=="string": ctrl = TextBox() ctrl.setText(value) - self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl}) + self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl} elif node_type=="password": ctrl = PasswordTextBox() ctrl.setText(value) - self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl}) + self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl} elif node_type=="textbox": ctrl = TextArea() ctrl.setText(value) - self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl}) + self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl} elif node_type=="bool": ctrl = CheckBox() ctrl.setChecked(value=="true") - self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl}) + self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl} elif node_type=="list": + _options = [(option.getAttribute("label"), option.getAttribute("value")) for option in elem.getElementsByTagName("option")] + attr_map = {label: value for label, value in _options} ctrl = ListBox() ctrl.setMultipleSelect(elem.getAttribute("multi")=='yes') - for option in elem.getElementsByTagName("option"): - ctrl.addItem(option.getAttribute("value")) + for option in _options: + ctrl.addItem(option[0]) ctrl.selectItem(value) - self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl}) + self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl, 'attr_map': attr_map} elif node_type=="button": callback_id = elem.getAttribute("callback_id") ctrl = Button(value, self.onButtonPress) @@ -190,6 +192,8 @@ top=cat_dom.documentElement self.node_type = top.getAttribute("type") self.title = top.getAttribute("title") or self.title + self.session_id = top.getAttribute("session_id") or None + self.submit_id = top.getAttribute("submit") or None if top.nodeName != "sat_xmlui" or not self.node_type in ['form', 'param', 'window']: raise InvalidXMLUI @@ -216,7 +220,6 @@ def onButtonPress(self, button): print "onButtonPress (%s)" % (button,) callback_id, fields = button.param_id - data = {"callback_id":callback_id} for field in fields: ctrl = self.ctrl_list[field] if isinstance(ctrl['control'],ListBox): @@ -226,8 +229,7 @@ else: data[field] = ctrl['control'].getText() - self.host.bridge.call('launchAction', None, "button", data) - self.host.current_action_ids.add(id) + self.host.launchAction(callback_id, None) def onParamChange(self, widget): """Called when type is param and a widget to save is modified""" @@ -241,17 +243,23 @@ print "FIXME FIXME FIXME: Form submitting not managed yet" data = [] for ctrl_name in self.ctrl_list: - ctrl = self.ctrl_list[ctrl_name] + escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name) + ctrl = self.ctrl_list[escaped] if isinstance(ctrl['control'], ListBox): - data.append((ctrl_name, '\t'.join(ctrl['control'].getSelectedItemText()))) + data.append((escaped, '\t'.join([ctrl['attr_map'][label] for label in ctrl['control'].getSelectedItemText()]))) elif isinstance(ctrl['control'], CheckBox): - data.append((ctrl_name, "true" if ctrl['control'].isChecked() else "false")) + data.append((escaped, "true" if ctrl['control'].isChecked() else "false")) else: - data.append((ctrl_name, ctrl['control'].getText())) + data.append((escaped, ctrl['control'].getText())) if 'action_back' in self.misc: #FIXME FIXME FIXME: WTF ! Must be cleaned raise NotImplementedError elif 'callback' in self.misc: self.misc['callback'](data) + elif self.submit_id is not None: + data = dict(selected_values) + if self.session_id is not None: + data["session_id"] = self.session_id + self.host.launchAction(self.submit_id, data) else: print ("WARNING: The form data is not sent back, the type is not managed properly")