Subversion Repositories SmartDukaan

Rev

Rev 2489 | Rev 4506 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
2359 ankur.sing 3
import in.shop2020.catalog.dashboard.shared.Utils;
4
 
1961 ankur.sing 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.rpc.AsyncCallback;
13
import com.google.gwt.user.client.ui.DockLayoutPanel;
14
import com.google.gwt.user.client.ui.RootLayoutPanel;
15
 
2427 ankur.sing 16
/**
17
 * This is the entry point of dashboard application.
18
 * 
19
 */
1961 ankur.sing 20
public class CatalogDashboard implements EntryPoint {
21
 
22
    @UiTemplate("CatalogDashboard.ui.xml")
23
    interface CatalogBinder extends UiBinder<DockLayoutPanel, CatalogDashboard> {
24
    }
2066 ankur.sing 25
 
1961 ankur.sing 26
    private static final CatalogBinder binder = GWT.create(CatalogBinder.class);
27
    private final LoginServiceAsync loginService = GWT.create(LoginService.class);
2066 ankur.sing 28
 
2427 ankur.sing 29
    @UiField TopPanel topPanel;        // logo, welcome message and sign out link
30
    @UiField Shortcuts shortcuts;      // anchors to filter item list based on status 
31
    //TODO @UiField Filters filters;
32
    @UiField ItemList itemList;        // list of items
33
    @UiField ItemDetails itemDetails;  // details of an item selected in the list
34
    @UiField ItemActions itemActions;  // action buttons to update, add item or change item status
1961 ankur.sing 35
 
36
    RootLayoutPanel root;
37
    LoginScreen login;
38
 
39
    public void onModuleLoad() {
40
        root = RootLayoutPanel.get();
2027 ankur.sing 41
        root.getElement().setScrollLeft(10);
1961 ankur.sing 42
        login = new LoginScreen();
2119 ankur.sing 43
        //initMainDB("Testing");
44
        root.add(login);
1961 ankur.sing 45
        login.setLoginListener(new LoginScreen.LoginListener() {
46
            @Override
47
            public void onLoginPressed(String username, String password) {
2359 ankur.sing 48
                authenticateUser(username, password, Utils.ROLE_STAGING);
1961 ankur.sing 49
            }
2119 ankur.sing 50
        });
1961 ankur.sing 51
    }
52
 
2427 ankur.sing 53
    /**
54
     * Authenticates username and password and if successful, initialises 
55
     * main dashboard panel.
56
     * @param username 
57
     * @param password
58
     * @param role -- Utils.ROLE_STAGING (Login role for staging), another role 
59
     * is Utils.ROLE_PRODUCTION (for push to production username & password)
60
     */
2359 ankur.sing 61
    private void authenticateUser(String username, String password, int role) {
1961 ankur.sing 62
        final String uname = username;
2359 ankur.sing 63
        loginService.authenticateUser(username, password, role, new AsyncCallback<String>() {
1961 ankur.sing 64
            @Override
2027 ankur.sing 65
            public void onSuccess(String result) {
66
                if (result != null) {
67
                    GWT.log(result + " logged in catalog dashboard");
1961 ankur.sing 68
                    root.clear();
69
                    initMainDB(uname);
70
                    login.clearFields();
2027 ankur.sing 71
                } else {
72
                    login.setErrorText("Invalid username/password");    
1961 ankur.sing 73
                }
74
            }
75
            @Override
76
            public void onFailure(Throwable caught) {
2489 ankur.sing 77
                caught.printStackTrace();
2027 ankur.sing 78
                login.setErrorText("Error in authentication");
1961 ankur.sing 79
            }
80
        });
81
    }
82
 
83
    private void initMainDB(String username) {
84
        DockLayoutPanel dashboard = binder.createAndBindUi(this);
2126 ankur.sing 85
        itemActions.setItemDetails(itemDetails);
86
        itemList.setItemDetails(itemDetails);
2489 ankur.sing 87
        itemDetails.setCatalogDashboardPanel(this);
1961 ankur.sing 88
        topPanel.changeGreeting(username);
89
 
90
        topPanel.getSignOutLink().addClickHandler(new ClickHandler() {
91
            @Override
92
            public void onClick(ClickEvent event) {
93
                root.clear();
94
                root.add(login);
95
            }
96
        });
97
        root.clear();
98
        root.add(dashboard);
1992 ankur.sing 99
 
2427 ankur.sing 100
        /**
101
         * listener for anchors to filter item list based on statuses and some other parameters.
102
         * On click event, string of the anchor is passed as argument and the same listener is
103
         * taking different actions based on the different string arguments.
104
         */
1992 ankur.sing 105
        shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
106
            @Override
2027 ankur.sing 107
            public void onTreeItemClicked(String itemsType) {
2119 ankur.sing 108
                if(CatalogTree.ALL_ITEMS.equals(itemsType)) {
2027 ankur.sing 109
                    itemList.loadAllItems();
2208 ankur.sing 110
                } else if(CatalogTree.ALL_PHASED_OUT_ITEMS.equals(itemsType)) { 
111
                    itemList.loadAllPhasedOutItems();
112
                } else if(CatalogTree.ALL_PAUSED_ITEMS.equals(itemsType)) { 
113
                    itemList.loadAllPausedItems();
2119 ankur.sing 114
                } else if(CatalogTree.ALL_ACTIVE_ITEMS.equals(itemsType)) { 
115
                    itemList.loadAllActiveItems();
2359 ankur.sing 116
                } else if(CatalogTree.IN_PROCESS_ITEMS.equals(itemsType)) { 
117
                    itemList.loadAllInProcessItems();
118
                } else if(CatalogTree.CONTENT_COMPLETE_ITEMS.equals(itemsType)) { 
119
                    itemList.loadAllContentCompleteItems();
120
                } else if(CatalogTree.RISKY_ITEMS.equals(itemsType)) { 
121
                    itemList.loadAllRiskyItems();
2119 ankur.sing 122
                } else if(CatalogTree.BEST_DEALS.equals(itemsType)) {
2027 ankur.sing 123
                    itemList.loadBestDeals();
2119 ankur.sing 124
                } else if(CatalogTree.BEST_SELLERS.equals(itemsType)) {
2027 ankur.sing 125
                    itemList.loadBestSellers();
2119 ankur.sing 126
                } else if(CatalogTree.LATEST_ARRIVALS.equals(itemsType)) {
2027 ankur.sing 127
                    itemList.loadLatestArrivals();
3872 chandransh 128
                } else if(CatalogTree.SEARCH.equals(itemsType)) {
129
                    //Open the search dialog box
130
                    SearchItemBox box = new SearchItemBox(itemList);
131
                    box.center();
2027 ankur.sing 132
                }
1992 ankur.sing 133
            }
134
        });
1961 ankur.sing 135
    }
2489 ankur.sing 136
 
137
    ItemList getItemListWidget() {
138
        return this.itemList;
139
    }
140
 
141
    ItemDetails getItemDetailsWidget() {
142
        return this.itemDetails;
143
    }
1961 ankur.sing 144
}
2126 ankur.sing 145