VotingDetailsView.java 1.88 KB
package fi.codecrew.moya.web.cdiview.voting;

import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.model.Compo;
import fi.codecrew.moya.web.cdiview.GenericCDIView;

@Named
@ConversationScoped
public class VotingDetailsView extends GenericCDIView {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8373473936336396427L;

	@EJB
	private transient VotingBeanLocal votingBean;

	private Integer compoId;
	private String compoName;

	private Compo compo;

	private transient ListDataModel<EntryWrapper> entries;

	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(VotingDetailsView.class);

	public Integer getCompoId() {
		return compoId;
	}

	public String saveSort()
	{
		for (EntryWrapper e : entries)
		{
			setCompo(votingBean.saveSort(e.getEntry()).getCompo());
		}
		entries = EntryWrapper.init(getCompo().getCompoEntries(), votingBean, true);

		return null;
	}

	public void setCompoId(Integer compoId) {
		this.compoId = compoId;
	}

	public ListDataModel<EntryWrapper> getEntries() {
		return entries;
	}

	public void initView() {
		if (super.requirePermissions(CompoPermission.MANAGE))
		{
			setCompo(votingBean.getCompoById(compoId));
			entries = EntryWrapper.init(getCompo().getCompoEntries(), votingBean, true);
			super.beginConversation();
		}
	}

	public String getCompoName() {
		return compoName;
	}

	public void setCompoName(String compoName) {
		this.compoName = compoName;
	}

	public Compo getCompo() {
		return compo;
	}

	public void setCompo(Compo compo) {
		this.compo = compo;
	}

}