| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.client.MainPresenter.Display;
|
|
|
4 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEvent;
|
|
|
5 |
import in.shop2020.hotspot.dashbaord.client.event.SubmitLoginInfoEvent;
|
|
|
6 |
import in.shop2020.hotspot.dashbaord.client.event.SubmitLoginInfoHandler;
|
|
|
7 |
import in.shop2020.hotspot.dashbaord.client.inbox.InboxPresenter;
|
|
|
8 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
|
|
|
9 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
|
|
|
10 |
|
|
|
11 |
import net.customware.gwt.dispatch.client.DispatchAsync;
|
|
|
12 |
|
|
|
13 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
14 |
import org.enunes.gwt.mvp.client.presenter.BasePresenter;
|
|
|
15 |
import org.enunes.gwt.mvp.client.presenter.Presenter;
|
|
|
16 |
|
|
|
17 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
18 |
import com.google.inject.Inject;
|
|
|
19 |
import com.google.inject.Provider;
|
|
|
20 |
|
|
|
21 |
public class MainPresenterImpl extends BasePresenter<MainPresenter.Display> implements MainPresenter{
|
|
|
22 |
|
|
|
23 |
private final Provider<InboxPresenter> inboxProvider;
|
|
|
24 |
private final LoginDisplayPresenter lPresenter;
|
|
|
25 |
private Presenter<? extends org.enunes.gwt.mvp.client.view.Display> presenter;
|
|
|
26 |
private final DispatchAsync dispatcher;
|
|
|
27 |
|
|
|
28 |
@Inject
|
|
|
29 |
public MainPresenterImpl(EventBus eventBus, Display display, LoginDisplayPresenter loginpresenter,
|
|
|
30 |
Provider<InboxPresenter> inboxProvider, final DispatchAsync dispatcher ) {
|
|
|
31 |
super(eventBus, display);
|
|
|
32 |
this.inboxProvider = inboxProvider;
|
|
|
33 |
lPresenter = loginpresenter;
|
|
|
34 |
lPresenter.bind();
|
|
|
35 |
this.dispatcher = dispatcher;
|
|
|
36 |
display.addContent(loginpresenter.getDisplay());
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private void switchPresenter(
|
|
|
40 |
Presenter<? extends org.enunes.gwt.mvp.client.view.Display> presenter) {
|
|
|
41 |
|
|
|
42 |
if (this.presenter != null) {
|
|
|
43 |
this.presenter.unbind();
|
|
|
44 |
display.removeContent();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
this.presenter = presenter;
|
|
|
48 |
|
|
|
49 |
if (presenter != null) {
|
|
|
50 |
display.addContent(presenter.getDisplay());
|
|
|
51 |
this.presenter.bind();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
@Override
|
|
|
57 |
public void bind(){
|
|
|
58 |
super.bind();
|
|
|
59 |
registerHandler(eventBus.addHandler(SubmitLoginInfoEvent.getType(), new SubmitLoginInfoHandler() {
|
|
|
60 |
|
|
|
61 |
@Override
|
|
|
62 |
public void onSubmitLoginInfo(SubmitLoginInfoEvent event) {
|
|
|
63 |
|
|
|
64 |
dispatcher.execute(new AuthRequest(event.getUserName(), event.getPassword()), new AsyncCallback<AuthResponse>() {
|
|
|
65 |
|
|
|
66 |
@Override
|
|
|
67 |
public void onFailure(Throwable caught) {
|
|
|
68 |
lPresenter.showError("You do not seem in good terms with auth server. It is lost!");
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@Override
|
|
|
73 |
public void onSuccess(AuthResponse result) {
|
|
|
74 |
doAuth(result);
|
|
|
75 |
}
|
|
|
76 |
});
|
|
|
77 |
}
|
|
|
78 |
}));
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
private void doAuth(AuthResponse result){
|
|
|
82 |
if (result.isStatus()){
|
|
|
83 |
lPresenter.showError("Welcome! "+ result.getUsername() +", "+ result.getMessage());
|
|
|
84 |
|
|
|
85 |
final InboxPresenter inboxPresenter = inboxProvider.get();
|
|
|
86 |
inboxPresenter.initialize();
|
|
|
87 |
//inboxPresenter.refreshOrderList();
|
|
|
88 |
switchPresenter(inboxPresenter);
|
|
|
89 |
|
|
|
90 |
}
|
|
|
91 |
else
|
|
|
92 |
lPresenter.showError("Who are you man! Have we met before? ");
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
@Override
|
|
|
96 |
public void unbind() {
|
|
|
97 |
super.unbind();
|
|
|
98 |
if (presenter != null) {
|
|
|
99 |
presenter.unbind();
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
}
|