changeset 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
files browser_side/contact.py libervia.py public/libervia.css
diffstat 3 files changed, 117 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/contact.py	Sat Apr 16 18:06:02 2011 +0200
+++ b/browser_side/contact.py	Sun Apr 17 00:21:44 2011 +0200
@@ -160,6 +160,9 @@
            return True
        return False
 
+    def getGroups(self):
+        return self.groups.keys()
+
     def onMouseMove(self, sender, x, y):
         pass
         
--- a/libervia.py	Sat Apr 16 18:06:02 2011 +0200
+++ b/libervia.py	Sun Apr 17 00:21:44 2011 +0200
@@ -23,6 +23,9 @@
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.RootPanel import RootPanel
 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
+from pyjamas.ui.PopupPanel import PopupPanel
+from pyjamas.ui.HTML import HTML
+from pyjamas.Timer import Timer
 from pyjamas import Window
 from pyjamas.JSONService import JSONProxy
 from pyjamas.ui.KeyboardListener import KEY_ENTER
@@ -79,14 +82,91 @@
 
     def __init__(self, host):
         AutoCompleteTextBox.__init__(self)
+        self._popup = None
+        self._timer = Timer(notify=self._timeCb)
         self.host = host
 
     def addKey(self, key):
         self.getCompletionItems().completions.append(key)
 
+    def showWarning(self, target_data):
+        type, target = target_data
+        if type == "PUBLIC":
+            msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know"
+            style = "targetPublic"
+        elif type == "GROUP":
+            msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '')
+            style = "targetGroup"
+        elif type == "STATUS":
+            msg = "This will be your new status message"
+            style = "targetStatus"
+        elif type == "ONE2ONE":
+            msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target
+            style = "targetOne2One"
+        else:
+            print "WARNING: undetermined target for this message"
+            return
+        contents = HTML(msg)
+
+        self._popup = PopupPanel(autoHide=False, modal=False)
+        self._popup.target_data = target_data
+        self._popup.add(contents)
+        self._popup.setStyleName("warningPopup")
+        if style:
+            self._popup.addStyleName(style)
+
+        left = 0
+        top  = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2)   
+        self._popup.setPopupPosition(left, top)
+        self._popup.setPopupPosition(left, top)
+        self._popup.show()
+
+    def _timeCb(self, timer):
+        if self._popup:
+            self._popup.hide()
+        del self._popup
+        self._popup = None
+
+    def _getTarget(self, txt):
+        """Say who will receive the messsage
+        Return a tuple (target_type, target info)"""
+        type = None
+        target = None
+        if txt.startswith('@@: '):
+            type = "PUBLIC"
+        elif txt.startswith('@'):
+            type = "GROUP"
+            _end = txt.find(': ')
+            if _end == -1:
+                type = "STATUS"
+            else:
+                target = txt[1:_end] #only one target group is managed for the moment
+                if not target in self.host.contactPanel.getGroups():
+                    target = None
+        elif self.host.selected == None:
+            type = "STATUS"
+        elif isinstance(self.host.selected, ChatPanel):
+            type = "ONE2ONE"
+            target = str(self.host.selected.target)
+        else:
+            print self.host.selected
+            type = "UNKNOWN"
+        return (type, target)
+
     def onKeyPress(self, sender, keycode, modifiers):
+        _txt = self.getText()
+        if not self._popup:
+            self.showWarning(self._getTarget(_txt))
+        else:
+            _target = self._getTarget(_txt)
+            if _target != self._popup.target_data:
+                self._popup.hide()
+                del self._popup
+                self.showWarning(_target)
+
+        self._timer.schedule(1500)
+
         if keycode == KEY_ENTER and not self.visible:
-            _txt = self.getText()
             if _txt:
                 if _txt.startswith('@'):
                     self.host.bridge.call('sendMblog', None, self.getText())
--- a/public/libervia.css	Sat Apr 16 18:06:02 2011 +0200
+++ b/public/libervia.css	Sun Apr 17 00:21:44 2011 +0200
@@ -98,15 +98,15 @@
 /* CSS Reset END */
 
 .gwt-MenuBar,.gwt-MenuBar-horizontal {
-  background-color: #C3D9FF;
+  background-color: #01FF78;
   border: 1px solid #87B3FF;
   cursor: default;
 }
 
 .gwt-MenuBar-horizontal .gwt-MenuItem {
 }
-.gwt-MenuBar .gwt-MenuItem {
-  padding: 1px 4px 1px 4px;
+.gwt-MenuItem {
+  padding: 1px 20px 1px 10px;
   font-size: smaller;
   cursor: default;
 }
@@ -244,11 +244,40 @@
     background: #8f8;
 }
 
+/* Warning message */
+
+.warningPopup {
+    width: 100%;
+    text-align: center;
+    background-color: white;
+    border: 1px solid #87B3FF;
+    padding: 4px;
+}
+
+.warningTarget {
+    font-weight: bold;
+}
+
+.targetPublic {
+    background-color: red;
+}
+
+.targetGroup {
+    background-color: #00FFFB;
+}
+
+.targetOne2One {
+    background-color: #72FF06;
+}
+
+.targetStatus {
+}
+
 /* Misc */
 
 .selected_widget {
     /* this property is set when a widget is the current target of the uniBox
      * (messages entered in unibox will be sent to this widget)
      */
-  border: 3px dashed red;
+    border: 3px dashed red;
 }