1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.common.client.lo; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.assembly.data.Data; |
22 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
23 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
24 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
25 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
26 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
27 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
28 | |
import org.kuali.student.common.ui.client.widgets.KSDropDown; |
29 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
30 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
31 | |
import org.kuali.student.common.ui.client.widgets.KSTextBox; |
32 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
33 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
34 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.GroupFieldLayout; |
35 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.TableFieldLayout; |
36 | |
import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel; |
37 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
38 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
39 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
40 | |
import org.kuali.student.common.ui.client.widgets.list.impl.SimpleListItems; |
41 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
42 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
43 | |
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
44 | |
import org.kuali.student.lum.common.client.lo.rpc.LoCategoryRpcService; |
45 | |
import org.kuali.student.lum.common.client.lo.rpc.LoCategoryRpcServiceAsync; |
46 | |
import org.kuali.student.lum.lo.dto.LoCategoryInfo; |
47 | |
import org.kuali.student.lum.lo.dto.LoCategoryTypeInfo; |
48 | |
|
49 | |
import com.google.gwt.core.client.GWT; |
50 | |
import com.google.gwt.event.dom.client.ClickEvent; |
51 | |
import com.google.gwt.event.dom.client.ClickHandler; |
52 | |
import com.google.gwt.event.dom.client.KeyUpEvent; |
53 | |
import com.google.gwt.event.dom.client.KeyUpHandler; |
54 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
55 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
56 | |
import com.google.gwt.user.client.Window; |
57 | |
import com.google.gwt.user.client.ui.Anchor; |
58 | |
import com.google.gwt.user.client.ui.Composite; |
59 | |
import com.google.gwt.user.client.ui.FlowPanel; |
60 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
61 | |
|
62 | 0 | public class CategoryManagement extends Composite { |
63 | 0 | private KSButton addButton = new KSButton("Create", ButtonStyle.SECONDARY); |
64 | 0 | private KSButton deleteButton = new KSButton("Delete", ButtonStyle.SECONDARY); |
65 | 0 | private KSButton updateButton = new KSButton("Edit", ButtonStyle.SECONDARY); |
66 | |
|
67 | 0 | KSCheckBox accreditationCheckBox = new KSCheckBox("Accreditation"); |
68 | 0 | KSCheckBox skillCheckBox = new KSCheckBox("Skill"); |
69 | 0 | KSCheckBox subjectCheckBox = new KSCheckBox("Subject"); |
70 | 0 | KSTextBox wordsInCategoryTextBox = new KSTextBox(); |
71 | |
|
72 | 0 | static LoCategoryRpcServiceAsync loCatRpcServiceAsync = GWT.create(LoCategoryRpcService.class); |
73 | |
|
74 | 0 | CategoryManagementTable categoryManagementTable = null; |
75 | |
|
76 | 0 | FlowPanel mainPanel = new FlowPanel(); |
77 | 0 | FlowPanel tablePanel = new FlowPanel(); |
78 | 0 | HorizontalBlockFlowPanel layout = new HorizontalBlockFlowPanel(); |
79 | |
|
80 | |
List<LoCategoryTypeInfo> categoryTypeList; |
81 | |
private void initCategoryManagement() { |
82 | 0 | super.initWidget(layout); |
83 | 0 | layout.add(mainPanel); |
84 | 0 | layout.add(tablePanel); |
85 | |
|
86 | 0 | tablePanel.addStyleName("KSLOCategoryManagementTablePanel"); |
87 | 0 | mainPanel.addStyleName("KSLOCategoryManagementMainPanel"); |
88 | |
|
89 | 0 | HorizontalBlockFlowPanel titlePanel = new HorizontalBlockFlowPanel(); |
90 | |
|
91 | 0 | KSLabel funnelImg = new KSLabel(""); |
92 | 0 | funnelImg.addStyleName("KS-LOFunnelImg"); |
93 | 0 | titlePanel.add(funnelImg); |
94 | |
|
95 | 0 | KSLabel filterLabel = new KSLabel("Filter"); |
96 | 0 | filterLabel.addStyleName("KSLOCategoryManagementFilterLabel"); |
97 | 0 | titlePanel.add(filterLabel); |
98 | |
|
99 | 0 | mainPanel.add(titlePanel); |
100 | |
|
101 | 0 | addButton.addStyleName("KS-LOSecondaryButton"); |
102 | 0 | deleteButton.addStyleName("KS-LOSecondaryButton"); |
103 | 0 | updateButton.addStyleName("KS-LOSecondaryButton"); |
104 | |
|
105 | 0 | accreditationCheckBox.setValue(true); |
106 | 0 | skillCheckBox.setValue(true); |
107 | 0 | subjectCheckBox.setValue(true); |
108 | |
|
109 | 0 | HorizontalBlockFlowPanel linkButtonPanel = new HorizontalBlockFlowPanel(); |
110 | 0 | linkButtonPanel.addStyleName("KSLOCategoryManagementFilterPanel"); |
111 | |
|
112 | 0 | KSLabel spacer = new KSLabel(""); |
113 | 0 | spacer.setWidth("60px"); |
114 | 0 | KSLabel divider = new KSLabel("|"); |
115 | |
|
116 | 0 | Anchor selectAllLink = new Anchor("Select All"); |
117 | 0 | selectAllLink.addStyleName("KS-LOSelectAllHyperlink"); |
118 | 0 | linkButtonPanel.add(selectAllLink); |
119 | 0 | selectAllLink.addClickHandler(new ClickHandler(){ |
120 | |
@Override |
121 | |
public void onClick(ClickEvent event) { |
122 | 0 | accreditationCheckBox.setValue(true); |
123 | 0 | skillCheckBox.setValue(true); |
124 | 0 | subjectCheckBox.setValue(true); |
125 | 0 | filterCategoryByType(); |
126 | 0 | } |
127 | |
}); |
128 | |
|
129 | 0 | linkButtonPanel.add(divider); |
130 | |
|
131 | 0 | Anchor clearLink = new Anchor("Clear"); |
132 | 0 | clearLink.addStyleName("KS-LOClearHyperlink"); |
133 | 0 | linkButtonPanel.add(clearLink); |
134 | 0 | clearLink.addClickHandler(new ClickHandler(){ |
135 | |
@Override |
136 | |
public void onClick(ClickEvent event) { |
137 | 0 | accreditationCheckBox.setValue(false); |
138 | 0 | skillCheckBox.setValue(false); |
139 | 0 | subjectCheckBox.setValue(false); |
140 | 0 | wordsInCategoryTextBox.setText(null); |
141 | 0 | filterCategoryByType(); |
142 | 0 | } |
143 | |
}); |
144 | |
|
145 | 0 | mainPanel.add(linkButtonPanel); |
146 | |
|
147 | 0 | VerticalFlowPanel filterPanel = new VerticalFlowPanel(); |
148 | |
|
149 | 0 | filterPanel.add(accreditationCheckBox); |
150 | 0 | filterPanel.add(skillCheckBox); |
151 | 0 | filterPanel.add(subjectCheckBox); |
152 | |
|
153 | 0 | FieldElement wordsInCategory = new FieldElement("By words in category", wordsInCategoryTextBox); |
154 | 0 | filterPanel.add(wordsInCategory); |
155 | 0 | mainPanel.add(filterPanel); |
156 | |
|
157 | 0 | tablePanel.add(addButton); |
158 | 0 | tablePanel.add(updateButton); |
159 | 0 | tablePanel.add(deleteButton); |
160 | 0 | updateButton.setEnabled(false); |
161 | 0 | deleteButton.setEnabled(false); |
162 | |
|
163 | 0 | if(this.categoryManagementTable == null) { |
164 | 0 | categoryManagementTable = new CategoryManagementTable(); |
165 | |
} |
166 | |
else{ |
167 | 0 | categoryManagementTable.addStyleName("KSLOCategoryManagementTable"); |
168 | |
} |
169 | 0 | categoryManagementTable.getTable().addSelectionChangeHandler(new SelectionChangeHandler(){ |
170 | |
|
171 | |
@Override |
172 | |
public void onSelectionChange(SelectionChangeEvent event) { |
173 | 0 | if(categoryManagementTable.getSelectedRows().size() > 0){ |
174 | 0 | updateButton.setEnabled(true); |
175 | 0 | deleteButton.setEnabled(true); |
176 | |
} |
177 | |
else{ |
178 | 0 | updateButton.setEnabled(false); |
179 | 0 | deleteButton.setEnabled(false); |
180 | |
} |
181 | 0 | } |
182 | |
}); |
183 | |
|
184 | 0 | tablePanel.add(categoryManagementTable); |
185 | |
|
186 | 0 | loCatRpcServiceAsync.getLoCategoryTypes(new KSAsyncCallback<List<LoCategoryTypeInfo>>() { |
187 | |
@Override |
188 | |
public void handleFailure(Throwable caught) { |
189 | 0 | GWT.log("getLoCategoryTypes failed", caught); |
190 | 0 | Window.alert("Get LoCategory Types failed"); |
191 | 0 | } |
192 | |
@Override |
193 | |
public void onSuccess(List<LoCategoryTypeInfo> results) { |
194 | 0 | categoryTypeList = results; |
195 | 0 | categoryManagementTable.loadTable(new Callback<Boolean>(){ |
196 | |
@Override |
197 | |
public void exec(Boolean result) { |
198 | |
|
199 | 0 | } |
200 | |
}); |
201 | 0 | } |
202 | |
}); |
203 | |
|
204 | 0 | wordsInCategoryTextBox.addKeyUpHandler(new KeyUpHandler() { |
205 | |
@Override |
206 | |
public void onKeyUp(KeyUpEvent event) { |
207 | 0 | filterCategoryByWords(); |
208 | 0 | } |
209 | |
|
210 | |
}); |
211 | 0 | subjectCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
212 | |
@Override |
213 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
214 | 0 | filterCategoryByType(); |
215 | 0 | } |
216 | |
}); |
217 | 0 | skillCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
218 | |
@Override |
219 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
220 | 0 | filterCategoryByType(); |
221 | |
|
222 | 0 | } |
223 | |
}); |
224 | 0 | accreditationCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
225 | |
@Override |
226 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
227 | 0 | filterCategoryByType(); |
228 | 0 | } |
229 | |
}); |
230 | |
|
231 | 0 | addButton.addClickHandler(new ClickHandler() { |
232 | |
@Override |
233 | |
public void onClick(ClickEvent event) { |
234 | 0 | CreateCategoryDialog dialog = new CreateCategoryDialog(); |
235 | 0 | dialog.setCategoryType(categoryTypeList); |
236 | 0 | dialog.show(); |
237 | 0 | } |
238 | |
}); |
239 | 0 | deleteButton.addClickHandler(new ClickHandler() { |
240 | |
@Override |
241 | |
public void onClick(ClickEvent event) { |
242 | |
|
243 | 0 | String id = categoryManagementTable.getSelectedLoCategoryInfoId(); |
244 | 0 | if(id != null){ |
245 | 0 | loCatRpcServiceAsync.getData(id, new KSAsyncCallback<Data>() { |
246 | |
@Override |
247 | |
public void handleFailure(Throwable caught) { |
248 | 0 | GWT.log("getSelectedLoCategoryInfo failed", caught); |
249 | 0 | Window.alert("Get Selected Lo Category failed"); |
250 | 0 | } |
251 | |
|
252 | |
@Override |
253 | |
public void onSuccess(Data result) { |
254 | 0 | DeleteConfirmationDialog dialog = new DeleteConfirmationDialog(); |
255 | 0 | dialog.setCategory(CategoryDataUtil.toLoCategoryInfo(result)); |
256 | 0 | dialog.show(); |
257 | 0 | } |
258 | |
}); |
259 | |
} |
260 | |
|
261 | 0 | } |
262 | |
}); |
263 | 0 | updateButton.addClickHandler(new ClickHandler() { |
264 | |
@Override |
265 | |
public void onClick(ClickEvent event) { |
266 | 0 | String id = categoryManagementTable.getSelectedLoCategoryInfoId(); |
267 | 0 | if(id != null){ |
268 | 0 | loCatRpcServiceAsync.getData(id, new KSAsyncCallback<Data>() { |
269 | |
@Override |
270 | |
public void handleFailure(Throwable caught) { |
271 | 0 | GWT.log("getSelectedLoCategoryInfo failed", caught); |
272 | 0 | Window.alert("Get Selected Lo Category failed"); |
273 | 0 | } |
274 | |
@Override |
275 | |
public void onSuccess(Data result) { |
276 | 0 | UpdateCategoryDialog dialog = new UpdateCategoryDialog(); |
277 | 0 | dialog.setCategory(CategoryDataUtil.toLoCategoryInfo(result)); |
278 | 0 | dialog.setCategoryType(categoryTypeList); |
279 | 0 | dialog.show(); |
280 | 0 | } |
281 | |
}); |
282 | |
} |
283 | 0 | } |
284 | |
}); |
285 | 0 | } |
286 | |
|
287 | 0 | public CategoryManagement() { |
288 | 0 | initCategoryManagement(); |
289 | 0 | } |
290 | |
|
291 | 0 | public CategoryManagement(boolean hideInactiveCategories, boolean isMultiSelect) { |
292 | 0 | this.categoryManagementTable = new CategoryManagementTable(hideInactiveCategories, isMultiSelect); |
293 | 0 | initCategoryManagement(); |
294 | 0 | } |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | 0 | public CategoryManagement(boolean hideInactiveCategories, boolean isMultiSelect, List<LoCategoryInfo> loCategoriesToFilter) { |
308 | 0 | this.categoryManagementTable = new CategoryManagementTable(hideInactiveCategories, isMultiSelect, loCategoriesToFilter); |
309 | 0 | initCategoryManagement(); |
310 | 0 | } |
311 | |
public List<LoCategoryInfo> getSelectedCategoryList(){ |
312 | 0 | return categoryManagementTable.getSelectedLoCategoryInfos(); |
313 | |
} |
314 | |
|
315 | |
private void filterCategoryByType() { |
316 | |
|
317 | 0 | List<ResultRow> bufferList = new ArrayList<ResultRow>(); |
318 | 0 | if(subjectCheckBox.getValue() == true){ |
319 | 0 | bufferList.addAll(categoryManagementTable.getRowsByType("subject")); |
320 | |
} |
321 | 0 | if(skillCheckBox.getValue() == true){ |
322 | 0 | bufferList.addAll(categoryManagementTable.getRowsByType("skill")); |
323 | |
} |
324 | 0 | if(accreditationCheckBox.getValue() == true){ |
325 | 0 | bufferList.addAll(categoryManagementTable.getRowsByType("accreditation")); |
326 | |
} |
327 | 0 | categoryManagementTable.redraw(bufferList); |
328 | |
|
329 | 0 | } |
330 | |
|
331 | |
private void filterCategoryByWords() { |
332 | |
|
333 | 0 | List<ResultRow> bufferList = new ArrayList<ResultRow>(); |
334 | 0 | String input = wordsInCategoryTextBox.getText(); |
335 | 0 | if(input != null && (!input.isEmpty())){ |
336 | 0 | List<ResultRow> tmpList = categoryManagementTable.getRowsLikeName(input); |
337 | 0 | bufferList.addAll(tmpList); |
338 | 0 | categoryManagementTable.redraw(bufferList); |
339 | 0 | } else { |
340 | 0 | filterCategoryByType(); |
341 | |
} |
342 | 0 | } |
343 | |
|
344 | |
public void setDeleteButtonEnabled(boolean b) { |
345 | 0 | deleteButton.setVisible(b); |
346 | 0 | } |
347 | |
|
348 | |
public void setUpdateButtonEnabled(boolean b) { |
349 | 0 | updateButton.setVisible(b); |
350 | 0 | } |
351 | |
|
352 | |
public void setInsertButtonEnabled(boolean b) { |
353 | 0 | addButton.setVisible(b); |
354 | 0 | } |
355 | |
class DeleteConfirmationDialog extends KSLightBox { |
356 | 0 | KSLabel categoryNameLabel = new KSLabel(); |
357 | 0 | KSLabel categoryTypeLabel = new KSLabel(); |
358 | 0 | HorizontalPanel spacer = new HorizontalPanel(); |
359 | |
LoCategoryInfo categoryInfo; |
360 | 0 | KSButton deleteButton = new KSButton("Delete"); |
361 | 0 | KSButton cancelButton = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED); |
362 | 0 | KSTextBox nameTextBox = new KSTextBox(); |
363 | 0 | KSDropDown typeListBox = new KSDropDown(); |
364 | |
|
365 | 0 | TableFieldLayout layout = new TableFieldLayout(); |
366 | 0 | FlowPanel mainPanel = new FlowPanel(); |
367 | |
|
368 | |
|
369 | 0 | public DeleteConfirmationDialog() { |
370 | 0 | this.setSize(540, 200); |
371 | |
|
372 | 0 | mainPanel.addStyleName("LOCategoryDialogSpacing"); |
373 | 0 | layout.addStyleName("LOCategoryDelete"); |
374 | 0 | mainPanel.add(layout); |
375 | |
|
376 | 0 | layout.setLayoutTitle(SectionTitle.generateH2Title("Delete Category")); |
377 | 0 | layout.setInstructions("You are about to delete the following:"); |
378 | 0 | FieldElement category = new FieldElement("Category", categoryNameLabel); |
379 | 0 | FieldElement type = new FieldElement("Type", categoryTypeLabel); |
380 | 0 | layout.addField(category); |
381 | 0 | layout.addField(type); |
382 | |
|
383 | 0 | this.addButton(deleteButton); |
384 | 0 | this.addButton(cancelButton); |
385 | |
|
386 | 0 | deleteButton.addClickHandler(new ClickHandler() { |
387 | |
@Override |
388 | |
public void onClick(ClickEvent event) { |
389 | |
|
390 | 0 | categoryInfo.setState("inactive"); |
391 | 0 | loCatRpcServiceAsync.saveData(CategoryDataUtil.toData(categoryInfo), new KSAsyncCallback<DataSaveResult>(){ |
392 | |
@Override |
393 | |
public void handleFailure(Throwable caught) { |
394 | 0 | GWT.log("updateLoCategory failed ", caught); |
395 | 0 | Window.alert("Switch LoCategory state to inactive failed "); |
396 | 0 | } |
397 | |
@Override |
398 | |
public void onSuccess(DataSaveResult result) { |
399 | |
|
400 | |
|
401 | 0 | if(result.getValidationResults()!=null && !result.getValidationResults().isEmpty()){ |
402 | 0 | Window.alert("Update LO Category failed: " + result.getValidationResults().get(0).getMessage()); |
403 | |
}else{ |
404 | 0 | KSNotifier.add(new KSNotification("Update LO Category Successful", false, 3000)); |
405 | |
|
406 | 0 | categoryManagementTable.loadTable(new Callback<Boolean>(){ |
407 | |
|
408 | |
@Override |
409 | |
public void exec(Boolean result) { |
410 | 0 | if(result){ |
411 | 0 | filterCategoryByType(); |
412 | |
} |
413 | |
|
414 | 0 | } |
415 | |
}); |
416 | |
} |
417 | 0 | } |
418 | |
}); |
419 | |
|
420 | 0 | DeleteConfirmationDialog.this.hide(); |
421 | 0 | } |
422 | |
}); |
423 | |
|
424 | 0 | cancelButton.addClickHandler(new ClickHandler() { |
425 | |
@Override |
426 | |
public void onClick(ClickEvent event) { |
427 | 0 | DeleteConfirmationDialog.this.hide(); |
428 | 0 | } |
429 | |
|
430 | |
}); |
431 | 0 | super.setWidget(mainPanel); |
432 | 0 | } |
433 | |
|
434 | |
public void setCategory(LoCategoryInfo cate) { |
435 | 0 | categoryInfo = cate; |
436 | 0 | categoryNameLabel.setText(categoryInfo.getName()); |
437 | 0 | categoryTypeLabel.setText(categoryInfo.getType()); |
438 | 0 | } |
439 | |
} |
440 | |
class UpdateCategoryDialog extends KSLightBox { |
441 | 0 | KSButton okButton = new KSButton("Save"); |
442 | 0 | KSButton cancelButton = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED); |
443 | 0 | KSTextBox nameTextBox = new KSTextBox(); |
444 | 0 | KSDropDown typeListBox = new KSDropDown(); |
445 | |
|
446 | 0 | GroupFieldLayout layout = new GroupFieldLayout(); |
447 | 0 | FlowPanel mainPanel = new FlowPanel(); |
448 | |
LoCategoryInfo categoryInfo; |
449 | |
|
450 | 0 | public UpdateCategoryDialog() { |
451 | 0 | this.setSize(540, 200); |
452 | 0 | mainPanel.addStyleName("LOCategoryDialogSpacing"); |
453 | 0 | layout.setLayoutTitle(SectionTitle.generateH2Title("Edit Category")); |
454 | |
|
455 | 0 | FieldElement category = new FieldElement("Category", nameTextBox); |
456 | 0 | FieldElement type = new FieldElement("Type", typeListBox); |
457 | 0 | layout.addField(category); |
458 | 0 | layout.addField(type); |
459 | |
|
460 | |
|
461 | 0 | this.addButton(okButton); |
462 | 0 | this.addButton(cancelButton); |
463 | |
|
464 | 0 | mainPanel.add(layout); |
465 | 0 | super.setWidget(mainPanel); |
466 | 0 | okButton.addClickHandler(new ClickHandler() { |
467 | |
@Override |
468 | |
public void onClick(ClickEvent event) { |
469 | 0 | LoCategoryInfo cate = getCategory(); |
470 | 0 | boolean error = false; |
471 | 0 | layout.clearValidation(); |
472 | 0 | if(nameTextBox.getText().isEmpty()){ |
473 | 0 | layout.addValidationErrorMessage("Category", "Required"); |
474 | 0 | error = true; |
475 | |
} |
476 | 0 | if(typeListBox.getSelectedItem() == null || typeListBox.getSelectedItem().isEmpty()){ |
477 | 0 | layout.addValidationErrorMessage("Type", "Required"); |
478 | 0 | error = true; |
479 | |
} |
480 | |
|
481 | 0 | if(!error){ |
482 | 0 | loCatRpcServiceAsync.saveData(CategoryDataUtil.toData(cate), new KSAsyncCallback<DataSaveResult>(){ |
483 | |
@Override |
484 | |
public void handleFailure(Throwable caught) { |
485 | 0 | GWT.log("updateLoCategory failed ", caught); |
486 | 0 | Window.alert("Update LoCategory failed "); |
487 | 0 | } |
488 | |
@Override |
489 | |
public void onSuccess(DataSaveResult result) { |
490 | 0 | if(result.getValidationResults()!=null && !result.getValidationResults().isEmpty()){ |
491 | 0 | Window.alert("Update LO Category failed: " + result.getValidationResults().get(0).getMessage()); |
492 | |
}else{ |
493 | 0 | KSNotifier.add(new KSNotification("Update LO Category Successful", false, 3000)); |
494 | 0 | categoryManagementTable.loadTable(new Callback<Boolean>(){ |
495 | |
|
496 | |
@Override |
497 | |
public void exec(Boolean result) { |
498 | 0 | if(result){ |
499 | 0 | filterCategoryByType(); |
500 | |
} |
501 | |
|
502 | 0 | } |
503 | |
}); |
504 | |
} |
505 | 0 | } |
506 | |
}); |
507 | |
|
508 | 0 | UpdateCategoryDialog.this.hide(); |
509 | |
} |
510 | 0 | } |
511 | |
|
512 | |
}); |
513 | |
|
514 | 0 | cancelButton.addClickHandler(new ClickHandler() { |
515 | |
|
516 | |
@Override |
517 | |
public void onClick(ClickEvent event) { |
518 | 0 | UpdateCategoryDialog.this.hide(); |
519 | 0 | } |
520 | |
|
521 | |
}); |
522 | 0 | super.setWidget(mainPanel); |
523 | 0 | } |
524 | |
|
525 | |
public void setCategoryType(List<LoCategoryTypeInfo> categoryTypeList) { |
526 | 0 | typeListBox.clear(); |
527 | 0 | SimpleListItems categoryTypes = new SimpleListItems(); |
528 | 0 | for (LoCategoryTypeInfo type : categoryTypeList) { |
529 | 0 | categoryTypes.addItem(type.getId(), type.getDesc()); |
530 | |
} |
531 | 0 | typeListBox.setListItems(categoryTypes); |
532 | 0 | } |
533 | |
|
534 | |
public void setCategory(LoCategoryInfo cate) { |
535 | 0 | categoryInfo = cate; |
536 | 0 | nameTextBox.setText(categoryInfo.getName()); |
537 | 0 | typeListBox.selectItem(categoryInfo.getType()); |
538 | 0 | } |
539 | |
|
540 | |
public LoCategoryInfo getCategory() { |
541 | 0 | categoryInfo.setName(nameTextBox.getText()); |
542 | |
|
543 | 0 | categoryInfo.setType(typeListBox.getSelectedItem()); |
544 | 0 | return categoryInfo; |
545 | |
} |
546 | |
} |
547 | |
|
548 | |
class CreateCategoryDialog extends KSLightBox { |
549 | 0 | KSButton okButton = new KSButton("Save"); |
550 | 0 | KSButton cancelButton = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED); |
551 | 0 | KSTextBox nameTextBox = new KSTextBox(); |
552 | 0 | KSDropDown typeListBox = new KSDropDown(); |
553 | |
|
554 | 0 | GroupFieldLayout layout = new GroupFieldLayout(); |
555 | 0 | FlowPanel mainPanel = new FlowPanel(); |
556 | |
|
557 | 0 | public CreateCategoryDialog() { |
558 | 0 | this.setSize(540, 200); |
559 | 0 | mainPanel.addStyleName("LOCategoryDialogSpacing"); |
560 | 0 | layout.setLayoutTitle(SectionTitle.generateH2Title("Create New Category")); |
561 | |
|
562 | 0 | FieldElement category = new FieldElement("Category", nameTextBox); |
563 | 0 | FieldElement type = new FieldElement("Type", typeListBox); |
564 | 0 | layout.addField(category); |
565 | 0 | layout.addField(type); |
566 | |
|
567 | |
|
568 | 0 | this.addButton(okButton); |
569 | 0 | this.addButton(cancelButton); |
570 | |
|
571 | 0 | mainPanel.add(layout); |
572 | 0 | super.setWidget(mainPanel); |
573 | 0 | okButton.addClickHandler(new ClickHandler() { |
574 | |
@Override |
575 | |
public void onClick(ClickEvent event) { |
576 | 0 | LoCategoryInfo cate = getCategory(); |
577 | 0 | boolean error = false; |
578 | 0 | layout.clearValidation(); |
579 | 0 | if(nameTextBox.getText().isEmpty()){ |
580 | 0 | layout.addValidationErrorMessage("Category", "Required"); |
581 | 0 | error = true; |
582 | |
} |
583 | 0 | if(typeListBox.getSelectedItem() == null || typeListBox.getSelectedItem().isEmpty()){ |
584 | 0 | layout.addValidationErrorMessage("Type", "Required"); |
585 | 0 | error = true; |
586 | |
} |
587 | |
|
588 | 0 | if(!error){ |
589 | 0 | loCatRpcServiceAsync.saveData(CategoryDataUtil.toData(cate), new KSAsyncCallback<DataSaveResult>(){ |
590 | |
@Override |
591 | |
public void handleFailure(Throwable caught) { |
592 | 0 | Window.alert("Create LO Category failed: " + caught.getMessage()); |
593 | 0 | } |
594 | |
@Override |
595 | |
public void onSuccess(DataSaveResult result) { |
596 | 0 | if(result.getValidationResults()!=null && !result.getValidationResults().isEmpty()){ |
597 | 0 | Window.alert("Create LO Category failed: " + result.getValidationResults().get(0).getMessage()); |
598 | |
}else{ |
599 | 0 | KSNotifier.add(new KSNotification("Create LO Category Successful", false, 3000)); |
600 | 0 | categoryManagementTable.loadTable(new Callback<Boolean>(){ |
601 | |
|
602 | |
@Override |
603 | |
public void exec(Boolean result) { |
604 | 0 | if(result){ |
605 | 0 | filterCategoryByType(); |
606 | |
} |
607 | |
|
608 | 0 | } |
609 | |
}); |
610 | |
} |
611 | 0 | } |
612 | |
}); |
613 | |
|
614 | 0 | CreateCategoryDialog.this.hide(); |
615 | |
} |
616 | 0 | } |
617 | |
}); |
618 | 0 | cancelButton.addClickHandler(new ClickHandler() { |
619 | |
|
620 | |
@Override |
621 | |
public void onClick(ClickEvent event) { |
622 | 0 | CreateCategoryDialog.this.hide(); |
623 | 0 | } |
624 | |
|
625 | |
}); |
626 | 0 | } |
627 | |
|
628 | |
public void setCategoryType(List<LoCategoryTypeInfo> categoryTypeList) { |
629 | 0 | typeListBox.clear(); |
630 | 0 | SimpleListItems categoryTypes = new SimpleListItems(); |
631 | 0 | for (LoCategoryTypeInfo type : categoryTypeList) { |
632 | 0 | categoryTypes.addItem(type.getId(), type.getDesc()); |
633 | |
} |
634 | 0 | typeListBox.setListItems(categoryTypes); |
635 | 0 | } |
636 | |
|
637 | |
public LoCategoryInfo getCategory() { |
638 | 0 | LoCategoryInfo info = new LoCategoryInfo(); |
639 | 0 | info.setName(nameTextBox.getText()); |
640 | 0 | info.setType(typeListBox.getSelectedItem()); |
641 | 0 | info.setState("active"); |
642 | 0 | info.setLoRepository("kuali.loRepository.key.singleUse"); |
643 | |
|
644 | 0 | return info; |
645 | |
} |
646 | |
} |
647 | |
|
648 | |
} |
649 | |
|
650 | |
|