| 3558 |
rajveer |
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;
|
|
|
15 |
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
16 |
import com.google.gwt.user.client.ui.ListBox;
|
|
|
17 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
18 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* This dialog is used to add/edit item related prices (SellingPrice, MRP) for a source.
|
|
|
22 |
*
|
|
|
23 |
*/
|
|
|
24 |
public class SourcePricesDialog extends DialogBox {
|
|
|
25 |
|
|
|
26 |
interface Binder extends UiBinder<Widget, SourcePricesDialog> { }
|
|
|
27 |
private static final Binder binder = GWT.create(Binder.class);
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Listener for update button click.
|
|
|
31 |
*/
|
|
|
32 |
public interface SourcePriceUpdateListener{
|
|
|
33 |
boolean onUpdate(double mrp, double sellingPrice, long sourceId);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
private SourcePriceUpdateListener sourcePriceUpdateListener;
|
|
|
37 |
|
|
|
38 |
@UiField Button closeButton, updateButton;
|
|
|
39 |
@UiField TextBox mrp, sellingPrice;
|
|
|
40 |
@UiField ListBox source;
|
|
|
41 |
|
|
|
42 |
public SourcePricesDialog() {
|
|
|
43 |
setText("Source Prices");
|
|
|
44 |
setWidget(binder.createAndBindUi(this));
|
|
|
45 |
setAnimationEnabled(true);
|
|
|
46 |
center();
|
|
|
47 |
for(Entry<Long, String> e : Utils.getAllSources().entrySet()){
|
|
|
48 |
source.addItem(e.getValue());
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public SourcePricesDialog(String mrp, String sellingPrice) {
|
|
|
53 |
this();
|
|
|
54 |
setPrices(mrp, sellingPrice);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public void setPrices(String mrp, String sellingPrice) {
|
|
|
58 |
this.mrp.setText(mrp);
|
|
|
59 |
this.sellingPrice.setText(sellingPrice);
|
|
|
60 |
this.source.setEnabled(false);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* listener for click on update button is set in ItemDetails and ItemForm
|
|
|
65 |
* @param vPriceUpdateListener
|
|
|
66 |
*/
|
|
|
67 |
public void setSourcePriceUpdateListener(SourcePriceUpdateListener sPriceUpdateListener) {
|
|
|
68 |
this.sourcePriceUpdateListener = sPriceUpdateListener;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
@UiHandler("closeButton")
|
|
|
72 |
void onCloseClicked(ClickEvent event) {
|
|
|
73 |
hide();
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
@UiHandler("updateButton")
|
|
|
77 |
void onEditClicked(ClickEvent event) {
|
|
|
78 |
double mrp, sellingPrice;
|
|
|
79 |
try {
|
|
|
80 |
mrp = Double.parseDouble(this.mrp.getText());
|
|
|
81 |
sellingPrice = Double.parseDouble(this.sellingPrice.getText());
|
|
|
82 |
} catch(NumberFormatException ex) {
|
|
|
83 |
Window.alert("Price format is not valid.");
|
|
|
84 |
return;
|
|
|
85 |
}
|
|
|
86 |
long sourceId = Utils.getSourceId(this.source.getItemText(this.source.getSelectedIndex()));
|
|
|
87 |
if(sourcePriceUpdateListener.onUpdate(mrp, sellingPrice, sourceId)) {
|
|
|
88 |
hide();
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|