Subversion Repositories SmartDukaan

Rev

Rev 2359 | Details | Compare with Previous | Last modification | View Log | RSS feed

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