Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
346:82f9e92379b0 | 347:f1ba38043d78 |
---|---|
38 from pyjamas import DOM | 38 from pyjamas import DOM |
39 from pyjamas import Window | 39 from pyjamas import Window |
40 from __pyjamas__ import doc | 40 from __pyjamas__ import doc |
41 | 41 |
42 from tools import html_sanitize, setPresenceStyle | 42 from tools import html_sanitize, setPresenceStyle |
43 from base_panels import ChatText, OccupantsList, PopupMenuPanel | 43 from base_panels import ChatText, OccupantsList, PopupMenuPanel, LightTextEditor |
44 from datetime import datetime | 44 from datetime import datetime |
45 from time import time | 45 from time import time |
46 from card_game import CardPanel | 46 from card_game import CardPanel |
47 from radiocol import RadioColPanel | 47 from radiocol import RadioColPanel |
48 from menu import Menu | 48 from menu import Menu |
895 if self.host.contact_panel.isContactInGroup(group, jid): | 895 if self.host.contact_panel.isContactInGroup(group, jid): |
896 return True | 896 return True |
897 return False | 897 return False |
898 | 898 |
899 | 899 |
900 class StatusPanel(HTMLPanel, ClickHandler, FocusHandler, KeyboardHandler): | 900 class StatusPanel(LightTextEditor, ClickHandler): |
901 | 901 |
902 EMPTY_STATUS = '<click to set a status>' | 902 EMPTY_STATUS = '<click to set a status>' |
903 | 903 |
904 def __init__(self, host, status=''): | 904 def __init__(self, host, status=''): |
905 self.host = host | 905 self.host = host |
906 self.status = status | 906 self.status = status |
907 HTMLPanel.__init__(self, self.__getContent()) | 907 LightTextEditor.__init__(self, self.__getStatus(), True, lambda status: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, status)) |
908 self.setStyleName('statusPanel') | 908 self.setStyleName('statusPanel') |
909 ClickHandler.__init__(self) | 909 ClickHandler.__init__(self) |
910 FocusHandler.__init__(self) | |
911 KeyboardHandler.__init__(self) | |
912 self.addClickListener(self) | 910 self.addClickListener(self) |
913 | 911 |
914 def __getContent(self): | 912 def __getStatus(self): |
915 return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status or self.EMPTY_STATUS)} | 913 return html_sanitize(self.status or self.EMPTY_STATUS) |
916 | 914 |
917 def changeStatus(self, new_status): | 915 def changeStatus(self, new_status): |
918 self.status = new_status | 916 self.status = new_status |
919 self.setHTML(self.__getContent()) | 917 self.setContent(self.__getStatus()) |
920 | 918 |
921 def onClick(self, sender): | 919 def onClick(self, sender): |
922 self.textarea = TextArea() | 920 self.edit(True) |
923 self.textarea.setStyleName('status-edit') | |
924 self.textarea.setText(self.status) | |
925 self.textarea.addKeyboardListener(self) | |
926 self.setVisible(False) | |
927 self.parent.insert(self.textarea, self.parent.getWidgetIndex(self)) | |
928 self.textarea.setFocus(True) | |
929 self.textarea.setSelectionRange(0, len(self.status)) | |
930 self.textarea.addFocusListener(self) | |
931 self.textarea.addKeyboardListener(self) | |
932 | |
933 def onKeyPress(self, sender, keycode, modifiers): | |
934 text = self.textarea.getText() | |
935 | |
936 if keycode == KEY_ENTER: | |
937 if text != self.status: | |
938 self.host.bridge.call('setStatus', None, self.host.status_panel.presence, text) | |
939 self.parent.remove(self.textarea) | |
940 self.setVisible(True) | |
941 | |
942 def onLostFocus(self, sender): | |
943 FocusHandler.onLostFocus(self, sender) | |
944 if sender == self.textarea: | |
945 self.onKeyPress(self, KEY_ENTER, None) | |
946 | 921 |
947 | 922 |
948 class PresenceStatusPanel(HorizontalPanel, ClickHandler): | 923 class PresenceStatusPanel(HorizontalPanel, ClickHandler): |
949 | 924 |
950 def __init__(self, host, presence="", status=""): | 925 def __init__(self, host, presence="", status=""): |