Subversion Repositories SmartDukaan

Rev

Rev 1992 | Rev 2066 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1992 Rev 2027
Line 39... Line 39...
39
 
39
 
40
    RootLayoutPanel root;
40
    RootLayoutPanel root;
41
    LoginScreen login;
41
    LoginScreen login;
42
 
42
 
43
    public void onModuleLoad() {
43
    public void onModuleLoad() {
44
 
-
 
45
        root = RootLayoutPanel.get();
44
        root = RootLayoutPanel.get();
-
 
45
        root.getElement().setScrollLeft(10);
46
        login = new LoginScreen();
46
        login = new LoginScreen();
47
        //initMainDB("Testing");
47
        //initMainDB("Testing");
48
        root.add(login);
48
        root.add(login);
49
        login.setLoginListener(new LoginScreen.LoginListener() {
49
        login.setLoginListener(new LoginScreen.LoginListener() {
50
            @Override
50
            @Override
Line 54... Line 54...
54
        });
54
        });
55
    }
55
    }
56
 
56
 
57
    private void authenticateUser(String username, String password) {
57
    private void authenticateUser(String username, String password) {
58
        final String uname = username;
58
        final String uname = username;
59
        loginService.authenticateUser(username, password, new AsyncCallback<Long>() {
59
        loginService.authenticateUser(username, password, new AsyncCallback<String>() {
60
            @Override
60
            @Override
61
            public void onSuccess(Long result) {
61
            public void onSuccess(String result) {
62
                if (result != -1) {
62
                if (result != null) {
-
 
63
                    GWT.log(result + " logged in catalog dashboard");
63
                    root.clear();
64
                    root.clear();
64
                    initMainDB(uname);
65
                    initMainDB(uname);
65
                    login.clearFields();
66
                    login.clearFields();
-
 
67
                } else {
-
 
68
                    login.setErrorText("Invalid username/password");    
66
                }
69
                }
67
            }
70
            }
68
            @Override
71
            @Override
69
            public void onFailure(Throwable caught) {
72
            public void onFailure(Throwable caught) {
70
                login.setErrorText("Invalid username/password");
73
                login.setErrorText("Error in authentication");
71
            }
74
            }
72
        });
75
        });
73
    }
76
    }
74
 
77
 
75
    private void initMainDB(String username) {
78
    private void initMainDB(String username) {
76
        DockLayoutPanel dashboard = binder.createAndBindUi(this);
79
        DockLayoutPanel dashboard = binder.createAndBindUi(this);
77
        topPanel.changeGreeting(username);
80
        topPanel.changeGreeting(username);
78
        itemList.setListener(new ItemList.Listener() {
81
        itemList.setListener(new ItemList.Listener() {
79
            public void onItemSelected(Item item) {
82
            public void onItemSelected(long itemId) {
-
 
83
                catalogService.getItem(itemId, new AsyncCallback<Item>() {
-
 
84
                    @Override
-
 
85
                    public void onSuccess(Item result) {
80
                itemDetails.setItemDetails(item);
86
                        itemDetails.setItemDetails(result);
-
 
87
                    }
-
 
88
                    
-
 
89
                    @Override
-
 
90
                    public void onFailure(Throwable caught) {
-
 
91
                        Window.alert("Unable to fetch item details.");
-
 
92
                    }
-
 
93
                });
81
            }
94
            }
82
        });
95
        });
83
 
96
 
84
        itemDetails.setItemUpdateListener(new ItemDetails.ItemUpdateListener() {
97
        itemDetails.setItemUpdateListener(new ItemDetails.ItemUpdateListener() {
85
            @Override
98
            @Override
Line 110... Line 123...
110
        root.clear();
123
        root.clear();
111
        root.add(dashboard);
124
        root.add(dashboard);
112
        
125
        
113
        shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
126
        shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
114
            @Override
127
            @Override
115
            public void onTreeItemClicked() {
128
            public void onTreeItemClicked(String itemsType) {
-
 
129
                //showWaitCursor();
-
 
130
                if(itemsType == CatalogTree.ALL_ITEMS) {
-
 
131
                    itemList.loadAllItems();
-
 
132
                } else if(itemsType == CatalogTree.BEST_DEALS) {
-
 
133
                    itemList.loadBestDeals();
-
 
134
                } else if(itemsType == CatalogTree.BEST_SELLERS) {
-
 
135
                    itemList.loadBestSellers();
-
 
136
                } else if(itemsType == CatalogTree.LATEST_ARRIVALS) {
116
                // TODO Auto-generated method stub
137
                    itemList.loadLatestArrivals();
117
                
138
                }
-
 
139
//                itemDetails = new ItemDetails();
-
 
140
                //showDefaultCursor();
118
            }
141
            }
119
        });
142
        });
120
    }
143
    }
-
 
144
    
-
 
145
    /*public static void showWaitCursor() {
-
 
146
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
-
 
147
    }
-
 
148
     
-
 
149
    public static void showDefaultCursor() {
-
 
150
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
-
 
151
    }*/
121
}
152
}