001: /*
002: * ManageEPeopleMain.java
003: *
004: * Version: $Revision: 1.0 $
005: *
006: * Date: $Date: 2006/07/13 23:20:54 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.xmlui.aspect.administrative.eperson;
041:
042: import java.sql.SQLException;
043:
044: import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
045: import org.dspace.app.xmlui.wing.Message;
046: import org.dspace.app.xmlui.wing.WingException;
047: import org.dspace.app.xmlui.wing.element.Body;
048: import org.dspace.app.xmlui.wing.element.Cell;
049: import org.dspace.app.xmlui.wing.element.CheckBox;
050: import org.dspace.app.xmlui.wing.element.Division;
051: import org.dspace.app.xmlui.wing.element.List;
052: import org.dspace.app.xmlui.wing.element.PageMeta;
053: import org.dspace.app.xmlui.wing.element.Row;
054: import org.dspace.app.xmlui.wing.element.Table;
055: import org.dspace.app.xmlui.wing.element.Text;
056: import org.dspace.eperson.EPerson;
057:
058: /**
059: * The manage epeople page is the starting point page for managing
060: * epeople. From here the user is able to browse or search for epeople,
061: * once identified the user can selected them for deletition by selecting
062: * the checkboxes and clicking delete or click their name to edit the
063: * eperson.
064: *
065: * @author Alexey Maslov
066: * @author Scott Phillips
067: */
068: public class ManageEPeopleMain extends AbstractDSpaceTransformer {
069:
070: /** Language Strings */
071: private static final Message T_title = message("xmlui.administrative.eperson.ManageEPeopleMain.title");
072:
073: private static final Message T_eperson_trail = message("xmlui.administrative.eperson.general.epeople_trail");
074:
075: private static final Message T_main_head = message("xmlui.administrative.eperson.ManageEPeopleMain.main_head");
076:
077: private static final Message T_actions_head = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_head");
078:
079: private static final Message T_actions_create = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_create");
080:
081: private static final Message T_actions_create_link = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_create_link");
082:
083: private static final Message T_actions_browse = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_browse");
084:
085: private static final Message T_actions_browse_link = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_browse_link");
086:
087: private static final Message T_actions_search = message("xmlui.administrative.eperson.ManageEPeopleMain.actions_search");
088:
089: private static final Message T_search_help = message("xmlui.administrative.eperson.ManageEPeopleMain.search_help");
090:
091: private static final Message T_dspace_home = message("xmlui.general.dspace_home");
092:
093: private static final Message T_go = message("xmlui.general.go");
094:
095: private static final Message T_search_head = message("xmlui.administrative.eperson.ManageEPeopleMain.search_head");
096:
097: private static final Message T_search_column1 = message("xmlui.administrative.eperson.ManageEPeopleMain.search_column1");
098:
099: private static final Message T_search_column2 = message("xmlui.administrative.eperson.ManageEPeopleMain.search_column2");
100:
101: private static final Message T_search_column3 = message("xmlui.administrative.eperson.ManageEPeopleMain.search_column3");
102:
103: private static final Message T_search_column4 = message("xmlui.administrative.eperson.ManageEPeopleMain.search_column4");
104:
105: private static final Message T_submit_delete = message("xmlui.administrative.eperson.ManageEPeopleMain.submit_delete");
106:
107: private static final Message T_no_results = message("xmlui.administrative.eperson.ManageEPeopleMain.no_results");
108:
109: /**
110: * The total number of entries to show on a page
111: */
112: private static final int PAGE_SIZE = 15;
113:
114: public void addPageMeta(PageMeta pageMeta) throws WingException {
115: pageMeta.addMetadata("title").addContent(T_title);
116: pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
117: pageMeta.addTrailLink(contextPath + "/admin/epeople",
118: T_eperson_trail);
119: }
120:
121: public void addBody(Body body) throws WingException, SQLException {
122: /* Get and setup our parameters */
123: int page = parameters.getParameterAsInteger("page", 0);
124: int highlightID = parameters.getParameterAsInteger(
125: "highlightID", -1);
126: String query = URLDecode(parameters.getParameter("query", null));
127: String baseURL = contextPath
128: + "/admin/epeople?administrative-continue="
129: + knot.getId();
130: int resultCount = EPerson.searchResultCount(context, query);
131: EPerson[] epeople = EPerson.search(context, query, page
132: * PAGE_SIZE, PAGE_SIZE);
133:
134: // DIVISION: eperson-main
135: Division main = body.addInteractiveDivision("epeople-main",
136: contextPath + "/admin/epeople", Division.METHOD_POST,
137: "primary administrative eperson");
138: main.setHead(T_main_head);
139:
140: // DIVISION: eperson-actions
141: Division actions = main.addDivision("epeople-actions");
142: actions.setHead(T_actions_head);
143:
144: List actionsList = actions.addList("actions");
145: actionsList.addLabel(T_actions_create);
146: actionsList.addItemXref(baseURL + "&submit_add",
147: T_actions_create_link);
148: actionsList.addLabel(T_actions_browse);
149: actionsList.addItemXref(baseURL + "&query&submit_search",
150: T_actions_browse_link);
151:
152: actionsList.addLabel(T_actions_search);
153: org.dspace.app.xmlui.wing.element.Item actionItem = actionsList
154: .addItem();
155: Text queryField = actionItem.addText("query");
156: if (query != null)
157: queryField.setValue(query);
158: queryField.setHelp(T_search_help);
159: actionItem.addButton("submit_search").setValue(T_go);
160:
161: // DIVISION: eperson-search
162: Division search = main.addDivision("eperson-search");
163: search.setHead(T_search_head);
164:
165: // If there are more than 10 results the paginate the division.
166: if (resultCount > PAGE_SIZE) {
167: // If there are enough results then paginate the results
168: int firstIndex = page * PAGE_SIZE + 1;
169: int lastIndex = page * PAGE_SIZE + epeople.length;
170:
171: String nextURL = null, prevURL = null;
172: if (page < (resultCount / PAGE_SIZE))
173: nextURL = baseURL + "&page=" + (page + 1);
174: if (page > 0)
175: prevURL = baseURL + "&page=" + (page - 1);
176:
177: search.setSimplePagination(resultCount, firstIndex,
178: lastIndex, prevURL, nextURL);
179: }
180:
181: Table table = search.addTable("eperson-search-table",
182: epeople.length + 1, 1);
183: Row header = table.addRow(Row.ROLE_HEADER);
184: header.addCell().addContent(T_search_column1);
185: header.addCell().addContent(T_search_column2);
186: header.addCell().addContent(T_search_column3);
187: header.addCell().addContent(T_search_column4);
188:
189: CheckBox selectEPerson;
190: for (EPerson person : epeople) {
191: String epersonID = String.valueOf(person.getID());
192: String fullName = person.getFullName();
193: String email = person.getEmail();
194: String url = baseURL + "&submit_edit&epersonID="
195: + epersonID;
196:
197: Row row;
198: if (person.getID() == highlightID)
199: // This is a highlighted eperson
200: row = table.addRow(null, null, "highlight");
201: else
202: row = table.addRow();
203:
204: selectEPerson = row.addCell().addCheckBox("select_eperson");
205: selectEPerson.setLabel(epersonID);
206: selectEPerson.addOption(epersonID);
207:
208: row.addCellContent(epersonID);
209: row.addCell().addXref(url, fullName);
210: row.addCell().addXref(url, email);
211: }
212:
213: if (epeople.length <= 0) {
214: Cell cell = table.addRow().addCell(1, 4);
215: cell.addHighlight("italic").addContent(T_no_results);
216: } else {
217: search.addPara().addButton("submit_delete").setValue(
218: T_submit_delete);
219: }
220:
221: main.addHidden("administrative-continue")
222: .setValue(knot.getId());
223:
224: }
225: }
|