| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.client;
|
|
|
2 |
|
| 4397 |
rajveer |
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadAlertsEvent;
|
| 4364 |
rajveer |
4 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderCountsEvent;
|
| 167 |
ashish |
5 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEvent;
|
| 306 |
ashish |
6 |
import in.shop2020.hotspot.dashbaord.client.event.SignOutEvent;
|
|
|
7 |
import in.shop2020.hotspot.dashbaord.client.event.SignOutEventHandler;
|
| 167 |
ashish |
8 |
import in.shop2020.hotspot.dashbaord.client.event.SubmitLoginInfoEvent;
|
|
|
9 |
import in.shop2020.hotspot.dashbaord.client.event.SubmitLoginInfoHandler;
|
|
|
10 |
import in.shop2020.hotspot.dashbaord.client.inbox.InboxPresenter;
|
|
|
11 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
|
|
|
12 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
|
| 345 |
ashish |
13 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
|
| 19269 |
manish.sha |
14 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderCategory;
|
| 4364 |
rajveer |
15 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 167 |
ashish |
16 |
|
|
|
17 |
import net.customware.gwt.dispatch.client.DispatchAsync;
|
|
|
18 |
|
|
|
19 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
20 |
import org.enunes.gwt.mvp.client.presenter.BasePresenter;
|
|
|
21 |
import org.enunes.gwt.mvp.client.presenter.Presenter;
|
|
|
22 |
|
|
|
23 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
24 |
import com.google.inject.Inject;
|
|
|
25 |
import com.google.inject.Provider;
|
|
|
26 |
|
|
|
27 |
public class MainPresenterImpl extends BasePresenter<MainPresenter.Display> implements MainPresenter{
|
|
|
28 |
|
|
|
29 |
private final Provider<InboxPresenter> inboxProvider;
|
|
|
30 |
private final LoginDisplayPresenter lPresenter;
|
|
|
31 |
private Presenter<? extends org.enunes.gwt.mvp.client.view.Display> presenter;
|
|
|
32 |
private final DispatchAsync dispatcher;
|
|
|
33 |
|
|
|
34 |
@Inject
|
|
|
35 |
public MainPresenterImpl(EventBus eventBus, Display display, LoginDisplayPresenter loginpresenter,
|
| 5455 |
rajveer |
36 |
Provider<InboxPresenter> inboxProvider, final DispatchAsync dispatcher ) {
|
| 167 |
ashish |
37 |
super(eventBus, display);
|
|
|
38 |
this.inboxProvider = inboxProvider;
|
|
|
39 |
lPresenter = loginpresenter;
|
|
|
40 |
lPresenter.bind();
|
|
|
41 |
this.dispatcher = dispatcher;
|
|
|
42 |
display.addContent(loginpresenter.getDisplay());
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
private void switchPresenter(
|
|
|
46 |
Presenter<? extends org.enunes.gwt.mvp.client.view.Display> presenter) {
|
|
|
47 |
|
|
|
48 |
if (this.presenter != null) {
|
|
|
49 |
this.presenter.unbind();
|
|
|
50 |
display.removeContent();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
this.presenter = presenter;
|
|
|
54 |
|
|
|
55 |
if (presenter != null) {
|
|
|
56 |
display.addContent(presenter.getDisplay());
|
|
|
57 |
this.presenter.bind();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public void bind(){
|
|
|
64 |
super.bind();
|
| 306 |
ashish |
65 |
registerHandler(eventBus.addHandler(SignOutEvent.getType(), new SignOutEventHandler() {
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void doSignout(SignOutEvent event) {
|
|
|
69 |
signOut();
|
|
|
70 |
}
|
|
|
71 |
}));
|
|
|
72 |
|
| 167 |
ashish |
73 |
registerHandler(eventBus.addHandler(SubmitLoginInfoEvent.getType(), new SubmitLoginInfoHandler() {
|
|
|
74 |
|
|
|
75 |
@Override
|
|
|
76 |
public void onSubmitLoginInfo(SubmitLoginInfoEvent event) {
|
|
|
77 |
|
|
|
78 |
dispatcher.execute(new AuthRequest(event.getUserName(), event.getPassword()), new AsyncCallback<AuthResponse>() {
|
|
|
79 |
|
|
|
80 |
@Override
|
|
|
81 |
public void onFailure(Throwable caught) {
|
|
|
82 |
lPresenter.showError("You do not seem in good terms with auth server. It is lost!");
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
@Override
|
|
|
86 |
public void onSuccess(AuthResponse result) {
|
|
|
87 |
doAuth(result);
|
|
|
88 |
}
|
|
|
89 |
});
|
|
|
90 |
}
|
|
|
91 |
}));
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private void doAuth(AuthResponse result){
|
|
|
95 |
if (result.isStatus()){
|
|
|
96 |
lPresenter.showError("Welcome! "+ result.getUsername() +", "+ result.getMessage());
|
|
|
97 |
|
| 345 |
ashish |
98 |
if(result.getNext() == NEXT.INBOX){
|
|
|
99 |
final InboxPresenter inboxPresenter = inboxProvider.get();
|
|
|
100 |
inboxPresenter.setUsername(result.getUsername());
|
| 493 |
rajveer |
101 |
inboxPresenter.setWarehouseId(result.getWarehouseId());
|
| 8303 |
amar.kumar |
102 |
inboxPresenter.setSource(result.getSource());
|
| 2843 |
chandransh |
103 |
inboxPresenter.setUserType(result.getUserType());
|
|
|
104 |
inboxPresenter.setBillingType(result.getBillingType());
|
| 5110 |
mandeep.dh |
105 |
inboxPresenter.setWarehouses(result.getWarehouses());
|
| 4606 |
rajveer |
106 |
inboxPresenter.setProviders(result.getProviders());
|
| 5769 |
rajveer |
107 |
inboxPresenter.setStores(result.getStores());
|
| 2449 |
chandransh |
108 |
inboxPresenter.initialize();
|
|
|
109 |
|
| 345 |
ashish |
110 |
//inboxPresenter.refreshOrderList();
|
|
|
111 |
|
|
|
112 |
inboxPresenter.getDisplay().changeGreeting(result.getUsername());
|
|
|
113 |
switchPresenter(inboxPresenter);
|
|
|
114 |
eventBus.fireEvent(new LoadOrderListEvent());
|
| 4366 |
rajveer |
115 |
for(OrderType orderType: OrderType.values()){
|
|
|
116 |
eventBus.fireEvent(new LoadOrderCountsEvent(orderType));
|
|
|
117 |
}
|
| 19269 |
manish.sha |
118 |
for(OrderCategory orderType: OrderCategory.values()){
|
|
|
119 |
eventBus.fireEvent(new LoadOrderCountsEvent(orderType));
|
|
|
120 |
}
|
| 4446 |
rajveer |
121 |
eventBus.fireEvent(new LoadAlertsEvent(true, false, 1));
|
| 345 |
ashish |
122 |
}
|
| 438 |
rajveer |
123 |
|
| 167 |
ashish |
124 |
}
|
|
|
125 |
else
|
|
|
126 |
lPresenter.showError("Who are you man! Have we met before? ");
|
|
|
127 |
}
|
|
|
128 |
|
| 306 |
ashish |
129 |
private void signOut(){
|
|
|
130 |
|
|
|
131 |
lPresenter.reset();
|
|
|
132 |
switchPresenter(lPresenter);
|
|
|
133 |
}
|
|
|
134 |
|
| 167 |
ashish |
135 |
@Override
|
|
|
136 |
public void unbind() {
|
|
|
137 |
super.unbind();
|
|
|
138 |
if (presenter != null) {
|
|
|
139 |
presenter.unbind();
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|