Subversion Repositories SmartDukaan

Rev

Rev 2126 | Rev 2427 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2126 Rev 2359
Line 3... Line 3...
3
import in.shop2020.catalog.dashboard.shared.Item;
3
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.Utils;
4
import in.shop2020.catalog.dashboard.shared.Utils;
5
 
5
 
6
import com.google.gwt.core.client.GWT;
6
import com.google.gwt.core.client.GWT;
7
import com.google.gwt.event.dom.client.ClickEvent;
7
import com.google.gwt.event.dom.client.ClickEvent;
-
 
8
import com.google.gwt.event.dom.client.ClickHandler;
8
import com.google.gwt.uibinder.client.UiBinder;
9
import com.google.gwt.uibinder.client.UiBinder;
9
import com.google.gwt.uibinder.client.UiField;
10
import com.google.gwt.uibinder.client.UiField;
10
import com.google.gwt.uibinder.client.UiHandler;
11
import com.google.gwt.uibinder.client.UiHandler;
11
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.ui.Button;
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.HorizontalPanel;
-
 
17
import com.google.gwt.user.client.ui.RadioButton;
14
import com.google.gwt.user.client.ui.ResizeComposite;
18
import com.google.gwt.user.client.ui.ResizeComposite;
-
 
19
import com.google.gwt.user.client.ui.VerticalPanel;
15
import com.google.gwt.user.client.ui.Widget;
20
import com.google.gwt.user.client.ui.Widget;
16
 
21
 
17
public class ItemActions extends ResizeComposite{
22
public class ItemActions extends ResizeComposite{
18
 
23
 
19
    interface ItemActionsUiBinder extends UiBinder<Widget, ItemActions> {}
24
    interface ItemActionsUiBinder extends UiBinder<Widget, ItemActions> {}
20
    private static ItemActionsUiBinder uiBinder = GWT.create(ItemActionsUiBinder.class);
25
    private static ItemActionsUiBinder uiBinder = GWT.create(ItemActionsUiBinder.class);
21
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
26
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
22
    
27
    
23
    private ItemDetails itemDetails;
28
    private ItemDetails itemDetails;
24
    
29
    
25
    @UiField Button addItem, updateItem, phaseoutItem, activateItem, markAliveItem, pauseItem;
30
    @UiField Button addItem, updateItem, pushItemToProd, phaseoutItem, activateItem, markAliveItem, pauseItem;
-
 
31
    @UiField Button markRisky, unmarkRisky;
-
 
32
    @UiField Button generateMasterSheet;
26
    
33
    
27
    public ItemActions(){
34
    public ItemActions(){
28
        initWidget(uiBinder.createAndBindUi(this));
35
        initWidget(uiBinder.createAndBindUi(this));
29
    }
36
    }
30
    
37
    
Line 110... Line 117...
110
                Window.alert("Error while marking item " + itemId + " IN PROCESS");
117
                Window.alert("Error while marking item " + itemId + " IN PROCESS");
111
            }
118
            }
112
        });
119
        });
113
    }
120
    }
114
    
121
    
-
 
122
    @UiHandler("pushItemToProd")
-
 
123
    void pushItemToProduction(ClickEvent event) {
-
 
124
        if(itemDetails.getItem() == null) {
-
 
125
            Window.alert("Please select an item to update");
-
 
126
            return;
-
 
127
        }
-
 
128
        AuthenticateDialog authDialog = new AuthenticateDialog(itemDetails.getItem());
-
 
129
        authDialog.show();
-
 
130
    }
-
 
131
    
-
 
132
    @UiHandler("markRisky")
-
 
133
    void markRisky(ClickEvent event) {
-
 
134
        changeRiskyFlag(true);
-
 
135
    }
-
 
136
    
-
 
137
    @UiHandler("unmarkRisky")
-
 
138
    void unmarkRisky(ClickEvent event) {
-
 
139
        changeRiskyFlag(false);
-
 
140
    }
-
 
141
    
-
 
142
    @UiHandler("generateMasterSheet")
-
 
143
    void generateMasterSheet(ClickEvent event)  {
-
 
144
        createDialog();
-
 
145
    }
-
 
146
    
-
 
147
    private void createDialog() {
-
 
148
        VerticalPanel vp = new VerticalPanel();
-
 
149
        final DialogBox db = new DialogBox();
-
 
150
        db.setText("Master Sheet Download");
-
 
151
        final RadioButton handsetsRB = new RadioButton("vendorCategory", "Handsets");
-
 
152
        final RadioButton accRB = new RadioButton("vendorCategory", "Accessories");
-
 
153
        handsetsRB.setValue(true);
-
 
154
        HorizontalPanel hpRB = new HorizontalPanel();
-
 
155
        hpRB.add(handsetsRB);
-
 
156
        hpRB.add(accRB);
-
 
157
        
-
 
158
        vp.add(hpRB);
-
 
159
        
-
 
160
        Button submitButton = new Button("OK");
-
 
161
        Button cancelButton = new Button("Cancel");
-
 
162
        HorizontalPanel hpButtons = new HorizontalPanel();
-
 
163
        hpButtons.setSpacing(5);
-
 
164
        hpButtons.add(submitButton);
-
 
165
        hpButtons.add(cancelButton);
-
 
166
        
-
 
167
        vp.add(hpRB);
-
 
168
        vp.add(hpButtons);
-
 
169
        db.add(vp);
-
 
170
        submitButton.addClickHandler(new ClickHandler() {
-
 
171
            @Override
-
 
172
            public void onClick(ClickEvent event) {
-
 
173
                String vendorCategory;
-
 
174
                if(handsetsRB.getValue()) {
-
 
175
                    vendorCategory = "Handsets";
-
 
176
                } else {
-
 
177
                    vendorCategory = "Accessories";
-
 
178
                }
-
 
179
                String link = GWT.getHostPageBaseURL() + "mastersheet/download?vendorCategory=" + vendorCategory;
-
 
180
                Window.open(link, "_self", "Master Sheet Download");
-
 
181
                db.hide();
-
 
182
            }
-
 
183
        });
-
 
184
        cancelButton.addClickHandler(new ClickHandler() {
-
 
185
            @Override
-
 
186
            public void onClick(ClickEvent event) {
-
 
187
                db.hide();
-
 
188
            }
-
 
189
        });
-
 
190
        db.center();
-
 
191
        db.setAnimationEnabled(true);
-
 
192
        db.show();
-
 
193
    }
-
 
194
    
-
 
195
    private void changeRiskyFlag(boolean risky) {
-
 
196
        Item item = itemDetails.getItem();
-
 
197
        if(item == null) {
-
 
198
            Window.alert("Please select an item to mark/unmark as risky");
-
 
199
            return;
-
 
200
        }
-
 
201
        if(risky && item.isRisky()) {
-
 
202
            Window.alert("Item already marked as risky");
-
 
203
            return;
-
 
204
        }
-
 
205
        if(!risky && !item.isRisky()) {
-
 
206
            Window.alert("Item not marked as risky");
-
 
207
            return;
-
 
208
        }
-
 
209
        catalogService.changeItemRiskyFlag(item.getId(), risky, new AsyncCallback<Boolean>() {
-
 
210
            @Override
-
 
211
            public void onSuccess(Boolean result) {
-
 
212
                if(result) {
-
 
213
                    Window.alert("Done!");
-
 
214
                } else {
-
 
215
                    Window.alert("Error while marking/unmarking risky flag on staging/production server.");
-
 
216
                }
-
 
217
            }
-
 
218
            @Override
-
 
219
            public void onFailure(Throwable caught) {
-
 
220
                Window.alert("Error");
-
 
221
            }
-
 
222
        });
-
 
223
    }
-
 
224
    
115
    public void setItemDetails(ItemDetails itemDetails) {
225
    public void setItemDetails(ItemDetails itemDetails) {
116
        this.itemDetails = itemDetails;
226
        this.itemDetails = itemDetails;
117
    }
227
    }
118
    
228
    
119
    private long validateStatusChange(int toStatus) {
229
    private long validateStatusChange(int toStatus) {