Lägga till länkar och editera dom
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@283 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
16e1d3cf08
commit
5dd878f6f9
src/main/java/se/su/dsv/scipro/knol/resource/page
@ -0,0 +1,54 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.knol.resource.page;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.Tag;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class ResourceModel implements IClusterable {
|
||||
|
||||
private String info;
|
||||
private String link;
|
||||
private String linkName;
|
||||
private String infoEdit;
|
||||
private String linkEdit;
|
||||
private String linkNameEdit;
|
||||
private Collection<Tag> selectedTagList;
|
||||
private Collection<Tag> selectedTagListEdit;
|
||||
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
public String getLinkName() {
|
||||
return linkName;
|
||||
}
|
||||
public String getInfoEdit() {
|
||||
return infoEdit;
|
||||
}
|
||||
public String getLinkEdit() {
|
||||
return linkEdit;
|
||||
}
|
||||
public String getLinkNameEdit() {
|
||||
return linkNameEdit;
|
||||
}
|
||||
public Collection<Tag> getSelectedTagList() {
|
||||
return selectedTagList;
|
||||
}
|
||||
public Collection<Tag> getSelectedTagListEdit() {
|
||||
return selectedTagListEdit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
|
||||
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>
|
||||
<h4>Resource link</h4>
|
||||
<form wicket:id="resourceForm">
|
||||
Link Address:
|
||||
<input type="text" wicket:id="link"/>
|
||||
<div/>
|
||||
Link Name:
|
||||
<input type="text" wicket:id="linkName"/>
|
||||
<div/>
|
||||
Info:
|
||||
<br />
|
||||
<textarea wicket:id="info" ></textarea>
|
||||
<div/>
|
||||
<select wicket:id="selectedTagList"></select>
|
||||
<div/>
|
||||
<input type="submit" wicket:id="submitButton" />
|
||||
<div wicket:id="editContainer">
|
||||
|
||||
|
||||
<div wicket:id = linkAddressLabel/>
|
||||
<input type="text" wicket:id="linkEdit"/>
|
||||
<div/>
|
||||
<div wicket:id = linkNameLabel/>
|
||||
<input type="text" wicket:id="linkNameEdit"/>
|
||||
<div/>
|
||||
<div wicket:id = infoLabel/>
|
||||
<textarea wicket:id="infoEdit" ></textarea>
|
||||
<div/>
|
||||
<select wicket:id="selectedTagListEdit"></select>
|
||||
<div/>
|
||||
<input type="submit" wicket:id="submitButtonEdit" />
|
||||
</div>
|
||||
</form>
|
||||
<div wicket:id="listContainer">
|
||||
<table wicket:id = "link-item">
|
||||
<tr>
|
||||
<hr/>
|
||||
</tr>
|
||||
<tr><strong>Resource</strong></tr>
|
||||
<tr >
|
||||
<td wicket:id="date"></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td wicket:id="user"></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td><a href="#" target="_new" wicket:id="link">this body will be replaced</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td wicket:id="info"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td wicket:id="tag"></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td><a href="#" wicket:id="editLink">Edit</a></td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td><a href="#" wicket:id="deleteLink">Delete</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,325 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.knol.resource.page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
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.ChoiceRenderer;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.ListMultipleChoice;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.link.ExternalLink;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.util.ListModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
|
||||
import se.su.dsv.scipro.basepages.PublicPage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.LinkDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RatingDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ResourceDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.TagDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Link;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.Tag;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class ResourcePage extends PublicPage {
|
||||
|
||||
@SpringBean
|
||||
private ResourceDao resourceDao;
|
||||
|
||||
@SpringBean
|
||||
private RatingDao ratingDao;
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
private LinkDao linkDao;
|
||||
|
||||
@SpringBean
|
||||
private TagDao tagDao;
|
||||
|
||||
private WebMarkupContainer listContainer;
|
||||
|
||||
private ListView<Link> linkListView;
|
||||
|
||||
private Collection<Tag> selectedTagList = new ArrayList<Tag>();
|
||||
private Collection<Tag> selectedTagListEdit = new ArrayList<Tag>();
|
||||
|
||||
private User user;
|
||||
|
||||
private boolean edit;
|
||||
private WebMarkupContainer editContainer;
|
||||
|
||||
private TextArea<String> info;
|
||||
private TextField<String> linkAddress, linkName;
|
||||
private ListMultipleChoice<Tag> userMultipleChoiceListEdit;
|
||||
|
||||
private Link editLink;
|
||||
|
||||
public ResourcePage(PageParameters pp) {
|
||||
super(pp);
|
||||
Link link = linkDao.load(2L);
|
||||
user = userDao.load(1L);
|
||||
|
||||
loadListView();
|
||||
listContainer = new WebMarkupContainer("listContainer");
|
||||
listContainer.add(linkListView);
|
||||
listContainer.setOutputMarkupId(true);
|
||||
add(listContainer);
|
||||
add(new ResourceForm("resourceForm"));
|
||||
|
||||
}
|
||||
|
||||
public class ResourceForm extends Form<ResourceModel> {
|
||||
public ResourceForm(String name) {
|
||||
super(name, new CompoundPropertyModel<ResourceModel>(
|
||||
new ResourceModel()));
|
||||
|
||||
add(new TextArea<String>("info"));
|
||||
add(new TextField<String>("link"));
|
||||
add(new TextField<String>("linkName"));
|
||||
|
||||
final ListMultipleChoice<Tag> userMultipleChoiceList = new ListMultipleChoice<Tag>(
|
||||
"selectedTagList", new ListModel<Tag>(
|
||||
tagDao.findAll()), new ChoiceRenderer<Tag>(
|
||||
"tag")) {
|
||||
private static final long serialVersionUID = -7117603450416845711L;
|
||||
|
||||
@Override
|
||||
protected CharSequence getDefaultChoice(Object selected) {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
OnChangeAjaxBehavior userSelectBehaviour = new OnChangeAjaxBehavior() {
|
||||
|
||||
private static final long serialVersionUID = 3412906970812300312L;
|
||||
|
||||
@Override
|
||||
protected void onUpdate(AjaxRequestTarget target) {
|
||||
selectedTagList = userMultipleChoiceList.getModelObject();
|
||||
}
|
||||
};
|
||||
userMultipleChoiceList.add(userSelectBehaviour);
|
||||
|
||||
userMultipleChoiceList.setOutputMarkupId(true);
|
||||
add(userMultipleChoiceList);
|
||||
add(new AjaxButton("submitButton", new Model<String>("Add link")) {
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
ResourceModel resourceModel = ((ResourceModel) form
|
||||
.getModelObject());
|
||||
Link link = new Link();
|
||||
link.setInfo(resourceModel.getInfo());
|
||||
link.setLink(resourceModel.getLink());
|
||||
link.setUser(user);
|
||||
link.setTagList(new ArrayList<Tag>(selectedTagList));
|
||||
if (resourceModel.getLinkName() != null) {
|
||||
link.setLinkName(resourceModel.getLinkName());
|
||||
}
|
||||
linkDao.save(link);
|
||||
loadListView();
|
||||
listContainer.removeAll();
|
||||
listContainer.add(linkListView);
|
||||
target.addComponent(listContainer);
|
||||
}
|
||||
});
|
||||
|
||||
editContainer = new WebMarkupContainer("editContainer");
|
||||
editContainer.setOutputMarkupId(true);
|
||||
|
||||
editContainer.add(new Label("linkAddressLabel", "Link Address:") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
editContainer.add(new Label("linkNameLabel", "Link Name:") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
editContainer.add(new Label("infoLabel", "Info:") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
|
||||
editContainer.add(info = new TextArea<String>("infoEdit") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
editContainer.add(linkAddress = new TextField<String>("linkEdit") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
editContainer.add(linkName = new TextField<String>("linkNameEdit") {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
userMultipleChoiceListEdit = new ListMultipleChoice<Tag>(
|
||||
"selectedTagListEdit", new ListModel<Tag>(
|
||||
tagDao.findAll()), new ChoiceRenderer<Tag>(
|
||||
"tag")) {
|
||||
private static final long serialVersionUID = -7117603450416845711L;
|
||||
|
||||
@Override
|
||||
protected CharSequence getDefaultChoice(Object selected) {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
};
|
||||
|
||||
OnChangeAjaxBehavior userSelectBehaviourEdit = new OnChangeAjaxBehavior() {
|
||||
|
||||
private static final long serialVersionUID = 3412906970812300312L;
|
||||
|
||||
@Override
|
||||
protected void onUpdate(AjaxRequestTarget target) {
|
||||
selectedTagListEdit = userMultipleChoiceListEdit.getModelObject();
|
||||
}
|
||||
};
|
||||
userMultipleChoiceListEdit.add(userSelectBehaviourEdit);
|
||||
editContainer.add(userMultipleChoiceListEdit);
|
||||
editContainer.add(new AjaxButton("submitButtonEdit",
|
||||
new Model<String>("Edit link")) {
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
ResourceModel resourceModel = ((ResourceModel) form
|
||||
.getModelObject());
|
||||
editLink.setInfo(resourceModel.getInfoEdit());
|
||||
editLink.setLink(resourceModel.getLinkEdit());
|
||||
editLink.setUser(user);
|
||||
editLink.setTagList(new ArrayList<Tag>(selectedTagListEdit));
|
||||
if (resourceModel.getLinkNameEdit() != null) {
|
||||
editLink.setLinkName(resourceModel.getLinkNameEdit());
|
||||
}
|
||||
linkDao.save(editLink);
|
||||
loadListView();
|
||||
listContainer.removeAll();
|
||||
listContainer.add(linkListView);
|
||||
edit = false;
|
||||
target.addComponent(listContainer);
|
||||
target.addComponent(editContainer);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return edit;
|
||||
}
|
||||
});
|
||||
|
||||
add(editContainer);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void loadListView() {
|
||||
linkListView = new ListView<Link>("link-item", linkDao.findAll()) {
|
||||
|
||||
@Override
|
||||
protected void populateItem(final ListItem<Link> item) {
|
||||
final Link link = item.getModelObject();
|
||||
item.add(new Label("date", link.getDateCreated().toString()));
|
||||
item.add(new Label("user", link.getUser().getFirstName() + " "
|
||||
+ link.getUser().getLastName()));
|
||||
if (link.getLinkName() == null) {
|
||||
item.add(new ExternalLink("link", link.getLink(), link
|
||||
.getLink()));
|
||||
} else {
|
||||
item.add(new ExternalLink("link", link.getLink(), link
|
||||
.getLinkName()));
|
||||
}
|
||||
item.add(new Label("info", link.getInfo()));
|
||||
String tags = "";
|
||||
|
||||
int count = 0;
|
||||
for (Tag tag : link.getTagList()) {
|
||||
if (count == 0) {
|
||||
tags = tag.getTag();
|
||||
count++;
|
||||
} else {
|
||||
tags += ", " + tag.getTag();
|
||||
}
|
||||
}
|
||||
|
||||
item.add(new Label("tag", tags));
|
||||
|
||||
item.add(new AjaxLink<Recipient>("deleteLink") {
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
Link link2 = linkDao.reLoad(link);
|
||||
if (link2.equals(editLink)) {
|
||||
edit = false;
|
||||
target.addComponent(editContainer);
|
||||
}
|
||||
linkDao.delete(link2);
|
||||
loadListView();
|
||||
listContainer.removeAll();
|
||||
listContainer.add(linkListView);
|
||||
target.addComponent(listContainer);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
item.add(new AjaxLink<Recipient>("editLink") {
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
edit = true;
|
||||
editLink = linkDao.reLoad(link);
|
||||
linkAddress.setModelObject(editLink.getLink());
|
||||
linkName.setModelObject(editLink.getLinkName());
|
||||
info.setModelObject(editLink.getInfo());
|
||||
userMultipleChoiceListEdit.setModelObject(editLink.getTagList());
|
||||
target.addComponent(editContainer);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user