commit 309935161a1825f271840831e83a75a4c68a09c2
Author: Tomáš Šimandl <tomas.simandl@gmail.com>
Date:   Mon Aug 27 11:32:49 2018 +0200

    Added save button

diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/ShowGraph.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/ShowGraph.java
index 70ab77e..db06129 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/ShowGraph.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/ShowGraph.java
@@ -25,19 +25,33 @@ public class ShowGraph extends HttpServlet {
 
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-    	// render
+        // should save button be displayed?
+        Integer loggedUserId = (Integer) request.getSession().getAttribute("logged_user_id");
+        String diagramIdStr = request.getParameter("diagramId");
+
+        boolean showSaveButton  = loggedUserId != null;
+
+        if (showSaveButton && diagramIdStr != null){
+            Integer diagramId = Integer.parseInt(diagramIdStr);
+
+            DB db = new DB(getServletContext());
+            Diagram diagram = new Diagram(db, diagramId);
+
+            showSaveButton = diagram.getUserId() == loggedUserId;
+        }
+
+        request.setAttribute("show_icon_save", showSaveButton);
+
+
+        // render
         RequestDispatcher rd = getServletContext().getRequestDispatcher("/showGraph.jsp");
         rd.forward(request, response);
     }
 
+    /*
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-        // should save button be displayed?
-		boolean showSaveButton = request.getParameter("diagram_id") != null && request.getParameter("diagram_hash") != null;
-		request.setAttribute("show_icon_save", showSaveButton);
-
 
-/*
 		// is it only a demo diagram?
 		if (request.getParameter("demo_id") != null) {
 			request.getSession().setAttribute("demo_id", request.getParameter("demo_id"));
@@ -142,10 +156,11 @@ public class ShowGraph extends HttpServlet {
 			}
 
 			request.getSession().setAttribute("id_diagram", request.getParameter("id_diagram"));
-        }*/
+        }
 
         // render
 		RequestDispatcher rd = getServletContext().getRequestDispatcher("/showGraph.jsp");
 		rd.forward(request, response);
     }
+    */
 }
diff --git a/sources/src/main/webapp/logged_user_menu.jsp b/sources/src/main/webapp/logged_user_menu.jsp
index 70c376f..68ddf02 100644
--- a/sources/src/main/webapp/logged_user_menu.jsp
+++ b/sources/src/main/webapp/logged_user_menu.jsp
@@ -7,7 +7,7 @@
 	<ul>	
 		<c:forEach items="${diagramNames}" var="diagramName">
 			<li id="diagram_id_${diagramName.id}">
-				<a href="/graph?diagramId=${diagramNames.id}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
+				<a href="/graph?diagramId=${diagramName.id}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
 			</li>
 		</c:forEach>
 		<li id="diagram_id_new">
diff --git a/sources/src/main/webapp/showGraph.jsp b/sources/src/main/webapp/showGraph.jsp
index ed9ba56..cc3aa2f 100644
--- a/sources/src/main/webapp/showGraph.jsp
+++ b/sources/src/main/webapp/showGraph.jsp
@@ -1,4 +1,5 @@
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 <%@page import="java.util.Map"%>
 <%@page import="com.google.gson.Gson"%>
 <%@page import="com.google.gson.GsonBuilder"%>
@@ -164,6 +165,13 @@
 								<img src="images/png_save.png" id="applyLayoutImg" alt="Save diagram as PNG.">
 							</button>
 						</li>
+						<c:if test="${show_icon_save}">
+							<li>
+								<button class="btn save-diagram" id="btnSaveDiagramToDb" title="Save diagram.">
+									<img src="images/icon_save.png" id="applyLayoutImg" alt="Save diagram">
+								</button>
+							</li>
+						</c:if>
 						<li>
 							<hr class="navbar-separator">
 						</li>
