| 2105 |
ankur.sing |
1 |
|
| 1992 |
ankur.sing |
2 |
package in.shop2020.catalog.dashboard.client;
|
|
|
3 |
|
| 2105 |
ankur.sing |
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
5 |
|
|
|
6 |
import java.util.Map.Entry;
|
|
|
7 |
|
| 1992 |
ankur.sing |
8 |
import com.google.gwt.core.client.GWT;
|
|
|
9 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
12 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
13 |
import com.google.gwt.user.client.Window;
|
|
|
14 |
import com.google.gwt.user.client.ui.Button;
|
|
|
15 |
import com.google.gwt.user.client.ui.DialogBox;
|
| 2105 |
ankur.sing |
16 |
import com.google.gwt.user.client.ui.ListBox;
|
| 1992 |
ankur.sing |
17 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
18 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
public class VendorPricesDialog extends DialogBox {
|
|
|
22 |
|
|
|
23 |
interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
|
|
|
24 |
private static final Binder binder = GWT.create(Binder.class);
|
|
|
25 |
|
|
|
26 |
public interface VendorPriceUpdateListener{
|
| 2105 |
ankur.sing |
27 |
boolean onUpdate(String itemKey, double mop, double dp, double tp, long vendorId);
|
| 1992 |
ankur.sing |
28 |
}
|
|
|
29 |
|
|
|
30 |
private VendorPriceUpdateListener vendorPriceUpdateListener;
|
|
|
31 |
|
|
|
32 |
@UiField Button closeButton, updateButton;
|
| 2105 |
ankur.sing |
33 |
@UiField TextBox itemKey, mop, dealerPrice, transferPrice;
|
|
|
34 |
@UiField ListBox vendor;
|
| 1992 |
ankur.sing |
35 |
|
| 2105 |
ankur.sing |
36 |
public VendorPricesDialog() {
|
|
|
37 |
setText("Vendor Prices");
|
|
|
38 |
setWidget(binder.createAndBindUi(this));
|
|
|
39 |
setAnimationEnabled(true);
|
|
|
40 |
//setGlassEnabled(true);
|
|
|
41 |
center();
|
|
|
42 |
for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
|
|
|
43 |
vendor.addItem(e.getValue());
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public VendorPricesDialog(String itemKey, String mop, String dp, String tp) {
|
|
|
48 |
this();
|
|
|
49 |
setPrices(itemKey, mop, dp, tp);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public void setPrices(String itemKey, String mop, String dp, String tp) {
|
|
|
53 |
this.itemKey.setText(itemKey);
|
| 1992 |
ankur.sing |
54 |
this.mop.setText(mop);
|
|
|
55 |
this.dealerPrice.setText(dp);
|
|
|
56 |
this.transferPrice.setText(tp);
|
| 2105 |
ankur.sing |
57 |
this.vendor.setEnabled(false);
|
|
|
58 |
this.itemKey.setEnabled(false);
|
| 1992 |
ankur.sing |
59 |
}
|
|
|
60 |
|
|
|
61 |
/*@Override
|
|
|
62 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) {
|
|
|
63 |
super.onPreviewNativeEvent(preview);
|
|
|
64 |
|
|
|
65 |
NativeEvent evt = preview.getNativeEvent();
|
|
|
66 |
if (evt.getType().equals("keydown")) {
|
|
|
67 |
// Use the popup's key preview hooks to close the dialog when either
|
|
|
68 |
// enter or escape is pressed.
|
|
|
69 |
switch (evt.getKeyCode()) {
|
|
|
70 |
case KeyCodes.KEY_ENTER:
|
|
|
71 |
case KeyCodes.KEY_ESCAPE:
|
|
|
72 |
hide();
|
|
|
73 |
break;
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}*/
|
|
|
77 |
|
| 2105 |
ankur.sing |
78 |
public void setVendorDetailsUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
|
| 1992 |
ankur.sing |
79 |
this.vendorPriceUpdateListener = vPriceUpdateListener;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
@UiHandler("closeButton")
|
|
|
83 |
void onCloseClicked(ClickEvent event) {
|
|
|
84 |
hide();
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
@UiHandler("updateButton")
|
|
|
88 |
void onEditClicked(ClickEvent event) {
|
|
|
89 |
double mop;
|
|
|
90 |
double dp;
|
|
|
91 |
double tp;
|
| 2105 |
ankur.sing |
92 |
long vendorId;
|
|
|
93 |
String key;
|
| 1992 |
ankur.sing |
94 |
try {
|
|
|
95 |
mop = Double.parseDouble(this.mop.getText());
|
|
|
96 |
dp = Double.parseDouble(this.dealerPrice.getText());
|
|
|
97 |
tp = Double.parseDouble(this.transferPrice.getText());
|
| 2105 |
ankur.sing |
98 |
vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
|
|
|
99 |
key = itemKey.getText().trim();
|
|
|
100 |
if(key.isEmpty()) {
|
|
|
101 |
Window.alert("Item key cannot be empty");
|
|
|
102 |
return;
|
|
|
103 |
}
|
| 1992 |
ankur.sing |
104 |
} catch(NumberFormatException ex) {
|
|
|
105 |
Window.alert("Price format is not valid.");
|
|
|
106 |
return;
|
|
|
107 |
}
|
| 2105 |
ankur.sing |
108 |
if(vendorPriceUpdateListener.onUpdate(key, mop, dp, tp, vendorId)) {
|
|
|
109 |
hide();
|
|
|
110 |
}
|
| 1992 |
ankur.sing |
111 |
}
|
|
|
112 |
}
|