001: /**********************************************************************************
002: *
003: * $Id: RemoveAssignmentBean.java 22020 2007-03-01 01:01:23Z louis@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
022:
023: import java.io.Serializable;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.service.gradebook.shared.StaleObjectModificationException;
028: import org.sakaiproject.tool.gradebook.Assignment;
029: import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
030:
031: /**
032: * Backing Bean for removing assignments from a gradebook.
033: *
034: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
035: */
036: public class RemoveAssignmentBean extends GradebookDependentBean
037: implements Serializable {
038: private static final Log logger = LogFactory
039: .getLog(RemoveAssignmentBean.class);
040:
041: // View maintenance fields - serializable.
042: private Long assignmentId;
043: private boolean removeConfirmed;
044: private Assignment assignment;
045:
046: protected void init() {
047: if (assignmentId != null) {
048: assignment = getGradebookManager().getAssignment(
049: assignmentId);
050: if (assignment == null) {
051: // The assignment might have been removed since this link was set up.
052: if (logger.isWarnEnabled())
053: logger.warn("No assignmentId=" + assignmentId
054: + " in gradebookUid " + getGradebookUid());
055:
056: // TODO Deliver an appropriate message.
057: }
058: }
059: }
060:
061: public String removeAssignment() {
062: if (removeConfirmed) {
063: try {
064: getGradebookManager().removeAssignment(assignmentId);
065: } catch (StaleObjectModificationException e) {
066: FacesUtil
067: .addErrorMessage(getLocalizedString("remove_assignment_locking_failure"));
068: return null;
069: }
070: String authzLevel = (getGradebookBean().getAuthzService()
071: .isUserAbleToGradeAll(getGradebookUid())) ? "instructor"
072: : "TA";
073: getGradebookBean().getEventTrackingService().postEvent(
074: "gradebook.deleteItem",
075: "/gradebook/" + getGradebookId() + "/"
076: + assignment.getName() + "/" + authzLevel);
077: FacesUtil.addRedirectSafeMessage(getLocalizedString(
078: "remove_assignment_success",
079: new String[] { assignment.getName() }));
080: return "overview";
081: } else {
082: FacesUtil
083: .addErrorMessage(getLocalizedString("remove_assignment_confirmation_required"));
084: return null;
085: }
086: }
087:
088: public String cancel() {
089: // Go back to the Assignment Details page for this assignment.
090: AssignmentDetailsBean assignmentDetailsBean = (AssignmentDetailsBean) FacesUtil
091: .resolveVariable("assignmentDetailsBean");
092: assignmentDetailsBean.setAssignmentId(assignmentId);
093: return "assignmentDetails";
094: }
095:
096: public Assignment getAssignment() {
097: return assignment;
098: }
099:
100: public void setAssignment(Assignment assignment) {
101: this .assignment = assignment;
102: }
103:
104: /**
105: * @return Returns the assignmentId.
106: */
107: public Long getAssignmentId() {
108: return assignmentId;
109: }
110:
111: /**
112: * @param assignmentId The assignmentId to set.
113: */
114: public void setAssignmentId(Long assignmentId) {
115: this .assignmentId = assignmentId;
116: }
117:
118: /**
119: * @return Returns the removeConfirmed.
120: */
121: public boolean isRemoveConfirmed() {
122: return removeConfirmed;
123: }
124:
125: /**
126: * @param removeConfirmed The removeConfirmed to set.
127: */
128: public void setRemoveConfirmed(boolean removeConfirmed) {
129: this.removeConfirmed = removeConfirmed;
130: }
131: }
|