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