Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DS-1968] Select the collection already selected in the previous operation (JSPUI) #518

Merged
2 commits merged into from Oct 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,231 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.webui.jsptag;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.dspace.app.util.CollectionDropDown;
import org.dspace.app.webui.util.UIUtil;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.core.Context;

/**
* Renders select element to select collection with parent community
* object.
*
* @author Keiji Suzuki
*/
public class SelectCollectionTag extends TagSupport
{

/** the class description */
private String klass;

/** the name description */
private String name;

/** the id description */
private String id;

/** the collection id */
private int collection = -1;

public SelectCollectionTag()
{
super();
}

public int doStartTag() throws JspException
{
JspWriter out = pageContext.getOut();
StringBuffer sb = new StringBuffer();

try
{
HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest();
Context context = UIUtil.obtainContext(hrq);
Map<Community, List<Collection>> commCollList = new LinkedHashMap<Community, List<Collection>>();

for (Community topcommunity : Community.findAllTop(context))
{
for (Collection collection : topcommunity.getCollections())
{
List<Collection> clist = null;
if (commCollList.containsKey(topcommunity))
{
clist = commCollList.get(topcommunity);
}
else
{
clist = new ArrayList<Collection>();
}
clist.add(collection);
commCollList.put(topcommunity, clist);
}

for (Community subcommunity : topcommunity.getSubcommunities())
{
addCommCollList(subcommunity, commCollList);
}
}

sb.append("<select");
if (name != null)
{
sb.append(" name=\"").append(name).append("\"");
}
if (klass != null)
{
sb.append(" class=\"").append(klass).append("\"");
}
if (id != null)
{
sb.append(" id=\"").append(id).append("\"");
}
sb.append(">\n");

ResourceBundle msgs = ResourceBundle.getBundle("Messages", context.getCurrentLocale());
String firstOption = msgs.getString("jsp.submit.start-lookup-submission.select.collection.defaultoption");
sb.append("<option value=\"-1\"");
if (collection == -1) sb.append(" selected=\"selected\"");
sb.append(">").append(firstOption).append("</option>\n");

Iterator<Community> iter = commCollList.keySet().iterator();
while(iter.hasNext())
{
Community comm = iter.next();
//sb.append("<optgroup label=\"").append(getCommName(comm)).append("\">\n");
for (Collection coll : commCollList.get(comm))
{
sb.append("<option value=\"").append(coll.getID()).append("\"");
if (collection == coll.getID())
{
sb.append(" selected=\"selected\"");
}
sb.append(">").append(CollectionDropDown.collectionPath(coll)).append("</option>\n");
}
//sb.append("</optgroup>\n");
}
sb.append("</select>\n");

out.print(sb.toString());
}
catch (IOException e)
{
throw new JspException(e);
}
catch (SQLException e)
{
throw new JspException(e);
}

return SKIP_BODY;
}

private void addCommCollList(Community community, Map<Community,
List<Collection>> commCollList) throws SQLException
{
for (Collection collection : community.getCollections())
{
List<Collection> clist = null;
if (commCollList.containsKey(community))
{
clist = commCollList.get(community);
}
else
{
clist = new ArrayList<Collection>();
}
clist.add(collection);
commCollList.put(community, clist);
}

for (Community subcommunity : community.getSubcommunities())
{
addCommCollList(subcommunity, commCollList);
}

}

private String getCommName(Community community) throws SQLException
{
StringBuffer sb = new StringBuffer("");
Community[] parents = community.getAllParents();
for (Community parent : parents)
{
sb.insert(0, parent.getMetadata("name")+"/");
}
sb.append(community.getMetadata("name"));

return sb.toString().substring(1);
}


public String getKlass()
{
return klass;
}

public void setKlass(String klass)
{
this.klass = klass;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public int getCollection()
{
return collection;
}

public void setCollection(int collection)
{
this.collection = collection;
}

public void release()
{
klass = null;
name = null;
id = null;
collection = -1;
}
}

Expand Up @@ -122,6 +122,7 @@ public void doPreProcessing(Context context, HttpServletRequest request,
* With no parameters, this servlet prepares for display of the Select
* Collection JSP.
*/
int collection_id = UIUtil.getIntParameter(request, "collection");
int collectionID = UIUtil.getIntParameter(request, "collectionid");
Collection col = null;

Expand Down Expand Up @@ -159,6 +160,7 @@ public void doPreProcessing(Context context, HttpServletRequest request,

// save collections to request for JSP
request.setAttribute("collections", collections);
request.setAttribute("collection_id", collection_id);
request.setAttribute("collectionID", collectionID);

Map<String, List<String>> identifiers2providers = slService
Expand Down
34 changes: 34 additions & 0 deletions dspace-jspui/src/main/webapp/WEB-INF/dspace-tags.tld
Expand Up @@ -521,4 +521,38 @@

</tag>

<tag>
<name>selectcollection</name>
<tagclass>org.dspace.app.webui.jsptag.SelectCollectionTag</tagclass>
<bodycontent>empty</bodycontent>
<info>
Tag for making collection select element with community heading
</info>

<attribute>
<name>klass</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

<attribute>
<name>collection</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

</tag>

</taglib>
3 changes: 1 addition & 2 deletions dspace-jspui/src/main/webapp/static/js/submission-lookup.js
Expand Up @@ -81,7 +81,7 @@ submissionLookupSearch = function(){
submissionLookupDetails = function(button, suffixID){
var uuid = j(button).data('uuid');
var mydata = new Object();
var suuidID = 'suuid' + suffixID
var suuidID = 'suuid' + suffixID;
mydata['s_uuid'] = j('#'+suuidID).val();
mydata['type'] = 'details';
mydata['i_uuid'] = uuid;
Expand Down Expand Up @@ -174,7 +174,6 @@ submissionLookupShowDetails = function(info){
modalbody.append(detailsDiv);

modalbody.append(j('#select-collection-div'));
j('#select-collection').val(info.collection);

var modalfooter = j('#loading-details .modal-footer');
var start = j('<button class="btn btn-success" type="button">');
Expand Down
12 changes: 1 addition & 11 deletions dspace-jspui/src/main/webapp/submit/select-collection.jsp
Expand Up @@ -72,17 +72,7 @@
<label for="tcollection" class="input-group-addon">
<fmt:message key="jsp.submit.select-collection.collection"/>
</label>
<select class="form-control" name="collection" id="tcollection">
<option value="-1"></option>
<%
for (int i = 0; i < collections.length; i++)
{
%>
<option value="<%= collections[i].getID() %>"><%= collections[i].getMetadata("name") %></option>
<%
}
%>
</select>
<dspace:selectcollection klass="form-control" id="tcollection" collection="-1"/>
</div><br/>
<%-- Hidden fields needed for SubmissionController servlet to know which step is next--%>
<%= SubmissionController.getSubmissionParameters(context, request) %>
Expand Down
27 changes: 7 additions & 20 deletions dspace-jspui/src/main/webapp/submit/start-lookup-submission.jsp
Expand Up @@ -41,8 +41,8 @@
Collection[] collections =
(Collection[]) request.getAttribute("collections");

//get community handle
int communityId = (Integer) request.getAttribute("collectionID");
//get collection id from the collection home
int collection_id = (Integer) request.getAttribute("collection_id");

//check if we need to display the "no collection selected" error
Boolean noCollection = (Boolean) request.getAttribute("no.collection");
Expand Down Expand Up @@ -235,7 +235,7 @@
<%
}
%>
</select>
</select>
</div>
</div>
<div class="form-group">
Expand All @@ -252,14 +252,10 @@
<div class="form-group" id="select-collection-file-div">
<label class="col-md-3" for="select-collection-file"><fmt:message key="jsp.submit.start-lookup-submission.byfile.filecollection"/>:</label>
<div class="col-md-6">
<select class="form-control submission-file-loader" name="select-collection-file" id="select-collection-file">
<% for (Collection c : collections) { %>
<option value="<%= c.getID() %>"><%= c.getName() %></option>
<% } %>
</select>
<dspace:selectcollection klass="form-control submission-file-loader" name="select-collection-file" id="select-collection-file" collection="<%= collection_id %>"/>
</div>
<button class="btn btn-primary col-md-2 pull-right" type="button" id="loadfile_go"><fmt:message key="jsp.submit.start-lookup-submission.byfile.process"/></button>
</div>
<button class="btn btn-primary col-md-2 pull-right" type="button" id="loadfile_go"><fmt:message key="jsp.submit.start-lookup-submission.byfile.process"/></button>
</form>
</div>
<%
Expand All @@ -281,12 +277,7 @@
<label for="select-collection-manual"><fmt:message key="jsp.submit.start-lookup-submission.select.collection.label"/></label>
</div>
<div class="col-md-7">
<select class="form-control" id="select-collection-manual">
<option value="-1"><fmt:message key="jsp.submit.start-lookup-submission.select.collection.defaultoption"/></option>
<% for (Collection c : collections) { %>
<option value="<%= c.getID() %>"><%= c.getName() %></option>
<% } %>
</select>
<dspace:selectcollection klass="form-control" id="select-collection-manual" collection="<%= collection_id %>"/>
</div>
</div>
<form class="form-horizontal" id="form-submission" action="" method="post">
Expand All @@ -307,11 +298,7 @@
</div>
<div id="hidden-area" style="display: none;">
<div id="select-collection-div">
<select class="form-control" id="select-collection">
<% for (Collection c : collections) { %>
<option value="<%= c.getID() %>"><%= c.getName() %></option>
<% } %>
</select>
<dspace:selectcollection klass="form-control" id="select-collection" collection="<%= collection_id %>"/>
</div>
</div>

Expand Down