| Line 1... |
Line 1... |
| 1 |
package in.shop2020.catalog.dashboard.client;
|
1 |
package in.shop2020.catalog.dashboard.client;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
| 4 |
|
4 |
|
| 5 |
import java.util.Date;
|
5 |
import java.util.Date;
|
| - |
|
6 |
import java.util.Map;
|
| - |
|
7 |
import java.util.Map.Entry;
|
| 6 |
|
8 |
|
| 7 |
import com.google.gwt.core.client.GWT;
|
9 |
import com.google.gwt.core.client.GWT;
|
| 8 |
import com.google.gwt.event.dom.client.ClickEvent;
|
10 |
import com.google.gwt.event.dom.client.ClickEvent;
|
| - |
|
11 |
import com.google.gwt.event.dom.client.ClickHandler;
|
| - |
|
12 |
import com.google.gwt.resources.client.CssResource;
|
| 9 |
import com.google.gwt.uibinder.client.UiBinder;
|
13 |
import com.google.gwt.uibinder.client.UiBinder;
|
| 10 |
import com.google.gwt.uibinder.client.UiField;
|
14 |
import com.google.gwt.uibinder.client.UiField;
|
| 11 |
import com.google.gwt.uibinder.client.UiHandler;
|
15 |
import com.google.gwt.uibinder.client.UiHandler;
|
| 12 |
import com.google.gwt.user.client.Window;
|
16 |
import com.google.gwt.user.client.Window;
|
| 13 |
import com.google.gwt.user.client.ui.Button;
|
17 |
import com.google.gwt.user.client.ui.Button;
|
| - |
|
18 |
import com.google.gwt.user.client.ui.FlexTable;
|
| - |
|
19 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
| 14 |
import com.google.gwt.user.client.ui.Label;
|
20 |
import com.google.gwt.user.client.ui.Label;
|
| 15 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
21 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
| 16 |
import com.google.gwt.user.client.ui.TextBox;
|
22 |
import com.google.gwt.user.client.ui.TextBox;
|
| 17 |
import com.google.gwt.user.client.ui.Widget;
|
23 |
import com.google.gwt.user.client.ui.Widget;
|
| 18 |
|
24 |
|
| 19 |
public class ItemDetails extends ResizeComposite {
|
25 |
public class ItemDetails extends ResizeComposite {
|
| 20 |
|
26 |
|
| 21 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
27 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
| 22 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
28 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
| 23 |
|
29 |
|
| 24 |
public interface PriceUpdateListener {
|
30 |
public interface ItemUpdateListener {
|
| 25 |
void onPriceUpdate(long itemId, double sellingPrice);
|
31 |
void onItemUpdate(Item item);
|
| 26 |
}
|
32 |
}
|
| 27 |
private PriceUpdateListener priceUpdateListener;
|
- |
|
| 28 |
|
33 |
|
| - |
|
34 |
interface ItemDetailStyle extends CssResource{
|
| - |
|
35 |
String greenLabel();
|
| - |
|
36 |
String fieldChanged();
|
| - |
|
37 |
}
|
| - |
|
38 |
|
| - |
|
39 |
private ItemUpdateListener itemUpdateListener;
|
| - |
|
40 |
|
| 29 |
private final Item item;
|
41 |
private Item item;
|
| 30 |
|
42 |
|
| - |
|
43 |
@UiField ItemDetailStyle style;
|
| 31 |
@UiField Label itemId, productGroup, brand, modelNumber, modelName, color;
|
44 |
@UiField Label itemId, productGroup, brand, modelNumber, modelName, color;
|
| 32 |
@UiField Label category, comments;
|
45 |
@UiField Label category, comments;
|
| 33 |
@UiField Label catalogItemId;
|
46 |
@UiField Label catalogItemId;
|
| 34 |
@UiField TextBox sellingPrice;
|
- |
|
| 35 |
@UiField Label mrp, mop, dealerPrice, weight;
|
47 |
@UiField TextBox sellingPrice, mrp, /*mop, dealerPrice, transferPrice,*/ weight;
|
| 36 |
@UiField Label addedOn, startDate, retireDate, updatedOn;
|
48 |
@UiField Label addedOn, startDate, retireDate, updatedOn;
|
| 37 |
@UiField Label bestDealsText, bestDealsValue;
|
49 |
@UiField Label bestDealsText, bestDealsValue, itemStatus;
|
| - |
|
50 |
@UiField FlexTable headerAvailability, availabilityTable;
|
| - |
|
51 |
@UiField FlexTable headerPricing, pricingTable;
|
| 38 |
@UiField Button submit;
|
52 |
@UiField Button submit;
|
| 39 |
|
53 |
|
| 40 |
public ItemDetails(Item item){
|
54 |
public ItemDetails(Item item){
|
| 41 |
this.item = item;
|
- |
|
| 42 |
initWidget(uiBinder.createAndBindUi(this));
|
55 |
initWidget(uiBinder.createAndBindUi(this));
|
| - |
|
56 |
initAvailabilityHeader();
|
| - |
|
57 |
initPricingHeader();
|
| 43 |
setItemDetails(this.item);
|
58 |
setItemDetails(item);
|
| 44 |
}
|
59 |
}
|
| 45 |
|
60 |
|
| 46 |
public ItemDetails() {
|
61 |
public ItemDetails() {
|
| 47 |
this.item = null;
|
62 |
this.item = null;
|
| 48 |
initWidget(uiBinder.createAndBindUi(this));
|
63 |
initWidget(uiBinder.createAndBindUi(this));
|
| - |
|
64 |
|
| - |
|
65 |
initAvailabilityHeader();
|
| - |
|
66 |
initPricingHeader();
|
| 49 |
}
|
67 |
}
|
| 50 |
|
68 |
|
| 51 |
public void setItemDetails(Item item){
|
69 |
public void setItemDetails(Item item){
|
| - |
|
70 |
this.item = item;
|
| 52 |
itemId.setText(item.getId()+"");
|
71 |
itemId.setText(item.getId()+"");
|
| 53 |
productGroup.setText(item.getProductGroup());
|
72 |
productGroup.setText(item.getProductGroup());
|
| 54 |
brand.setText(item.getBrand());
|
73 |
brand.setText(item.getBrand());
|
| 55 |
modelNumber.setText(item.getModelNumber());
|
74 |
modelNumber.setText(item.getModelNumber());
|
| 56 |
modelName.setText(item.getModelName());
|
75 |
modelName.setText(item.getModelName());
|
| Line 59... |
Line 78... |
| 59 |
category.setText(item.getCategory()+"");
|
78 |
category.setText(item.getCategory()+"");
|
| 60 |
comments.setText(item.getComments());
|
79 |
comments.setText(item.getComments());
|
| 61 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
80 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
| 62 |
|
81 |
|
| 63 |
mrp.setText(item.getMrp()+"");
|
82 |
mrp.setText(item.getMrp()+"");
|
| 64 |
mop.setText(item.getMop()+"");
|
- |
|
| 65 |
sellingPrice.setText(item.getSellingPrice()+"");
|
83 |
sellingPrice.setText(item.getSellingPrice()+"");
|
| - |
|
84 |
/*mop.setText(item.getMop()+"");
|
| 66 |
dealerPrice.setText(item.getDealerPrice()+"");
|
85 |
dealerPrice.setText(item.getDealerPrice()+"");
|
| - |
|
86 |
transferPrice.setText(item.getTransferPrice()+"");*/
|
| 67 |
weight.setText(item.getWeight()+"");
|
87 |
weight.setText(item.getWeight()+"");
|
| 68 |
|
88 |
|
| 69 |
addedOn.setText(getDisplayableDate(item.getAddedOn()));
|
89 |
addedOn.setText(getDisplayableDate(item.getAddedOn()));
|
| 70 |
startDate.setText(getDisplayableDate(item.getStartDate()));
|
90 |
startDate.setText(getDisplayableDate(item.getStartDate()));
|
| 71 |
retireDate.setText(getDisplayableDate(item.getRetireDate()));
|
91 |
retireDate.setText(getDisplayableDate(item.getRetireDate()));
|
| 72 |
updatedOn.setText(getDisplayableDate(item.getUpdatedOn()));
|
92 |
updatedOn.setText(getDisplayableDate(item.getUpdatedOn()));
|
| 73 |
|
93 |
|
| 74 |
bestDealsText.setText(item.getBestDealsText());
|
94 |
bestDealsText.setText(item.getBestDealsText());
|
| 75 |
bestDealsValue.setText(item.getBestDealsValue()+"");
|
95 |
bestDealsValue.setText(item.getBestDealsValue()+"");
|
| - |
|
96 |
|
| - |
|
97 |
itemStatus.setText(item.getItemStatus());
|
| - |
|
98 |
|
| - |
|
99 |
updateAvailabilityTable(item.getAvailability());
|
| - |
|
100 |
|
| - |
|
101 |
updatePricingTable(item.getVendorPricings());
|
| 76 |
}
|
102 |
}
|
| 77 |
|
103 |
|
| - |
|
104 |
private void initAvailabilityHeader(){
|
| - |
|
105 |
// Initialize the header.
|
| - |
|
106 |
headerAvailability.getColumnFormatter().setWidth(0, "128px");
|
| - |
|
107 |
headerAvailability.getColumnFormatter().setWidth(1, "128px");
|
| - |
|
108 |
|
| - |
|
109 |
headerAvailability.setText(0, 0, "Warehouse Id");
|
| - |
|
110 |
headerAvailability.setText(0, 1, "Availability");
|
| - |
|
111 |
|
| - |
|
112 |
}
|
| - |
|
113 |
|
| - |
|
114 |
private void initPricingHeader(){
|
| - |
|
115 |
// Initialize the header.
|
| - |
|
116 |
headerPricing.getColumnFormatter().setWidth(0, "128px");
|
| - |
|
117 |
headerPricing.getColumnFormatter().setWidth(1, "128px");
|
| - |
|
118 |
headerPricing.getColumnFormatter().setWidth(2, "128px");
|
| - |
|
119 |
headerPricing.getColumnFormatter().setWidth(3, "128px");
|
| - |
|
120 |
|
| - |
|
121 |
headerPricing.setText(0, 0, "Vendor Id");
|
| - |
|
122 |
headerPricing.setText(0, 1, "MOP");
|
| - |
|
123 |
headerPricing.setText(0, 2, "Dealer Price");
|
| - |
|
124 |
headerPricing.setText(0, 3, "Transfer Price");
|
| - |
|
125 |
}
|
| - |
|
126 |
|
| - |
|
127 |
private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
|
| - |
|
128 |
availabilityTable.removeAllRows();
|
| - |
|
129 |
if(availabilityMap == null) {
|
| - |
|
130 |
return;
|
| - |
|
131 |
}
|
| - |
|
132 |
availabilityTable.getColumnFormatter().setWidth(0, "128px");
|
| - |
|
133 |
availabilityTable.getColumnFormatter().setWidth(1, "128px");
|
| - |
|
134 |
|
| - |
|
135 |
|
| - |
|
136 |
int i=0;
|
| - |
|
137 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()){
|
| - |
|
138 |
int col = 0;
|
| - |
|
139 |
availabilityTable.setText(i, col++, availability.getKey() + "");
|
| - |
|
140 |
availabilityTable.setText(i, col++, availability.getValue() + "");
|
| - |
|
141 |
i++;
|
| - |
|
142 |
}
|
| - |
|
143 |
}
|
| - |
|
144 |
|
| - |
|
145 |
private void updatePricingTable(Map<Long, double[]> pricings){
|
| - |
|
146 |
pricingTable.removeAllRows();
|
| - |
|
147 |
if(pricings == null || pricings.isEmpty()) {
|
| - |
|
148 |
return;
|
| - |
|
149 |
}
|
| - |
|
150 |
pricingTable.getColumnFormatter().setWidth(0, "128px");
|
| - |
|
151 |
pricingTable.getColumnFormatter().setWidth(1, "128px");
|
| - |
|
152 |
pricingTable.getColumnFormatter().setWidth(2, "128px");
|
| - |
|
153 |
pricingTable.getColumnFormatter().setWidth(3, "128px");
|
| - |
|
154 |
|
| - |
|
155 |
|
| - |
|
156 |
int i=0;
|
| - |
|
157 |
for(Entry<Long, double[]> pricing : pricings.entrySet()){
|
| - |
|
158 |
int col = 0;
|
| - |
|
159 |
pricingTable.setText(i, col++, pricing.getKey() + "");
|
| - |
|
160 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_MOP] + "");
|
| - |
|
161 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_DP] + "");
|
| - |
|
162 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_TP] + "");
|
| - |
|
163 |
Button editButton = new Button("Edit");
|
| - |
|
164 |
pricingTable.setWidget(i, col++, editButton);
|
| - |
|
165 |
i++;
|
| - |
|
166 |
editButton.addClickHandler(new ClickHandler() {
|
| - |
|
167 |
@Override
|
| - |
|
168 |
public void onClick(ClickEvent event) {
|
| - |
|
169 |
Cell cell = pricingTable.getCellForEvent(event);
|
| - |
|
170 |
int row = cell.getRowIndex();
|
| - |
|
171 |
long vendorId = Long.parseLong(pricingTable.getText(row, 0));
|
| - |
|
172 |
updateVendorPrices(vendorId, row);
|
| - |
|
173 |
}
|
| - |
|
174 |
});
|
| - |
|
175 |
}
|
| - |
|
176 |
}
|
| - |
|
177 |
|
| - |
|
178 |
|
| 78 |
//TODO: This code is duplicated between here and OrderList. Move it to a Utility class.
|
179 |
//TODO: This code is duplicated between here and OrderList. Move it to a Utility class.
|
| 79 |
private String getDisplayableDate(Long millis){
|
180 |
private String getDisplayableDate(Long millis){
|
| 80 |
Date date = new Date();
|
181 |
Date date = new Date();
|
| 81 |
date.setTime(millis);
|
182 |
date.setTime(millis);
|
| 82 |
String dateString = date.toString();
|
183 |
String dateString = date.toString();
|
| 83 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
184 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
| 84 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
185 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
| 85 |
return dateString;
|
186 |
return dateString;
|
| 86 |
}
|
187 |
}
|
| 87 |
|
188 |
|
| 88 |
public void setPriceUpdateListener(PriceUpdateListener priceUpdatelistener) {
|
189 |
public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
|
| 89 |
this.priceUpdateListener = priceUpdatelistener;
|
190 |
this.itemUpdateListener = itemUpdatelistener;
|
| 90 |
}
|
191 |
}
|
| 91 |
|
192 |
|
| 92 |
@UiHandler("submit")
|
193 |
@UiHandler("submit")
|
| 93 |
void onSubmitPressed(ClickEvent clickEvent) {
|
194 |
void onSubmitPressed(ClickEvent clickEvent) {
|
| 94 |
long id = Long.parseLong(this.itemId.getText());
|
195 |
//long id = Long.parseLong(this.itemId.getText());
|
| 95 |
try {
|
196 |
try {
|
| 96 |
double sp = Double.parseDouble(this.sellingPrice.getText());
|
- |
|
| 97 |
priceUpdateListener.onPriceUpdate(id, sp);
|
197 |
updateItem();
|
| 98 |
} catch(NumberFormatException ex) {
|
198 |
} catch(NumberFormatException ex) {
|
| 99 |
Window.alert("Price format is not correct.");
|
199 |
Window.alert("Price format is not correct.");
|
| - |
|
200 |
return;
|
| 100 |
}
|
201 |
}
|
| - |
|
202 |
itemUpdateListener.onItemUpdate(item);
|
| 101 |
}
|
203 |
}
|
| 102 |
|
204 |
|
| - |
|
205 |
void updateItem() throws NumberFormatException {
|
| - |
|
206 |
item.setSellingPrice(Double.parseDouble(this.sellingPrice.getText()));
|
| - |
|
207 |
/*item.setTransferPrice(Double.parseDouble(this.transferPrice.getText()));
|
| - |
|
208 |
item.setDealerPrice(Double.parseDouble(this.dealerPrice.getText()));
|
| - |
|
209 |
item.setMop(Double.parseDouble(this.mop.getText()));*/
|
| - |
|
210 |
item.setWeight(Double.parseDouble(this.weight.getText()));
|
| - |
|
211 |
item.setMrp(Double.parseDouble(this.mrp.getText()));
|
| - |
|
212 |
}
|
| - |
|
213 |
|
| - |
|
214 |
private void updateVendorPrices(final long vendorId, final int row) {
|
| - |
|
215 |
String mop = pricingTable.getText(row, 1);
|
| - |
|
216 |
String dp = pricingTable.getText(row, 2);
|
| - |
|
217 |
String tp = pricingTable.getText(row, 3);
|
| - |
|
218 |
VendorPricesDialog vpd = new VendorPricesDialog(mop, dp, tp);
|
| - |
|
219 |
vpd.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
| - |
|
220 |
@Override
|
| - |
|
221 |
public void onPriceUpdate(double mop, double dp, double tp) {
|
| - |
|
222 |
pricingTable.setText(row, 1, mop + "");
|
| - |
|
223 |
pricingTable.setText(row, 2, dp + "");
|
| - |
|
224 |
pricingTable.setText(row, 3, tp + "");
|
| - |
|
225 |
item.getVendorPricings().get(vendorId)[Item.INDEX_MOP] = mop;
|
| - |
|
226 |
item.getVendorPricings().get(vendorId)[Item.INDEX_DP] = dp;
|
| - |
|
227 |
item.getVendorPricings().get(vendorId)[Item.INDEX_TP] = tp;
|
| - |
|
228 |
item.setMop(mop);
|
| - |
|
229 |
item.setDealerPrice(dp);
|
| - |
|
230 |
item.setTransferPrice(tp);
|
| - |
|
231 |
}
|
| - |
|
232 |
});
|
| - |
|
233 |
vpd.show();
|
| - |
|
234 |
}
|
| - |
|
235 |
|
| - |
|
236 |
/*
|
| - |
|
237 |
@UiHandler("sellingPrice")
|
| - |
|
238 |
void onSPUpdate(KeyPressEvent keyPressEvent) {
|
| - |
|
239 |
if(Double.parseDouble(sellingPrice.getText()) != item.getSellingPrice()) {
|
| - |
|
240 |
sellingPrice.getElement().addClassName(style.fieldChanged());
|
| - |
|
241 |
} else {
|
| - |
|
242 |
sellingPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
243 |
}
|
| - |
|
244 |
}
|
| - |
|
245 |
|
| - |
|
246 |
@UiHandler("mop")
|
| - |
|
247 |
void onMOPUpdate(KeyPressEvent keyPressEvent) {
|
| - |
|
248 |
if(Double.parseDouble(mop.getText()) != item.getMop()) {
|
| - |
|
249 |
mop.getElement().addClassName(style.fieldChanged());
|
| - |
|
250 |
} else {
|
| - |
|
251 |
mop.getElement().addClassName(style.greenLabel());
|
| - |
|
252 |
}
|
| - |
|
253 |
}
|
| - |
|
254 |
|
| - |
|
255 |
@UiHandler("dealerPrice")
|
| - |
|
256 |
void onDPUpdate(KeyPressEvent keyPressEvent) {
|
| - |
|
257 |
if(Double.parseDouble(dealerPrice.getText()) != item.getDealerPrice()) {
|
| - |
|
258 |
dealerPrice.getElement().addClassName(style.fieldChanged());
|
| - |
|
259 |
} else {
|
| - |
|
260 |
dealerPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
261 |
}
|
| - |
|
262 |
}
|
| - |
|
263 |
|
| - |
|
264 |
@UiHandler("transferPrice")
|
| - |
|
265 |
void onTPUpdate(KeyPressEvent keyPressEvent) {
|
| - |
|
266 |
if(Double.parseDouble(transferPrice.getText()) != item.getTransferPrice()) {
|
| - |
|
267 |
transferPrice.getElement().addClassName(style.fieldChanged());
|
| - |
|
268 |
} else {
|
| - |
|
269 |
transferPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
270 |
}
|
| - |
|
271 |
}
|
| - |
|
272 |
|
| - |
|
273 |
@UiHandler("weight")
|
| - |
|
274 |
void onWeightUpdate(KeyPressEvent keyPressEvent) {
|
| - |
|
275 |
if(Double.parseDouble(weight.getText()) != item.getWeight()) {
|
| - |
|
276 |
weight.getElement().addClassName(style.fieldChanged());
|
| - |
|
277 |
} else {
|
| - |
|
278 |
weight.getElement().addClassName(style.greenLabel());
|
| - |
|
279 |
}
|
| - |
|
280 |
}
|
| - |
|
281 |
|
| - |
|
282 |
void applyDefaultStyles() {
|
| - |
|
283 |
sellingPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
284 |
mop.getElement().addClassName(style.greenLabel());
|
| - |
|
285 |
dealerPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
286 |
transferPrice.getElement().addClassName(style.greenLabel());
|
| - |
|
287 |
weight.getElement().addClassName(style.greenLabel());
|
| - |
|
288 |
}*/
|
| - |
|
289 |
|
| 103 |
}
|
290 |
}
|