Browse Source

Выпадающие списки подправлены

Кинетик 5 years ago
parent
commit
e1f1cc7a9f

+ 4 - 0
.idea/artifacts/MephorceAuth_war_exploded.xml

@@ -12,6 +12,10 @@
           <element id="library" level="project" name="Spring MVC-4.3.4.RELEASE" />
           <element id="library" level="project" name="Hibernate 5.2.3-5.2.3" />
           <element id="library" level="project" name="com.mysql.jdbc_5.1.5" />
+          <element id="library" level="project" name="jstl-1.2" />
+          <element id="library" level="project" name="gson-2.2.2" />
+          <element id="library" level="project" name="jstl" />
+          <element id="library" level="project" name="com.fasterxml.jackson.core:jackson-core:2.8.5" />
         </element>
       </element>
     </root>

+ 6 - 0
.idea/jsLibraryMappings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptLibraryMappings">
+    <file url="PROJECT" libraries="{jQuery-2.0.0}" />
+  </component>
+</project>

+ 10 - 0
.idea/libraries/com_fasterxml_jackson_core_jackson_core_2_8_5.xml

@@ -0,0 +1,10 @@
+<component name="libraryTable">
+  <library name="com.fasterxml.jackson.core:jackson-core:2.8.5" type="repository">
+    <properties maven-id="com.fasterxml.jackson.core:jackson-core:2.8.5" />
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/jackson-core-2.8.5.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 9 - 0
.idea/libraries/gson_2_2_2.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="gson-2.2.2">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/gson-2.2.2.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 4 - 0
MephorceAuth.iml

@@ -48,5 +48,9 @@
     <orderEntry type="library" name="Hibernate 5.2.3-5.2.3" level="project" />
     <orderEntry type="library" name="com.mysql.jdbc_5.1.5" level="project" />
     <orderEntry type="library" name="jstl-1.2" level="project" />
+    <orderEntry type="library" name="gson-2.2.2" level="project" />
+    <orderEntry type="library" name="jQuery-2.0.0" level="application" />
+    <orderEntry type="library" name="jstl" level="project" />
+    <orderEntry type="library" name="com.fasterxml.jackson.core:jackson-core:2.8.5" level="project" />
   </component>
 </module>

BIN
lib/gson-2.2.2.jar


BIN
lib/jackson-core-2.8.5.jar


BIN
lib/jstl.jar


+ 13 - 4
src/controller/controller.java

@@ -7,6 +7,7 @@ import HibernateEntities.StudentsEntity;
 import HibernateEntities.UsersEntity;
 import LoginEntities.LoginClient;
 import LoginEntities.LoginUser;
+import com.google.gson.Gson;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
@@ -62,8 +63,6 @@ public class controller {
                     return mvClient;
                 } else {
                     mvUsers.addObject("message","");
-                    List<GroupsEntity> groupList = getGroupList();
-                    mvStudent.addObject("groupList",groupList);
                     mvStudent.addObject("studentLogin", new LoginClient());
                     return mvStudent;
                 }
@@ -117,9 +116,19 @@ public class controller {
     }
     @RequestMapping(value = "/loadStudents", method = RequestMethod.GET)
     public @ResponseBody
-    List<StudentsEntity> loadStudents(@RequestParam(value = "groupId", required = true) Integer groupId) throws IllegalStateException {
+    Set<StudentsEntity> loadStudents(@RequestParam(value = "groupId", required = true) Integer groupId) throws IllegalStateException {
         List<StudentsEntity> stList = loadStudent(groupId);
-        return stList;
+        return new HashSet<>(stList);
+    }
+    @RequestMapping(value = "/loadGroups", method = RequestMethod.GET)
+    public @ResponseBody
+    Set<GroupsEntity> loadGroups(){
+        List<GroupsEntity> groupList = getGroupList();
+        return new HashSet<>(groupList);
+    }
+    @RequestMapping(value = "/checkStudent", method = RequestMethod.GET)
+    public ModelAndView checkStudent(@ModelAttribute("studentLogin") LoginClient student){
+        return mvUsers;
     }
     @RequestMapping(value="/aboutUs")
     public ModelAndView aboutUs(){

File diff suppressed because it is too large
+ 4 - 0
web/WEB-INF/lib/jquery-3.1.1.min.js


+ 62 - 27
web/WEB-INF/views/loginViews/studentBar.jsp

@@ -19,29 +19,63 @@
         <%@include file="../cssforpr.css" %>
         <%@include file="../bootstrap.min.css" %>
     </style>
-</head>
-<script type="text/javascript" charset="utf-8">
-    $("select#groupId").change(function(){
-        $.getJSON("/loadStudents",{groupId: $(this).val()}, function(j){
-            var options = '';
-            for (var i = 0; i < j.length; i++) {
-                options += '<option value="' + j[i].stFamily + '">' + j[i].stFamily + '</option>';
-            }
-            $("select#studentId").html(options);
-        });
-    });
+    <script type="text/javascript"
+            src="<c:url value='/WEB-INF/lib/jquery-3.1.1.min.js' />"></script>
 
-    $("select#groupId").change(function(){
-        $.getJSON("/loadStudents",{groupId: $(this).val()}, function(j){
-            var options = '';
-            for (var i = 0; i < j.length; i++) {
-                options += '<option value="' + j[i].stFamily + '">' + j[i].stFamily + '</option>';
-            }
-            $("select#studentId").html(options);
+    <c:url var="getGroups" value="/loadGroups" />
+    <script type="text/javascript">
+        $(document).ready(
+            function() {
+                $.getJSON('${getGroups}', {
+                    ajax : 'true'
+                }, function(data) {
+                    var html = '<option value="">Выберите группу</option>';
+                    var len = data.length;
+                    for ( var i = 0; i < len; i++) {
+                        html += '<option value="' + data[i].groupId + '">'
+                            + data[i].groupName + '</option>';
+                    }
+                    html += '</option>';
+                    $('select#IdGroupPart').html(html);
+                });
+            });
+    </script>
+
+    <c:url var="getStudents" value="/loadStudents" />
+    <script type="text/javascript">
+        $(document).ready(function() {
+            $('#IdGroupPart').change(
+                function() {
+                    $.getJSON('${getStudents}', {
+                        groupId : $(this).val(),
+                        ajax : 'true'
+                    }, function(data) {
+                        var html = '<option value="">Выберите студента</option>';
+                        var len = data.length;
+                        for ( var i = 0; i < len; i++) {
+                            html += '<option value="' + data[i].studentsId + '">'
+                                + data[i].stFamily + '</option>';
+                        }
+                        html += '</option>';
+                        $('#IdStudentPart').html(html);
+                    });
+                });
         });
-    });
 </script>
-
+    <script type="text/javascript">
+        $(document).ready(function(){
+            $("#IdStudentPart").change(onSelectChange);
+        });
+        function onSelectChange() {
+            var selected = $("#IdStudentPart option:selected");
+            var output = "";
+            if(selected.val() != 0){
+                output = "Вы выбрали студента " + selected.text();
+            }
+            $("#output").html(output);
+        }
+    </script>
+</head>
 <body>
 
 <div class="inner">
@@ -58,15 +92,16 @@
 <div class="login-block">
 
     <h1>Вход как Исполнитель</h1>
-    <form:form method="post" modelAttribute="studentLogin" action="checkStudent">
-        <form:select id="groupId" path="">
-            <c:forEach items="${groupList}" var="group">
-                <form:option value="${group.groupId}" >${group.groupName}</form:option>
-            </c:forEach><br/>
+    <div id="output"></div>
+    <c:url value="checkStudent" var="checkStudentUrl" />
+    <form:form id="signUp" method="post" modelAttribute="studentLogin" action="${checkStudentUrl}">
+    <fieldset>
+        <form:select id="IdGroupPart" path="">
         </form:select>
-        <form:select id="studentId" path="name">
-            <form:option value="${group.groupId}" >${group.groupName}</form:option>
+        <form:select id="IdStudentPart" path="name">
+            <form:option value="">Выберите студента</form:option>
         </form:select>
+    </fieldset>
         <form:input path="password" type="password" value="" placeholder="Пароль" id="password"/>${passMessage}<br/>
         <form:button>Войти</form:button>
     </form:form>