Mercurial > hg > LGServices
changeset 22:2c6f44ef34ab
new: add comment textarea
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 23 Jun 2015 16:18:52 +0200 |
parents | 5b1856cd6b4f |
children | dcc160f7db38 |
files | src/main/java/de/mpiwg/gazetteer/utils/DBService.java src/main/java/de/mpiwg/web/jsp/BooksPage.java src/main/webapp/pages/books.jsp |
diffstat | 3 files changed, 54 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Tue Jun 23 14:20:36 2015 +0200 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Tue Jun 23 16:18:52 2015 +0200 @@ -705,5 +705,27 @@ } + + public void updateComment(String bookId, String comment) throws SQLException { + Connection conn = null; + Statement stmt = null; + + try { + String query = "UPDATE books SET comments='"+ comment + "' WHERE id='" + bookId + "'"; + conn = getNewConnection(); + stmt = conn.createStatement(); + int rs = stmt.executeUpdate(query); + + } catch (Exception e) { + e.printStackTrace(); + }finally{ + conn.close(); + } + + DBBook book = this.bookMap.get(bookId); + book.setComments(comment); + + + } }
--- a/src/main/java/de/mpiwg/web/jsp/BooksPage.java Tue Jun 23 14:20:36 2015 +0200 +++ b/src/main/java/de/mpiwg/web/jsp/BooksPage.java Tue Jun 23 16:18:52 2015 +0200 @@ -56,10 +56,8 @@ private String periodFilter = new String(); private String editionFilter = new String(); - private String filteringMessage; - public void loadParameters(HttpServletRequest request, HttpServletResponse response){ this.request = request; @@ -73,7 +71,7 @@ this.level2Filter = getParameter("level2Filter"); this.periodFilter = getParameter("periodFilter"); this.editionFilter = getParameter("editionFilter"); - + } @@ -262,7 +260,7 @@ e.printStackTrace(); } - logger.debug("toc_correction:"+DBService.getInstance().getBook(tocBookId).getTocCorrection()); + //logger.debug("toc_correction:"+DBService.getInstance().getBook(tocBookId).getTocCorrection()); } @@ -282,8 +280,20 @@ } public void saveComment() { - // TODO Auto-generated method stub - logger.debug("saveComment"); + + String bookComment = getParameter("bookComment"); + String currentBookId = getParameter("currentBookId"); + + logger.debug("saveComment. currentBookId=" + currentBookId + ", bookComment: "+ bookComment); + + try { + DBService.getInstance().updateComment(currentBookId, bookComment); + + } catch (Exception e) { + addMsg("There is an internal error: " + e.getLocalizedMessage()); + e.printStackTrace(); + } + }
--- a/src/main/webapp/pages/books.jsp Tue Jun 23 14:20:36 2015 +0200 +++ b/src/main/webapp/pages/books.jsp Tue Jun 23 16:18:52 2015 +0200 @@ -13,28 +13,17 @@ <jsp:include page="../componentes/headContent.jsp"/> <script> - // TODO delete this function - function setTocComment(t) { + + function setComment(t) { var notes = t.value; - var bookId = t.name; - console.log(notes); - console.log(bookId); - $.ajax({ - url: "<%=sessionBean.getApplicationBean().getRootServer()%>/methods/setTocComment.jsp", - type: 'POST', - dataType : 'json', - data : { - bookId : bookId, - notes : notes - }, - success: function(data){ - console.log("You've updated the comments of book: " + data); - }, - error: function(error) { - console.log("error to update toc comments"+ error); - alert('You have NOT updated the status of book. If this issue remains, please contact us. Thanks.'); - } - }); + //var bookId = t.name; + + var theForm = document.forms['booksForm']; + var input = document.createElement('input'); + input.type = 'hidden'; + input.name = 'bookComment'; + input.value = notes; + theForm.appendChild(input); } </script> @@ -449,17 +438,12 @@ <td><%= (book.getCurrentSectionVersion() == null) ? "" : book.getCurrentSectionVersion().getEditor() %></td> <td><%= (book.getCurrentSectionVersion() == null) ? "" : book.getCurrentSectionVersion().getDate() %></td> - <td> - <!-- - <div> - <textarea rows="2" cols="15" maxlength="100" name=<%=book.getId() %> > <%= book.getComments() %></textarea> - - <input type="image" alt="save comments" - onclick="setAction0('saveComment', 'booksForm', 'bookId', '<%=book.getId()%>');" - src="<%=sessionBean.getApplicationBean().getSaveImage()%>" width="20" height="20"/> - - </div> - --> + <td> + <textarea rows="2" cols="15" maxlength="100" name='<%=book.getId()%>' onchange="setComment(this)" ><%=book.getComments()%></textarea> + <input type="image" alt="save comment" + onclick="setAction0('saveComment', 'booksForm', 'currentBookId', '<%=book.getId()%>');" + src="<%=sessionBean.getApplicationBean().getSaveImage()%>" width="20" height="20"/> + </td> </tr>