Subversion Repositories SmartDukaan

Rev

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

Rev 5460 Rev 5586
Line 36... Line 36...
36
public class ItemForm extends DialogBox implements ComingSoon{
36
public class ItemForm extends DialogBox implements ComingSoon{
37
 
37
 
38
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
38
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
39
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
39
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
40
    
40
    
41
    private final String HANDSETS = "Handsets",
-
 
42
                         ACCESSORIES = "Accessories";
-
 
43
    
-
 
44
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
41
    private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
45
    private final int TABLE_INDEX_VENDORID = 0,
42
    private final int TABLE_INDEX_VENDORID = 0,
46
                      TABLE_INDEX_VENDOR_DESC = 1, 
43
                      TABLE_INDEX_VENDOR_DESC = 1, 
47
                      TABLE_INDEX_ITEM_KEY = 2,
44
                      TABLE_INDEX_ITEM_KEY = 2,
48
                      TABLE_INDEX_MOP = 2,
45
                      TABLE_INDEX_MOP = 2,
49
                      TABLE_INDEX_DP = 3,
46
                      TABLE_INDEX_DP = 3,
50
                      TABLE_INDEX_TP = 4;
47
                      TABLE_INDEX_TP = 4;
-
 
48
    
-
 
49
    private static boolean entityIdMandatory = Utils.isEntityIdMandatory();
51
 
50
 
52
    @UiField TextBox productGroup;
51
    @UiField TextBox productGroup, catalogItemId;
53
    @UiField TextBox brand, modelNumber, modelName, color, comments;
52
    @UiField TextBox brand, modelNumber, modelName, color, comments;
54
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank;
53
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank;
55
    @UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
54
    @UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
56
    @UiField Button addButton, cancelButton, comingSoonButton;
55
    @UiField Button addButton, cancelButton, comingSoonButton;
57
    @UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance;
56
    @UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance;
Line 66... Line 65...
66
        initVendorPricesHeader();
65
        initVendorPricesHeader();
67
        preferredVendor.addItem("select");
66
        preferredVendor.addItem("select");
68
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
67
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
69
        	preferredVendor.addItem(e.getValue());
68
        	preferredVendor.addItem(e.getValue());
70
        }
69
        }
-
 
70
        if(!entityIdMandatory) {
-
 
71
        	catalogItemId.setEnabled(false);
-
 
72
        }
71
    }
73
    }
72
    
74
    
73
    /**
75
    /**
74
     * initialises vendor item key table header. Creates an Add button and
76
     * initialises vendor item key table header. Creates an Add button and
75
     * adds click event listener to it to create and pop up a dialog for adding 
77
     * adds click event listener to it to create and pop up a dialog for adding 
Line 199... Line 201...
199
    /**
201
    /**
200
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
202
     * On add button click a new Item instance is created and all the information from UI fields is dumped in this item instance.
201
     * This item instance is then passed to the service to be added to the database.
203
     * This item instance is then passed to the service to be added to the database.
202
     */
204
     */
203
    void addItem(ClickEvent event) {
205
    void addItem(ClickEvent event) {
204
        //TODO: validate UI fields
206
    	if(entityIdMandatory) {
205
        catalogService.checkSimilarItem(brand.getText().trim(), modelNumber.getText().trim(),
207
    		long entityId = 0;
-
 
208
    		try {
206
        		modelName.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
209
                if(!catalogItemId.getText().trim().isEmpty()) {
207
            @Override
-
 
208
            public void onFailure(Throwable caught) {
210
                    entityId = Long.parseLong(catalogItemId.getText().trim());
209
                GWT.log("Error checking similar item");
211
                    if(entityId <= 0) {
210
                Window.alert("Error checking similar item");
212
                        throw new NumberFormatException("Invalid value of Catalog Item Id");
211
                return;
213
                    }
212
            }
214
                }
213
            @Override
215
                else {
214
            public void onSuccess(Long result) {
-
 
215
                if(result != 0) {
-
 
216
                    Window.alert("Similar product exists with Item Id " + result);
216
                	Window.alert("Catalog Item Id can not be empty");
217
                    return;
217
                	return;
218
                }
218
                }
-
 
219
            } catch(NumberFormatException ex) {
-
 
220
                Window.alert("Invalid value of Catalog Item Id");
219
                addNewItem();
221
                return;
220
            }
222
            }
-
 
223
	    	catalogService.checkEntityId(entityId, new AsyncCallback<Boolean>() {
-
 
224
	            @Override
-
 
225
	            public void onFailure(Throwable caught) {
-
 
226
	                GWT.log("Error checking Catalog Item Id");
-
 
227
	                Window.alert("Error checking Catalog Item Id");
-
 
228
	                return;
-
 
229
	            }
-
 
230
	            @Override
-
 
231
	            public void onSuccess(Boolean result) {
-
 
232
		        	if(!result) {
-
 
233
	                    Window.alert("Invalid value of Catalog Item Id");
-
 
234
	                    return;
-
 
235
	                }
-
 
236
	                addNewItem();
-
 
237
		        }
-
 
238
	        });
-
 
239
    	}
-
 
240
    	else {
-
 
241
	        catalogService.checkSimilarItem(brand.getText().trim(), modelNumber.getText().trim(),
-
 
242
	        		modelName.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
-
 
243
	            @Override
-
 
244
	            public void onFailure(Throwable caught) {
-
 
245
	                GWT.log("Error checking similar item");
-
 
246
	                Window.alert("Error checking similar item");
-
 
247
	                return;
-
 
248
	            }
-
 
249
	            @Override
-
 
250
	            public void onSuccess(Long result) {
-
 
251
	                if(result != 0) {
-
 
252
	                    Window.alert("Similar product exists with Item Id " + result);
-
 
253
	                    return;
-
 
254
	                }
-
 
255
	                addNewItem();
-
 
256
	            }
221
        });
257
	        });
-
 
258
    	}
222
    }
259
    }
223
    
260
    
224
    private void addNewItem() {
261
    private void addNewItem() {
225
        Item item = new Item();
262
        Item item = new Item();
226
        
263
        
Line 229... Line 266...
229
        }
266
        }
230
        else {
267
        else {
231
        	Window.alert("Product Group can not be empty.");
268
        	Window.alert("Product Group can not be empty.");
232
            return;
269
            return;
233
        }
270
        }
-
 
271
        
-
 
272
        if(entityIdMandatory) {
-
 
273
	        try {
-
 
274
	            if(!catalogItemId.getText().trim().isEmpty()) {
-
 
275
	                long entityId = Long.parseLong(catalogItemId.getText().trim());
-
 
276
	                if(entityId <= 0) {
-
 
277
	                    throw new NumberFormatException("Invalid value of Catalog Item Id");
-
 
278
	                }
-
 
279
	                item.setCatalogItemId(entityId);
-
 
280
	            }
-
 
281
	            else {
-
 
282
	            	Window.alert("Catalog Item Id can not be empty");
-
 
283
	            	return;
-
 
284
	            }
-
 
285
	        } catch(NumberFormatException ex) {
-
 
286
	            Window.alert("Invalid value of Catalog Item Id");
-
 
287
	            return;
-
 
288
	        }
-
 
289
        }
-
 
290
        
234
        item.setBrand(brand.getText().trim());
291
        item.setBrand(brand.getText().trim());
235
        item.setModelNumber(modelNumber.getText().trim());
292
        item.setModelNumber(modelNumber.getText().trim());
236
        item.setModelName(modelName.getText().trim());
293
        item.setModelName(modelName.getText().trim());
237
        item.setColor(color.getText().trim());
294
        item.setColor(color.getText().trim());
238
        item.setComments(comments.getText().trim());
295
        item.setComments(comments.getText().trim());