package org.bbop.apollo.gwt.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;
import org.bbop.apollo.gwt.client.rest.UserRestService;

/**
 * Created by ndunn on 3/17/15.
 */
//  TODO: this needs to be moved into UIBinder into its own class
public class LoginDialog extends DialogBox {

    // TODO: move to UIBinder
    private VerticalPanel panel = new VerticalPanel();
    private Grid grid = new Grid(2,2);
    private Button okButton = new Button("Login");
    private TextBox username = new TextBox();
    private PasswordTextBox passwordTextBox = new PasswordTextBox();
    private HorizontalPanel horizontalPanel = new HorizontalPanel();
    private CheckBox rememberMeCheckBox = new CheckBox("Remember me");

    //
    public LoginDialog() {
//            // Set the dialog box's caption.
        setText("Login");
//
//            // Enable animation.
        setAnimationEnabled(true);
//
//            // Enable glass background.
        setGlassEnabled(true);

        grid.setHTML(0, 0, "Username");
        grid.setWidget(0, 1, username);
        grid.setHTML(1, 0, "Password");
        grid.setWidget(1, 1, passwordTextBox);
        panel.add(grid);
        

        horizontalPanel.add(rememberMeCheckBox);
        horizontalPanel.add(new HTML("&nbsp;&nbsp;&nbsp;&nbsp;"));
        horizontalPanel.add(okButton);
        panel.add(horizontalPanel);
//
//            // DialogBox is a SimplePanel, so you have to set its widget property to
//            // whatever you want its contents to be.
       

        okButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                doLogin(username.getText().trim(),passwordTextBox.getText(),rememberMeCheckBox.getValue());
            }
        });
        setWidget(panel);
    }

    public void doLogin(String username,String password,Boolean rememberMe){
        UserRestService.login(username, password,rememberMe);
    }
}


@@ -160,24 +160,253 @@
 gwt.
-user.client.ui.*
+event.dom.client.KeyCodes;%0Aimport com.google.gwt.event.dom.client.KeyCodes;%0Aimport com.google.gwt.dom.client.NativeEvent;%0Aimport com.google.gwt.user.client.ui.*;%0Aimport com.google.gwt.user.client.Event.*;%0Aimport com.google.gwt.user.client.Window
 ;%0Aim
@@ -1047,15 +1047,8 @@
 );%0A%0A
-    //%0A
     
@@ -1070,22 +1070,16 @@
 log() %7B%0A
-//    
         
@@ -1137,30 +1137,24 @@
 ogin%22);%0A
-//%0A// 
         
    // En
@@ -1137,35 +1137,32 @@
 ogin%22);%0A        
-   
 // Enable animat
@@ -1201,25 +1201,16 @@
 (true);%0A
-//%0A//    
         
@@ -1666,17 +1666,8 @@
 l);%0A
-//%0A//    
     
@@ -1747,14 +1747,8 @@
  to%0A
-//    
     
@@ -1792,25 +1792,16 @@
  to be.%0A
-       %0A%0A
         
@@ -2085,16 +2085,404 @@
 );%0A    %7D
+%0A    @Override%0A    public void onPreviewNativeEvent(NativePreviewEvent e) %7B%0A        NativeEvent nativeEvent = e.getNativeEvent();%0A        if (%22keydown%22.equals(nativeEvent.getType())) %7B%0A            if (nativeEvent.getKeyCode() == KeyCodes.KEY_ENTER) %7B%0A                doLogin(username.getText().trim(),passwordTextBox.getText(),rememberMeCheckBox.getValue());%0A            %7D%0A        %7D%0A    %7D
 %0A%0A    pu

Allow enter key from login popup. Fixes #212