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