Subversion Repositories SmartDukaan

Rev

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

Rev 2359 Rev 2427
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.shared;
1
package in.shop2020.catalog.dashboard.shared;
2
 
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
3
import in.shop2020.catalog.dashboard.client.CatalogService;
4
import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;
4
import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;
5
import in.shop2020.model.v1.catalog.status;
-
 
6
 
5
 
7
import java.util.Date;
6
import java.util.Date;
8
import java.util.List;
-
 
9
import java.util.Map;
7
import java.util.Map;
10
import java.util.Map.Entry;
8
import java.util.Map.Entry;
11
 
9
 
12
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.user.client.DOM;
11
import com.google.gwt.user.client.DOM;
14
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.Window;
15
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.rpc.AsyncCallback;
16
import com.google.gwt.user.client.ui.RootPanel;
14
import com.google.gwt.user.client.ui.RootPanel;
17
 
15
 
-
 
16
/**
-
 
17
 * Utility methods goes here
-
 
18
 *
-
 
19
 */
18
public class Utils {
20
public class Utils {
-
 
21
    // item status values. These should be analogous to status enum in status.java
-
 
22
    // These values are used in the client side to check if transition from one status to another is 
19
    //public static final int MODE_ADD = 0, MODE_EDIT = 1;
23
    // valid. Also see validateStatusChange method
-
 
24
    // FIXME: These should be read from the ThriftConfig file and not hard-coded here.
20
    public static final int PHASED_OUT = 0,
25
    public static final int PHASED_OUT = 0,
21
                            DELETED = 1,
26
                            DELETED = 1,
22
                            PAUSED = 2,
27
                            PAUSED = 2,
23
                            ACTIVE = 3,
28
                            ACTIVE = 3,
24
                            IN_PROCESS = 4,
29
                            IN_PROCESS = 4,
25
                            CONTENT_COMPLETE = 5;
30
                            CONTENT_COMPLETE = 5;
-
 
31
    
-
 
32
    // role column in helper.catalogdashboarduser table. role specifies 
-
 
33
    // the username-pwd pair for staging or for production.
-
 
34
    // production password is needed while updating item on production server.
26
    public static final int ROLE_STAGING = 0, ROLE_PRODUCTION = 1;
35
    public static final int ROLE_STAGING = 0, ROLE_PRODUCTION = 1;
-
 
36
    
27
    private static Map<Long, String> vendors, warehouses;
37
    private static Map<Long, String> vendors, warehouses;
28
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
-
 
29
    
38
    
-
 
39
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
30
    
40
    
31
 
-
 
32
    static {
41
    static {
33
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
42
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
34
            @Override
43
            @Override
35
            public void onSuccess(Map<Long, String> result) {
44
            public void onSuccess(Map<Long, String> result) {
36
                vendors = result;
45
                vendors = result;
Line 82... Line 91...
82
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
91
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
83
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
92
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
84
        return dateString;      
93
        return dateString;      
85
    }
94
    }
86
    
95
    
-
 
96
    /**
-
 
97
     * Since in vendor combo box, vendor name is populated, this method is used to get Id from name
-
 
98
     * @param vendor name
-
 
99
     * @return vendor Id corresponding to the name
-
 
100
     */
87
    public static long getVendorId(String vendorDesc) {
101
    public static long getVendorId(String vendorDesc) {
88
        if(vendors == null) {
102
        if(vendors == null) {
89
            return 0;
103
            return 0;
90
        }
104
        }
91
        for(Entry<Long, String> v : vendors.entrySet()) {
105
        for(Entry<Long, String> v : vendors.entrySet()) {
Line 94... Line 108...
94
            }
108
            }
95
        }
109
        }
96
        return 0;
110
        return 0;
97
    }
111
    }
98
    
112
    
-
 
113
    /**
-
 
114
     * validates item object. ProductGroup, brand, modelNumber, modelName should not be empty or null.
-
 
115
     * Also does item and vendor prices validations (MRP >= SP, MRP >= MOP, TP <= MOP)
-
 
116
     * Vendor Item Key should not be empty or null
-
 
117
     * @param item
-
 
118
     * @return
-
 
119
     */
99
    public static boolean validateItem(Item item) {
120
    public static boolean validateItem(Item item) {
100
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
121
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
101
            Window.alert("Product Group cannot be empty.");
122
            Window.alert("Product Group cannot be empty.");
102
            return false;
123
            return false;
103
        }
124
        }
Line 135... Line 156...
135
            }
156
            }
136
        }
157
        }
137
        return true;
158
        return true;
138
    }
159
    }
139
    
160
    
-
 
161
    
140
    public static boolean validateStatusChange(int fromStatus, int toStatus) {
162
    public static boolean validateStatusChange(int fromStatus, int toStatus) {
141
        switch(toStatus) {
163
        switch(toStatus) {
142
        case PHASED_OUT: 
164
        case PHASED_OUT: 
143
            switch(fromStatus) {
165
            switch(fromStatus) {
144
            case IN_PROCESS: return true;
166
            case IN_PROCESS: return true;
Line 162... Line 184...
162
            default: return false;
184
            default: return false;
163
            }
185
            }
164
        }
186
        }
165
        return true;
187
        return true;
166
    }
188
    }
167
    
-
 
168
    public static void showWaitCursor() {
-
 
169
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
-
 
170
    }
-
 
171
     
-
 
172
    public static void showDefaultCursor() {
-
 
173
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
-
 
174
    }
-
 
175
    
-
 
176
    
-
 
177
}
189
}