Subversion Repositories SmartDukaan

Rev

Rev 2119 | Rev 6759 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
2427 ankur.sing 20
/**
21
 * This dialog is used to add/edit item related prices (DealerPrice, MOP, TransferPrice) for a vendor.
22
 *
23
 */
1992 ankur.sing 24
public class VendorPricesDialog extends DialogBox {
25
 
2427 ankur.sing 26
    interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
27
    private static final Binder binder = GWT.create(Binder.class);
1992 ankur.sing 28
 
2427 ankur.sing 29
    /**
30
     * Listener for update button click.
31
     */
32
    public interface VendorPriceUpdateListener{
33
        boolean onUpdate(double mop, double dp, double tp, long vendorId);
34
    }
1992 ankur.sing 35
 
2427 ankur.sing 36
    private VendorPriceUpdateListener vendorPriceUpdateListener;
1992 ankur.sing 37
 
2427 ankur.sing 38
    @UiField Button closeButton, updateButton;
39
    @UiField TextBox mop, dealerPrice, transferPrice;
40
    @UiField ListBox vendor;
41
 
42
    public VendorPricesDialog() {
43
        setText("Vendor Prices");
44
        setWidget(binder.createAndBindUi(this));
45
        setAnimationEnabled(true);
46
        center();
47
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
48
            vendor.addItem(e.getValue());
49
        }
50
    }
51
 
52
    public VendorPricesDialog(String mop, String dp, String tp) {
53
        this();
54
        setPrices(mop, dp, tp);
55
    }
56
 
57
    public void setPrices(String mop, String dp, String tp) {
58
        this.mop.setText(mop);
59
        this.dealerPrice.setText(dp);
60
        this.transferPrice.setText(tp);
61
        this.vendor.setEnabled(false);
62
    }
63
 
64
    /**
65
     * listener for click on update button is set in ItemDetails and ItemForm
66
     * @param vPriceUpdateListener
67
     */
68
    public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
69
        this.vendorPriceUpdateListener = vPriceUpdateListener;
70
    }
71
 
72
    @UiHandler("closeButton")
73
    void onCloseClicked(ClickEvent event) {
74
        hide();
75
    }
76
 
77
    @UiHandler("updateButton")
78
    void onEditClicked(ClickEvent event) {
79
        double mop, dp, tp;
80
        try {
81
            mop = Double.parseDouble(this.mop.getText());
82
            dp = Double.parseDouble(this.dealerPrice.getText());
83
            tp = Double.parseDouble(this.transferPrice.getText());
84
        } catch(NumberFormatException ex) {
85
            Window.alert("Price format is not valid.");
86
            return;
87
        }
88
        long vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
89
        if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
90
            hide();
91
        }
92
    }
1992 ankur.sing 93
}