Subversion Repositories SmartDukaan

Rev

Rev 2359 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2359 Rev 2427
Line 14... Line 14...
14
import com.google.gwt.user.client.ui.DialogBox;
14
import com.google.gwt.user.client.ui.DialogBox;
15
import com.google.gwt.user.client.ui.PasswordTextBox;
15
import com.google.gwt.user.client.ui.PasswordTextBox;
16
import com.google.gwt.user.client.ui.TextBox;
16
import com.google.gwt.user.client.ui.TextBox;
17
import com.google.gwt.user.client.ui.Widget;
17
import com.google.gwt.user.client.ui.Widget;
18
 
18
 
-
 
19
/**
-
 
20
 * This dialog is created when PushToProduction button is pressed.
-
 
21
 * It authenticates the PushToProduction username and password and calls 
-
 
22
 * CatalogService.updateItemOnProduction if authentication is successful.
-
 
23
 * 
19
 
24
 */
20
public class AuthenticateDialog extends DialogBox {
25
public class AuthenticateDialog extends DialogBox {
21
 
26
 
22
    interface Binder extends UiBinder<Widget, AuthenticateDialog> { }
27
    interface Binder extends UiBinder<Widget, AuthenticateDialog> { }
23
    private static final Binder binder = GWT.create(Binder.class);
28
    private static final Binder binder = GWT.create(Binder.class);
24
    
29
    
Line 29... Line 34...
29
    @UiField PasswordTextBox password;
34
    @UiField PasswordTextBox password;
30
    @UiField Button cancelButton, submitButton;
35
    @UiField Button cancelButton, submitButton;
31
 
36
 
32
    private final Item item;
37
    private final Item item;
33
    
38
    
-
 
39
    /**
-
 
40
     * Instantiates this dialog from ItemActions.java on PushToProduction button press.
-
 
41
     * @param - item object which needs to be updated on production server.
-
 
42
     */
34
    public AuthenticateDialog(Item item) {
43
    public AuthenticateDialog(Item item) {
35
        setText("Authentication for Production Update");
44
        setText("Authentication for Production Update");
36
        setWidget(binder.createAndBindUi(this));
45
        setWidget(binder.createAndBindUi(this));
37
        setAnimationEnabled(true);
46
        setAnimationEnabled(true);
38
        center();
47
        center();
39
        this.item = item;
48
        this.item = item;
40
    }
49
    }
41
    
50
    
42
    @UiHandler("submitButton")
51
    @UiHandler("submitButton")
43
    void authenticate(ClickEvent event) {
52
    void authenticate(ClickEvent event) {
-
 
53
        //authenticate username & password with production role.
44
        loginService.authenticateUser(userId.getText(), password.getText(), Utils.ROLE_PRODUCTION, new AsyncCallback<String>() {
54
        loginService.authenticateUser(userId.getText(), password.getText(), Utils.ROLE_PRODUCTION, new AsyncCallback<String>() {
45
            @Override
55
            @Override
46
            public void onSuccess(String result) {
56
            public void onSuccess(String result) {
47
                if(result != null) {
57
                if(result != null) {
-
 
58
                    //Authentication successful. Call update on production.
48
                    pushToProduction();
59
                    pushToProduction();
49
                } else {
60
                } else {
50
                    Window.alert("Authentication failed");
61
                    Window.alert("Authentication failed");
51
                }
62
                }
52
            }
63
            }
53
            @Override
64
            @Override
54
            public void onFailure(Throwable caught) {
65
            public void onFailure(Throwable caught) {
55
                Window.alert("Authentication failed");
66
                Window.alert("Authentication failed");
56
            }
67
            }
57
        });
68
        });
58
 
-
 
59
    }
69
    }
60
    
70
    
61
    private void pushToProduction() {
71
    private void pushToProduction() {
62
        if(item == null) {
72
        if(item == null) {
63
            Window.alert("Please select an item to push to production");
73
            Window.alert("Please select an item to push to production");
64
            return;
74
            return;
65
        }
75
        }
-
 
76
        // returns string. If there is some error while updating on production, string will be the error message
-
 
77
        // otherwise it will be success message.
66
        catalogService.updateItemOnProduction(item, new AsyncCallback<Boolean>() {
78
        catalogService.updateItemOnProduction(item, new AsyncCallback<String>() {
67
            @Override
79
            @Override
68
            public void onSuccess(Boolean result) {
80
            public void onSuccess(String result) {
69
                if(result) {
81
                Window.alert(result);
70
                    Window.alert("Item updated successfully on production");
-
 
71
                    hide();
82
                hide();
72
                } else {
-
 
73
                    Window.alert("Error while updating item on production");
-
 
74
                }
-
 
75
            }
83
            }
76
            @Override
84
            @Override
77
            public void onFailure(Throwable caught) {
85
            public void onFailure(Throwable caught) {
78
                Window.alert("Error while updating item on production");
86
                Window.alert("Error while updating item on production");
79
            }
87
            }
Line 82... Line 90...
82
    
90
    
83
    @UiHandler("cancelButton")
91
    @UiHandler("cancelButton")
84
    void cancel(ClickEvent event) {
92
    void cancel(ClickEvent event) {
85
        hide();
93
        hide();
86
    }
94
    }
87
    
-
 
88
    public void hide() {
-
 
89
        //TODO check if super.hide() destroys the object otherwise
-
 
90
        // everytime push to production is called, a new object of AuthenticateDialog
-
 
91
        // is created.
-
 
92
        super.hide();
-
 
93
    }
-
 
94
}
95
}