Refactored the checkbox and added tests when cleaning and/or filtering.
This commit is contained in:
parent
f0f71ccd47
commit
b1a5c7902b
src/main/java/se/su/dsv/scipro/supervisor/panels
@ -46,7 +46,6 @@
|
||||
<div class="span-12">
|
||||
<label>Include inactive keywords:</label><br />
|
||||
<input type="checkbox" wicket:id="includeDeleted" />
|
||||
<span wicket:id="deletedLabel">[label]</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -64,16 +64,8 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
|
||||
private Label deletedLabel = new Label("deletedLabel", Boolean.FALSE.toString()) {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public SupervisorUnmatchedThesisPanel(String id, final Component feedBackPanel) {
|
||||
super(id);
|
||||
deletedLabel.setOutputMarkupId(true);
|
||||
ProjectIdeaDataProvider allProvider = new ProjectIdeaDataProvider();
|
||||
Params params = setUpParams(allProvider);
|
||||
Label totalProjectIdeas = new Label("totalProjectIdeas", Integer.toString(allProvider.size()));
|
||||
@ -154,7 +146,6 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
Keyword kw = keywordList.get(0);
|
||||
item.replace(new Label("supervisorUnit", new Model<String>(kw.getKeyword())));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,14 +194,9 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
|
||||
public AutoCompleteObjectField<Keyword, Long> createKeywordAC(final String wicketId, final KeywordTypeDao.TYPE keyWordType,
|
||||
final List<Keyword> keywords, final Component feedBackPanel,
|
||||
final WebMarkupContainer keyWordsContainer) {
|
||||
final WebMarkupContainer keyWordsContainer, final AjaxCheckBox includeDeletedChbx) {
|
||||
return new AutoCompleteObjectField<Keyword, Long>(wicketId, Keyword.class) {
|
||||
private static final long serialVersionUID = 7734889540424308421L;
|
||||
boolean includeDeleted = false;
|
||||
|
||||
public void setIncludeDeleted(boolean includeDeleted) {
|
||||
this.includeDeleted = includeDeleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyword loadObject(Long keywordId) {
|
||||
@ -241,11 +227,7 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
|
||||
@Override
|
||||
public Iterator<Keyword> getChoices(String input) {
|
||||
if(deletedLabel.getDefaultModelObject().equals(Boolean.TRUE.toString())) {
|
||||
includeDeleted = true;
|
||||
} else if(deletedLabel.getDefaultModelObject().equals(Boolean.FALSE.toString())) {
|
||||
includeDeleted = false;
|
||||
}
|
||||
boolean includeDeleted = includeDeletedChbx.getModelObject() != null ? includeDeletedChbx.getModelObject() : false;
|
||||
final KeywordType kwtype = keywordTypeDao.findByType(keyWordType);
|
||||
return keywordDao.getAutoCompleteCapableSupervisors(kwtype, input, includeDeleted).iterator();
|
||||
}
|
||||
@ -329,10 +311,18 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
keywordListView.setOutputMarkupId(true);
|
||||
keyWordsContainer.add(keywordListView);
|
||||
add(keyWordsContainer);
|
||||
|
||||
final AutoCompleteObjectField<Keyword, Long> regKeyWordAc = createKeywordAC("regKeyWordAC", KeywordTypeDao.TYPE.REGULAR, keywords, feedBackPanel, keyWordsContainer);
|
||||
final AutoCompleteObjectField<Keyword, Long> unitKeyWordAc = createKeywordAC("unitKeyWordAC", KeywordTypeDao.TYPE.UNIT, keywords, feedBackPanel, keyWordsContainer);
|
||||
final AutoCompleteObjectField<Keyword, Long> areaKeyWordAc = createKeywordAC("areaKeyWordAC", KeywordTypeDao.TYPE.RESEARCH_AREA, keywords, feedBackPanel, keyWordsContainer);
|
||||
|
||||
final AjaxCheckBox includeDeletedChbx = new AjaxCheckBox("includeDeleted", new Model<Boolean>()) {
|
||||
private static final long serialVersionUID = -1810576794268334574L;
|
||||
@Override
|
||||
protected void onUpdate(AjaxRequestTarget target) {
|
||||
target.addComponent(this);
|
||||
}
|
||||
};
|
||||
includeDeletedChbx.setOutputMarkupId(true);
|
||||
final AutoCompleteObjectField<Keyword, Long> regKeyWordAc = createKeywordAC("regKeyWordAC", KeywordTypeDao.TYPE.REGULAR, keywords, feedBackPanel, keyWordsContainer, includeDeletedChbx);
|
||||
final AutoCompleteObjectField<Keyword, Long> unitKeyWordAc = createKeywordAC("unitKeyWordAC", KeywordTypeDao.TYPE.UNIT, keywords, feedBackPanel, keyWordsContainer, includeDeletedChbx);
|
||||
final AutoCompleteObjectField<Keyword, Long> areaKeyWordAc = createKeywordAC("areaKeyWordAC", KeywordTypeDao.TYPE.RESEARCH_AREA, keywords, feedBackPanel, keyWordsContainer, includeDeletedChbx);
|
||||
regKeyWordAc.setOutputMarkupId(true);
|
||||
unitKeyWordAc.setOutputMarkupId(true);
|
||||
areaKeyWordAc.setOutputMarkupId(true);
|
||||
@ -350,19 +340,7 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
final FilterFormProjectClassPanel projectClassPanel = new FilterFormProjectClassPanel("projectClassPanel", new ArrayList<ProjectClass>());
|
||||
projectClassPanel.setOutputMarkupId(true);
|
||||
add(projectClassPanel);
|
||||
final AjaxCheckBox includeDeletedChbx = new AjaxCheckBox("includeDeleted", new Model<Boolean>()) {
|
||||
@Override
|
||||
protected void onUpdate(AjaxRequestTarget target) {
|
||||
if (getModelObject()) {
|
||||
deletedLabel.setDefaultModel(new Model(Boolean.TRUE.toString()));
|
||||
} else {
|
||||
deletedLabel.setDefaultModel(new Model(Boolean.FALSE.toString()));
|
||||
}
|
||||
target.addComponent(deletedLabel);
|
||||
}
|
||||
};
|
||||
add(includeDeletedChbx);
|
||||
add(deletedLabel);
|
||||
|
||||
|
||||
AjaxButton filterButton = new AjaxButton("filterButton", new Model<String>("Filter")) {
|
||||
@ -370,15 +348,22 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
params.setTitleContains(titleField.getModelObject());
|
||||
params.setTitleContains(titleField.getModelObject() != null ? titleField.getModelObject() : "");
|
||||
List<ProjectClass> pclasses = projectClassPanel.getSelectedprojectClasses();
|
||||
if (!pclasses.isEmpty()) {
|
||||
params.setProjectClasses(pclasses);
|
||||
} else if(params.getProjectClasses() == null || params.getProjectClasses().size() == 0) {
|
||||
addProjectClasses(params);
|
||||
}
|
||||
|
||||
if(!keywords.isEmpty()) {
|
||||
params.setKeywords(keywords); // there should always be a project class, we may otherwise get an NPE when we clear() in clearSearchTermsButton#onSubmit
|
||||
for(Keyword keyword : keywords) {
|
||||
if(keyword.isDeleted()) {
|
||||
params.setIncludeDeleted(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
params.setSubmittedAfter(dateFrom.getModelObject());
|
||||
params.setSubmittedBefore(dateTo.getModelObject());
|
||||
@ -394,9 +379,14 @@ public class SupervisorUnmatchedThesisPanel extends Panel {
|
||||
private static final long serialVersionUID = 443680343329839590L;
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
((ListView) keyWordsContainer.get("keywordList")).getModelObject().clear();
|
||||
List<Keyword> keywordList = ((ListView) keyWordsContainer.get("keywordList")).getModelObject();
|
||||
if(keywordList != null && !keywordList.isEmpty()) {
|
||||
keywordList.clear();
|
||||
}
|
||||
titleField.setModelObject(null);
|
||||
projectClassPanel.getSelectedprojectClasses().clear();
|
||||
includeDeletedChbx.setDefaultModelObject(false);
|
||||
target.addComponent(includeDeletedChbx);
|
||||
target.addComponent(feedBackPanel);
|
||||
target.addComponent(keyWordsContainer);
|
||||
target.addComponent(titleField);
|
||||
|
Loading…
x
Reference in New Issue
Block a user