changeset 87:910cfd8521dd

1. Add ?Source? column in Section Page 2. Add pagination in Section Page
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 19 May 2017 20:12:34 +0200
parents 53ca65aad5f7
children f4242db6206b
files src/main/java/de/mpiwg/web/jsp/JSPProxy.java src/main/java/de/mpiwg/web/jsp/SearchPage.java src/main/webapp/componentes/paginator.jsp src/main/webapp/pages/search.jsp
diffstat 4 files changed, 409 insertions(+), 349 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Fri May 19 20:09:47 2017 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Fri May 19 20:12:34 2017 +0200
@@ -243,6 +243,10 @@
 					getSessionBean().getSearchPage().sortByStartPageUp();
 				} else if(StringUtils.equals(action, "sortByStartPageDown")){
 					getSessionBean().getSearchPage().sortByStartPageDown();
+				} else if(StringUtils.equals(action, "sortBySourceUp")){
+					getSessionBean().getSearchPage().sortBySourceUp();
+				} else if(StringUtils.equals(action, "sortBySourceDown")){
+					getSessionBean().getSearchPage().sortBySourceDown();
 				}
 
 				return SearchPage.page;
--- a/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Fri May 19 20:09:47 2017 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Fri May 19 20:12:34 2017 +0200
@@ -29,55 +29,57 @@
 import de.mpiwg.web.search.SortSectionByPeriod;
 import de.mpiwg.web.search.SortSectionByStartPage;
 import de.mpiwg.web.search.SortSectionByVolume;
+import de.mpiwg.web.search.SortSectionBySource;
 
 public class SearchPage extends AbstractJSPPage{
-	
+
 	private static Logger logger = Logger.getLogger(SearchPage.class);
-	
+
 	public static String bean = "searchBean";
 	public static String page = "pages/search.jsp";
-	
-	
+
+
 	private static Integer SEARCH_IN_SECTION_NAME = 0;
 	private static Integer SEARCH_IN_BOOK_NAME = 1;
 	//private static Integer SEARCH_FULL_TEXT = 2;
-	
-	
+
+
 	private Map<Long, List<LGBranch>> branchesMap;
 	private List<DBSection> completeSectionList;
 	private List<DBSection> filteredSectionList;
 	private List<DBSection> displaySectionList;
-	
+
 	private String searchTerm = new String();
 	private Integer searchIn = SEARCH_IN_SECTION_NAME;
-	
+
 	private String dynastyFilter = new String();
 	private String adminTypeFilter = new String();
 	private String level1Filter = new String();
 	private String level2Filter = new String();
-	
+
 	private String bookNameFilter = new String();
 	private String periodFilter = new String();
 	private String sectionNameFilter = new String();
-	
+	private String sourceFilter = new String();
+
 	private DataPaginator paginator = new DataPaginator();
 	private String searchMessage;
 	private String filteringMessage;
-	
+
 
 	private Map<Long, List<LGTopicSectionRelation>> topicSectionRelationMap;
-	
-	
+
+
 	@Override
 	public void init(){
 		super.init();
 	}
-	
+
 	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
-		
+
 		this.request = request;
 		this.response = response;
-		
+
 		this.searchTerm = getParameter("searchTerm");
 		this.dynastyFilter = getParameter("dynastyFilter");
 		this.adminTypeFilter = getParameter("adminTypeFilter");
@@ -86,102 +88,103 @@
 		this.bookNameFilter = getParameter("bookNameFilter");
 		this.periodFilter = getParameter("periodFilter");
 		this.sectionNameFilter = getParameter("sectionNameFilter");
-		
+		this.sourceFilter = getParameter("sourceFilter");
+
 		this.searchIn = getIntParameter("searchIn");
-			
+
 	}
-	
+
 	public void updateTopicSectionRelation() {
-		logger.debug("updateTopicSectionRelation");	
+		logger.debug("updateTopicSectionRelation");
 		this.loadTopicSectionRelation();
 		this.filter();
-		
+
 	}
-	
-	public void search(){		
+
+	public void search(){
 		logger.debug("Searching: " + this.searchTerm);
-		
+
 		this.dynastyFilter = new String();
 		this.level1Filter = new String();
 		this.adminTypeFilter = new String();
-		
+
 		if(StringUtils.isNotEmpty(this.searchTerm)){
 			this.loadBranches();
-			
+
 			this.loadTopicSectionRelation();
-			
+
 			// TODO load all books for the difference set??
-			
-			
+
+
 			try {
 				List<String> terms = splitTerms();
-				
+
 				if(SEARCH_IN_SECTION_NAME.equals(this.searchIn)){
 					System.out.println("Section Search in Section Name");
 					this.completeSectionList = DBService.searchSection(terms);
-					
+
 				}else if(SEARCH_IN_BOOK_NAME.equals(this.searchIn)){
 					System.out.println("Section Search in Book Name");
 					this.completeSectionList = DBService.searchBook(terms, "name");
 
 				} /*else if (SEARCH_FULL_TEXT.equals(this.searchIn)) {
 					System.out.println("Full Text Search");
-					DBService.searchFullText(terms);	
+					DBService.searchFullText(terms);
 				}
 				*/
-				
+
 				Collections.sort(this.completeSectionList);
 				filter();
-								
+
 			} catch (Exception e) {
 				internalError(e);
-			}			
+			}
 		}
 	}
-	
-	public void filter(){	
+
+	public void filter(){
 		this.filteredSectionList = new ArrayList<DBSection>();
 		if (this.completeSectionList != null) {
-		
+
 			for(DBSection section : this.completeSectionList){
 				if(!this.filteredSectionList.contains(section)){
-						
+
 					if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) &&
 							(StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) &&
 							(StringUtils.isEmpty(level2Filter) || StringUtils.startsWith(section.getBook().getLevel2(), level2Filter)) &&
 							(StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(section.getBook().getName(), bookNameFilter)) &&
 							(StringUtils.isEmpty(periodFilter) || StringUtils.startsWith(section.getBook().getPeriod(), periodFilter)) &&
 							(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(section.getName(), sectionNameFilter)) &&
-							
+              (StringUtils.isEmpty(sourceFilter) || StringUtils.contains(section.getBook().getSource(), sourceFilter)) &&
 							(StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter))
 									){
 						this.filteredSectionList.add(section);
-					}	
+					}
 				}
 			}
-			
-		
-			
+
+
+
 			if(completeSectionList.size() > 0){
 				this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm;
 				this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering";
-	
+
 				this.paginator.setCurrentPage(0);
 				this.paginator.resetNumberOfPages(filteredSectionList.size());
-								
+
 			}else{
 				this.searchMessage = "No sections found for the term(s): " + this.searchTerm;
 				this.filteredSectionList = null;
 				this.filteringMessage = "";
-					
+
 				this.paginator.setCurrentPage(0);
 				this.paginator.resetNumberOfPages(0);
 			}
-				
+
 			this.updateCurrentSections();
 		}
 	}
-	
+
 	private void updateCurrentSections() {
 		this.paginator.initCount();
 		int startRecord = this.paginator.getCurrentPage()
@@ -193,24 +196,24 @@
 			if(mod == 0){
 				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 			}else{
-				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + mod);	
+				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + mod);
 			}
-			
+
 		}else{
-			this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());	
+			this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 		}
-		
+
 		for(DBSection section : this.displaySectionList){
 			section.setBranches(this.branchesMap.get(section.getId()));
 			section.setTopicSectionRelation(this.topicSectionRelationMap.get(section.getId()));
 		}
 	}
-	
+
 	private void loadBranches(){
 		this.branchesMap = new HashMap<Long, List<LGBranch>>();
 		// List<LGBranch> list = DataProvider.getInstance().getBranches(getSessionBean().getUser().getId());
 		List<LGBranch> list = DataProvider.getInstance().getAllExistingBranches();
-		
+
 		for(LGBranch branch : list){
 			branch.loadTransientData();
 			if(this.branchesMap.get(branch.getSectionId()) == null){
@@ -219,11 +222,11 @@
 			this.branchesMap.get(branch.getSectionId()).add(branch);
 		}
 	}
-	
+
 	private void loadTopicSectionRelation(){
 		this.topicSectionRelationMap = new HashMap<Long, List<LGTopicSectionRelation>>();
 		List<LGTopicSectionRelation> list = DataProvider.getInstance().getAllExistingTopicSectionRelation();
-		
+
 		for(LGTopicSectionRelation relation : list){
 			relation.loadTransientData();
 			if(this.topicSectionRelationMap.get(relation.getSectionId()) == null){
@@ -232,16 +235,16 @@
 			this.topicSectionRelationMap.get(relation.getSectionId()).add(relation);
 		}
 	}
-	
-	
+
+
 	private List<String> splitTerms(){
 		List<String> rs = new ArrayList<String>();
 		String[] array = this.searchTerm.split(",");
-		
+
 		for(String tmp : array){
 			tmp = tmp.replace(" ", "");
 			if(StringUtils.isNotEmpty(tmp)){
-				rs.add(tmp);	
+				rs.add(tmp);
 			}
 		}
 		return rs;
@@ -256,11 +259,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestLevel1(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -270,11 +273,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestLevel2(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -284,12 +287,12 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
-	
+
+
 	public List<String> suggestBookName(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -299,11 +302,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestPeriod(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -313,11 +316,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestAdminType(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -327,7 +330,7 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
@@ -340,11 +343,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 
 	public static Integer getSEARCH_IN_SECTION_NAME() {
 		return SEARCH_IN_SECTION_NAME;
@@ -427,7 +430,7 @@
 	public void setPaginator(DataPaginator paginator) {
 		this.paginator = paginator;
 	}
-	
+
 	public void firstPage() {
 		this.paginator.first();
 		this.updateCurrentSections();
@@ -489,7 +492,7 @@
 	public void setLevel1Filter(String level1Filter) {
 		this.level1Filter = level1Filter;
 	}
-	
+
 	public String getDynastyFilter() {
 		return dynastyFilter;
 	}
@@ -530,153 +533,172 @@
 		this.periodFilter = periodFilter;
 	}
 
-	
-	
+	public String getSourceFilter() {
+		return sourceFilter;
+	}
+
+
+	public void setSourceFilter(String sourceFilter) {
+		this.sourceFilter = sourceFilter;
+	}
+
+
 	/////// Sorting
-	
+
 	public void sortByBookNameUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookName());
 		filter();
 	}
-	
+
 	public void sortByBookNameDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookName());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortBySectionNameUp(){
 		Collections.sort(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortBySectionNameDown(){
 		Collections.sort(this.completeSectionList);
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByAuthorUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByAuthor());
 		filter();
 	}
-	
+
 	public void sortByAuthorDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByAuthor());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByPeriodUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByPeriod());
 		filter();
 	}
-	
+
 	public void sortByPeriodDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByPeriod());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByVolumeUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByVolume());
 		filter();
 	}
-	
+
 	public void sortByVolumeDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByVolume());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
-	
+
+
 	public void sortBySectionIdUp(){
 		Collections.sort(this.completeSectionList, new SortSectionById());
 		this.filter();
 	}
-	
+
 	public void sortBySectionIdDown(){
 		Collections.sort(this.completeSectionList, new SortSectionById());
 		Collections.reverse(completeSectionList);
 		this.filter();
 	}
-	
+
 	public void sortByEditionUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByEdition());
 		filter();
 	}
-	
+
 	public void sortByEditionDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByEdition());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByDynastyUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByDynasty());
 		filter();
 	}
-	
+
 	public void sortByDynastyDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByDynasty());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByBookIdUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookId());
 		filter();
 	}
-	
+
 	public void sortByBookIdDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookId());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByLevel1Up(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel1());
 		filter();
 	}
-	
+
 	public void sortByLevel1Down(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel1());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByLevel2Up(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
 		filter();
 	}
-	
+
 	public void sortByLevel2Down(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByAdminTypeUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByAdminType());
 		filter();
 	}
-	
+
 	public void sortByAdminTypeDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByAdminType());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByStartPageUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByStartPage());
 		filter();
 	}
-	
+
 	public void sortByStartPageDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByStartPage());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
 
-	
+	public void sortBySourceUp(){
+		Collections.sort(this.completeSectionList, new SortSectionBySource());
+		filter();
+	}
+
+	public void sortBySourceDown(){
+		Collections.sort(this.completeSectionList, new SortSectionBySource());
+		Collections.reverse(completeSectionList);
+		filter();
+	}
+
+
 }
--- a/src/main/webapp/componentes/paginator.jsp	Fri May 19 20:09:47 2017 +0200
+++ b/src/main/webapp/componentes/paginator.jsp	Fri May 19 20:12:34 2017 +0200
@@ -1,25 +1,25 @@
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
 <jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
-		
+
 		<% String formName = request.getParameter("formName"); %>
-		
+
 		<table style="width: 300px; margin-left: auto;margin-right: auto;">
 			<tr>
 				<td>
-					<input 
+					<input
 						type="image"
 						src="<%=sessionBean.getApplicationBean().getPaginatorFirst()%>"
 						onclick="setAction('firstPage','<%=formName%>');"/>
 				</td>
 				<td>
-					<input 				
+					<input
 						type="image"
 						src="<%=sessionBean.getApplicationBean().getPaginatorFr()%>"
 						onclick="setAction('fastRewind', '<%=formName%>');"/>
 				</td>
 				<td>
-					<input 				
+					<input
 						type="image"
 						src="<%=sessionBean.getApplicationBean().getPaginatorPrevious()%>"
 						onclick="setAction('previousPage', '<%=formName%>');"/>
@@ -27,13 +27,14 @@
 				<td>
 				<% if (formName.equals("booksForm")) { %>
 					<%=sessionBean.getBooksPage().getPaginator().getRecordStatus() %>
-						
+
 				<% } else if (formName.equals("searchForm")) { %>
 					<%=sessionBean.getSearchPage().getPaginator().getRecordStatus() %>
-					
+
 				<% } else if (formName.equals("fullTextSearchForm")) { %>
 					<%=sessionBean.getFullTextSearchPage().getPaginator().getRecordStatus() %>
-				
+				<% } else if (formName.equals("homeForm")) { %>
+						<%=sessionBean.getHomePage().getPaginator().getRecordStatus() %>
 				<% } %>
 				</td>
 				<td>
@@ -43,16 +44,16 @@
 						onclick="setAction('nextPage', '<%=formName%>');"/>
 				</td>
 				<td>
-					<input 				
+					<input
 						type="image"
 						src="<%=sessionBean.getApplicationBean().getPaginatorFf()%>"
 						onclick="setAction('fastForward', '<%=formName%>');"/>
 				</td>
 				<td>
-					<input 	
-						src="<%=sessionBean.getApplicationBean().getPaginatorLast()%>"						
+					<input
+						src="<%=sessionBean.getApplicationBean().getPaginatorLast()%>"
 						type="image"
 						onclick="setAction('lastPage', '<%=formName%>');"/>
 				</td>
 			</tr>
-		</table>
\ No newline at end of file
+		</table>
--- a/src/main/webapp/pages/search.jsp	Fri May 19 20:09:47 2017 +0200
+++ b/src/main/webapp/pages/search.jsp	Fri May 19 20:12:34 2017 +0200
@@ -5,27 +5,26 @@
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
 <jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
-	
 
 <html>
 
 <head>
 
-	<jsp:include page="../componentes/headContent.jsp"/>	
-	
+	<jsp:include page="../componentes/headContent.jsp"/>
+
 	<script>
-	
+
 		$(function() {
-		
+
 			$("#addAllSectionsToTopic").click(function() {
-				
-					
+
+
 				var r = confirm("Add all sections to a topic?");
 				if (r == true) {
 				    console.log("addAllSectionsToTopic");
-				    
+
 					var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/addSectionToTopic.jsp?addAllSections=1&sourceBean=search";
-					
+
 					$.ajax( url0 )
 					.done(function(data) {
 						$( "#dialogAddSectionToTopicTable" ).replaceWith(data);
@@ -34,17 +33,17 @@
 				  	.fail(function() {
 				    	console.error("Error calling: " + query);
 				  	});
-			  	
+
 				}
 
 			});
-			
+
 			$( ".addSectionToTopic" ).click(function() {
 				var sectionId = $( this ).data('section-id');
 				//console.log("addSectionToTopic. sectionId = " + sectionId);
-						
+
 				var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/addSectionToTopic.jsp?sectionId=" + sectionId + "&sourceBean=search";
-		
+
 				$.ajax( url0 )
 				.done(function(data) {
 					$( "#dialogAddSectionToTopicTable" ).replaceWith(data);
@@ -53,16 +52,16 @@
 			  	.fail(function() {
 			    	console.error("Error calling: " + query);
 			  	})
-					
+
 			});
-			
-			
+
+
 			var dialogAddSectionToTopic = $("#dialogAddSectionToTopic").dialog({
 				position: { my: "center", at: "top+400", of: window },	// TODO show dialog at cursor position?
 				autoOpen: false
-			});	  
-			
-		
+			});
+
+
 		    $( "#dialogMoreInfo" ).dialog({
 		        autoOpen: false,
 		        modal: true,
@@ -72,12 +71,12 @@
 		          duration: 1000
 		        }
 		      });
-		   
+
 			$( ".moreInfo" ).click(function() {
 				var sectionId = $( this ).data('section-id');
-				
+
 				var url0 = "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/sectionTableDetails.jsp?sectionId=" + sectionId;
-				
+
 				$.ajax( url0 )
 				.done(function(data) {
 					$( "#dialogMoreInfoTable" ).replaceWith(data);
@@ -86,11 +85,11 @@
 			  	.fail(function() {
 			    	console.error("Error calling: " + query);
 			  	})
-				
-				
-				
-		    });			
-			
+
+
+
+		    });
+
 			$("#searchTerm").autocomplete({
 				source : function(request, response) {
 					var radioButton0 = $("input[type='radio'][name='searchIn']:checked");
@@ -104,7 +103,86 @@
 							searchIn : searchInVal
 						},
 						success : function(data) {
-	
+
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});
+
+			$("#bookNameFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/bookNameAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});
+
+			$("#dynastyFilter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/dynastyAutocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+
+							response($.map(data, function(item) {
+								return {
+									label : item.name,
+									value : item.value,
+								}
+							}));
+						},
+						error : function(error) {
+							alert('error: ' + error);
+						}
+					});
+				},
+				minLength : 0
+			});
+
+
+			$("#level1Filter").autocomplete({
+				source : function(request, response) {
+					$.ajax({
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/level1Autocomplete.jsp",
+						type : "POST",
+						dataType : "json",
+						data : {
+							term : request.term
+						},
+						success : function(data) {
+
 							response($.map(data, function(item) {
 								return {
 									label : item.name,
@@ -119,44 +197,19 @@
 				},
 				minLength : 0
 			});
-			
-			$("#bookNameFilter").autocomplete({
+
+
+			$("#level2Filter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/bookNameAutocomplete.jsp",
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/level2Autocomplete.jsp",
 						type : "POST",
 						dataType : "json",
 						data : {
 							term : request.term
 						},
 						success : function(data) {
-	
-							response($.map(data, function(item) {
-								return {
-									label : item.name,
-									value : item.value,
-								}
-							}));
-						},
-						error : function(error) {
-							alert('error: ' + error);
-						}
-					});
-				},
-				minLength : 0
-			});	
-	
-			$("#dynastyFilter").autocomplete({
-				source : function(request, response) {
-					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/dynastyAutocomplete.jsp",
-						type : "POST",
-						dataType : "json",
-						data : {
-							term : request.term
-						},
-						success : function(data) {
-	
+
 							response($.map(data, function(item) {
 								return {
 									label : item.name,
@@ -170,20 +223,20 @@
 					});
 				},
 				minLength : 0
-			});	
-	
-			
-			$("#level1Filter").autocomplete({
+			});
+
+
+			$("#periodFilter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/level1Autocomplete.jsp",
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/periodAutocomplete.jsp",
 						type : "POST",
 						dataType : "json",
 						data : {
 							term : request.term
 						},
 						success : function(data) {
-	
+
 							response($.map(data, function(item) {
 								return {
 									label : item.name,
@@ -197,20 +250,20 @@
 					});
 				},
 				minLength : 0
-			});	
-			
+			});
 
-			$("#level2Filter").autocomplete({
+
+			$("#adminTypeFilter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/level2Autocomplete.jsp",
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/adminTypeAutocomplete.jsp",
 						type : "POST",
 						dataType : "json",
 						data : {
 							term : request.term
 						},
 						success : function(data) {
-	
+
 							response($.map(data, function(item) {
 								return {
 									label : item.name,
@@ -224,20 +277,19 @@
 					});
 				},
 				minLength : 0
-			});		
-			
-			
-			$("#periodFilter").autocomplete({
+			});
+
+			$("#sectionNameFilter").autocomplete({
 				source : function(request, response) {
 					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/periodAutocomplete.jsp",
+						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/sectionNameAutocomplete.jsp",
 						type : "POST",
 						dataType : "json",
 						data : {
 							term : request.term
 						},
 						success : function(data) {
-	
+
 							response($.map(data, function(item) {
 								return {
 									label : item.name,
@@ -251,62 +303,9 @@
 					});
 				},
 				minLength : 0
-			});	
-	
-			
-			$("#adminTypeFilter").autocomplete({
-				source : function(request, response) {
-					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/adminTypeAutocomplete.jsp",
-						type : "POST",
-						dataType : "json",
-						data : {
-							term : request.term
-						},
-						success : function(data) {
-	
-							response($.map(data, function(item) {
-								return {
-									label : item.name,
-									value : item.value,
-								}
-							}));
-						},
-						error : function(error) {
-							alert('error: ' + error);
-						}
-					});
-				},
-				minLength : 0
-			});		
-			
-			$("#sectionNameFilter").autocomplete({
-				source : function(request, response) {
-					$.ajax({
-						url : "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/sectionNameAutocomplete.jsp",
-						type : "POST",
-						dataType : "json",
-						data : {
-							term : request.term
-						},
-						success : function(data) {
-	
-							response($.map(data, function(item) {
-								return {
-									label : item.name,
-									value : item.value,
-								}
-							}));
-						},
-						error : function(error) {
-							alert('error: ' + error);
-						}
-					});
-				},
-				minLength : 0
-			});	
-			
-				
+			});
+
+
 			// enter pressed event, we don't want to always go to "search".
 			$(document).keypress(
 				function(event){
@@ -318,18 +317,18 @@
 								//console.log('filtering' + i);
 								setAction('filter', 'searchForm');
 								$("#searchForm").submit();
-								return false;		
+								return false;
 							}
-							
+
 						});
 				    }
 			});
-			
-			
-			
+
+
+
 		});
-		
-		
+
+
 	</script>
 </head>
 
@@ -339,29 +338,29 @@
 	<div id="dialogMoreInfo" title="Section Details">
 	  <div id="dialogMoreInfoTable"></div>
 	</div>
- 	
+
 	<div id="dialogAddSectionToTopic" title="Add Section(s) into Topic:">
 		<div id="dialogAddSectionToTopicTable"></div>
 	</div>
 
 	<div id="page">
-	
+
 		<% if (sessionBean.getUser() == null) { %>
 			<label class="subTitel">You must login!</label>
 		<%} else if (sessionBean.getSearchPage().getSearchIn() == null) { %>
 			<label class="subTitel">The searchPage().getSearchIn() is null.</label>
-			
+
 		<% } else { %>
-				
+
 			<label class="subTitel">Search for Sections</label>
-			
+
 			<form name="searchForm" id="searchForm"
 				action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 				method="post"
 				class="contentForm">
-				<input name="bean" type="hidden" value="searchBean" /> 
-				
-				
+				<input name="bean" type="hidden" value="searchBean" />
+
+
 				<table style="width: 300px; margin-left: auto;margin-right: auto;">
 					<tr>
 						<td>
@@ -370,11 +369,11 @@
 								name="searchTerm"
 								type="text"
 								class="searchInput"
-								value="<%=sessionBean.getSearchPage().getSearchTerm()%>" />				
+								value="<%=sessionBean.getSearchPage().getSearchTerm()%>" />
 						</td>
 						<td>
 							<input
-								type="image" 
+								type="image"
 								onclick="setAction('search', 'searchForm');"
 								src="<%=sessionBean.getApplicationBean().getSearchImage()%>"/>
 						</td>
@@ -384,21 +383,20 @@
 							<label>Search in:</label>
 							<input type="radio" name="searchIn" value="0" <%= (sessionBean.getSearchPage().getSearchIn() == 0) ? "checked" : "" %>/><label>Section Name</label>
 							<input type="radio" name="searchIn" value="1" <%= (sessionBean.getSearchPage().getSearchIn() == 1) ? "checked" : "" %>/><label>Book Name</label>
-							
+
 						</td>
 					</tr>
 					<tr><td><label class="label"><%= (StringUtils.isNotEmpty(sessionBean.getSearchPage().getSearchMessage())) ? sessionBean.getSearchPage().getSearchMessage() : ""%></label></td></tr>
 					<tr><td><label class="label"><%= (StringUtils.isNotEmpty(sessionBean.getSearchPage().getFilteringMessage())) ? sessionBean.getSearchPage().getFilteringMessage() : ""%></label></td></tr>
 				</table>
-		
-		
+
+
 				<% if (sessionBean.getSearchPage().getCompleteSectionList() != null) { %>
-		
-		
+
 					<jsp:include page="../componentes/paginator.jsp">
 						<jsp:param name="formName" value="searchForm"/>
-					</jsp:include> 
-						
+					</jsp:include>
+
 					<div class="tableDiv double-scroll">
 						<table class="pageTable">
 							<tbody>
@@ -410,14 +408,14 @@
 												<td>
 													<table>
 														<tr><td>
-															<input type="image" 
+															<input type="image"
 																onclick="setAction('sortByBookIdUp', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
 														</td></tr>
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByBookIdDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -433,12 +431,12 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByBookNameUp', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
 														</td></tr>
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByBookNameDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																	
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -446,14 +444,14 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="bookNameFilter" id="bookNameFilter" value="<%= sessionBean.getSearchPage().getBookNameFilter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
+												</td>
 											</tr>
-										</table>					
+										</table>
 									</th>
 									<th>
 										<table class="sortTable">
@@ -469,7 +467,7 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByLevel1Down', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -477,17 +475,17 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="level1Filter" id="level1Filter" value="<%= sessionBean.getSearchPage().getLevel1Filter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
-											</tr>								
-										</table>	
+												</td>
+											</tr>
+										</table>
 									</th>
 									<th>
-										
+
 										<table class="sortTable">
 											<tr>
 												<td><label class="tableTitle">Level 2</label></td>
@@ -501,7 +499,7 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByLevel2Down', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -509,15 +507,15 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="level2Filter" id="level2Filter" value="<%= sessionBean.getSearchPage().getLevel2Filter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
-											</tr>								
+												</td>
+											</tr>
 										</table>
-									
+
 									</th>
 									<th>
 										<table class="sortTable">
@@ -533,7 +531,7 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByDynastyDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -541,14 +539,14 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="dynastyFilter" id="dynastyFilter" value="<%= sessionBean.getSearchPage().getDynastyFilter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
+												</td>
 											</tr>
-										</table>					
+										</table>
 									</th>
 									<th>
 										<table class="sortTable">
@@ -559,12 +557,12 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByPeriodUp', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
 														</td></tr>
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByPeriodDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -572,14 +570,14 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="periodFilter" id="periodFilter" value="<%= sessionBean.getSearchPage().getPeriodFilter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
+												</td>
 											</tr>
-										</table>						
+										</table>
 									</th>
 									<th>
 										<table class="sortTable">
@@ -595,7 +593,7 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByAdminTypeDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -603,14 +601,45 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="adminTypeFilter" id="adminTypeFilter" value="<%= sessionBean.getSearchPage().getAdminTypeFilter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
-											</tr>								
-										</table>	
+												</td>
+											</tr>
+										</table>
+									</th>
+									<th>
+										<table class="sortTable">
+											<tr>
+												<td><label class="tableTitle">Source</label></td>
+												<td>
+													<table>
+														<tr><td>
+															<input type="image"
+																onclick="setAction('sortBySourceUp', 'searchForm');"
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
+														</td></tr>
+														<tr><td>
+															<input type="image"
+																onclick="setAction('sortBySourceDown', 'searchForm');"
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
+														</td></tr>
+													</table>
+												</td>
+											</tr>
+											<tr>
+												<td>
+													<input type="text" class="filterInput" name="sourceFilter" id="sourceFilter" value="<%= sessionBean.getSearchPage().getSourceFilter()%>"/>
+												</td>
+												<td>
+													<input type="image"
+														onclick="setAction('filter', 'searchForm');"
+														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+												</td>
+											</tr>
+										</table>
 									</th>
 									<th>
 										<table class="sortTable">
@@ -621,12 +650,12 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortBySectionNameUp', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
 														</td></tr>
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortBySectionNameDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
@@ -634,14 +663,14 @@
 											<tr>
 												<td>
 													<input type="text" class="filterInput" name="sectionNameFilter" id="sectionNameFilter" value="<%= sessionBean.getSearchPage().getSectionNameFilter()%>"/>
-												</td>									
+												</td>
 												<td>
 													<input type="image"
 														onclick="setAction('filter', 'searchForm');"
 														src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
-												</td>							
-											</tr>	
-										</table>	
+												</td>
+											</tr>
+										</table>
 									</th>
 									<th>
 										<table class="sortTable">
@@ -652,40 +681,43 @@
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByStartPageUp', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
+																src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
 														</td></tr>
 														<tr><td>
 															<input type="image"
 																onclick="setAction('sortByStartPageDown', 'searchForm');"
-																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
+																src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>
 														</td></tr>
 													</table>
 												</td>
 											</tr>
-										</table>							
-									
+										</table>
+
 									</th>
 									<th><label class="tableTitle">Load Text</label></th>
-									
+
 									<th>
 										<label class="tableTitle">Add to Topic</label>
-										
+
 										<img id="addAllSectionsToTopic" width="15" height="15" title="Add all sections to Topic" src="<%=sessionBean.getApplicationBean().getPlusImage()%>">
-										
-										
+
+
 									</th>
 									<th><label class="tableTitle">Existing Tasks</label></th>
 								</tr>
-							
-				
-								<% 
+
+								<%
+								long userId = sessionBean.getUser().getId();
+		 					  long userDefaultTopicId = sessionBean.getTopicListPage().getDefaultTopicId(userId);
+		 					  String extractionInterfaceUrl = sessionBean.getApplicationBean().getExtractionInterfaceUrl();
+
 								for (DBSection section : sessionBean.getSearchPage().getDisplaySectionList()) {
 								%>
 								<tr>
 									<td>
 										<a href="<%=sessionBean.getApplicationBean().getTocInterfaceUrl()%>/check_sections_details.php?book_id=<%=section.getBook().getId() %>&amp;count=100&amp;sessionId=<%= session.getId()%>" target="blank">
 											<%=section.getBook().getId()%>
-										</a>	
+										</a>
 										<img title="More Information" src="<%=sessionBean.getApplicationBean().getMoreInfoImage()%>" data-section-id="<%=section.getId()%>" class="moreInfo"/>
 									</td>
 									<td><%=section.getBook().getName()%></td>
@@ -694,27 +726,28 @@
 									<td><%=section.getBook().getDynasty()%></td>
 									<td><%=section.getBook().getPeriod()%></td>
 									<td><%=section.getBook().getAdmin_type() %></td>
+									<td><%=section.getBook().getSource() %></td>
 									<td><%=section.getName()%></td>
 									<td><%=section.getPages()%></td>
-									
-									
+
+
 									<!-- View text in Ext-Interface -->
 									<td>
 										<a href="#"
 											title="Show Section in Extraction Interface"
-										 	onclick="sectionInExtractionInterface('<%=section.getId() %>', '<%=section.getName() %>', '<%=section.getBook().getId() %>', '<%=section.getBook().getName() %>', '<%=sessionBean.getTopicListPage().getCompleteTopicList().get(0).getId() %>', '<%=sessionBean.getUser().getId() %>','<%=sessionBean.getApplicationBean().getExtractionInterfaceUrl()%>');">
-										 	
+										 	onclick="sectionInExtractionInterface('<%=section.getId() %>', '<%=section.getName() %>', '<%=section.getBook().getId() %>', '<%=section.getBook().getName() %>', '<%=userDefaultTopicId %>', '<%=userId %>','<%=extractionInterfaceUrl%>');">
+
 										 	<img title="Show Section in Extraction Interface" src="<%=sessionBean.getApplicationBean().getShowImage()%>">
 										</a>
-										
+
 									</td>
-									
+
 									<!-- Add to Topic -->
 									<td style="max-width:300px;">
 										<!-- existing topic -->
 										<% if(section.getTopicSectionRelation() != null && !section.getTopicSectionRelation().isEmpty()) { %>
 											<lable>Already in topic: </lable>
-											<table style="width:100%">		
+											<table style="width:100%">
 												<% for(LGTopicSectionRelation relation : section.getTopicSectionRelation()) { %>
 													<tr>
 														<td>
@@ -723,23 +756,23 @@
 															</table>
 														</td>
 														<td style="max-width:150px">
-															
+
 															<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/topicPage.jsp?topicId=<%=relation.getTopicId() %>" >
 																<img title="Manage Topic" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
-															</a>												
-															
+															</a>
+
 														</td>
 													</tr>
 												<% } %>
 											</table>
 										<% } %>
-										
+
 										<img width="10" height="10" title="Add the section to Topic" src="<%=sessionBean.getApplicationBean().getPlusImage()%>" data-section-id="<%=section.getId()%>" class="addSectionToTopic">
-									
-									
+
+
 									</td>
-									
-									
+
+
 									<!-- Existing Tasks -->
 									<td style="max-width:300px;">
 										<% if(section.getBranches() != null && !section.getBranches().isEmpty()) { %>
@@ -756,7 +789,7 @@
 															<% if (branch.hasContributor(sessionBean.getUser().getId())) { %>
 															<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/pages/branchPage.jsp?branchId=<%=branch.getId() %>" >
 																<img title="Manage Branch" src="<%=sessionBean.getApplicationBean().getEditBranchImage()%>"/>
-															</a>												
+															</a>
 															<% } else { %>
 																<label>Contributors: <%=branch.getContributorsNameList() %></label>
 															<% } %>
@@ -766,25 +799,25 @@
 											</table>
 										<% } %>
 									</td>
-					
+
 								</tr>
 								<% } %>
 							</tbody>
 						</table>
-				
-						
+
+
 					<% } %>
-					
+
 					</div>
-					
+
 					<jsp:include page="../componentes/paginator.jsp">
 						<jsp:param name="formName" value="searchForm"/>
-					</jsp:include> 
-				
+					</jsp:include>
+
 			</form>
 
 		<% } %>
-		
+
 	</div>
 
 </body>