Mercurial > libervia-web
changeset 1:0a7c685faa53
ContactPanel: first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Jan 2011 20:31:25 +0100 |
parents | 140cec48224a |
children | 669c531a857e |
files | libervia.py libervia.tac public/libervia.css public/libervia.html |
diffstat | 4 files changed, 150 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia.py Sun Jan 30 21:50:22 2011 +0100 +++ b/libervia.py Mon Jan 31 20:31:25 2011 +0100 @@ -32,6 +32,7 @@ from pyjamas.ui.AutoComplete import AutoCompleteTextBox from pyjamas.JSONService import JSONProxy from register import RegisterPanel, RegisterBox +from pyjamas import DOM class LiberviaJsonProxy(JSONProxy): @@ -57,8 +58,6 @@ Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) else: Window.alert("Error: %s" % errobj['message']) - import pdb - pdb.set_trace() class RegisterCall(LiberviaJsonProxy): def __init__(self): @@ -112,30 +111,127 @@ def __init__(self): AutoCompleteTextBox.__init__(self) - self.setCompletionItems(['@amis: ','@famille: ', '@collègues']) + + def addKey(self, key): + self.getCompletionItems().completions.append(key) + +class GroupLabel(Label): + def __init__(self, group): + Label.__init__(self, group) + self.group = group + self.setStyleName('group') + +class ContactLabel(Label): + def __init__(self, jid, name=None): + if not name: + name=jid + Label.__init__(self, name) + self.jid=jid + self.setStyleName('contact') + +class GroupList(VerticalPanel): + + def __init__(self, parent): + VerticalPanel.__init__(self) + self._parent = parent + + def add(self, group): + _item = GroupLabel(group) + _item.addMouseListener(self._parent) + DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") + VerticalPanel.add(self, _item) + +class ContactList(VerticalPanel): + + def __init__(self): + VerticalPanel.__init__(self) + self.contacts=[] + + def __iter__(self): + return self.contacts.__iter__() + + def add(self, jid, name=None): + _item = ContactLabel(jid, name) + DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") + VerticalPanel.add(self, _item) + self.contacts.append(_item) class ContactPanel(SimplePanel): + """Manage the contacts and groups""" - def __init__(self): + def __init__(self, host): SimplePanel.__init__(self) + self.host = host + self.groups={} + self.vPanel = VerticalPanel() + _title = Label('Contacts') + _title.setStyleName('contactTitle') + + self._contactList = ContactList() + self._contactList.setStyleName('contactList') + self._groupList = GroupList(self) + self._groupList.setStyleName('groupList') + + self.vPanel.add(_title) + self.vPanel.add(self._groupList) + self.vPanel.add(self._contactList) + self.add(self.vPanel) + self.setStyleName('contactBox') + + def addContact(self, jid, attributes, groups): + """Add a contact to the panel + @param jid: jid + @attributes: cf SàT Bridge API's newContact + @param groups: list of groups""" + for group in groups: + if not self.groups.has_key(group): + self.groups[group] = set() + self._groupList.add(group) + self.host.magicBox.addKey("@%s: " % group) + self.groups[group].add(jid) + self._contactList.add(jid) + + def onMouseMove(self, sender, x, y): + pass + + def onMouseDown(self, sender, x, y): + pass + + def onMouseUp(self, sender, x, y): + pass + + def onMouseEnter(self, sender): + if isinstance(sender, GroupLabel): + for contact in self._contactList: + if contact.jid in self.groups[sender.group]: + contact.addStyleName("selected") + + def onMouseLeave(self, sender): + if isinstance(sender, GroupLabel): + for contact in self._contactList: + if contact.jid in self.groups[sender.group]: + contact.removeStyleName("selected") class MiddlePannel(HorizontalPanel): - def __init__(self): + def __init__(self,host): + self.host=host HorizontalPanel.__init__(self) + self.add(self.host.contactPanel) class MainPanel(VerticalPanel): - def __init__(self): + def __init__(self, host): + self.host=host VerticalPanel.__init__(self) self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) self.setVerticalAlignment(HasAlignment.ALIGN_TOP) menu = Menu() - magic_box = MagicBox() - middle_panel = MiddlePannel() + magic_box = host.magicBox + middle_panel = MiddlePannel(self.host) self.add(menu) self.add(magic_box) @@ -152,20 +248,22 @@ class SatWebFrontend: def onModuleLoad(self): - self.panel = MainPanel() + self.magicBox = MagicBox() + self.contactPanel = ContactPanel(self) + self.panel = MainPanel(self) self._dialog = None RootPanel().add(self.panel) self._register = RegisterCall() - self._register.call('isRegistered',self.isRegistered) + self._register.call('isRegistered',self._isRegisteredCB) - def isRegistered(self, registered): + def _isRegisteredCB(self, registered): if not registered: self._dialog = RegisterBox(self.logged,centered=True) self._dialog.show() else: - self._register.call('isConnected', self.isConnected) + self._register.call('isConnected', self._isConnectedCB) - def isConnected(self, connected): + def _isConnectedCB(self, connected): if not connected: self._register.call('connect',self.logged) else: @@ -175,11 +273,19 @@ if self._dialog: self._dialog.hide() del self._dialog # don't work if self._dialog is None - Window.alert("Logged successfuly :o)") + + #it's time to fill the page + bridge = BrigeCall() + bridge.call('getContacts', self._getContactsCB) + + def _getContactsCB(self, contacts_data): + for contact in contacts_data: + jid, attributes, groups = contact + self.contactPanel.addContact(jid, attributes, groups) if __name__ == '__main__': - pyjd.setup("./public/Libervia.html") + pyjd.setup("http://localhost:8080/libervia.html") app = SatWebFrontend() app.onModuleLoad() pyjd.run()
--- a/libervia.tac Sun Jan 30 21:50:22 2011 +0100 +++ b/libervia.tac Mon Jan 31 20:31:25 2011 +0100 @@ -42,9 +42,9 @@ self.sat_host=sat_host def render(self, request): - _session = request.getSession() + self.session = request.getSession() try: - profile = _session.sat_profile + profile = self.session.sat_profile except AttributeError: #user is not identified, we return a jsonrpc fault parsed = jsonrpclib.loads(request.content.read()) @@ -55,9 +55,8 @@ def jsonrpc_getContacts(self): """Return all passed args.""" - d = defer.Deferred() - reactor.callLater(10, d.callback, [unicode(contact[0]) for contact in self.sat_host.bridge.getContacts()]) - return d + profile = self.session.sat_profile + return self.sat_host.bridge.getContacts(profile) class Register(jsonrpc.JSONRPC): """This class manage the registration procedure with SàT @@ -232,13 +231,11 @@ def startService(self): reactor.listenTCP(8080, self.site) - + def run(self): - debug(_("running app")) reactor.run() def stop(self): - debug(_("stopping app")) reactor.stop()
--- a/public/libervia.css Sun Jan 30 21:50:22 2011 +0100 +++ b/public/libervia.css Mon Jan 31 20:31:25 2011 +0100 @@ -56,3 +56,26 @@ padding: 10px; } +/* Contact List */ + +.contactTitle { + font-style: italic; + border-bottom: 1px solid gray; + text-align: center; +} + +.group { + font-weight: bold; + font-size: small; +} + +div.group:hover { + text-decoration:underline; +} +.contact { + font-size: small; +} + +.selected { + background-color: yellow; +}
--- a/public/libervia.html Sun Jan 30 21:50:22 2011 +0100 +++ b/public/libervia.html Mon Jan 31 20:31:25 2011 +0100 @@ -21,7 +21,7 @@ <meta name="pygwt:module" content="libervia"> <link rel='stylesheet' href='libervia.css'> -<title>Salut à Toi web interface test</title> +<title>Libervia</title> </head> <body bgcolor="white"> <script language="javascript" src="bootstrap.js"></script>