| 2105 |
ankur.sing |
1 |
|
|
|
2 |
package in.shop2020.catalog.dashboard.client;
|
|
|
3 |
|
|
|
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
5 |
|
|
|
6 |
import java.util.Map.Entry;
|
|
|
7 |
|
|
|
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;
|
| 2119 |
ankur.sing |
15 |
import com.google.gwt.user.client.ui.CheckBox;
|
| 2105 |
ankur.sing |
16 |
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
17 |
import com.google.gwt.user.client.ui.ListBox;
|
|
|
18 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
19 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
public class VendorMappingDialog extends DialogBox {
|
|
|
23 |
|
| 2119 |
ankur.sing |
24 |
interface Binder extends UiBinder<Widget, VendorMappingDialog> { }
|
|
|
25 |
private static final Binder binder = GWT.create(Binder.class);
|
| 2105 |
ankur.sing |
26 |
|
| 2119 |
ankur.sing |
27 |
public interface VendorMappingUpdateListener{
|
|
|
28 |
boolean onUpdate(String itemKey, long vendorId);
|
|
|
29 |
}
|
| 2105 |
ankur.sing |
30 |
|
| 2119 |
ankur.sing |
31 |
private VendorMappingUpdateListener vendorMappingUpdateListener;
|
| 2105 |
ankur.sing |
32 |
|
| 2119 |
ankur.sing |
33 |
@UiField TextBox productGroup, brand, modelNumber, color;
|
|
|
34 |
@UiField CheckBox sameAsOurs;
|
|
|
35 |
@UiField Button generateKeyButton;
|
|
|
36 |
@UiField Button closeButton, updateButton;
|
|
|
37 |
@UiField TextBox itemKey;
|
|
|
38 |
@UiField ListBox vendor;
|
|
|
39 |
|
| 2126 |
ankur.sing |
40 |
private String ourProductGroup, ourBrand, ourColor, ourModelNum;
|
|
|
41 |
|
|
|
42 |
public VendorMappingDialog(String ourProductGroup, String ourBrand, String ourModelNum, String ourColor) {
|
| 2119 |
ankur.sing |
43 |
setText("Vendor Item Mapping");
|
|
|
44 |
setWidget(binder.createAndBindUi(this));
|
|
|
45 |
setAnimationEnabled(true);
|
|
|
46 |
//setGlassEnabled(true);
|
|
|
47 |
center();
|
|
|
48 |
for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
|
|
|
49 |
vendor.addItem(e.getValue());
|
|
|
50 |
}
|
| 2126 |
ankur.sing |
51 |
this.ourProductGroup = ourProductGroup;
|
|
|
52 |
this.ourBrand = ourBrand;
|
|
|
53 |
this.ourModelNum = ourModelNum;
|
|
|
54 |
this.ourColor = ourColor;
|
| 2119 |
ankur.sing |
55 |
}
|
|
|
56 |
|
| 2126 |
ankur.sing |
57 |
public VendorMappingDialog(String ourProductGroup, String ourBrand, String ourModelNum, String ourColor, String itemKey) {
|
|
|
58 |
this(ourProductGroup, ourBrand, ourModelNum, ourColor);
|
| 2119 |
ankur.sing |
59 |
setKey(itemKey);
|
|
|
60 |
}
|
| 2126 |
ankur.sing |
61 |
|
|
|
62 |
private void setKey(String itemKey) {
|
| 2119 |
ankur.sing |
63 |
this.itemKey.setText(itemKey);
|
|
|
64 |
this.vendor.setEnabled(false);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public void setVendorMappingUpdateListener(VendorMappingUpdateListener vMappingUpdateListener) {
|
|
|
68 |
this.vendorMappingUpdateListener = vMappingUpdateListener;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
@UiHandler("closeButton")
|
|
|
72 |
void onCloseClicked(ClickEvent event) {
|
|
|
73 |
hide();
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
@UiHandler("updateButton")
|
|
|
77 |
void onEditClicked(ClickEvent event) {
|
|
|
78 |
long vendorId;
|
|
|
79 |
String key;
|
|
|
80 |
vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
|
|
|
81 |
key = itemKey.getText().trim();
|
|
|
82 |
if(key.isEmpty()) {
|
|
|
83 |
Window.alert("Item key cannot be empty");
|
|
|
84 |
return;
|
|
|
85 |
}
|
|
|
86 |
if(vendorMappingUpdateListener.onUpdate(key, vendorId)) {
|
|
|
87 |
hide();
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
@UiHandler("generateKeyButton")
|
|
|
92 |
void generateKey(ClickEvent event) {
|
| 2359 |
ankur.sing |
93 |
String pg = productGroup.getText().toLowerCase().trim();
|
|
|
94 |
String br = brand.getText().toLowerCase().trim();
|
|
|
95 |
String mn = modelNumber.getText().toLowerCase().trim();
|
|
|
96 |
String clr = color.getText().toLowerCase().trim();
|
|
|
97 |
if(pg.equals("") || br.equals("") || mn.equals("")) {
|
|
|
98 |
Window.alert("Please fill up product group, brand and model number");
|
| 2119 |
ankur.sing |
99 |
return;
|
|
|
100 |
}
|
|
|
101 |
String key = pg + "|" + br + "|" + mn + "|" + clr;
|
|
|
102 |
itemKey.setText(key);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
@UiHandler("sameAsOurs")
|
|
|
106 |
void setDefaultKeyParams(ClickEvent event) {
|
|
|
107 |
if(sameAsOurs.getValue()) {
|
| 2126 |
ankur.sing |
108 |
productGroup.setText(ourProductGroup);
|
|
|
109 |
brand.setText(ourBrand);
|
|
|
110 |
modelNumber.setText(ourModelNum);
|
|
|
111 |
color.setText(ourColor);
|
|
|
112 |
} else {
|
|
|
113 |
productGroup.setText("");
|
|
|
114 |
brand.setText("");
|
|
|
115 |
modelNumber.setText("");
|
|
|
116 |
color.setText("");
|
| 2119 |
ankur.sing |
117 |
}
|
|
|
118 |
}
|
| 2105 |
ankur.sing |
119 |
}
|