| 2359 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
5 |
|
|
|
6 |
import com.google.gwt.core.client.GWT;
|
|
|
7 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
8 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
9 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
11 |
import com.google.gwt.user.client.Window;
|
|
|
12 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
13 |
import com.google.gwt.user.client.ui.Button;
|
|
|
14 |
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
15 |
import com.google.gwt.user.client.ui.PasswordTextBox;
|
|
|
16 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
17 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
public class AuthenticateDialog extends DialogBox {
|
|
|
21 |
|
|
|
22 |
interface Binder extends UiBinder<Widget, AuthenticateDialog> { }
|
|
|
23 |
private static final Binder binder = GWT.create(Binder.class);
|
|
|
24 |
|
|
|
25 |
private final LoginServiceAsync loginService = GWT.create(LoginService.class);
|
|
|
26 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
|
|
27 |
|
|
|
28 |
@UiField TextBox userId;
|
|
|
29 |
@UiField PasswordTextBox password;
|
|
|
30 |
@UiField Button cancelButton, submitButton;
|
|
|
31 |
|
|
|
32 |
private final Item item;
|
|
|
33 |
|
|
|
34 |
public AuthenticateDialog(Item item) {
|
|
|
35 |
setText("Authentication for Production Update");
|
|
|
36 |
setWidget(binder.createAndBindUi(this));
|
|
|
37 |
setAnimationEnabled(true);
|
|
|
38 |
center();
|
|
|
39 |
this.item = item;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
@UiHandler("submitButton")
|
|
|
43 |
void authenticate(ClickEvent event) {
|
|
|
44 |
loginService.authenticateUser(userId.getText(), password.getText(), Utils.ROLE_PRODUCTION, new AsyncCallback<String>() {
|
|
|
45 |
@Override
|
|
|
46 |
public void onSuccess(String result) {
|
|
|
47 |
if(result != null) {
|
|
|
48 |
pushToProduction();
|
|
|
49 |
} else {
|
|
|
50 |
Window.alert("Authentication failed");
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
@Override
|
|
|
54 |
public void onFailure(Throwable caught) {
|
|
|
55 |
Window.alert("Authentication failed");
|
|
|
56 |
}
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
private void pushToProduction() {
|
|
|
62 |
if(item == null) {
|
|
|
63 |
Window.alert("Please select an item to push to production");
|
|
|
64 |
return;
|
|
|
65 |
}
|
|
|
66 |
catalogService.updateItemOnProduction(item, new AsyncCallback<Boolean>() {
|
|
|
67 |
@Override
|
|
|
68 |
public void onSuccess(Boolean result) {
|
|
|
69 |
if(result) {
|
|
|
70 |
Window.alert("Item updated successfully on production");
|
|
|
71 |
hide();
|
|
|
72 |
} else {
|
|
|
73 |
Window.alert("Error while updating item on production");
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
@Override
|
|
|
77 |
public void onFailure(Throwable caught) {
|
|
|
78 |
Window.alert("Error while updating item on production");
|
|
|
79 |
}
|
|
|
80 |
});
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@UiHandler("cancelButton")
|
|
|
84 |
void cancel(ClickEvent event) {
|
|
|
85 |
hide();
|
|
|
86 |
}
|
|
|
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 |
}
|