| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
|
|
|
5 |
import com.google.gwt.core.client.EntryPoint;
|
|
|
6 |
import com.google.gwt.core.client.GWT;
|
|
|
7 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
8 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
9 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiTemplate;
|
|
|
12 |
import com.google.gwt.user.client.Window;
|
|
|
13 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
14 |
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
|
|
15 |
import com.google.gwt.user.client.ui.RootLayoutPanel;
|
|
|
16 |
|
|
|
17 |
public class CatalogDashboard implements EntryPoint {
|
|
|
18 |
|
|
|
19 |
@UiTemplate("CatalogDashboard.ui.xml")
|
|
|
20 |
interface CatalogBinder extends UiBinder<DockLayoutPanel, CatalogDashboard> {
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
private static final CatalogBinder binder = GWT.create(CatalogBinder.class);
|
|
|
24 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
|
|
25 |
private final LoginServiceAsync loginService = GWT.create(LoginService.class);
|
|
|
26 |
|
|
|
27 |
@UiField
|
|
|
28 |
TopPanel topPanel;
|
|
|
29 |
@UiField
|
|
|
30 |
ItemList itemList;
|
|
|
31 |
@UiField
|
|
|
32 |
ItemDetails itemDetails;
|
|
|
33 |
@UiField
|
|
|
34 |
Shortcuts shortcuts;
|
|
|
35 |
|
|
|
36 |
RootLayoutPanel root;
|
|
|
37 |
LoginScreen login;
|
|
|
38 |
|
|
|
39 |
public void onModuleLoad() {
|
|
|
40 |
|
|
|
41 |
root = RootLayoutPanel.get();
|
|
|
42 |
login = new LoginScreen();
|
|
|
43 |
root.add(login);
|
|
|
44 |
login.setLoginListener(new LoginScreen.LoginListener() {
|
|
|
45 |
@Override
|
|
|
46 |
public void onLoginPressed(String username, String password) {
|
|
|
47 |
authenticateUser(username, password);
|
|
|
48 |
/*
|
|
|
49 |
* if (username.equals("ankur") && password.equals("ankur")) {
|
|
|
50 |
* root.clear(); initMainDB(username); }
|
|
|
51 |
*/
|
|
|
52 |
}
|
|
|
53 |
});
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private void authenticateUser(String username, String password) {
|
|
|
57 |
final String uname = username;
|
|
|
58 |
loginService.authenticateUser(username, password, new AsyncCallback<Long>() {
|
|
|
59 |
@Override
|
|
|
60 |
public void onSuccess(Long result) {
|
|
|
61 |
if (result != -1) {
|
|
|
62 |
root.clear();
|
|
|
63 |
initMainDB(uname);
|
|
|
64 |
login.clearFields();
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
@Override
|
|
|
68 |
public void onFailure(Throwable caught) {
|
|
|
69 |
login.setErrorText("Invalid username/password");
|
|
|
70 |
}
|
|
|
71 |
});
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
private void initMainDB(String username) {
|
|
|
75 |
DockLayoutPanel dashboard = binder.createAndBindUi(this);
|
|
|
76 |
topPanel.changeGreeting(username);
|
|
|
77 |
itemList.setListener(new ItemList.Listener() {
|
|
|
78 |
public void onItemSelected(Item item) {
|
|
|
79 |
itemDetails.setItemDetails(item);
|
|
|
80 |
}
|
|
|
81 |
});
|
|
|
82 |
|
|
|
83 |
itemDetails.setPriceUpdateListener(new ItemDetails.PriceUpdateListener() {
|
|
|
84 |
@Override
|
|
|
85 |
public void onPriceUpdate(long itemId, double sellingPrice) {
|
|
|
86 |
catalogService.updatePrice(itemId, sellingPrice, new AsyncCallback<Void>() {
|
|
|
87 |
@Override
|
|
|
88 |
public void onSuccess(Void result) {
|
|
|
89 |
// TODO: refresh item list and disable submit button
|
|
|
90 |
Window.alert("Price updated successfully...Hurray !!!");
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void onFailure(Throwable caught) {
|
|
|
95 |
Window.alert("Error while updating price");
|
|
|
96 |
}
|
|
|
97 |
});
|
|
|
98 |
}
|
|
|
99 |
});
|
|
|
100 |
topPanel.getSignOutLink().addClickHandler(new ClickHandler() {
|
|
|
101 |
@Override
|
|
|
102 |
public void onClick(ClickEvent event) {
|
|
|
103 |
root.clear();
|
|
|
104 |
root.add(login);
|
|
|
105 |
}
|
|
|
106 |
});
|
|
|
107 |
root.clear();
|
|
|
108 |
root.add(dashboard);
|
|
|
109 |
}
|
|
|
110 |
}
|