changeset 314:70ac3067d641

browser_side: status can be edited with a click on it
author souliane <souliane@mailoo.org>
date Mon, 30 Dec 2013 13:02:03 +0100
parents 5ad70625867a
children 09205b410a53
files browser_side/panels.py public/libervia.css
diffstat 2 files changed, 50 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Mon Dec 30 13:00:41 2013 +0100
+++ b/browser_side/panels.py	Mon Dec 30 13:02:03 2013 +0100
@@ -891,20 +891,53 @@
         return False
 
 
-class StatusPanel(HTMLPanel):
+class StatusPanel(HTMLPanel, ClickHandler, FocusHandler, KeyboardHandler):
+
+    EMPTY_STATUS = '<click to set a status>'
+
     def __init__(self, host, status=''):
         self.host = host
-        self.status = status or '&nbsp;'
+        self.status = status
         HTMLPanel.__init__(self, self.__getContent())
         self.setStyleName('statusPanel')
+        ClickHandler.__init__(self)
+        FocusHandler.__init__(self)
+        KeyboardHandler.__init__(self)
+        self.addClickListener(self)
 
     def __getContent(self):
-        return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status)}
+        return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status or self.EMPTY_STATUS)}
 
     def changeStatus(self, new_status):
-        self.status = new_status or '&nbsp;'
+        self.status = new_status
         self.setHTML(self.__getContent())
 
+    def onClick(self, sender):
+        self.textarea = TextArea()
+        self.textarea.setStyleName('status-edit')
+        self.textarea.setText(self.status)
+        self.textarea.addKeyboardListener(self)
+        self.setVisible(False)
+        self.parent.insert(self.textarea, self.parent.getWidgetIndex(self))
+        self.textarea.setFocus(True)
+        self.textarea.setSelectionRange(0, len(self.status))
+        self.textarea.addFocusListener(self)
+        self.textarea.addKeyboardListener(self)
+
+    def onKeyPress(self, sender, keycode, modifiers):
+        text = self.textarea.getText()
+
+        if keycode == KEY_ENTER:
+            if text != self.status:
+                self.host.bridge.call('setStatus', None, self.host.status_panel.presence, text)
+            self.parent.remove(self.textarea)
+            self.setVisible(True)
+
+    def onLostFocus(self, sender):
+        FocusHandler.onLostFocus(self, sender)
+        if sender == self.textarea:
+            self.onKeyPress(self, KEY_ENTER, None)
+
 
 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
 
@@ -929,6 +962,8 @@
         panel = HorizontalPanel()
         panel.add(self.presence_button)
         panel.add(self.status_panel)
+        panel.setCellVerticalAlignment(self.presence_button, 'baseline')
+        panel.setCellVerticalAlignment(self.status_panel, 'baseline')
         panel.setStyleName("marginAuto")
         self.add(panel)
 
--- a/public/libervia.css	Mon Dec 30 13:00:41 2013 +0100
+++ b/public/libervia.css	Mon Dec 30 13:02:03 2013 +0100
@@ -133,7 +133,8 @@
 }
 
 .header {
-	background-color: #eee;
+    background-color: #eee;
+    border-bottom: 1px solid #ddd;
 }
 
 /* Misc Pyjamas stuff */
@@ -576,12 +577,10 @@
     margin: auto;
     text-align: center;
     width: 100%;
-    padding-top: 5px;
-    min-height: 30px;
+    padding: 5px 0px;
     text-shadow: 0 -1px 1px rgba(255,255,255,0.25);
     font-size: 1.2em;
     background-color: #eee;
-    border-bottom: 1px solid #ddd;
 }
 
 .presence-button {
@@ -594,6 +593,14 @@
     font-style: italic;
     font-weight: bold;
     color: #666;
+    cursor: pointer;
+}
+
+.status-edit {
+    font-style: italic;
+    font-weight: bold;
+    color: #666;
+    height: 25px;
 }
 
 /* RegisterBox */