Archived / Obsolete Documentation

Documentation in this space is no longer accurate.
Looking for official DSpace documentation? See all documentation

Background

For a presentation about AJAX I have modified the selection of epersons.
When you need to edit or delete an eperson or add an eperson to a group, as an administrator you need to select an e-person first. Finding and selecting an eperson in DSpace is not as easy as it could be, especially when you have more than a thousand epersons.

What it does

If an administrator needs to select an eperson a text field is presented where the name or e-mail address can be typed. Instantly the list of matching epersons is shown, and an eperson can be edited or deleted.

Try it at

Unfortunately this improvement is only visible to administrators of the DSpace system, and our test system is not open for everybody...

Below are some screenshots of the functionality, so you can at least see it. (email adresses are made unreadable in the screenshots for privacy reasons)

If you want to try it, implement it!

 

 

How it works

Via Javascript event handlers are attached to all input fields of the form. When something is changed in such an input field a AJAX http request is sent asynchronously to dspace. The EPersonListServlet handles this request and sends results back using JSON. Via javascript these results are displayed in HTML.

Which DSpace version

The modifications I made were made to Dspace 1.3.2, but with some modification you can get it to work in another version.

This is tested for Internet Explorer 6 and Firefox 2, but may not work with other web browsers...

How to install

This is a tested beta version, so it needs to mature...

Major changes are made to the SelectEPersonTag class, some changes to EPersonListServlet and EPerson. A JSP file must be added.

Step 1: Replace SelectEPersonTag.java

  • Download the file EPerson.java  The file SelectEPersonTag.java in src/org/dspace/app/webui/jsptag must be replaced (make a backup copy!)
  • edit jsp/WEB-INF/dspace-tags.tld and add the following to the selecteperson tag:
    <attribute>
      <name>popup</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>

Step 2: Edit EPersonListServlet.java

Merge EPersonListServlet.java   with the current version of the file (make a backup copy!):

The function doDSGet must start with the following code:

   String type = request.getParameter("type");
   if (type != null && type.equals("json")) \{
     String search = request.getParameter("search");
     String browse = null;
     String mode = request.getParameter("mode");
     String order = request.getParameter("order");
     int start = UIUtil.getIntParameter(request,"start");
     if (!mode.equals("search")) \{
       browse = search;
       search = null;
     \}
     EPerson[] epeople = EPerson.findAll(context, search, browse,order,15,start);
     request.setAttribute("epeople", epeople);
     JSPManager.showJSP(request, response, "/tools/eperson-list-json.jsp");
   \}
   else \{

Do not forget an extra closing bracket } at the end of the function doDSGet!

Step 3: Add eperson-list-json.jsp

Step 4: Add select_eperson.js and ajax.js

  • download Missing File:  Select_eperson.js and Ajax.js
  • place these files in the new directory ajax inside jsp

Step 5: Edit EPerson.java

  • download EPerson.java
  • merge this with the current version of the file (make a backup copy!). The following function was added:
   public static EPerson[] findAll(Context context, String search, String browse, String order, int limit, int start)
           throws SQLException
   \{
       String sql = "SELECT * FROM eperson WHERE eperson_id is null ";
       String col = order;
       if (order == null || !order.matches("^(eperson_id|email|lastname|firstname)$")) \{
         order = "lastname";
       \}
       int pid = -1;
       try \{
         if (search != null) \{
           pid = Integer.parseInt(search);
         \}
         else \{
           pid = Integer.parseInt(browse);
         \}
       \}
       catch (NumberFormatException e) \{
         pid = -1;
       \}
       if (search != null && !search.matches(".*[';].*")) \{
         if (col == null) col = "all";
         if (col.matches("^(all|email)$")) \{
           sql += " OR email ilike '%"+search+"%'";
         \}
         if (col.matches("^(all|firstname)$")) \{
           sql += " OR firstname ilike '%"+search+"%'";
         \}
         if (col.matches("^(all|lastname)$")) \{
           sql += " OR lastname ilike '%"+search+"%'";
         \}
         if (col.matches("^(all|eperson_id)$")) \{
           if (pid > 0) \{
             sql += " OR eperson_id = "+pid;
           \}
         \}
       \}
       else if (browse != null && !browse.matches(".*[';].*")) \{
         if (order.equals("eperson_id")) \{
           if (pid > 0) \{
             sql += " OR eperson_id >= "+pid;
           \}
         \}
         else \{
           sql += " OR "+order+" >= '"+browse+"'";
         \}
       \}
       sql +=       " ORDER BY "+order;
       if (limit > 0) \{
         sql +=       " LIMIT "+limit;
         if (start > 0) \{
           sql +=       " OFFSET "+start;
         \}
       \}
       TableRowIterator rows = DatabaseManager.query(context, sql);
       List epeopleRows = rows.toList();
       EPerson[] epeople = new EPerson[epeopleRows.size()];
       for (int i = 0; i < epeopleRows.size(); i++)
       \{
           TableRow row = (TableRow) epeopleRows.get(i);
           // First check the cache
           EPerson fromCache = (EPerson) context.fromCache(EPerson.class, row
                   .getIntColumn("eperson_id"));
           if (fromCache != null)
           \{
               epeople[i] = fromCache;
           \}
           else
           \{
               epeople[i] = new EPerson(context, row);
           \}
       \}
       return epeople;
   \}

Step 5: edit jsp/dspace-admin/eperson-main.jsp

  • Make a local copy of this file (copy it to jsp/local/dspace-admin/eperson-main.jsp)
  • Remove the "Edit" and "Delete..." buttons
  • Add popup="false" to the dspace:selecteperson tag

Step 6: edit jsp/tools/group-edit.jsp

  • Make a local copy of this file (copy it to jsp/local/tools/group-edit.jsp
  • Add popup="true" to the dspace:selecteperson tag

Step 7: edit jsp/tools/eperson-list.jsp

  • download Eperson-list_jsp.mht
  • place this file in the jsp/local/tools directory (if you already have a local version, please merge those files)

Step 8: build / install / restart

Do the stuff you normally do when deploying a new version of DSpace.

Contact me

If you need help, or have any comments, or you just want to inform me that you (are going to) use this, please contact me.

See inside the source files for my e-mail address.

  • No labels