Mercurial > libervia-web
comparison browser_side/menu.py @ 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 | 8635bc9db9bf |
children | 58442ed28f2b |
comparison
equal
deleted
inserted
replaced
151:a159cc29b556 | 152:7e87c87b7952 |
---|---|
22 import pyjd # this is dummy in pyjs | 22 import pyjd # this is dummy in pyjs |
23 from pyjamas.ui.SimplePanel import SimplePanel | 23 from pyjamas.ui.SimplePanel import SimplePanel |
24 from pyjamas.ui.VerticalPanel import VerticalPanel | 24 from pyjamas.ui.VerticalPanel import VerticalPanel |
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel | 25 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
26 from pyjamas.ui.DialogBox import DialogBox | 26 from pyjamas.ui.DialogBox import DialogBox |
27 from pyjamas.ui.FormPanel import FormPanel | |
28 from pyjamas.ui.FileUpload import FileUpload | |
27 from pyjamas.ui.MenuBar import MenuBar | 29 from pyjamas.ui.MenuBar import MenuBar |
28 from pyjamas.ui.MenuItem import MenuItem | 30 from pyjamas.ui.MenuItem import MenuItem |
29 from pyjamas.ui.ListBox import ListBox | 31 from pyjamas.ui.ListBox import ListBox |
30 from pyjamas.ui.Label import Label | 32 from pyjamas.ui.Label import Label |
31 from pyjamas.ui.TextBox import TextBox | 33 from pyjamas.ui.TextBox import TextBox |
61 self.popup.getOffsetWidth() - 22, | 63 self.popup.getOffsetWidth() - 22, |
62 self.getAbsoluteTop() + | 64 self.getAbsoluteTop() + |
63 self.getOffsetHeight() - 1) | 65 self.getOffsetHeight() - 1) |
64 self.popup.addStyleName('menuLastPopup') | 66 self.popup.addStyleName('menuLastPopup') |
65 | 67 |
68 class AvatarUpload(FormPanel): | |
69 | |
70 def __init__(self, close_cb=None): | |
71 FormPanel.__init__(self) | |
72 self.close_cb = close_cb | |
73 self.setEncoding(FormPanel.ENCODING_MULTIPART) | |
74 self.setMethod(FormPanel.METHOD_POST) | |
75 self.setAction("upload_avatar") | |
76 self.vPanel = VerticalPanel() | |
77 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') | |
78 self.vPanel.add(self.message) | |
79 | |
80 hPanel = HorizontalPanel() | |
81 hPanel.setSpacing(5) | |
82 self.file_upload = FileUpload() | |
83 self.file_upload.setName("avatar_path") | |
84 self.vPanel.add(self.file_upload) | |
85 | |
86 hPanel.add(Button("Cancel", getattr(self, "onCloseBtnClick"))) | |
87 self.upload_btn = Button("Upload avatar", getattr(self, "onSubmitBtnClick")) | |
88 hPanel.add(self.upload_btn) | |
89 | |
90 self.status = Label() | |
91 hPanel.add(self.status) | |
92 | |
93 self.vPanel.add(hPanel) | |
94 | |
95 self.add(self.vPanel) | |
96 self.addFormHandler(self) | |
97 | |
98 def setCloseCb(self, close_cb): | |
99 self.close_cb = close_cb | |
100 | |
101 def onCloseBtnClick(self): | |
102 if self.close_cb: | |
103 self.close_cb() | |
104 else: | |
105 print ("WARNING: no close method defined") | |
106 | |
107 def onSubmitBtnClick(self): | |
108 self.message.setHTML('<strong>Submitting, please wait...</strong>') | |
109 self.upload_btn.setEnabled(False) | |
110 self.submit() | |
111 | |
112 def onSubmit(self, event): | |
113 pass | |
114 | |
115 def onSubmitComplete(self, event): | |
116 result = event.getResults() | |
117 if result != "OK": | |
118 Window.alert('Something went wrong while submitting file') | |
119 self.close_cb() | |
66 | 120 |
67 class Menu(SimplePanel): | 121 class Menu(SimplePanel): |
68 | 122 |
69 def __init__(self, host): | 123 def __init__(self, host): |
70 self.host = host | 124 self.host = host |
93 menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract")) | 147 menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract")) |
94 menu_help.addItem("About", MenuCmd(self, "onAbout")) | 148 menu_help.addItem("About", MenuCmd(self, "onAbout")) |
95 | 149 |
96 menu_settings = MenuBar(vertical=True) | 150 menu_settings = MenuBar(vertical=True) |
97 #menu_settings.addItem("Parameters", MenuCmd(self, "onParameters")) | 151 #menu_settings.addItem("Parameters", MenuCmd(self, "onParameters")) |
152 menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) # XXX: temporary, will change when a full profile will be managed in SàT | |
98 | 153 |
99 menubar = LiberviaMenuBar() | 154 menubar = LiberviaMenuBar() |
100 | 155 |
101 for _name, _icon, _menu in [('General', 'home', menu_general), | 156 for _name, _icon, _menu in [('General', 'home', menu_general), |
102 ('Contacts', 'social', menu_contacts), | 157 ('Contacts', 'social', menu_contacts), |
261 _dialog.setSize('80%', '80%') | 316 _dialog.setSize('80%', '80%') |
262 _dialog.show() | 317 _dialog.show() |
263 | 318 |
264 self.host.bridge.call('getParamsUI', gotParams) | 319 self.host.bridge.call('getParamsUI', gotParams) |
265 | 320 |
321 def onAvatarUpload(self): | |
322 body = AvatarUpload() | |
323 _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE']) | |
324 body.setCloseCb(_dialog.close) | |
325 _dialog.setSize('40%', '40%') | |
326 | |
327 _dialog.show() | |
328 |