fixed some saves, removed an old panel
This commit is contained in:
parent
e2063cf24f
commit
50ab4aadc3
src/main/java/se/su/dsv/scipro
admin/pages
checklists/panels
@ -3,8 +3,6 @@ package se.su.dsv.scipro.admin.pages;
|
||||
import org.apache.wicket.PageParameters;
|
||||
|
||||
import se.su.dsv.scipro.admin.panels.AdminListCheckListTemplatePanel;
|
||||
import se.su.dsv.scipro.checklists.panels.CreateChecklistTemplatePanel;
|
||||
import se.su.dsv.scipro.checklists.panels.FunctionalListCheckListTemplatePanel;
|
||||
import se.su.dsv.scipro.data.enums.CheckListRole;
|
||||
import se.su.dsv.scipro.security.auth.Authorization;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
@ -1,57 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<wicket:panel>
|
||||
|
||||
<div class="span-10 last">
|
||||
<form wicket:id="form">
|
||||
<div wicket:id="feedbackPanel"></div>
|
||||
<div>
|
||||
<div>Template name</div>
|
||||
<input wicket:id="templateName" type="text" />
|
||||
</div>
|
||||
<p></p>
|
||||
<div wicket:id="categoryPanel"></div>
|
||||
<p></p>
|
||||
<div>Question</div>
|
||||
<div>
|
||||
<form wicket:id="addQuestionForm">
|
||||
<div>
|
||||
<input wicket:id="question" type="text" />
|
||||
</div>
|
||||
<input wicket:id="addQuestionButton" type="submit" />
|
||||
<p></p>
|
||||
<div wicket:id="container">
|
||||
<table class="rounded-corner">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="rounded-left-top rounded-left-right">Questions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="1" class="rounded-foot"> </td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<tr wicket:id="questions">
|
||||
<td wicket:id="questionLabel"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<p></p>
|
||||
<input wicket:id="save" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
@ -1,159 +0,0 @@
|
||||
package se.su.dsv.scipro.checklists.panels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.RequiredTextField;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.admin.pages.AdminCheckListPage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListTemplateDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckListTemplate;
|
||||
import se.su.dsv.scipro.data.dataobjects.ChecklistCategory;
|
||||
|
||||
|
||||
/**
|
||||
* @author fnorbe@dsv.su.se
|
||||
*/
|
||||
|
||||
public class CreateChecklistTemplatePanel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = 8862892008428526067L;
|
||||
|
||||
@SpringBean
|
||||
private CheckListTemplateDao checkListTemplateDao;
|
||||
|
||||
private String question = "";
|
||||
private String title = "";
|
||||
|
||||
private CheckListTemplate checkListTemplate = new CheckListTemplate();
|
||||
|
||||
|
||||
public CreateChecklistTemplatePanel(String id) {
|
||||
super(id);
|
||||
|
||||
question = "";
|
||||
title = "";
|
||||
|
||||
final FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackPanel");
|
||||
feedbackPanel.setOutputMarkupId(true);
|
||||
|
||||
final ChecklistCategoryPanel categoryPanel = new ChecklistCategoryPanel("categoryPanel", new ArrayList<ChecklistCategory>());
|
||||
|
||||
Form<CheckListTemplate> form = new Form<CheckListTemplate>("form");
|
||||
final Form<CheckListTemplate> addQuestionForm = new Form<CheckListTemplate>("addQuestionForm");
|
||||
final TextField<String> titleField = new RequiredTextField<String>("templateName",
|
||||
new PropertyModel<String>(this, "title"));
|
||||
titleField.setOutputMarkupId(true);
|
||||
final TextField<String> questionField = new TextField<String>("question",
|
||||
new PropertyModel<String>(this, "question"));
|
||||
questionField.setOutputMarkupId(true);
|
||||
questionField.setRequired(false);
|
||||
|
||||
final IModel<List<String>> questionModel = new LoadableDetachableModel<List<String>>(){
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected List<String> load() {
|
||||
return checkListTemplate.getQuestions();
|
||||
}
|
||||
};
|
||||
|
||||
final WebMarkupContainer container = new WebMarkupContainer("container");
|
||||
container.setOutputMarkupId(true);
|
||||
ListView<String> listView = new ListView<String>("questions", questionModel) {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void populateItem(ListItem<String> item) {
|
||||
Label question = new Label("questionLabel", item.getModel().getObject());
|
||||
item.add(question);
|
||||
}
|
||||
};
|
||||
|
||||
container.add(listView);
|
||||
|
||||
AjaxButton save = new AjaxButton("save", new Model<String>("Save template")) {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
|
||||
if(checkListTemplate.getQuestions() == null){
|
||||
|
||||
}else{
|
||||
|
||||
checkListTemplate.setCreator(SciProSession.get().getUser());
|
||||
checkListTemplate.setName(title);
|
||||
checkListTemplate.setCategories(categoryPanel.getSelectedCategories());
|
||||
checkListTemplate = checkListTemplateDao.save(checkListTemplate);
|
||||
checkListTemplate = new CheckListTemplate();
|
||||
title ="";
|
||||
question="";
|
||||
target.addComponent(container);
|
||||
target.addComponent(titleField);
|
||||
setResponsePage(new AdminCheckListPage(new PageParameters()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onError (final AjaxRequestTarget target, final Form<?> form) {
|
||||
target.addComponent(feedbackPanel);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
AjaxButton addQuestionButton = new AjaxButton("addQuestionButton", new Model<String>("Add question")) { static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
|
||||
try{
|
||||
checkListTemplate.addQuestion(new String(question));
|
||||
questionModel.detach();
|
||||
question = "";
|
||||
target.addComponent(questionField);
|
||||
target.addComponent(container);
|
||||
}catch(NullPointerException npe){
|
||||
feedbackPanel.error("Question cant be empty");
|
||||
target.addComponent(feedbackPanel);
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addQuestionForm.add(questionField);
|
||||
addQuestionForm.add(container);
|
||||
addQuestionForm.add(addQuestionButton);
|
||||
form.add(feedbackPanel);
|
||||
form.add(titleField);
|
||||
form.add(categoryPanel);
|
||||
form.add(addQuestionForm);
|
||||
form.add(save);
|
||||
|
||||
add(form);
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user