001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006,2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.poll.tool.producers;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import uk.org.ponder.messageutil.MessageLocator;
026: import uk.org.ponder.rsf.components.UIContainer;
027: import uk.org.ponder.rsf.components.UIELBinding;
028: import uk.org.ponder.rsf.components.UIOutput;
029: import uk.org.ponder.rsf.components.UIInternalLink;
030: import uk.org.ponder.rsf.components.UIForm;
031: import uk.org.ponder.rsf.components.UICommand;
032:
033: import uk.org.ponder.rsf.view.ComponentChecker;
034: import uk.org.ponder.rsf.view.ViewComponentProducer;
035: import uk.org.ponder.rsf.viewstate.ViewParameters;
036:
037: import org.sakaiproject.poll.logic.PollListManager;
038: import org.sakaiproject.poll.model.VoteCollection;
039: import org.sakaiproject.poll.model.Poll;
040: import org.sakaiproject.poll.model.Option;
041: import org.sakaiproject.poll.tool.params.VoteBean;
042:
043: import uk.org.ponder.rsf.flow.jsfnav.NavigationCase;
044: import uk.org.ponder.rsf.flow.jsfnav.NavigationCaseReporter;
045: import uk.org.ponder.rsf.viewstate.ViewParamsReporter;
046: import uk.org.ponder.rsf.viewstate.SimpleViewParameters;
047: import uk.org.ponder.rsf.viewstate.EntityCentredViewParameters;
048: import uk.org.ponder.localeutil.LocaleGetter;
049: import uk.org.ponder.rsf.components.UIInput;
050: import uk.org.ponder.beanutil.entity.EntityID;
051:
052: import java.util.List;
053: import java.util.ArrayList;
054:
055: public class PollOptionDeleteProducer implements ViewComponentProducer,
056: NavigationCaseReporter, ViewParamsReporter {
057: //,
058: public static final String VIEW_ID = "pollOptionDelete";
059: private static Log m_log = LogFactory
060: .getLog(PollOptionDeleteProducer.class);
061: private VoteBean voteBean;
062:
063: private MessageLocator messageLocator;
064: private LocaleGetter localegetter;
065:
066: public String getViewID() {
067:
068: return VIEW_ID;
069: }
070:
071: public void setVoteBean(VoteBean vb) {
072: this .voteBean = vb;
073: }
074:
075: public void setMessageLocator(MessageLocator messageLocator) {
076:
077: this .messageLocator = messageLocator;
078: }
079:
080: public void setLocaleGetter(LocaleGetter localegetter) {
081: this .localegetter = localegetter;
082: }
083:
084: private PollListManager pollListManager;
085:
086: public void setPollListManager(PollListManager p) {
087: this .pollListManager = p;
088: }
089:
090: public void fillComponents(UIContainer tofill,
091: ViewParameters viewparams, ComponentChecker arg2) {
092: m_log.info("rendering view");
093: Poll poll = null;
094: Option option = null;
095: UIOutput.make(tofill, "confirm_delete", messageLocator
096: .getMessage("delete_confirm"));
097: UIOutput.make(tofill, "error", messageLocator
098: .getMessage("delete_option_message"));
099: EntityCentredViewParameters ecvp = (EntityCentredViewParameters) viewparams;
100: if (poll == null || ecvp != null) {
101: //check the ecvp
102:
103: String strId = ecvp.getELPath().substring(
104: ecvp.getELPath().indexOf(".") + 1);
105: String type = strId.substring(0, strId.indexOf('_'));
106: String id = strId.substring(strId.indexOf('_') + 1);
107: m_log.debug("got id of " + strId);
108: if (type.equals("Poll")) {
109: poll = pollListManager.getPollById(new Long(id));
110: } else {
111: option = pollListManager.getOptionById(new Long(id));
112: poll = pollListManager.getPollById(option.getPollId());
113: }
114: }
115: UIOutput.make(tofill, "poll_text", option.getOptionText());
116: UIForm form = UIForm.make(tofill, "opt-form");
117: UIInput.make(form, "opt-text", "#{option.optionText}", option
118: .getOptionText());
119:
120: form.parameters.add(new UIELBinding("#{option.id}", option
121: .getId()));
122: form.parameters.add(new UIELBinding("#{option.pollId}", poll
123: .getPollId()));
124:
125: UICommand saveAdd = UICommand.make(form, "submit-option-add",
126: messageLocator.getMessage("delete_option_confirm"),
127: "#{pollToolBean.proccessActionDeleteOption}");
128: saveAdd.parameters.add(new UIELBinding("#{option.status}",
129: "delete"));
130:
131: UICommand cancel = UICommand.make(form, "cancel",
132: messageLocator.getMessage("new_poll_cancel"),
133: "#{pollToolBean.cancel}");
134: cancel.parameters.add(new UIELBinding("#{option.status}",
135: "cancel"));
136:
137: }
138:
139: public List reportNavigationCases() {
140: List togo = new ArrayList();
141: togo.add(new NavigationCase(null, new SimpleViewParameters(
142: this .VIEW_ID)));
143: togo.add(new NavigationCase("success",
144: new EntityCentredViewParameters(
145: AddPollProducer.VIEW_ID, new EntityID("Poll",
146: "0"))));
147: togo.add(new NavigationCase("cancel",
148: new EntityCentredViewParameters(
149: AddPollProducer.VIEW_ID, new EntityID("Poll",
150: "0"))));
151: return togo;
152: }
153:
154: public ViewParameters getViewParameters() {
155: return new EntityCentredViewParameters(VIEW_ID, new EntityID(
156: "Option", null));
157:
158: }
159:
160: }
|