Subversion Repositories SmartDukaan

Rev

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

Rev 2359 Rev 2427
Line 17... Line 17...
17
import com.google.gwt.user.client.ui.RadioButton;
17
import com.google.gwt.user.client.ui.RadioButton;
18
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;
19
import com.google.gwt.user.client.ui.VerticalPanel;
20
import com.google.gwt.user.client.ui.Widget;
20
import com.google.gwt.user.client.ui.Widget;
21
 
21
 
-
 
22
/**
-
 
23
 * Panel containing buttons for different actions on item.
-
 
24
 * e.g. update item, add new item, change item status, mark/unmark risky, push prices to production etc.
-
 
25
 * @author ankur
-
 
26
 *
-
 
27
 */
22
public class ItemActions extends ResizeComposite{
28
public class ItemActions extends ResizeComposite{
23
 
29
 
24
    interface ItemActionsUiBinder extends UiBinder<Widget, ItemActions> {}
30
    interface ItemActionsUiBinder extends UiBinder<Widget, ItemActions> {}
25
    private static ItemActionsUiBinder uiBinder = GWT.create(ItemActionsUiBinder.class);
31
    private static ItemActionsUiBinder uiBinder = GWT.create(ItemActionsUiBinder.class);
26
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
32
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
Line 31... Line 37...
31
    @UiField Button markRisky, unmarkRisky;
37
    @UiField Button markRisky, unmarkRisky;
32
    @UiField Button generateMasterSheet;
38
    @UiField Button generateMasterSheet;
33
    
39
    
34
    public ItemActions(){
40
    public ItemActions(){
35
        initWidget(uiBinder.createAndBindUi(this));
41
        initWidget(uiBinder.createAndBindUi(this));
-
 
42
        //pushItemToProd.setEnabled(false);
36
    }
43
    }
-
 
44
 
37
    
45
    
38
    @UiHandler("updateItem")
46
    @UiHandler("updateItem")
39
    void updateItem(ClickEvent event) {
47
    void updateItem(ClickEvent event) {
40
        itemDetails.updateItem();
48
        itemDetails.updateItem();
41
    }
49
    }
42
    
50
    
-
 
51
    /**
-
 
52
     * creates a new form to fill up item details and displays the form.
-
 
53
     * @param event
-
 
54
     */
43
    @UiHandler("addItem")
55
    @UiHandler("addItem")
44
    void addItem(ClickEvent event) {
56
    void addItem(ClickEvent event) {
45
        ItemForm itemForm = new ItemForm();
57
        ItemForm itemForm = new ItemForm();
46
        itemForm.center();
58
        itemForm.center();
47
        itemForm.show();
59
        itemForm.show();
Line 117... Line 129...
117
                Window.alert("Error while marking item " + itemId + " IN PROCESS");
129
                Window.alert("Error while marking item " + itemId + " IN PROCESS");
118
            }
130
            }
119
        });
131
        });
120
    }
132
    }
121
    
133
    
-
 
134
    /**
-
 
135
     * Creates and pops up authentication dialog for push to production username and password
-
 
136
     * @param event
-
 
137
     */
122
    @UiHandler("pushItemToProd")
138
    @UiHandler("pushItemToProd")
123
    void pushItemToProduction(ClickEvent event) {
139
    void pushItemToProduction(ClickEvent event) {
124
        if(itemDetails.getItem() == null) {
140
        if(itemDetails.getItem() == null) {
125
            Window.alert("Please select an item to update");
141
            Window.alert("Please select an item to update");
126
            return;
142
            return;
Line 141... Line 157...
141
    
157
    
142
    @UiHandler("generateMasterSheet")
158
    @UiHandler("generateMasterSheet")
143
    void generateMasterSheet(ClickEvent event)  {
159
    void generateMasterSheet(ClickEvent event)  {
144
        createDialog();
160
        createDialog();
145
    }
161
    }
-
 
162
 
146
    
163
    /**
-
 
164
     * Creates and pops up  dialog box containing two options. 
-
 
165
     * 1) Handsets 2) Accessories
-
 
166
     * Also creates submit and cancel buttons and add click event listeners to them.
-
 
167
     * On submit button click, request is sent to <code>in.shop2020.catalog.dashboard.server.FileDownloadServlet<code>
-
 
168
     */
147
    private void createDialog() {
169
    private void createDialog() {
148
        VerticalPanel vp = new VerticalPanel();
170
        VerticalPanel vp = new VerticalPanel();
149
        final DialogBox db = new DialogBox();
171
        final DialogBox db = new DialogBox();
150
        db.setText("Master Sheet Download");
172
        db.setText("Master Sheet Download");
151
        final RadioButton handsetsRB = new RadioButton("vendorCategory", "Handsets");
173
        final RadioButton handsetsRB = new RadioButton("vendorCategory", "Handsets");
Line 174... Line 196...
174
                if(handsetsRB.getValue()) {
196
                if(handsetsRB.getValue()) {
175
                    vendorCategory = "Handsets";
197
                    vendorCategory = "Handsets";
176
                } else {
198
                } else {
177
                    vendorCategory = "Accessories";
199
                    vendorCategory = "Accessories";
178
                }
200
                }
-
 
201
                // Servlet mapping mastersheet/download is mapped to in.shop2020.catalog.dashboard.server.FileDownloadServlet
179
                String link = GWT.getHostPageBaseURL() + "mastersheet/download?vendorCategory=" + vendorCategory;
202
                String link = GWT.getHostPageBaseURL() + "mastersheet/download?vendorCategory=" + vendorCategory;
180
                Window.open(link, "_self", "Master Sheet Download");
203
                Window.open(link, "_self", "Master Sheet Download");
181
                db.hide();
204
                db.hide();
182
            }
205
            }
183
        });
206
        });
Line 190... Line 213...
190
        db.center();
213
        db.center();
191
        db.setAnimationEnabled(true);
214
        db.setAnimationEnabled(true);
192
        db.show();
215
        db.show();
193
    }
216
    }
194
    
217
    
-
 
218
    /**
-
 
219
     * validates and then calls service method changeItemRiskyFlag to change risky flag.
-
 
220
     * @param risky
-
 
221
     */
195
    private void changeRiskyFlag(boolean risky) {
222
    private void changeRiskyFlag(boolean risky) {
196
        Item item = itemDetails.getItem();
223
        Item item = itemDetails.getItem();
197
        if(item == null) {
224
        if(item == null) {
198
            Window.alert("Please select an item to mark/unmark as risky");
225
            Window.alert("Please select an item to mark/unmark as risky");
199
            return;
226
            return;
Line 223... Line 250...
223
    }
250
    }
224
    
251
    
225
    public void setItemDetails(ItemDetails itemDetails) {
252
    public void setItemDetails(ItemDetails itemDetails) {
226
        this.itemDetails = itemDetails;
253
        this.itemDetails = itemDetails;
227
    }
254
    }
-
 
255
 
228
    
256
    /**
-
 
257
     * Validate item status change.
-
 
258
     * @param toStatus
-
 
259
     * @return item Id if validation is successful else -1
-
 
260
     */
229
    private long validateStatusChange(int toStatus) {
261
    private long validateStatusChange(int toStatus) {
230
        final Item item = itemDetails.getItem();
262
        final Item item = itemDetails.getItem();
231
        if(item == null) {
263
        if(item == null) {
232
            Window.alert(getAlertString(toStatus)[0]);
264
            Window.alert(getAlertString(toStatus)[0]);
233
            return -1;
265
            return -1;
Line 237... Line 269...
237
            return -1;
269
            return -1;
238
        }
270
        }
239
        return item.getId();
271
        return item.getId();
240
    }
272
    }
241
    
273
    
-
 
274
    /**
-
 
275
     * @param toStatus
-
 
276
     * @return messages to be show to the user if item status change validation fails.
-
 
277
     *       <br>-first message will be shown if no item is selected in the list
-
 
278
     *       <br>-second message is shown if validation for FromStatus to ToStatus fails.
-
 
279
     */
242
    private String[] getAlertString(int toStatus) {
280
    private String[] getAlertString(int toStatus) {
243
        String[] alertStr = {"", ""};
281
        String[] alertStr = {"", ""};
244
        switch(toStatus) {
282
        switch(toStatus) {
245
        case Utils.PAUSED: {
283
        case Utils.PAUSED: {
246
            alertStr[0] = "Please select an ACTIVE item to mark PAUSED";
284
            alertStr[0] = "Please select an ACTIVE item to mark PAUSED";