# HG changeset patch # User souliane # Date 1384723212 -3600 # Node ID 52e60dd2bc438c8cfde25e64b7362605843875ba # Parent 9eb9c7d41bdc95c02e13d69248a374901d5ccdf3 browser_side: send rich text to all the "To" recipients (groups and one2one) diff -r 9eb9c7d41bdc -r 52e60dd2bc43 browser_side/richtext.py --- a/browser_side/richtext.py Sun Nov 17 21:16:07 2013 +0100 +++ b/browser_side/richtext.py Sun Nov 17 22:20:12 2013 +0100 @@ -107,10 +107,11 @@ host.richtext.syncFromUniBox() return host.richtext.popup if parent is None else host.richtext - def setVisible(self, kwargs): + def setVisible(self, visible): """Called each time the widget is displayed, after creation or after having been hidden.""" - self.host.bridge.call('asyncGetParamA', self.setToolBar, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None) - FlexTable.setVisible(self, kwargs) + FlexTable.setVisible(self, visible) + if visible: + self.host.bridge.call('asyncGetParamA', self.setToolBar, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None) def __close(self): """Remove the widget from parent or close the popup.""" @@ -179,7 +180,7 @@ self.recipient.setContacts({"To": [target]} if target else {}) self.textarea.setText(data if data else "") - def syncToUniBox(self, recipients=None): + def syncToUniBox(self, recipients=None, emptyText=False): """Synchronize to unibox if a maximum of one recipient is set, and it is not set to for optional recipient type. That means synchronization is not done if more then one recipients are set @@ -199,7 +200,7 @@ return False # TODO: change this if later more then one recipients are allowed target = recipients[key][0] - self.host.uni_box.setText(self.textarea.getText()) + self.host.uni_box.setText("" if emptyText else self.textarea.getText()) from panels import ChatPanel, MicroblogPanel if target == "": return True @@ -236,20 +237,26 @@ def sendMessage(self): """Send the message.""" recipients = self.recipient.getContacts() - if self.syncToUniBox(recipients): - # also check that we actually have a message target and data - if len(recipients["To"]) > 0 and self.textarea.getText() != "": - from pyjamas.ui.KeyboardListener import KEY_ENTER - self.host.uni_box.onKeyPress(self.host.uni_box, KEY_ENTER, None) - self.__close() + for key in recipients: + if len(recipients[key]) > 0 and composition.RECIPIENT_TYPES[key]["optional"]: + InfoDialog("Feature in development", + "Sending a message to Cc or Bcc is not implemented yet!", Width="400px").center() + return + text = self.textarea.getText() + # check that we actually have a message target and data + if text == "" or len(recipients["To"]) == 0: + InfoDialog("Missing information", + "Some information are missing and the message hasn't been sent.", Width="400px").center() + return + self.syncToUniBox(recipients, emptyText=True) + targets = [] + for recipient in recipients["To"]: + if recipient.startswith("@"): + targets.append(("PUBLIC", None) if recipient == "@@" else ("GROUP", recipient[1:])) else: - InfoDialog("Missing information", - "Some information are missing and the message hasn't been sent," + - " but it has been stored to the quick box instead.", Width="400px").center() - return - InfoDialog("Feature in development", - "Sending a message to more the one recipient," + - " to Cc or Bcc is not implemented yet!", Width="400px").center() + targets.append(("chat", recipient)) + self.host.send(targets, text, rich=True) + self.__close() class RecipientManager(ListManager):