comparison browser_side/richtext.py @ 270:52e60dd2bc43

browser_side: send rich text to all the "To" recipients (groups and one2one)
author souliane <souliane@mailoo.org>
date Sun, 17 Nov 2013 22:20:12 +0100
parents d3c734669577
children aebb96bfa8d1
comparison
equal deleted inserted replaced
269:9eb9c7d41bdc 270:52e60dd2bc43
105 else: 105 else:
106 add(host.richtext, parent) 106 add(host.richtext, parent)
107 host.richtext.syncFromUniBox() 107 host.richtext.syncFromUniBox()
108 return host.richtext.popup if parent is None else host.richtext 108 return host.richtext.popup if parent is None else host.richtext
109 109
110 def setVisible(self, kwargs): 110 def setVisible(self, visible):
111 """Called each time the widget is displayed, after creation or after having been hidden.""" 111 """Called each time the widget is displayed, after creation or after having been hidden."""
112 self.host.bridge.call('asyncGetParamA', self.setToolBar, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None) 112 FlexTable.setVisible(self, visible)
113 FlexTable.setVisible(self, kwargs) 113 if visible:
114 self.host.bridge.call('asyncGetParamA', self.setToolBar, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None)
114 115
115 def __close(self): 116 def __close(self):
116 """Remove the widget from parent or close the popup.""" 117 """Remove the widget from parent or close the popup."""
117 if self._parent is None: 118 if self._parent is None:
118 self.popup.hide() 119 self.popup.hide()
177 """Synchronize from unibox.""" 178 """Synchronize from unibox."""
178 data, target = self.host.uni_box.getTargetAndData() 179 data, target = self.host.uni_box.getTargetAndData()
179 self.recipient.setContacts({"To": [target]} if target else {}) 180 self.recipient.setContacts({"To": [target]} if target else {})
180 self.textarea.setText(data if data else "") 181 self.textarea.setText(data if data else "")
181 182
182 def syncToUniBox(self, recipients=None): 183 def syncToUniBox(self, recipients=None, emptyText=False):
183 """Synchronize to unibox if a maximum of one recipient is set, 184 """Synchronize to unibox if a maximum of one recipient is set,
184 and it is not set to for optional recipient type. That means 185 and it is not set to for optional recipient type. That means
185 synchronization is not done if more then one recipients are set 186 synchronization is not done if more then one recipients are set
186 or if a recipient is set to an optional type (Cc, Bcc). 187 or if a recipient is set to an optional type (Cc, Bcc).
187 @return True if the sync could be done, False otherwise""" 188 @return True if the sync could be done, False otherwise"""
197 allowed -= count 198 allowed -= count
198 if allowed < 0 or composition.RECIPIENT_TYPES[key]["optional"]: 199 if allowed < 0 or composition.RECIPIENT_TYPES[key]["optional"]:
199 return False 200 return False
200 # TODO: change this if later more then one recipients are allowed 201 # TODO: change this if later more then one recipients are allowed
201 target = recipients[key][0] 202 target = recipients[key][0]
202 self.host.uni_box.setText(self.textarea.getText()) 203 self.host.uni_box.setText("" if emptyText else self.textarea.getText())
203 from panels import ChatPanel, MicroblogPanel 204 from panels import ChatPanel, MicroblogPanel
204 if target == "": 205 if target == "":
205 return True 206 return True
206 if target.startswith("@"): 207 if target.startswith("@"):
207 _class = MicroblogPanel 208 _class = MicroblogPanel
234 " from here.", Width="400px").center() 235 " from here.", Width="400px").center()
235 236
236 def sendMessage(self): 237 def sendMessage(self):
237 """Send the message.""" 238 """Send the message."""
238 recipients = self.recipient.getContacts() 239 recipients = self.recipient.getContacts()
239 if self.syncToUniBox(recipients): 240 for key in recipients:
240 # also check that we actually have a message target and data 241 if len(recipients[key]) > 0 and composition.RECIPIENT_TYPES[key]["optional"]:
241 if len(recipients["To"]) > 0 and self.textarea.getText() != "": 242 InfoDialog("Feature in development",
242 from pyjamas.ui.KeyboardListener import KEY_ENTER 243 "Sending a message to Cc or Bcc is not implemented yet!", Width="400px").center()
243 self.host.uni_box.onKeyPress(self.host.uni_box, KEY_ENTER, None) 244 return
244 self.__close() 245 text = self.textarea.getText()
246 # check that we actually have a message target and data
247 if text == "" or len(recipients["To"]) == 0:
248 InfoDialog("Missing information",
249 "Some information are missing and the message hasn't been sent.", Width="400px").center()
250 return
251 self.syncToUniBox(recipients, emptyText=True)
252 targets = []
253 for recipient in recipients["To"]:
254 if recipient.startswith("@"):
255 targets.append(("PUBLIC", None) if recipient == "@@" else ("GROUP", recipient[1:]))
245 else: 256 else:
246 InfoDialog("Missing information", 257 targets.append(("chat", recipient))
247 "Some information are missing and the message hasn't been sent," + 258 self.host.send(targets, text, rich=True)
248 " but it has been stored to the quick box instead.", Width="400px").center() 259 self.__close()
249 return
250 InfoDialog("Feature in development",
251 "Sending a message to more the one recipient," +
252 " to Cc or Bcc is not implemented yet!", Width="400px").center()
253 260
254 261
255 class RecipientManager(ListManager): 262 class RecipientManager(ListManager):
256 """A manager for sub-panels to set the recipients for each recipient type.""" 263 """A manager for sub-panels to set the recipients for each recipient type."""
257 264