def __init__(self,parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) ftable.setWidget(3, 0, Label("Username", wordWrap=False)) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) ftable.setWidget(4, 0, Label("Password", wordWrap=False)) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) ftable.setWidget(5, 0, Label("Confirm", wordWrap=False)) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) ftable.setWidget(6, 0, Label("Department", wordWrap=False)) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User", self.onAdd) self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel", self.onCancel) hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) return
def __init__(self,parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) ftable.setWidget(3, 0, Label("Username", wordWrap=False)) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) ftable.setWidget(4, 0, Label("Password", wordWrap=False)) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) ftable.setWidget(5, 0, Label("Confirm", wordWrap=False)) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) ftable.setWidget(6, 0, Label("Department", wordWrap=False)) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User") self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel") hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) return
def onModuleLoad(self): self.remote_py = MyBlogService() # Create a FormPanel and point it at a service. self.form = FormPanel() # Create a panel to hold all of the form widgets. vp=VerticalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="150px") self.form.setWidget(vp) header=HTML("<h2>LOGIN TO YOUR ACCOUNT</h2>") part1=header # Create a TextBox, giving it a name so that it will be submitted. self.userName = TextBox() self.userName.setName("userNameFormElement") self.userName.setPlaceholder("User Name") part2=self.userName self.password = PasswordTextBox() self.password.setName("passwordFormElement") self.password.setPlaceholder("Password") part3=self.password self.errorInfoLabel = Label() self.errorInfoLabel.setStyleName('error-info') part4=self.errorInfoLabel part4.setStyleName("errorlabel") # Add a 'submit' button. hpanel = HorizontalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="50px") partb=Button("Login", self) partb.setStyleName('btn') image=Label("Don''t have account? Sign up") anchor = Anchor(Widget=image, Href='/signup.html') parta=anchor hpanel.add(partb) hpanel.add(parta) part5=hpanel part5.setStyleName("hpanel") vp.add(part1) vp.add(part2) vp.add(part3) vp.add(part4) vp.add(part5) vp.setStyleName("signup") # Add an event handler to the form. self.form.addFormHandler(self) RootPanel().add(self.form)
def setup(self, x): edit = self.uid == self.app.uid or self.app.admin if not x: x = {'id': -1, 'handle': '', 'name': '' , 'admin': '', 'email': ''} self.uid = x['id'] self.name = TextBox() self.name.setText(x['name']) self.email = TextBox() self.email.setText(x['email']) self.password = PasswordTextBox() self.passwordRepeat = PasswordTextBox() self.handle = TextBox() self.admin = CheckBox() self.admin.setChecked( x['admin'] ) self.admin.setEnabled( self.app.admin ) self.table.setText(0,0, "ID"); self.table.setText(0,1, x['id']) self.table.setText(1,0, "Handle") if x['id'] == -1: self.table.setWidget(1,1, self.handle) else: self.table.setText(1,1, x['handle']) self.table.setText(2,0, "Name"); if edit: self.table.setWidget(2,1, self.name) else: self.table.setText(2,1, x['name']) self.table.setText(3,0, "Email") if edit: self.table.setWidget(3,1, self.email) else: self.table.setText(3,1, x['email']) self.table.setText(4,0, "Admin"); self.table.setWidget(4,1, self.admin) if edit: self.table.setText(5,0, "Password"); self.table.setWidget(5,1, self.password) self.table.setText(6,0, "Password Repeat"); self.table.setWidget(6,1, self.passwordRepeat) self.saveBtn = Button("Save",self.save) self.table.setWidget(7,1, self.saveBtn) if self.app.admin: self.table.setWidget(8,1, Button("Remove", self.delete)) if self.uid == -1: self.add('New user') else: self.add(x['handle'])
def __init__(self, app): DialogBox.__init__(self) self.app = app self.table=FlexTable() self.table.setText(0, 0, "Please enter username and password") self.table.getFlexCellFormatter().setColSpan(0, 0, 2) self.table.setText(1, 0, "Username") self.handle = TextBox() h = getCookie('handle') self.handle.setText(h) self.table.setWidget(1, 1, self.handle) self.table.setText(2, 0, "Password") self.pwd = PasswordTextBox() self.table.setWidget(2, 1, self.pwd) self.table.setHTML(3,0,"") self.table.getFlexCellFormatter().setColSpan(3, 0, 2) h = HorizontalPanel() self.table.setWidget(4,0, h) self.table.getFlexCellFormatter().setColSpan(4, 0, 2) h.add(Button("Ok", getattr(self, "onOk"))) h.add(Button("Cancel", getattr(self, "onClose"))) h.setSpacing(4) self.setHTML("<b>Login</b>") self.setWidget(self.table) left = (Window.getClientWidth() - 200) / 2 top = (Window.getClientHeight() - 100) / 2 self.setPopupPosition(left,top)
def __init__(self): Sink.__init__(self) self.fPasswordText = PasswordTextBox() self.fTextArea = TextArea() self.fTextBox = TextBox() panel = VerticalPanel() panel.setSpacing(8) panel.add(HTML("Normal text box:")) panel.add(self.createTextThing(self.fTextBox)) panel.add(HTML("Password text box:")) panel.add(self.createTextThing(self.fPasswordText)) panel.add(HTML("Text area:")) panel.add(self.createTextThing(self.fTextArea)) panel.add( HTML("""Textarea below demos oninput event. oninput allows to detect when the content of an element has changed. This is different from examples above, where changes are detected only if they are made with keyboard. oninput occurs when the content is changed through any user interface(keyboard, mouse, etc.). For example, at first type few chars, but then paste some text to the text areas above and below by selecting 'Paste' command from context menu or by dragging&dropping and see the difference. oninput is similar to onchange event, but onchange event fires only when a text-entry widget loses focus.""")) vp = VerticalPanel() self.echo = HTML() textArea = TextArea() vp.add(textArea) vp.add(self.echo) textArea.addInputListener(self) panel.add(vp) self.initWidget(panel)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory # update_object = PyjsDelegate( self.update_object, var = var ) multi_line = (factory.multi_line and (not factory.password)) or self.multi_line if factory.password: control = PasswordTextBox() elif multi_line: # control = TextArea() control = TextBox() else: control = TextBox() if multi_line: self.scrollable = True if factory.enter_set and (not multi_line): control.addKeyboadListener(self.update_object, "<Return>") control.addChangeListener(self.update_object) # if factory.auto_set: # control.addKeyboadListener( self.update_object ) # parent.add(control) self.control = control self.set_tooltip()
class LoginDialgoBox(DialogBox,RPCBase): def __init__(self, app): DialogBox.__init__(self) self.app = app self.table=FlexTable() self.table.setText(0, 0, "Please enter username and password") self.table.getFlexCellFormatter().setColSpan(0, 0, 2) self.table.setText(1, 0, "Username") self.handle = TextBox() h = getCookie('handle') self.handle.setText(h) self.table.setWidget(1, 1, self.handle) self.table.setText(2, 0, "Password") self.pwd = PasswordTextBox() self.table.setWidget(2, 1, self.pwd) self.table.setHTML(3,0,"") self.table.getFlexCellFormatter().setColSpan(3, 0, 2) h = HorizontalPanel() self.table.setWidget(4,0, h) self.table.getFlexCellFormatter().setColSpan(4, 0, 2) h.add(Button("Ok", getattr(self, "onOk"))) h.add(Button("Cancel", getattr(self, "onClose"))) h.setSpacing(4) self.setHTML("<b>Login</b>") self.setWidget(self.table) left = (Window.getClientWidth() - 200) / 2 top = (Window.getClientHeight() - 100) / 2 self.setPopupPosition(left,top) def onRemoteResponse(self, response, request_info): if response == "invalid_cookie": self.show() elif response == None or len(response) < 3: self.table.setHTML(3,0,"<b>Invalid username or password</b>") else: self.app.cookie = response[0] setCookie('cookie',response[0],1000*60*60*24) self.hide() self.app.logininit(response[1],response[2]) def onClose(self,env): Window.getLocation().setHref("http://www.google.com") def onOk(self, env): global gw setCookie('handle',self.handle.getText(),24*60*60*1000) x = self.pwd.getText() x = pwhash(x) gw.login(self.handle.getText(), x, self) def login(self): global gw if not self.app.cookie: self.show() else: gw.validateCookie(self.app.cookie, self)
class AuthPanel(VerticalPanel): def __init__(self, beginVerifyAuth, onClose, baseStyleName='gwt-authdlgbox'): """Initialize a new instance. beginVerifyAuth: callable that takes (string username, string password).Should call 'endVerifyAuth' when finished. onClose: callable that takes (AuthDlgBox sender, bool wasAuthorized, string username, string password). Called when Cancel is pressed, or OK is pressed and verification is successful. baseStyleName: base css name for type. baseStyleName + -label, -textbox, and -warninglabel should also be defined. """ VerticalPanel.__init__(self, StyleName=baseStyleName) self.onClose = onClose self.wasAuthorized = False self._beginVerifyAuth = beginVerifyAuth self.baseStyleName = baseStyleName self._createContent() def _createContent(self): self.add(self._createUsernamePanel()) self.add(self._createPasswordPanel()) self.add(self._createButtonPanel()) self.warningLabel = Label('', StyleName='-warninglabel') self.add(self.warningLabel) def _createUsernamePanel(self): hp = HorizontalPanel() hp.add(Label('Username: '******'-label')) self.usernameTB = TextBox(StyleName=self.baseStyleName + '-textbox') hp.add(self.usernameTB) return hp def _createPasswordPanel(self): hp = HorizontalPanel() hp.add(Label('Password: '******'-label')) self.passTB = PasswordTextBox(StyleName=self.baseStyleName + '-textbox') hp.add(self.passTB) return hp def _createButtonPanel(self): hp = HorizontalPanel() self.okBtn = Button('OK', self.onOk, StyleName=self.baseStyleName + '-button') self.cancelBtn = Button('Cancel', self.onCancel, StyleName=self.baseStyleName + '-button') hp.add(self.okBtn) hp.add(self.cancelBtn) return hp def getUserAndPass(self): return self.usernameTB.getText(), self.passTB.getText() def onOk(self, sender): self._beginVerifyAuth(*self.getUserAndPass()) return def onCancel(self, sender): self.onClose(self, False, None, None) return def endVerifyAuth(self, result, username, password, msg='Username/password invalid.'): if result: self.onClose(self, True, username, password) else: self.warningLabel.setText(msg)
def __init__(self): Sink.__init__(self) self.fPasswordText = PasswordTextBox() self.fTextArea = TextArea() self.fTextBox = TextBox() panel = VerticalPanel() panel.setSpacing(8) panel.add(HTML("Normal text box:")) panel.add(self.createTextThing(self.fTextBox)) panel.add(HTML("Password text box:")) panel.add(self.createTextThing(self.fPasswordText)) panel.add(HTML("Text area:")) panel.add(self.createTextThing(self.fTextArea)) self.initWidget(panel)
def __init__(self, listener): VerticalPanel.__init__(self, StyleName = "login") self.listener = listener self.remote = DataService(['login']) form_panel = VerticalPanel(ID = "container", StyleName = "form") self.error_message = Label(StyleName = "error-message") grid = Grid(2, 2, CellPadding=0, CellSpacing=0, StyleName = "form-grid") grid.setWidget(0, 0, Label(JS('gettext("Username:"******"label")) self.tb = TextBox(Name="username") grid.setWidget(0, 1, self.tb) grid.setWidget(1, 0, Label(JS('gettext("Password:"******"label")) self.ptb = PasswordTextBox(Name="password") grid.setWidget(1, 1, self.ptb) form_panel.add(Label(JS('gettext("User Login")'), StyleName = "form-title")) form_panel.add(self.error_message) form_panel.add(grid) button_box = HorizontalPanel(Width="100%") register_button = PseudoLink(JS('gettext("Create an account")'), self.onRegisterButtonClick) submit_button = Button(JS('gettext("Login")'), self.onSubmitButtonClick) button_box.add(register_button) button_box.add(submit_button) button_box.setCellHorizontalAlignment(submit_button, HasAlignment.ALIGN_RIGHT) form_panel.add(button_box) self.add(form_panel)
def onModuleLoad(self): self.form = FormPanel() self.remote_py = MyBlogService() self.form.setAction("/index.html") vp = VerticalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_CENTER, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="100%", Height="150px") self.form.setWidget(vp) header = HTML( "<h2>CREATE MY ACCOUNT</h2><h3>Welcome to signup form</h3>") part1 = header hpn = HorizontalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="92%", Height="60px") self.fname = TextBox() self.fname.setName("fname") self.fname.setPlaceholder("First Name") hpn.add(self.fname) self.lname = TextBox() self.lname.setName("lname") self.lname.setPlaceholder("Last Name") hpn.add(self.lname) hpn.setCellWidth(self.fname, "70%") hpn.setCellWidth(self.lname, "30%") part2 = hpn self.uname = TextBox() self.uname.setName("uname") self.uname.setPlaceholder("User Name") part3 = self.uname self.password = PasswordTextBox() self.password.setName("passsignup") self.password.setPlaceholder("Choose a password") part4 = self.password self.rpassword = PasswordTextBox() self.rpassword.setName("rpasssignup") self.rpassword.setPlaceholder("Confirm your password") part5 = self.rpassword self.email = TextBox() self.email.setName("emailsignup") self.email.setPlaceholder("Enter your email address ") part6 = self.email self.errorlabel = Label() self.errorlabel.setStyleName("errorlabel") part7 = self.errorlabel hpanel = HorizontalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_CENTER, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="100%", Height="50px") partb = Button("Signup", self) partb.setStyleName('btn') image = Label("Already have account! Sign in") anchor = Anchor(Widget=image, Href='/index.html') parta = anchor hpanel.add(partb) hpanel.add(parta) hpanel.setStyleName("hpanel") part8 = hpanel vp.add(part1) vp.add(part2) vp.add(part3) vp.add(part4) vp.add(part5) vp.add(part6) vp.add(part7) vp.add(part8) vp.setCellHeight(part1, "5%") vp.setCellHeight(part2, "10%") vp.setCellHeight(part3, "10%") vp.setCellHeight(part4, "10%") vp.setCellHeight(part5, "10%") vp.setCellHeight(part6, "10%") vp.setCellHeight(part7, "10%") vp.setCellHeight(part8, "10%") vp.setStyleName("signup") self.form.addFormHandler(self) RootPanel().add(self.form)
def _createPasswordPanel(self): hp = HorizontalPanel() hp.add(Label('Password: '******'-label')) self.passTB = PasswordTextBox(StyleName=self.baseStyleName + '-textbox') hp.add(self.passTB) return hp
class LoginPanel(VerticalPanel): def __init__(self, listener): VerticalPanel.__init__(self, StyleName = "login") self.listener = listener self.remote = DataService(['login']) form_panel = VerticalPanel(ID = "container", StyleName = "form") self.error_message = Label(StyleName = "error-message") grid = Grid(2, 2, CellPadding=0, CellSpacing=0, StyleName = "form-grid") grid.setWidget(0, 0, Label(JS('gettext("Username:"******"label")) self.tb = TextBox(Name="username") grid.setWidget(0, 1, self.tb) grid.setWidget(1, 0, Label(JS('gettext("Password:"******"label")) self.ptb = PasswordTextBox(Name="password") grid.setWidget(1, 1, self.ptb) form_panel.add(Label(JS('gettext("User Login")'), StyleName = "form-title")) form_panel.add(self.error_message) form_panel.add(grid) button_box = HorizontalPanel(Width="100%") register_button = PseudoLink(JS('gettext("Create an account")'), self.onRegisterButtonClick) submit_button = Button(JS('gettext("Login")'), self.onSubmitButtonClick) button_box.add(register_button) button_box.add(submit_button) button_box.setCellHorizontalAlignment(submit_button, HasAlignment.ALIGN_RIGHT) form_panel.add(button_box) self.add(form_panel) def onShow(self, sender): self.error_message.setText("") def onRegisterButtonClick(self, sender): self.listener.onRegister(self) def onSubmitButtonClick(self, sender): self.remote.login(self.tb.getText(), self.ptb.getText(), self) def onRemoteResponse(self, response, request_info): ''' Called when a response is received from a RPC. ''' if request_info.method == 'login': if response['success']: self.listener.onLogin(self) else: self.error_message.setText(response['error_message']) else: Window.alert('Unrecognized JSONRPC method.') def onRemoteError(self, code, message, request_info): Window.alert(message)
def __init__(self): SimplePanel.__init__(self) field = PasswordTextBox() field.setWidth("100px") self.add(field)
class UserForm(AbsolutePanel): MODE_ADD = "modeAdd"; MODE_EDIT = "modeEdit"; user = None mode = None usernameInput = None firstInput = None lastInput = None emailInput = None passwordInput = None confirmInput = None departmentCombo = None addBtn = None cancelBtn = None def __init__(self,parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) w = Label("* Username", wordWrap=False) w.addMouseListener(TooltipListener("Required, not changable")) ftable.setWidget(3, 0, w) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) w = Label("* Password", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(4, 0, w) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) w = Label("* Confirm", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(5, 0, w) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) w = Label("* Department", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(6, 0, w) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User") self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel") hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) self.clearForm() return def clearForm(self): self.user = None self.usernameInput.setText('') self.firstInput.setText('') self.lastInput.setText('') self.emailInput.setText('') self.passwordInput.setText('') self.confirmInput.setText('') self.departmentCombo.setItemTextSelection(None) self.updateMode(self.MODE_ADD) self.checkValid() def updateUser(self, user): def setText(elem, value): if value: elem.setText(value) else: elem.setText("") self.user = user setText(self.usernameInput, self.user.username) setText(self.firstInput, self.user.fname) setText(self.lastInput, self.user.lname) setText(self.emailInput, self.user.email) setText(self.passwordInput, self.user.password) setText(self.confirmInput, self.user.password) self.departmentCombo.setItemTextSelection([self.user.department]) self.checkValid() def updateDepartmentCombo(self,choices, default_): self.departmentCombo.clear() for choice in choices: self.departmentCombo.addItem(choice) self.departmentCombo.selectValue(default_) def updateMode(self, mode): self.mode = mode if self.mode == self.MODE_ADD: self.addBtn.setText("Add User") else: self.addBtn.setText("Update User") def checkValid(self, evt=None): if self.enableSubmit(self.usernameInput.getText(),self.passwordInput.getText(),self.confirmInput.getText(), self.departmentCombo.getSelectedItemText(True)): self.addBtn.setEnabled(True) else: self.addBtn.setEnabled(False) def enableSubmit(self, u, p, c, d): return (len(u) > 0 and len(p) >0 and p == c and len(d) > 0) def onClick(self, sender): pass def onKeyUp(self, sender, keyCode, modifiers): self.checkValid() def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): pass
class UserTab(EntityTab): def __init__(self,app, uid): global gw EntityTab.__init__(self, app) self.table = FlexTable() self.uid = uid self.load() def load(self): global gw if self.uid == -1: self.setup(None) else: gw.getUserDetails(self.app.cookie, self.uid, self) def setup(self, x): edit = self.uid == self.app.uid or self.app.admin if not x: x = {'id': -1, 'handle': '', 'name': '' , 'admin': '', 'email': ''} self.uid = x['id'] self.name = TextBox() self.name.setText(x['name']) self.email = TextBox() self.email.setText(x['email']) self.password = PasswordTextBox() self.passwordRepeat = PasswordTextBox() self.handle = TextBox() self.admin = CheckBox() self.admin.setChecked( x['admin'] ) self.admin.setEnabled( self.app.admin ) self.table.setText(0,0, "ID"); self.table.setText(0,1, x['id']) self.table.setText(1,0, "Handle") if x['id'] == -1: self.table.setWidget(1,1, self.handle) else: self.table.setText(1,1, x['handle']) self.table.setText(2,0, "Name"); if edit: self.table.setWidget(2,1, self.name) else: self.table.setText(2,1, x['name']) self.table.setText(3,0, "Email") if edit: self.table.setWidget(3,1, self.email) else: self.table.setText(3,1, x['email']) self.table.setText(4,0, "Admin"); self.table.setWidget(4,1, self.admin) if edit: self.table.setText(5,0, "Password"); self.table.setWidget(5,1, self.password) self.table.setText(6,0, "Password Repeat"); self.table.setWidget(6,1, self.passwordRepeat) self.saveBtn = Button("Save",self.save) self.table.setWidget(7,1, self.saveBtn) if self.app.admin: self.table.setWidget(8,1, Button("Remove", self.delete)) if self.uid == -1: self.add('New user') else: self.add(x['handle']) def onUpdate(self, response, request_info): self.uid = response self.load() self.app.usersTab.reload() def save(self, _): global gw pwd="" if self.password.getText() != "" or self.passwordRepeat.getText() != "": if self.password.getText() != self.passwordRepeat.getText(): Window.alert("Passwords differ"); return pwd = pwhash(self.password.getText()) gw.updateUser(self.app.cookie, self.uid, self.handle.getText(), self.name.getText(), pwd, self.admin.isChecked(), self.email.getText(), RPCCall(self.onUpdate)) def onDelete(self, response, request_info): self.app.usersTab.reload() self.remove() def delete(self,_): global gw gw.deleteUser(self.app.cookie, self.uid, RPCCall(self.onDelete) ) def onRemoteResponse(self, response, request_info): self.setup(response)
class Index: def onModuleLoad(self): self.remote_py = MyBlogService() # Create a FormPanel and point it at a service. self.form = FormPanel() # Create a panel to hold all of the form widgets. vp=VerticalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="150px") self.form.setWidget(vp) header=HTML("<h2>LOGIN TO YOUR ACCOUNT</h2>") part1=header # Create a TextBox, giving it a name so that it will be submitted. self.userName = TextBox() self.userName.setName("userNameFormElement") self.userName.setPlaceholder("User Name") part2=self.userName self.password = PasswordTextBox() self.password.setName("passwordFormElement") self.password.setPlaceholder("Password") part3=self.password self.errorInfoLabel = Label() self.errorInfoLabel.setStyleName('error-info') part4=self.errorInfoLabel part4.setStyleName("errorlabel") # Add a 'submit' button. hpanel = HorizontalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="50px") partb=Button("Login", self) partb.setStyleName('btn') image=Label("Don''t have account? Sign up") anchor = Anchor(Widget=image, Href='/signup.html') parta=anchor hpanel.add(partb) hpanel.add(parta) part5=hpanel part5.setStyleName("hpanel") vp.add(part1) vp.add(part2) vp.add(part3) vp.add(part4) vp.add(part5) vp.setStyleName("signup") # Add an event handler to the form. self.form.addFormHandler(self) RootPanel().add(self.form) def onClick(self, sender): if (len(self.userName.getText()) == 0 or len(self.password.getText()) == 0): self.errorInfoLabel.setText("Username or Password required") else: self.errorInfoLabel.setText('') self.authenticateUser() def authenticateUser(self): self.remote_py.callMethod('authenticateUser', [self.userName.getText(), self.password.getText()], self) def onRemoteResponse(self, response, requestInfo): self.errorInfoLabel.setText('') d = datetime.date.today() + datetime.timedelta(days=1) setCookie("LoggedInUser", response, d, path='/') loggedInUser = json.loads(response) if loggedInUser["is_superuser"] == True: Window.setLocation("/admin.html") else: Window.setLocation("/home.html") def onRemoteError(self, code, error_dict, requestInfo): if code == 401: self.errorInfoLabel.setText("Invalid Credentials. Please try again.")
class UserForm(AbsolutePanel): MODE_ADD = "modeAdd" MODE_EDIT = "modeEdit" user = None mode = None usernameInput = None firstInput = None lastInput = None emailInput = None passwordInput = None confirmInput = None departmentCombo = None addBtn = None cancelBtn = None def __init__(self, parent): AbsolutePanel.__init__(self) ftable = FlexTable() ftable.setWidget(0, 0, Label("First Name", wordWrap=False)) ftableFormatter = ftable.getFlexCellFormatter() self.firstInput = TextBox() self.firstInput.addChangeListener(self.checkValid) self.firstInput.addKeyboardListener(self) ftable.setWidget(0, 1, self.firstInput) ftable.setWidget(1, 0, Label("Last Name", wordWrap=False)) self.lastInput = TextBox() self.lastInput.addChangeListener(self.checkValid) self.lastInput.addKeyboardListener(self) ftable.setWidget(1, 1, self.lastInput) ftable.setWidget(2, 0, Label("Email", wordWrap=False)) self.emailInput = TextBox() self.emailInput.addChangeListener(self.checkValid) self.emailInput.addKeyboardListener(self) ftable.setWidget(2, 1, self.emailInput) w = Label("* Username", wordWrap=False) w.addMouseListener(TooltipListener("Required, not changable")) ftable.setWidget(3, 0, w) self.usernameInput = TextBox() self.usernameInput.addChangeListener(self.checkValid) self.usernameInput.addKeyboardListener(self) ftable.setWidget(3, 1, self.usernameInput) w = Label("* Password", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(4, 0, w) self.passwordInput = PasswordTextBox() self.passwordInput.addChangeListener(self.checkValid) self.passwordInput.addKeyboardListener(self) ftable.setWidget(4, 1, self.passwordInput) w = Label("* Confirm", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(5, 0, w) self.confirmInput = PasswordTextBox() self.confirmInput.addChangeListener(self.checkValid) self.confirmInput.addKeyboardListener(self) ftable.setWidget(5, 1, self.confirmInput) w = Label("* Department", wordWrap=False) w.addMouseListener(TooltipListener("Required")) ftable.setWidget(6, 0, w) self.departmentCombo = ListBox() self.departmentCombo.addChangeListener(self.checkValid) self.departmentCombo.addKeyboardListener(self) ftable.setWidget(6, 1, self.departmentCombo) hpanel = HorizontalPanel() self.addBtn = Button("Add User") self.addBtn.setEnabled(False) hpanel.add(self.addBtn) self.cancelBtn = Button("Cancel") hpanel.add(self.cancelBtn) ftable.setWidget(7, 0, hpanel) ftableFormatter.setColSpan(7, 0, 2) self.add(ftable) self.clearForm() return def clearForm(self): self.user = None self.usernameInput.setText('') self.firstInput.setText('') self.lastInput.setText('') self.emailInput.setText('') self.passwordInput.setText('') self.confirmInput.setText('') self.departmentCombo.setItemTextSelection(None) self.updateMode(self.MODE_ADD) self.checkValid() def updateUser(self, user): def setText(elem, value): if value: elem.setText(value) else: elem.setText("") self.user = user setText(self.usernameInput, self.user.username) setText(self.firstInput, self.user.fname) setText(self.lastInput, self.user.lname) setText(self.emailInput, self.user.email) setText(self.passwordInput, self.user.password) setText(self.confirmInput, self.user.password) self.departmentCombo.setItemTextSelection([self.user.department]) self.checkValid() def updateDepartmentCombo(self, choices, default_): self.departmentCombo.clear() for choice in choices: self.departmentCombo.addItem(choice) self.departmentCombo.selectValue(default_) def updateMode(self, mode): self.mode = mode if self.mode == self.MODE_ADD: self.addBtn.setText("Add User") else: self.addBtn.setText("Update User") def checkValid(self, evt=None): if self.enableSubmit(self.usernameInput.getText(), self.passwordInput.getText(), self.confirmInput.getText(), self.departmentCombo.getSelectedItemText(True)): self.addBtn.setEnabled(True) else: self.addBtn.setEnabled(False) def enableSubmit(self, u, p, c, d): return (len(u) > 0 and len(p) > 0 and p == c and len(d) > 0) def onClick(self, sender): pass def onKeyUp(self, sender, keyCode, modifiers): self.checkValid() def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): pass
class Signup: def onModuleLoad(self): self.form = FormPanel() self.remote_py = MyBlogService() self.form.setAction("/index.html") vp = VerticalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_CENTER, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="100%", Height="150px") self.form.setWidget(vp) header = HTML( "<h2>CREATE MY ACCOUNT</h2><h3>Welcome to signup form</h3>") part1 = header hpn = HorizontalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_LEFT, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="92%", Height="60px") self.fname = TextBox() self.fname.setName("fname") self.fname.setPlaceholder("First Name") hpn.add(self.fname) self.lname = TextBox() self.lname.setName("lname") self.lname.setPlaceholder("Last Name") hpn.add(self.lname) hpn.setCellWidth(self.fname, "70%") hpn.setCellWidth(self.lname, "30%") part2 = hpn self.uname = TextBox() self.uname.setName("uname") self.uname.setPlaceholder("User Name") part3 = self.uname self.password = PasswordTextBox() self.password.setName("passsignup") self.password.setPlaceholder("Choose a password") part4 = self.password self.rpassword = PasswordTextBox() self.rpassword.setName("rpasssignup") self.rpassword.setPlaceholder("Confirm your password") part5 = self.rpassword self.email = TextBox() self.email.setName("emailsignup") self.email.setPlaceholder("Enter your email address ") part6 = self.email self.errorlabel = Label() self.errorlabel.setStyleName("errorlabel") part7 = self.errorlabel hpanel = HorizontalPanel(BorderWidth=0, HorizontalAlignment=HasAlignment.ALIGN_CENTER, VerticalAlignment=HasAlignment.ALIGN_MIDDLE, Width="100%", Height="50px") partb = Button("Signup", self) partb.setStyleName('btn') image = Label("Already have account! Sign in") anchor = Anchor(Widget=image, Href='/index.html') parta = anchor hpanel.add(partb) hpanel.add(parta) hpanel.setStyleName("hpanel") part8 = hpanel vp.add(part1) vp.add(part2) vp.add(part3) vp.add(part4) vp.add(part5) vp.add(part6) vp.add(part7) vp.add(part8) vp.setCellHeight(part1, "5%") vp.setCellHeight(part2, "10%") vp.setCellHeight(part3, "10%") vp.setCellHeight(part4, "10%") vp.setCellHeight(part5, "10%") vp.setCellHeight(part6, "10%") vp.setCellHeight(part7, "10%") vp.setCellHeight(part8, "10%") vp.setStyleName("signup") self.form.addFormHandler(self) RootPanel().add(self.form) def onClick(self, sender): add = self.email.getText() match = re.match( '^[a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', add) if (len(self.fname.getText()) == 0 or len(self.lname.getText()) == 0): self.errorlabel.setText("First Name or Last name can't be empty ") elif (len(self.uname.getText()) == 0): self.errorlabel.setText("Username can't be empty ") elif (len(self.password.getText()) == 0): self.errorlabel.setText("Password can't be empty ") elif (len(self.rpassword.getText()) == 0): self.errorlabel.setText("confirm your password") elif ((self.password.getText() != self.rpassword.getText())): self.errorlabel.setText("Password should be same!") elif match == None: self.errorlabel.setText("invalid email") else: self.errorlabel.setText('') self.createUser() def onSubmitComplete(self, event): Window.alert(event.getResults()) def createUser(self): self.remote_py.callMethod('createUser', [ self.fname.getText(), self.lname.getText(), self.uname.getText(), self.email.getText(), self.password.getText() ], self) def onRemoteResponse(self, response, requestInfo): self.errorlabel.setText('') Window.alert("Signed up successfully. Please login.") Window.setLocation("/index.html") def onRemoteError(self, code, error_dict, requestInfo): if code == 500: self.errorlabel.setText("user name already exists .")