Skip to content

Commit

Permalink
SAM-2420 Samigo returns to the Question pool list page after performi…
Browse files Browse the repository at this point in the history
…ng any action (copy, add, move...) instead of returning to the previous page

git-svn-id: https://source.sakaiproject.org/svn/sam/trunk@315861 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
juanjmerono committed Dec 3, 2014
1 parent b667a6c commit 1beb34c
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class QuestionPoolBean implements Serializable

/** Use serialVersionUID for interoperability. */
private final static long serialVersionUID = 418920360211039758L;
public final static String ORIGIN_TOP = "poolList";

private String name;
private Collection pools;
Expand Down Expand Up @@ -168,6 +169,7 @@ public class QuestionPoolBean implements Serializable
private String addOrEdit;
private String outcome;
private String outcomeEdit;
private long outcomePool;
private String unsharePoolSource;
private String deletePoolSource; // either from poolList.jsp , or from editPool.jsp
private String addPoolSource; // either from poolList.jsp , or from editPool.jsp
Expand Down Expand Up @@ -1083,6 +1085,20 @@ public void setOutcomeEdit(String param)
this.outcomeEdit= param;
}

public long getOutcomePool()
{
return outcomePool;
}

/**
* set the outcome for doit()
* @param param
*/
public void setOutcomePool(long param)
{
this.outcomePool= param;
}

public String getDeletePoolSource()
{
return deletePoolSource;
Expand Down Expand Up @@ -1200,24 +1216,28 @@ public void resetFields()
// Item level actions
public String startCopyQuestion()
{
setOutComeParams();
this.sourcePart = null;
getCheckedQuestion();
return "copyPool";
}

public String startMoveQuestion()
{
setOutComeParams();
getCheckedQuestion();
return "movePool";
}

public String startCopyQuestions() {
setOutComeParams("editPool");
this.sourcePart = null;
getCheckedQuestions();
return "copyPool";
}

public String startMoveQuestions() {
setOutComeParams("editPool");
getCheckedQuestions();
return "movePool";
}
Expand All @@ -1227,6 +1247,7 @@ public String moveQuestion() {
String destId = "";
sourceId = this.getCurrentPool().getId().toString();
ArrayList sourceItemIds = this.getCurrentItemIds();
String originId = Long.toString(ORIGIN_TOP.equals(getOutcome())?0:getOutcomePool());

destId = ContextUtil.lookupParam("movePool:selectedRadioBtn");

Expand Down Expand Up @@ -1257,10 +1278,9 @@ public String moveQuestion() {
EventTrackingService.post(EventTrackingService.newEvent("sam.questionpool.questionmoved", "/sam/" +AgentFacade.getCurrentSiteId() + "/sourceId=" + sourceId + " destId=" + destId, true));


buildTree();
setQpDataModelByLevel();
setOutComeTree(originId);

return "poolList";
return getOutcome();
}

// This is the link in edit assessment to copy all questions to a pool
Expand Down Expand Up @@ -1321,7 +1341,7 @@ public String copyQuestion() {

ArrayList destpools = ContextUtil.paramArrayValueLike("checkboxes");
// sourceId = this.getCurrentPool().getId();

String originId = Long.toString(ORIGIN_TOP.equals(getOutcome())?0:getOutcomePool());
Iterator iter = destpools.iterator();
while (iter.hasNext()) {

Expand Down Expand Up @@ -1357,9 +1377,9 @@ public String copyQuestion() {
}
}

buildTree();
setQpDataModelByLevel();
return "poolList";
setOutComeTree(originId);

return getOutcome();
}

public String copyQuestionsFromPart() {
Expand Down Expand Up @@ -1500,6 +1520,7 @@ public void getCheckedQuestions() {
public String startCopyPool()
{
log.debug("inside startCopyPool()");
setOutComeParams();
getCheckedPool();
buildTreeCopy();
setActionType("pool");
Expand All @@ -1510,6 +1531,7 @@ public String startCopyPool()
public String startMovePool()
{
log.debug("inside startMovePool()");
setOutComeParams();
getCheckedPool();
buildTreeCopy();
setActionType("pool");
Expand Down Expand Up @@ -1577,6 +1599,7 @@ public String copyPool(){
ArrayList destpools= ContextUtil.paramArrayValueLike("checkboxes");
sourceId = this.getCurrentPool().getId();
String currentName=this.getCurrentPool().getDisplayName();
String originId = Long.toString(ORIGIN_TOP.equals(getOutcome())?0:getOutcomePool());
Iterator iter = destpools.iterator();

while(iter.hasNext())
Expand All @@ -1593,7 +1616,7 @@ public String copyPool(){
QuestionPoolFacade oldPool =delegate.getPool(sourceId, AgentFacade.getAgentString());
//if dest != source's parent, then throw error if dest has a duplicate pool name
if(!destId.equals((oldPool.getParentPoolId()).toString())){
isUnique=delegate.poolIsUnique("0",currentName,destId, AgentFacade.getAgentString());
isUnique=delegate.poolIsUnique(originId,currentName,destId, AgentFacade.getAgentString());
if(!isUnique){
String err1=rb.getString("copy_duplicateName_error");
FacesContext context=FacesContext.getCurrentInstance();
Expand All @@ -1619,9 +1642,9 @@ public String copyPool(){
}
}

buildTree();
setQpDataModelByLevel();
return "poolList";
setOutComeTree(originId);

return getOutcome();

}

Expand All @@ -1631,6 +1654,7 @@ public String movePool(){
String destId = "";
sourceId = this.getCurrentPool().getId().toString();
String currentName=this.getCurrentPool().getDisplayName();
String originId = Long.toString(ORIGIN_TOP.equals(getOutcome())?0:getOutcomePool());
boolean isUnique=true;
destId= ContextUtil.lookupParam("movePool:selectedRadioBtn");

Expand All @@ -1640,7 +1664,7 @@ public String movePool(){
try
{
QuestionPoolService delegate = new QuestionPoolService();
isUnique=delegate.poolIsUnique("0",currentName,destId, AgentFacade.getAgentString());
isUnique=delegate.poolIsUnique(originId,currentName,destId, AgentFacade.getAgentString());
if(!isUnique){
String err1=rb.getString("move_duplicateName_error");
FacesContext context = FacesContext.getCurrentInstance();
Expand All @@ -1660,16 +1684,15 @@ public String movePool(){
}
}

buildTree();
setQpDataModelByLevel();
setOutComeTree(originId);

return "poolList";
return getOutcome();
}

public String addPool() {
String addsource = "poollist";
addsource = (String) FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("addsource");
setOutComeParams();
addsource = getOutcome();
this.setAddPoolSource(addsource);
startCreatePool();
this.setAddOrEdit("add");
Expand Down Expand Up @@ -1741,6 +1764,7 @@ public String unsharePool(){


public String confirmRemovePool(){
setOutComeParams();
// used by the editpool.jsp to remove one subpool at a time
this.setDeletePoolSource("editpool");

Expand Down Expand Up @@ -1822,9 +1846,18 @@ public String removePool(){
}

public String cancelPool() {
if(ORIGIN_TOP.equals(getOutcome())){
setCurrentPool(null);
setOutcomePool(0);
buildTree();
setQpDataModelByLevel();
return "poolList";
}else{
startEditPoolAgain(Long.toString(getOutcomePool()));
buildTree();
setSubQpDataModelByLevel();
}

return getOutcome();
}

public String importPool(){
Expand Down Expand Up @@ -1954,6 +1987,7 @@ public String selectQuestionType() {
ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");
String poolid = ContextUtil.lookupParam("poolId");
if (poolid != null) {
setOutComeParams();
itemauthorbean.setQpoolId(poolid);
itemauthorbean.setTarget(ItemAuthorBean.FROM_QUESTIONPOOL);

Expand Down Expand Up @@ -2157,12 +2191,16 @@ private void setPoolInfo(QuestionPoolDataBean pool) {
}

public void setQpDataModelByLevel() {
Collection objects = tree.getSortedObjects();

// construct the sortedList, pools need to be sorted one level at a time
// so the hierachical structure can be maintained. Here, we start from root = 0,
setQpDataModelByLevel(new Long("0"));
}

public void setQpDataModelByLevel(Long poolId) {
Collection objects = tree.getSortedObjects();

if (objects != null) {
ArrayList sortedList = sortPoolByLevel(new Long("0"), objects,
ArrayList sortedList = sortPoolByLevel(poolId, objects,
getSortProperty(), getSortAscending());
ListDataModel model = new ListDataModel((List) sortedList);
QuestionPoolDataModel qpDataModel = new QuestionPoolDataModel(tree,
Expand Down Expand Up @@ -2499,4 +2537,28 @@ public String transferPoolOwnership() {
return "";
}
}

public void setOutComeTree(String originId){
if(ORIGIN_TOP.equals(getOutcome())){
buildTree();
setQpDataModelByLevel();
}else{
startEditPoolAgain(originId);
buildTree();
setSubQpDataModelByLevel();
}
}

public void setOutComeParams(){
setOutComeParams(null);
}

public void setOutComeParams(String outcome){
if(outcome==null){
setOutcome((String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("outCome"));
}else{
setOutcome(outcome);
}
setOutcomePool((getCurrentPool()!=null)?getCurrentPool().getId():0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public void processAction(ActionEvent ae) throws AbortProcessingException
QuestionPoolBean qpoolbean= (QuestionPoolBean) ContextUtil.lookupBean("questionpool");
String currentName= TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, qpoolbean.getCurrentPool().getDisplayName());

String addsource = (String)ae.getComponent().getAttributes().get("addsource");
qpoolbean.setAddPoolSource(addsource);

boolean isUnique=true;
QuestionPoolService service = new QuestionPoolService();
QuestionPoolDataBean bean = qpoolbean.getCurrentPool();
Expand Down Expand Up @@ -177,11 +180,11 @@ public boolean savePool(QuestionPoolBean qpbean) {

// System.out.println( "SAVE - POOLSOURCE= "+qpbean.getAddPoolSource());
//where do you get value from addPoolSource? It always return null though.
if ("editpool".equals(qpbean.getAddPoolSource())) {
if ("editpool".equals(qpbean.getAddPoolSource()) && !qpbean.ORIGIN_TOP.equals(qpbean.getOutcome())) {
// so reset subpools tree
// QuestionPoolFacade thepool= delegate.getPool(parentid, AgentFacade.getAgentString());
// qpbean.getCurrentPool().setNumberOfSubpools(thepool.getSubPoolSize().toString());
qpbean.startEditPoolAgain(parentid.toString()); // return to edit poolwith the current pool set to the parentpoo
qpbean.startEditPoolAgain(Long.toString(qpbean.getOutcomePool())); // return to edit pool with the pool where the action was performed

// Reset the properties for current pool to reflect the early changes (before click on "Add") in edit pool
QuestionPoolDataBean currentPool = qpbean.getCurrentPool();
Expand All @@ -200,9 +203,19 @@ public boolean savePool(QuestionPoolBean qpbean) {
qpbean.setAddPoolSource("");
qpbean.setSubQpDataModelByLevel();
}
else if("editpoolattr".equals(qpbean.getAddPoolSource())){
//when change the pool's field
qpbean.startEditPoolAgain(bean.getId().toString());
qpbean.setOutcomeEdit("editPool");
qpbean.setOutcome("editPool");
qpbean.setSubQpDataModelByLevel();
}
else {
qpbean.setOutcomeEdit("poolList");
qpbean.setOutcome("poolList");
qpbean.setCurrentPool(null);
qpbean.setOutcomePool(0);

qpbean.setQpDataModelByLevel();
}
// set outcome for action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {
if (ae != null && ae.getComponent().getId().equals("questionPoolsLink")) {
qpoolbean.buildTree();
}
//Reset the currentpool in root
qpoolbean.setCurrentPool(null);
qpoolbean.setQpDataModelByLevel();
}
}
6 changes: 3 additions & 3 deletions samigo/samigo-app/src/webapp/jsf/questionpool/addPool.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ function textCounter(field, maxlimit) {
<h:commandButton id="submit" action="#{questionpool.doit}"
value="#{questionPoolMessages.save}" styleClass="active">
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.questionpool.PoolSaveListener" />
<f:attribute name="addsource" value="editpool"/>
</h:commandButton>
<h:commandButton style="act" value="#{commonMessages.cancel_action}" action="poolList" immediate="true">
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.questionpool.QuestionPoolListener" />
</h:commandButton>
<h:commandButton style="act" value="#{commonMessages.cancel_action}" action="#{questionpool.cancelPool}" immediate="true"/>


</p>
</h:form>
Expand Down
5 changes: 4 additions & 1 deletion samigo/samigo-app/src/webapp/jsf/questionpool/editPool.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function textCounter(field, maxlimit) {
<div style="margin-top:1em;margin-bottom:2.5em">
<h:commandButton id="Update" rendered="#{questionpool.importToAuthoring == 'false'}" action="#{questionpool.getOutcomeEdit}" value="#{questionPoolMessages.update}">
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.questionpool.PoolSaveListener" />
<f:attribute name="addsource" value="editpoolattr"/>
</h:commandButton>
</div>

Expand All @@ -131,7 +132,7 @@ function textCounter(field, maxlimit) {
<h:commandLink title="#{questionPoolMessages.t_addSubpool}" rendered="#{questionpool.importToAuthoring != 'true' && questionpool.owner==questionpool.currentPool.owner}" id="addlink" immediate="true" action="#{questionpool.addPool}">
<h:outputText id="add" value="#{questionPoolMessages.t_addSubpool}"/>
<f:param name="qpid" value="#{questionpool.currentPool.id}"/>
<f:param name="addsource" value="editpool"/>
<f:param name="outCome" value="editPool"/>
</h:commandLink>
</h:panelGrid>
</h4>
Expand Down Expand Up @@ -159,13 +160,15 @@ function textCounter(field, maxlimit) {
<h:commandLink title="#{questionPoolMessages.t_addQuestion}" rendered="#{questionpool.importToAuthoring != 'true'}" id="addQlink" immediate="true" action="#{questionpool.selectQuestionType}">
<h:outputText id="addq" value="#{questionPoolMessages.t_addQuestion}"/>
<f:param name="poolId" value="#{questionpool.currentPool.id}"/>
<f:param name="outCome" value="editPool"/>
</h:commandLink>
</h:panelGrid>
</h4>
<div class="tier2">
<div class="navIntraToolLink">
<h:commandButton id="removeSubmit" rendered="#{questionpool.importToAuthoring == 'false'}" action="#{questionpool.doit}" value="#{commonMessages.remove_action}">
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.questionpool.StartRemoveItemsListener" />
<f:param name="outCome" value="editPool"/>
</h:commandButton>

<h:outputText escape="false" value=" | " rendered="#{questionpool.importToAuthoring != 'true'}" />
Expand Down
1 change: 1 addition & 0 deletions samigo/samigo-app/src/webapp/jsf/questionpool/movePool.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<p class="act">
<h:commandButton type="submit" immediate="true" id="poolSubmit" value="#{questionPoolMessages.move}"
action="#{questionpool.movePool}" rendered="#{questionpool.actionType == 'pool'}" styleClass="active">
<f:param name="qpid" value="#{questionpool.currentPool.parentPoolId}"/>
</h:commandButton>

<h:commandButton type="submit" immediate="true" id="itemSubmit" value="#{questionPoolMessages.move}"
Expand Down
Loading

0 comments on commit 1beb34c

Please sign in to comment.