comparison browser_side/register.py @ 216:9827cda1a6b0

browser_side: added key listener to login and register panels - pressing enter set the focus to the next field or validate the form fix bug 29
author souliane <souliane@mailoo.org>
date Sun, 08 Sep 2013 13:40:01 +0200
parents 3d998119237e
children 759fd7386e1e
comparison
equal deleted inserted replaced
215:e830a0c60d32 216:9827cda1a6b0
35 from pyjamas.ui.Label import Label 35 from pyjamas.ui.Label import Label
36 from pyjamas.ui.PopupPanel import PopupPanel 36 from pyjamas.ui.PopupPanel import PopupPanel
37 from pyjamas.ui.Image import Image 37 from pyjamas.ui.Image import Image
38 from pyjamas.ui.Hidden import Hidden 38 from pyjamas.ui.Hidden import Hidden
39 from pyjamas import Window 39 from pyjamas import Window
40 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER
40 import re 41 import re
41 42
42 43
43 class RegisterPanel(FormPanel): 44 class RegisterPanel(FormPanel):
44 45
56 main_panel.add(left_side) 57 main_panel.add(left_side)
57 58
58 ##TabPanel## 59 ##TabPanel##
59 tab_bar = TabBar() 60 tab_bar = TabBar()
60 tab_bar.setStyleName('registerPanel_tabs') 61 tab_bar.setStyleName('registerPanel_tabs')
61 self.right_side = TabPanel(tab_bar) 62 self.right_side = TabPanel(tab_bar)
62 self.right_side.setStyleName('registerPanel_right_side') 63 self.right_side.setStyleName('registerPanel_right_side')
63 main_panel.add(self.right_side) 64 main_panel.add(self.right_side)
64 main_panel.setCellWidth(self.right_side, '100%') 65 main_panel.setCellWidth(self.right_side, '100%')
65
66 66
67 ##Login tab## 67 ##Login tab##
68 login_tab = SimplePanel() 68 login_tab = SimplePanel()
69 login_tab.setStyleName('registerPanel_content') 69 login_tab.setStyleName('registerPanel_content')
70 login_vpanel = VerticalPanel() 70 login_vpanel = VerticalPanel()
71 login_tab.setWidget(login_vpanel) 71 login_tab.setWidget(login_vpanel)
72 72
73
74 self.login_warning_msg = Label('') 73 self.login_warning_msg = Label('')
75 self.login_warning_msg.setVisible(False) 74 self.login_warning_msg.setVisible(False)
76 self.login_warning_msg.setStyleName('formWarning') 75 self.login_warning_msg.setStyleName('formWarning')
77 login_vpanel.add(self.login_warning_msg) 76 login_vpanel.add(self.login_warning_msg)
78 77
79 login_label = Label('Login:') 78 login_label = Label('Login:')
80 self.login_box = TextBox() 79 self.login_box = TextBox()
81 self.login_box.setName("login") 80 self.login_box.setName("login")
81 self.login_box.addKeyboardListener(self)
82 login_pass_label = Label('Password:') 82 login_pass_label = Label('Password:')
83 login_pass_box = PasswordTextBox() 83 self.login_pass_box = PasswordTextBox()
84 login_pass_box.setName("login_password") 84 self.login_pass_box.setName("login_password")
85 self.login_pass_box.addKeyboardListener(self)
86
85 login_vpanel.add(login_label) 87 login_vpanel.add(login_label)
86 login_vpanel.add(self.login_box) 88 login_vpanel.add(self.login_box)
87 login_vpanel.add(login_pass_label) 89 login_vpanel.add(login_pass_label)
88 login_vpanel.add(login_pass_box) 90 login_vpanel.add(self.login_pass_box)
89 login_but = Button("Log in", getattr(self, "onLogin")) 91 login_but = Button("Log in", getattr(self, "onLogin"))
90 login_but.setStyleName('button') 92 login_but.setStyleName('button')
91 login_but.addStyleName('red') 93 login_but.addStyleName('red')
92 login_vpanel.add(login_but) 94 login_vpanel.add(login_but)
93 95
94 #The hidden submit_type field 96 #The hidden submit_type field
95 self.submit_type = Hidden('submit_type') 97 self.submit_type = Hidden('submit_type')
96 login_vpanel.add(self.submit_type) 98 login_vpanel.add(self.submit_type)
97 99
98
99 ##Register tab## 100 ##Register tab##
100 register_tab = SimplePanel() 101 register_tab = SimplePanel()
101 register_tab.setStyleName('registerPanel_content') 102 register_tab.setStyleName('registerPanel_content')
102 register_vpanel = VerticalPanel() 103 register_vpanel = VerticalPanel()
103 register_tab.setWidget(register_vpanel) 104 register_tab.setWidget(register_vpanel)
104 105
105 self.register_warning_msg = Label('') 106 self.register_warning_msg = Label('')
106 self.register_warning_msg.setVisible(False) 107 self.register_warning_msg.setVisible(False)
107 self.register_warning_msg.setStyleName('formWarning') 108 self.register_warning_msg.setStyleName('formWarning')
108 register_vpanel.add(self.register_warning_msg) 109 register_vpanel.add(self.register_warning_msg)
109 110
110 register_login_label = Label('Login:') 111 register_login_label = Label('Login:')
111 self.register_login_box = TextBox() 112 self.register_login_box = TextBox()
112 self.register_login_box.setName("register_login") 113 self.register_login_box.setName("register_login")
114 self.register_login_box.addKeyboardListener(self)
113 email_label = Label('E-mail:') 115 email_label = Label('E-mail:')
114 self.email_box = TextBox() 116 self.email_box = TextBox()
115 self.email_box.setName("email") 117 self.email_box.setName("email")
118 self.email_box.addKeyboardListener(self)
116 register_pass_label = Label('Password:') 119 register_pass_label = Label('Password:')
117 self.register_pass_box = PasswordTextBox() 120 self.register_pass_box = PasswordTextBox()
118 self.register_pass_box.setName("register_password") 121 self.register_pass_box.setName("register_password")
122 self.register_pass_box.addKeyboardListener(self)
119 register_vpanel.add(register_login_label) 123 register_vpanel.add(register_login_label)
120 register_vpanel.add(self.register_login_box) 124 register_vpanel.add(self.register_login_box)
121 register_vpanel.add(email_label) 125 register_vpanel.add(email_label)
122 register_vpanel.add(self.email_box) 126 register_vpanel.add(self.email_box)
123 register_vpanel.add(register_pass_label) 127 register_vpanel.add(register_pass_label)
124 register_vpanel.add(self.register_pass_box) 128 register_vpanel.add(self.register_pass_box)
125 129
126 register_but = Button("Register", getattr(self, "onRegister")) 130 register_but = Button("Register", getattr(self, "onRegister"))
127 register_but.setStyleName('button') 131 register_but.setStyleName('button')
128 register_but.addStyleName('red') 132 register_but.addStyleName('red')
129 register_vpanel.add(register_but) 133 register_vpanel.add(register_but)
130 134
131 self.right_side.add(login_tab, 'Login') 135 self.right_side.add(login_tab, 'Login')
132 self.right_side.add(register_tab, 'Register') 136 self.right_side.add(register_tab, 'Register')
133 self.right_side.selectTab(0) 137 self.right_side.selectTab(0)
134 login_tab.setWidth(None) 138 login_tab.setWidth(None)
135 register_tab.setWidth(None) 139 register_tab.setWidth(None)
136 140
137 self.add(main_panel) 141 self.add(main_panel)
138 self.addFormHandler(self) 142 self.addFormHandler(self)
139 self.setAction('register_api/login') 143 self.setAction('register_api/login')
144
145 def onKeyPress(self, sender, keycode, modifiers):
146 if keycode == KEY_ENTER:
147 if sender == self.login_box:
148 self.login_pass_box.setFocus(True)
149 elif sender == self.login_pass_box:
150 self.onLogin(None)
151 elif sender == self.register_login_box:
152 self.email_box.setFocus(True)
153 elif sender == self.email_box:
154 self.register_pass_box.setFocus(True)
155 elif sender == self.register_pass_box:
156 self.onRegister(None)
157
158 def onKeyUp(self, sender, keycode, modifiers):
159 pass
160
161 def onKeyDown(self, sender, keycode, modifiers):
162 pass
140 163
141 def onLogin(self, button): 164 def onLogin(self, button):
142 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE): 165 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
143 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -') 166 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
144 self.login_warning_msg.setVisible(True) 167 self.login_warning_msg.setVisible(True)
156 else: 179 else:
157 self.register_warning_msg.setVisible(False) 180 self.register_warning_msg.setVisible(False)
158 self.submit_type.setValue('register') 181 self.submit_type.setValue('register')
159 self.submit() 182 self.submit()
160 183
161
162 def onSubmit(self, event): 184 def onSubmit(self, event):
163 pass 185 pass
164 186
165 def onSubmitComplete(self, event): 187 def onSubmitComplete(self, event):
166 result = event.getResults() 188 result = event.getResults()