diff browser_side/panels.py @ 347:f1ba38043d78

browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
author souliane <souliane@mailoo.org>
date Fri, 07 Feb 2014 20:14:11 +0100
parents 44491e963eee
children f488692c4903
line wrap: on
line diff
--- a/browser_side/panels.py	Fri Feb 07 20:08:28 2014 +0100
+++ b/browser_side/panels.py	Fri Feb 07 20:14:11 2014 +0100
@@ -40,7 +40,7 @@
 from __pyjamas__ import doc
 
 from tools import html_sanitize, setPresenceStyle
-from base_panels import ChatText, OccupantsList, PopupMenuPanel
+from base_panels import ChatText, OccupantsList, PopupMenuPanel, LightTextEditor
 from datetime import datetime
 from time import time
 from card_game import CardPanel
@@ -897,52 +897,27 @@
         return False
 
 
-class StatusPanel(HTMLPanel, ClickHandler, FocusHandler, KeyboardHandler):
+class StatusPanel(LightTextEditor, ClickHandler):
 
     EMPTY_STATUS = '<click to set a status>'
 
     def __init__(self, host, status=''):
         self.host = host
         self.status = status
-        HTMLPanel.__init__(self, self.__getContent())
+        LightTextEditor.__init__(self, self.__getStatus(), True, lambda status: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, status))
         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 or self.EMPTY_STATUS)}
+    def __getStatus(self):
+        return html_sanitize(self.status or self.EMPTY_STATUS)
 
     def changeStatus(self, new_status):
         self.status = new_status
-        self.setHTML(self.__getContent())
+        self.setContent(self.__getStatus())
 
     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)
+        self.edit(True)
 
 
 class PresenceStatusPanel(HorizontalPanel, ClickHandler):