Mercurial > libervia-web
changeset 152:7e87c87b7952
browser side: temporary avatar upload dialog is added to setting menu
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Dec 2012 01:05:55 +0100 |
parents | a159cc29b556 |
children | ada146bac8fe |
files | browser_side/menu.py |
diffstat | 1 files changed, 63 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/menu.py Fri Dec 28 01:05:22 2012 +0100 +++ b/browser_side/menu.py Fri Dec 28 01:05:55 2012 +0100 @@ -24,6 +24,8 @@ from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.DialogBox import DialogBox +from pyjamas.ui.FormPanel import FormPanel +from pyjamas.ui.FileUpload import FileUpload from pyjamas.ui.MenuBar import MenuBar from pyjamas.ui.MenuItem import MenuItem from pyjamas.ui.ListBox import ListBox @@ -63,6 +65,58 @@ self.getOffsetHeight() - 1) self.popup.addStyleName('menuLastPopup') +class AvatarUpload(FormPanel): + + def __init__(self, close_cb=None): + FormPanel.__init__(self) + self.close_cb = close_cb + self.setEncoding(FormPanel.ENCODING_MULTIPART) + self.setMethod(FormPanel.METHOD_POST) + self.setAction("upload_avatar") + self.vPanel = VerticalPanel() + self.message = HTML('Please select an image to show as your avatar...<br>Your picture must be a square an will be resized to 64x64 pixels if necessary') + self.vPanel.add(self.message) + + hPanel = HorizontalPanel() + hPanel.setSpacing(5) + self.file_upload = FileUpload() + self.file_upload.setName("avatar_path") + self.vPanel.add(self.file_upload) + + hPanel.add(Button("Cancel", getattr(self, "onCloseBtnClick"))) + self.upload_btn = Button("Upload avatar", getattr(self, "onSubmitBtnClick")) + hPanel.add(self.upload_btn) + + self.status = Label() + hPanel.add(self.status) + + self.vPanel.add(hPanel) + + self.add(self.vPanel) + self.addFormHandler(self) + + def setCloseCb(self, close_cb): + self.close_cb = close_cb + + def onCloseBtnClick(self): + if self.close_cb: + self.close_cb() + else: + print ("WARNING: no close method defined") + + def onSubmitBtnClick(self): + self.message.setHTML('<strong>Submitting, please wait...</strong>') + self.upload_btn.setEnabled(False) + self.submit() + + def onSubmit(self, event): + pass + + def onSubmitComplete(self, event): + result = event.getResults() + if result != "OK": + Window.alert('Something went wrong while submitting file') + self.close_cb() class Menu(SimplePanel): @@ -95,6 +149,7 @@ menu_settings = MenuBar(vertical=True) #menu_settings.addItem("Parameters", MenuCmd(self, "onParameters")) + menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) # XXX: temporary, will change when a full profile will be managed in SàT menubar = LiberviaMenuBar() @@ -263,3 +318,11 @@ self.host.bridge.call('getParamsUI', gotParams) + def onAvatarUpload(self): + body = AvatarUpload() + _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE']) + body.setCloseCb(_dialog.close) + _dialog.setSize('40%', '40%') + + _dialog.show() +