comparison libervia.py @ 21:77c2e48efa29

browser side: a warning message now show who will receive the message entered in UniBox, with a color depending on how many people will be able to see it
author Goffi <goffi@goffi.org>
date Sun, 17 Apr 2011 00:21:44 +0200
parents 8f4b1a8914c3
children 586f69e85559
comparison
equal deleted inserted replaced
20:8f4b1a8914c3 21:77c2e48efa29
21 21
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.RootPanel import RootPanel 24 from pyjamas.ui.RootPanel import RootPanel
25 from pyjamas.ui.AutoComplete import AutoCompleteTextBox 25 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
26 from pyjamas.ui.PopupPanel import PopupPanel
27 from pyjamas.ui.HTML import HTML
28 from pyjamas.Timer import Timer
26 from pyjamas import Window 29 from pyjamas import Window
27 from pyjamas.JSONService import JSONProxy 30 from pyjamas.JSONService import JSONProxy
28 from pyjamas.ui.KeyboardListener import KEY_ENTER 31 from pyjamas.ui.KeyboardListener import KEY_ENTER
29 from browser_side.register import RegisterPanel, RegisterBox 32 from browser_side.register import RegisterPanel, RegisterBox
30 from browser_side.contact import ContactPanel 33 from browser_side.contact import ContactPanel
77 80
78 class UniBox(AutoCompleteTextBox): 81 class UniBox(AutoCompleteTextBox):
79 82
80 def __init__(self, host): 83 def __init__(self, host):
81 AutoCompleteTextBox.__init__(self) 84 AutoCompleteTextBox.__init__(self)
85 self._popup = None
86 self._timer = Timer(notify=self._timeCb)
82 self.host = host 87 self.host = host
83 88
84 def addKey(self, key): 89 def addKey(self, key):
85 self.getCompletionItems().completions.append(key) 90 self.getCompletionItems().completions.append(key)
86 91
92 def showWarning(self, target_data):
93 type, target = target_data
94 if type == "PUBLIC":
95 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know"
96 style = "targetPublic"
97 elif type == "GROUP":
98 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '')
99 style = "targetGroup"
100 elif type == "STATUS":
101 msg = "This will be your new status message"
102 style = "targetStatus"
103 elif type == "ONE2ONE":
104 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target
105 style = "targetOne2One"
106 else:
107 print "WARNING: undetermined target for this message"
108 return
109 contents = HTML(msg)
110
111 self._popup = PopupPanel(autoHide=False, modal=False)
112 self._popup.target_data = target_data
113 self._popup.add(contents)
114 self._popup.setStyleName("warningPopup")
115 if style:
116 self._popup.addStyleName(style)
117
118 left = 0
119 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2)
120 self._popup.setPopupPosition(left, top)
121 self._popup.setPopupPosition(left, top)
122 self._popup.show()
123
124 def _timeCb(self, timer):
125 if self._popup:
126 self._popup.hide()
127 del self._popup
128 self._popup = None
129
130 def _getTarget(self, txt):
131 """Say who will receive the messsage
132 Return a tuple (target_type, target info)"""
133 type = None
134 target = None
135 if txt.startswith('@@: '):
136 type = "PUBLIC"
137 elif txt.startswith('@'):
138 type = "GROUP"
139 _end = txt.find(': ')
140 if _end == -1:
141 type = "STATUS"
142 else:
143 target = txt[1:_end] #only one target group is managed for the moment
144 if not target in self.host.contactPanel.getGroups():
145 target = None
146 elif self.host.selected == None:
147 type = "STATUS"
148 elif isinstance(self.host.selected, ChatPanel):
149 type = "ONE2ONE"
150 target = str(self.host.selected.target)
151 else:
152 print self.host.selected
153 type = "UNKNOWN"
154 return (type, target)
155
87 def onKeyPress(self, sender, keycode, modifiers): 156 def onKeyPress(self, sender, keycode, modifiers):
157 _txt = self.getText()
158 if not self._popup:
159 self.showWarning(self._getTarget(_txt))
160 else:
161 _target = self._getTarget(_txt)
162 if _target != self._popup.target_data:
163 self._popup.hide()
164 del self._popup
165 self.showWarning(_target)
166
167 self._timer.schedule(1500)
168
88 if keycode == KEY_ENTER and not self.visible: 169 if keycode == KEY_ENTER and not self.visible:
89 _txt = self.getText()
90 if _txt: 170 if _txt:
91 if _txt.startswith('@'): 171 if _txt.startswith('@'):
92 self.host.bridge.call('sendMblog', None, self.getText()) 172 self.host.bridge.call('sendMblog', None, self.getText())
93 elif self.host.selected == None: 173 elif self.host.selected == None:
94 print "changement de status pour", _txt 174 print "changement de status pour", _txt