diff browser_side/register.py @ 66:9d8e79ac4c9c

Login/Register box: integration of Adrien Vigneron's design
author Goffi <goffi@goffi.org>
date Wed, 15 Jun 2011 00:52:02 +0200
parents 12e889a683ce
children b096facaa5b3
line wrap: on
line diff
--- a/browser_side/register.py	Wed Jun 15 00:49:34 2011 +0200
+++ b/browser_side/register.py	Wed Jun 15 00:52:02 2011 +0200
@@ -3,7 +3,8 @@
 
 """
 Libervia: a Salut à Toi frontend
-Copyright (C) 2011  Jérôme Poisson (goffi@goffi.org)
+Copyright (C) 2011  Jérôme Poisson <goffi@goffi.org>
+Copyright (C) 2011  Adrien Vigneron <adrienvigneron@mailoo.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
@@ -22,7 +23,11 @@
 #This page manage subscription and new account creation
 import pyjd # this is dummy in pyjs
 
+from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.TabPanel import TabPanel
+from pyjamas.ui.TabBar import TabBar
 from pyjamas.ui.Grid import Grid
 from pyjamas.ui.PasswordTextBox import PasswordTextBox
 from pyjamas.ui.TextBox import TextBox
@@ -30,14 +35,14 @@
 from pyjamas.ui.Button import Button
 from pyjamas.ui.Label import Label
 from pyjamas.ui.CheckBox import CheckBox
-from pyjamas.ui.DialogBox import DialogBox
+from pyjamas.ui.PopupPanel import PopupPanel
+from pyjamas.ui.Image import Image
+from pyjamas.ui.Hidden import Hidden
 from pyjamas import Window
 from pyjamas.ui import HasAlignment
 import re
 
 
-
-
 class RegisterPanel(FormPanel):
 
     def __init__(self, callback):
@@ -45,79 +50,92 @@
         @param callback: method to call if login successful
         """
         FormPanel.__init__(self)
+        self.setSize('600px', '350px')
         self.callback = callback
         self.setMethod(FormPanel.METHOD_POST)
-        vPanel = VerticalPanel()
-        vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
+        main_panel = HorizontalPanel()
+        main_panel.setStyleName('registerPanel_main')
+        left_side = Image("register_left.png")
+        main_panel.add(left_side)
+
+        ##TabPanel##
+        tab_bar = TabBar()
+        tab_bar.setStyleName('registerPanel_tabs')
+        right_side = TabPanel(tab_bar) 
+        right_side.setStyleName('registerPanel_right_side')
+        main_panel.add(right_side)
+        main_panel.setCellWidth(right_side, '100%')
+        
+
+        ##Login tab##
+        login_tab = SimplePanel()
+        login_tab.setStyleName('registerPanel_content')
+        login_vpanel = VerticalPanel()
+        login_tab.setWidget(login_vpanel)
+        
+        
         self.warning_msg = Label()
         self.warning_msg.setVisible(False)
         self.warning_msg.setStyleName('formWarning')
-        vPanel.add(self.warning_msg)
+        #login_vpanel.add(self.warning_msg)
 
+        login_label = Label('Login:')
         self.login_box = TextBox()
         self.login_box.setName("login")
-        self.pass_box = PasswordTextBox()
-        self.pass_box.setName("password")
-        login_grid = Grid(2, 2)
-        login_grid.setText(0,0,"Login:")
-        login_grid.setWidget(0,1, self.login_box)
-        login_grid.setText(1,0, "Password:")
-        login_grid.setWidget(1,1, self.pass_box)
-        vPanel.add(login_grid)
+        login_pass_label = Label('Password:')
+        login_pass_box = PasswordTextBox()
+        login_pass_box.setName("login_password")
+        login_vpanel.add(login_label)
+        login_vpanel.add(self.login_box)
+        login_vpanel.add(login_pass_label)
+        login_vpanel.add(login_pass_box)
+        login_but = Button("Log in", getattr(self, "onLogin"))
+        login_but.setStyleName('button')
+        login_but.addStyleName('red')
+        login_vpanel.add(login_but)
+
+        #The hidden submit_type field
+        self.submit_type = Hidden('submit_type')
+        login_vpanel.add(self.submit_type)
+
         
-        self.new_account = CheckBox('Register new account')
-        self.new_account.setName('new_account')
-        self.new_account.addClickListener(self.onNewAccountChecked)
-        vPanel.add(self.new_account)
+        ##Register tab##
+        register_tab = SimplePanel()
+        register_tab.setStyleName('registerPanel_content')
+        register_vpanel = VerticalPanel()
+        register_tab.setWidget(register_vpanel)
         
-        
+        register_login_label = Label('Login:')
+        register_login_box = TextBox()
+        register_login_box.setName("register_login")
+        email_label = Label('E-mail:')
         self.email_box = TextBox()
         self.email_box.setName("email")
-        self.register_grid = Grid(1, 2)
-        self.register_grid.setText(0,0,"email:")
-        self.register_grid.setWidget(0,1, self.email_box)
-        self.register_grid.setVisible(False)
-        vPanel.add(self.register_grid)
-        self.info_register_lb = Label('Your password will be sent to the given email')
-        self.info_register_lb.setVisible(False)
-        vPanel.add(self.register_grid)
-        vPanel.add(self.info_register_lb)
+        register_pass_label = Label('Password:')
+        self.register_pass_box = PasswordTextBox()
+        self.register_pass_box.setName("register_password")
+        register_vpanel.add(register_login_label)
+        register_vpanel.add(register_login_box)
+        register_vpanel.add(email_label)
+        register_vpanel.add(self.email_box)
+        register_vpanel.add(register_pass_label)
+        register_vpanel.add(self.register_pass_box)
+         
+        register_but = Button("Register", getattr(self, "onRegister"))
+        register_but.setStyleName('button')
+        register_but.addStyleName('red')
+        register_vpanel.add(register_but)
         
-        self.login_but = Button("Login", getattr(self, "onLogin"))
-        vPanel.add(self.login_but)
-        self.register_but = Button("Register", getattr(self, "onRegister"))
-        self.register_but.setVisible(False)
-        vPanel.add(self.register_but)
-        self.add(vPanel)
+        right_side.add(login_tab, 'Login')
+        right_side.add(register_tab, 'Register')
+        right_side.selectTab(0)
+        
+        self.add(main_panel)
         self.addFormHandler(self)
         self.setAction('register_api/login')
 
-    def changeMode(self, mode):
-        """Change the configuration of the dialog
-        @param mode: "login" or "register"""
-        if mode == "register":
-            self.pass_box.setEnabled(False)
-            self.register_grid.setVisible(True)
-            self.info_register_lb.setVisible(True)
-            self.login_but.setVisible(False)
-            self.register_but.setVisible(True)
-            self.new_account.setChecked(True)
-        else:
-            self.pass_box.setEnabled(True)
-            self.register_grid.setVisible(False)
-            self.info_register_lb.setVisible(False)
-            self.login_but.setVisible(True)
-            self.register_but.setVisible(False)
-            self.new_account.setChecked(False)
-
-
-    def onNewAccountChecked(self, sender):
-        if sender.isChecked():
-            self.changeMode("register")
-        else:
-            self.changeMode("login")
-
     def onLogin(self, button):
+        self.submit_type.setValue('login')
         self.submit()
 
     def onRegister(self, button):
@@ -130,6 +148,7 @@
             self.warning_msg.setVisible(True)
         else:
             self.warning_msg.setVisible(False)
+            self.submit_type.setValue('register')
             self.submit()
 
     
@@ -149,16 +168,23 @@
             self.warning_msg.setVisible(True)
         elif result == "REGISTRATION":
             self.warning_msg.setVisible(False)
-            self.changeMode('login')
-            self.pass_box.setText('')
+            self.register_pass_box.setText('')
             Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO')
         else:
             Window.alert('Submit error: %s' % result)
 
-class RegisterBox(DialogBox):
+class RegisterBox(PopupPanel):
 
     def __init__(self, callback, *args,**kwargs):
-        DialogBox.__init__(self,*args,**kwargs)
+        PopupPanel.__init__(self,*args,**kwargs)
         _form = RegisterPanel(callback)
-        self.setHTML('<b>You are not identified, please log in</b>')
         self.setWidget(_form)
+    
+    def onWindowResized(self, width, height):
+        super(RegisterBox, self).onWindowResized(width, height)
+        self.centerBox()
+
+    def show(self):
+        super(RegisterBox, self).show()
+        self.centerBox()
+