├── target ├── spring-mvc-app │ ├── WEB-INF │ │ ├── lib │ │ │ ├── jstl-1.2.jar │ │ │ ├── jsp-api-2.2.jar │ │ │ ├── hsqldb-2.3.3.jar │ │ │ ├── spring-aop-5.3.20.jar │ │ │ ├── spring-core-5.3.20.jar │ │ │ ├── spring-jcl-5.3.20.jar │ │ │ ├── spring-web-5.3.20.jar │ │ │ ├── spring-beans-5.3.20.jar │ │ │ ├── spring-context-5.3.20.jar │ │ │ ├── spring-webmvc-5.3.20.jar │ │ │ ├── spring-tx-4.2.4.RELEASE.jar │ │ │ ├── javax.annotation-api-1.3.2.jar │ │ │ ├── spring-expression-5.3.20.jar │ │ │ └── spring-jdbc-4.2.4.RELEASE.jar │ │ ├── classes │ │ │ ├── com │ │ │ │ └── arseniisemenov │ │ │ │ │ └── springapp │ │ │ │ │ ├── models │ │ │ │ │ └── User.class │ │ │ │ │ └── controllers │ │ │ │ │ ├── UserMapper.class │ │ │ │ │ ├── DBController$1.class │ │ │ │ │ ├── DBController$2.class │ │ │ │ │ ├── DBController.class │ │ │ │ │ ├── DataController.class │ │ │ │ │ └── HomeController.class │ │ │ ├── test-data.sql │ │ │ ├── dbschema.sql │ │ │ └── util.properties │ │ ├── views │ │ │ ├── about │ │ │ │ └── about.jsp │ │ │ ├── error │ │ │ │ └── errorpage.jsp │ │ │ ├── create │ │ │ │ └── create.jsp │ │ │ ├── user │ │ │ │ └── user.jsp │ │ │ ├── edit │ │ │ │ └── edit.jsp │ │ │ └── index.jsp │ │ ├── web.xml │ │ ├── config │ │ │ └── applicationContextMVC.xml │ │ └── tags │ │ │ └── template.tag │ ├── META-INF │ │ └── MANIFEST.MF │ └── resources │ │ ├── css │ │ └── modern-business.css │ │ └── js │ │ ├── contact_me.js │ │ ├── bootstrap.min.js │ │ └── jqBootstrapValidation.js └── classes │ ├── com │ └── arseniisemenov │ │ └── springapp │ │ ├── models │ │ └── User.class │ │ └── controllers │ │ ├── DBController.class │ │ ├── UserMapper.class │ │ ├── DBController$1.class │ │ ├── DBController$2.class │ │ ├── DataController.class │ │ └── HomeController.class │ ├── test-data.sql │ ├── dbschema.sql │ └── util.properties ├── .idea ├── .gitignore ├── encodings.xml ├── webContexts.xml ├── compiler.xml ├── misc.xml ├── jarRepositories.xml └── uiDesigner.xml ├── src └── main │ ├── java │ └── com │ │ └── arseniisemenov │ │ └── springapp │ │ ├── controllers │ │ ├── HomeController.java │ │ ├── DataController.java │ │ └── DBController.java │ │ └── models │ │ └── User.java │ ├── resources │ ├── test-data.sql │ ├── dbschema.sql │ └── util.properties │ └── webapp │ ├── WEB-INF │ ├── views │ │ ├── about │ │ │ └── about.jsp │ │ ├── error │ │ │ └── errorpage.jsp │ │ ├── create │ │ │ └── create.jsp │ │ ├── user │ │ │ └── user.jsp │ │ ├── index.jsp │ │ └── edit │ │ │ └── edit.jsp │ ├── web.xml │ ├── config │ │ └── applicationContextMVC.xml │ └── tags │ │ └── template.tag │ └── resources │ ├── css │ └── modern-business.css │ └── js │ ├── contact_me.js │ ├── bootstrap.min.js │ └── jqBootstrapValidation.js └── pom.xml /target/spring-mvc-app/WEB-INF/lib/jstl-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/jstl-1.2.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/jsp-api-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/jsp-api-2.2.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/hsqldb-2.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/hsqldb-2.3.3.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-aop-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-aop-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-core-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-core-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-jcl-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-jcl-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-web-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-web-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-beans-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-beans-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-context-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-context-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-webmvc-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-webmvc-5.3.20.jar -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/models/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/models/User.class -------------------------------------------------------------------------------- /target/spring-mvc-app/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: IntelliJ IDEA 3 | Built-By: arsenijsemenov 4 | Build-Jdk: Oracle OpenJDK version 17.0.2 5 | 6 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-tx-4.2.4.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-tx-4.2.4.RELEASE.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/javax.annotation-api-1.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/javax.annotation-api-1.3.2.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-expression-5.3.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-expression-5.3.20.jar -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/lib/spring-jdbc-4.2.4.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/lib/spring-jdbc-4.2.4.RELEASE.jar -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/DBController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/DBController.class -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/UserMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/UserMapper.class -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/DBController$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/DBController$1.class -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/DBController$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/DBController$2.class -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/DataController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/DataController.class -------------------------------------------------------------------------------- /target/classes/com/arseniisemenov/springapp/controllers/HomeController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/classes/com/arseniisemenov/springapp/controllers/HomeController.class -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/models/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/models/User.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/UserMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/UserMapper.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController$1.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController$2.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DBController.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DataController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/DataController.class -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/HomeController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonamenko/Java_Meeting_7/HEAD/target/spring-mvc-app/WEB-INF/classes/com/arseniisemenov/springapp/controllers/HomeController.class -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/webContexts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/com/arseniisemenov/springapp/controllers/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.arseniisemenov.springapp.controllers; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | @GetMapping("/about") 9 | public String About() { 10 | return "about/about"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /target/classes/test-data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Арсений Семенов','+380123456789', 'testemail@gmail.com', 'blog.com.ua', 'Good Person'); 2 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Вася Пупкин','+380123456789', 'testemail2@gmail.com', 'blog2.com.ua', null); 3 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Петя Пупкин','+380123456789', 'testemail3@gmail.com', null, 'Good Worker'); 4 | -------------------------------------------------------------------------------- /src/main/resources/test-data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Арсений Семенов','+380123456789', 'testemail@gmail.com', 'blog.com.ua', 'Good Person'); 2 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Вася Пупкин','+380123456789', 'testemail2@gmail.com', 'blog2.com.ua', null); 3 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Петя Пупкин','+380123456789', 'testemail3@gmail.com', null, 'Good Worker'); 4 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/test-data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Арсений Семенов','+380123456789', 'testemail@gmail.com', 'blog.com.ua', 'Good Person'); 2 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Вася Пупкин','+380123456789', 'testemail2@gmail.com', 'blog2.com.ua', null); 3 | INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES ('Петя Пупкин','+380123456789', 'testemail3@gmail.com', null, 'Good Worker'); 4 | -------------------------------------------------------------------------------- /target/classes/dbschema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS AUTHORITIES; 2 | DROP TABLE IF EXISTS USER; 3 | DROP TABLE IF EXISTS LOG; 4 | 5 | --USER TABLE 6 | CREATE TABLE IF NOT EXISTS USER ( 7 | ID INT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL PRIMARY KEY, 8 | NAME VARCHAR(255) NOT NULL, 9 | PHONE VARCHAR(255) NOT NULL, 10 | EMAIL VARCHAR(255) NOT NULL, 11 | BLOG VARCHAR(255), 12 | NOTE VARCHAR(255) 13 | ); 14 | 15 | -------------------------------------------------------------------------------- /src/main/resources/dbschema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS AUTHORITIES; 2 | DROP TABLE IF EXISTS USER; 3 | DROP TABLE IF EXISTS LOG; 4 | 5 | --USER TABLE 6 | CREATE TABLE IF NOT EXISTS USER ( 7 | ID INT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL PRIMARY KEY, 8 | NAME VARCHAR(255) NOT NULL, 9 | PHONE VARCHAR(255) NOT NULL, 10 | EMAIL VARCHAR(255) NOT NULL, 11 | BLOG VARCHAR(255), 12 | NOTE VARCHAR(255) 13 | ); 14 | 15 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/dbschema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS AUTHORITIES; 2 | DROP TABLE IF EXISTS USER; 3 | DROP TABLE IF EXISTS LOG; 4 | 5 | --USER TABLE 6 | CREATE TABLE IF NOT EXISTS USER ( 7 | ID INT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL PRIMARY KEY, 8 | NAME VARCHAR(255) NOT NULL, 9 | PHONE VARCHAR(255) NOT NULL, 10 | EMAIL VARCHAR(255) NOT NULL, 11 | BLOG VARCHAR(255), 12 | NOTE VARCHAR(255) 13 | ); 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/about/about.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | About 11 | 12 | 13 |

About Page

14 |
15 | 16 |
17 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/error/errorpage.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Error 11 | 12 | 13 |

Error page

14 |
15 | 16 |
17 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/about/about.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | About 11 | 12 | 13 |

About Page

14 |
15 | 16 |
17 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/error/errorpage.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Error 11 | 12 | 13 |

Error page

14 |
15 | 16 |
17 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /target/classes/util.properties: -------------------------------------------------------------------------------- 1 | site.maintenance=false 2 | 3 | #MYSQL Specific properties 4 | jdbc.driverClass=com.mysql.jdbc.Driver 5 | jdbc.url=jdbc:mysql://127.0.0.1/ 6 | jdbc.username=production username 7 | jdbc.password=production password 8 | 9 | #HSQLDB Specific properties 10 | jdbc.hsqldb.driverClass=org.hsqldb.jdbcDriver 11 | jdbc.hsqldb.url=jdbc:hsqldb:mem://localhost 12 | jdbc.hsqldb.username=sa 13 | jdbc.hsqldb.password= 14 | 15 | #Java Mail properties 16 | java.mail.username=info@javastudy.ru 17 | java.mail.password= 18 | java.mail.host=smtp.gmail.com 19 | 20 | test.param=test parameter property -------------------------------------------------------------------------------- /src/main/resources/util.properties: -------------------------------------------------------------------------------- 1 | site.maintenance=false 2 | 3 | #MYSQL Specific properties 4 | jdbc.driverClass=com.mysql.jdbc.Driver 5 | jdbc.url=jdbc:mysql://127.0.0.1/ 6 | jdbc.username=production username 7 | jdbc.password=production password 8 | 9 | #HSQLDB Specific properties 10 | jdbc.hsqldb.driverClass=org.hsqldb.jdbcDriver 11 | jdbc.hsqldb.url=jdbc:hsqldb:mem://localhost 12 | jdbc.hsqldb.username=sa 13 | jdbc.hsqldb.password= 14 | 15 | #Java Mail properties 16 | java.mail.username=info@javastudy.ru 17 | java.mail.password= 18 | java.mail.host=smtp.gmail.com 19 | 20 | test.param=test parameter property -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/classes/util.properties: -------------------------------------------------------------------------------- 1 | site.maintenance=false 2 | 3 | #MYSQL Specific properties 4 | jdbc.driverClass=com.mysql.jdbc.Driver 5 | jdbc.url=jdbc:mysql://127.0.0.1/ 6 | jdbc.username=production username 7 | jdbc.password=production password 8 | 9 | #HSQLDB Specific properties 10 | jdbc.hsqldb.driverClass=org.hsqldb.jdbcDriver 11 | jdbc.hsqldb.url=jdbc:hsqldb:mem://localhost 12 | jdbc.hsqldb.username=sa 13 | jdbc.hsqldb.password= 14 | 15 | #Java Mail properties 16 | java.mail.username=info@javastudy.ru 17 | java.mail.password= 18 | java.mail.host=smtp.gmail.com 19 | 20 | test.param=test parameter property -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/com/arseniisemenov/springapp/models/User.java: -------------------------------------------------------------------------------- 1 | package com.arseniisemenov.springapp.models; 2 | 3 | public class User { 4 | private int Id; 5 | private String Name; 6 | private String Phone; 7 | private String Email; 8 | private String Blog; 9 | private String Note; 10 | 11 | public int getId() { 12 | return Id; 13 | } 14 | public void setId(int id) { 15 | Id = id; 16 | } 17 | 18 | public String getName() { 19 | return Name; 20 | } 21 | public void setName(String name) { 22 | Name = name; 23 | } 24 | 25 | public String getPhone() { 26 | return Phone; 27 | } 28 | public void setPhone(String phone) { 29 | Phone = phone; 30 | } 31 | 32 | public String getEmail() { 33 | return Email; 34 | } 35 | public void setEmail(String email) { 36 | Email = email; 37 | } 38 | 39 | public String getBlog() { 40 | return Blog; 41 | } 42 | public void setBlog(String blog) { 43 | Blog = blog; 44 | } 45 | 46 | public String getNote() { 47 | return Note; 48 | } 49 | public void setNote(String note) { 50 | Note = note; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/create/create.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Create 11 | 12 | 13 |

Добавление адреса

14 | 15 |
16 |
17 | 20 | 23 | 26 | 29 | 32 | 33 |
34 |
35 |
36 | 37 |
38 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/create/create.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Create 11 | 12 | 13 |

Добавление адреса

14 | 15 |
16 |
17 | 20 | 23 | 26 | 29 | 32 | 33 |
34 |
35 |
36 | 37 |
38 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/user/user.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | User 11 | 12 | 13 |

Адрес

14 | 15 | 16 | 17 | 18 |
19 | Edit 20 | Delete 21 |
22 | 23 |
24 |

${user.name}

25 | Id: ${user.id} 26 |
Телефон: ${user.phone}
27 |
E-Mail: ${user.email}
28 | 29 |
Блог: 30 | ${user.blog} 31 |
32 |
33 |
Примечание: ${user.note}
34 |
35 |
36 |
37 | 38 |
39 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/user/user.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | User 11 | 12 | 13 |

Адрес

14 | 15 | 16 | 17 | 18 |
19 | Edit 20 | Delete 21 |
22 | 23 |
24 |

${user.name}

25 | Id: ${user.id} 26 |
Телефон: ${user.phone}
27 |
E-Mail: ${user.email}
28 | 29 |
Блог: 30 | ${user.blog} 31 |
32 |
33 |
Примечание: ${user.note}
34 |
35 |
36 |
37 | 38 |
39 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Homepage 11 | 12 | 13 |

Адресная книга

14 | 15 | 16 | Create 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 |
IdNamePhone
${user.id} 33 | ${user.name} 34 | ${user.phone}
40 |
41 |
42 | 43 |
44 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/views/edit/edit.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Edit 11 | 12 | 13 |

Редактирование адреса

14 | 15 |
16 | 17 |
18 | 21 | 24 | 27 | 30 | 33 | 34 |
35 |
36 |
37 |
38 | 39 |
40 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/edit/edit.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Edit 11 | 12 | 13 |

Редактирование адреса

14 | 15 |
16 | 17 |
18 | 21 | 24 | 27 | 30 | 33 | 34 |
35 |
36 |
37 |
38 | 39 |
40 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | spring-mvc-app 8 | 9 | 10 | 11 | 12 | encodingFilter 13 | org.springframework.web.filter.CharacterEncodingFilter 14 | 15 | encoding 16 | UTF-8 17 | 18 | 19 | forceEncoding 20 | true 21 | 22 | 23 | 24 | encodingFilter 25 | /* 26 | 27 | 28 | 29 | dispatcher 30 | org.springframework.web.servlet.DispatcherServlet 31 | 32 | contextConfigLocation 33 | /WEB-INF/config/applicationContextMVC.xml 34 | 35 | 1 36 | 37 | 38 | 39 | dispatcher 40 | / 41 | 42 | 43 | 44 | 404 45 | /WEB-INF/views/error/errorpage.jsp 46 | 47 | 48 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/views/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 6 | <%@ taglib prefix="page" tagdir="/WEB-INF/tags" %> 7 | 8 | 9 | 10 | Homepage 11 | 12 | 13 |

Адресная книга

14 | 15 | 16 | Create 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | <%-- Get Users--%> 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 |
IdNamePhone
${user.id} 34 | ${user.name} 35 | ${user.phone}
41 |
42 |
43 | 44 |
45 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | spring-mvc-app 8 | 9 | 10 | 11 | 12 | encodingFilter 13 | org.springframework.web.filter.CharacterEncodingFilter 14 | 15 | encoding 16 | UTF-8 17 | 18 | 19 | forceEncoding 20 | true 21 | 22 | 23 | 24 | encodingFilter 25 | /* 26 | 27 | 28 | 29 | dispatcher 30 | org.springframework.web.servlet.DispatcherServlet 31 | 32 | contextConfigLocation 33 | /WEB-INF/config/applicationContextMVC.xml 34 | 35 | 1 36 | 37 | 38 | 39 | dispatcher 40 | / 41 | 42 | 43 | 44 | 404 45 | /WEB-INF/views/error/errorpage.jsp 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/webapp/resources/css/modern-business.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Start Bootstrap - Modern Business HTML Template (http://startbootstrap.com) 3 | * Code licensed under the Apache License v2.0. 4 | * For details, see http://www.apache.org/licenses/LICENSE-2.0. 5 | */ 6 | 7 | /* Global Styles */ 8 | 9 | html, 10 | body { 11 | height: 100%; 12 | } 13 | 14 | body { 15 | padding-top: 50px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 16 | } 17 | 18 | .img-portfolio { 19 | margin-bottom: 30px; 20 | } 21 | 22 | .img-hover:hover { 23 | opacity: 0.8; 24 | } 25 | 26 | /* Home Page Carousel */ 27 | 28 | header.carousel { 29 | height: 50%; 30 | } 31 | 32 | header.carousel .item, 33 | header.carousel .item.active, 34 | header.carousel .carousel-inner { 35 | height: 100%; 36 | } 37 | 38 | header.carousel .fill { 39 | width: 100%; 40 | height: 100%; 41 | background-position: center; 42 | background-size: cover; 43 | } 44 | 45 | /* 404 Page Styles */ 46 | 47 | .error-404 { 48 | font-size: 100px; 49 | } 50 | 51 | /* Pricing Page Styles */ 52 | 53 | .price { 54 | display: block; 55 | font-size: 50px; 56 | line-height: 50px; 57 | } 58 | 59 | .price sup { 60 | top: -20px; 61 | left: 2px; 62 | font-size: 20px; 63 | } 64 | 65 | .period { 66 | display: block; 67 | font-style: italic; 68 | } 69 | 70 | /* Footer Styles */ 71 | 72 | footer { 73 | margin: 50px 0; 74 | } 75 | 76 | /* Responsive Styles */ 77 | 78 | @media(max-width:991px) { 79 | .customer-img, 80 | .img-related { 81 | margin-bottom: 30px; 82 | } 83 | } 84 | 85 | @media(max-width:767px) { 86 | .img-portfolio { 87 | margin-bottom: 15px; 88 | } 89 | 90 | header.carousel .carousel { 91 | height: 70%; 92 | } 93 | } -------------------------------------------------------------------------------- /target/spring-mvc-app/resources/css/modern-business.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Start Bootstrap - Modern Business HTML Template (http://startbootstrap.com) 3 | * Code licensed under the Apache License v2.0. 4 | * For details, see http://www.apache.org/licenses/LICENSE-2.0. 5 | */ 6 | 7 | /* Global Styles */ 8 | 9 | html, 10 | body { 11 | height: 100%; 12 | } 13 | 14 | body { 15 | padding-top: 50px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 16 | } 17 | 18 | .img-portfolio { 19 | margin-bottom: 30px; 20 | } 21 | 22 | .img-hover:hover { 23 | opacity: 0.8; 24 | } 25 | 26 | /* Home Page Carousel */ 27 | 28 | header.carousel { 29 | height: 50%; 30 | } 31 | 32 | header.carousel .item, 33 | header.carousel .item.active, 34 | header.carousel .carousel-inner { 35 | height: 100%; 36 | } 37 | 38 | header.carousel .fill { 39 | width: 100%; 40 | height: 100%; 41 | background-position: center; 42 | background-size: cover; 43 | } 44 | 45 | /* 404 Page Styles */ 46 | 47 | .error-404 { 48 | font-size: 100px; 49 | } 50 | 51 | /* Pricing Page Styles */ 52 | 53 | .price { 54 | display: block; 55 | font-size: 50px; 56 | line-height: 50px; 57 | } 58 | 59 | .price sup { 60 | top: -20px; 61 | left: 2px; 62 | font-size: 20px; 63 | } 64 | 65 | .period { 66 | display: block; 67 | font-style: italic; 68 | } 69 | 70 | /* Footer Styles */ 71 | 72 | footer { 73 | margin: 50px 0; 74 | } 75 | 76 | /* Responsive Styles */ 77 | 78 | @media(max-width:991px) { 79 | .customer-img, 80 | .img-related { 81 | margin-bottom: 30px; 82 | } 83 | } 84 | 85 | @media(max-width:767px) { 86 | .img-portfolio { 87 | margin-bottom: 15px; 88 | } 89 | 90 | header.carousel .carousel { 91 | height: 70%; 92 | } 93 | } -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/config/applicationContextMVC.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/config/applicationContextMVC.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/tags/template.tag: -------------------------------------------------------------------------------- 1 | 2 | <%@tag description="Template Site tag" pageEncoding="UTF-8"%> 3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> 5 | 6 | <%@attribute name="title" fragment="true" %> 7 | 8 | 9 | <jsp:invoke fragment="title"/> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 53 | 54 |
55 | 56 |
57 | 58 | 59 |
60 | 61 |
62 |
63 |
64 |

Copyright © Arsenii Semenov

65 |
66 |
67 |
68 |
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /target/spring-mvc-app/WEB-INF/tags/template.tag: -------------------------------------------------------------------------------- 1 | 2 | <%@tag description="Template Site tag" pageEncoding="UTF-8"%> 3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> 5 | 6 | <%@attribute name="title" fragment="true" %> 7 | 8 | 9 | <jsp:invoke fragment="title"/> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 53 | 54 |
55 | 56 |
57 | 58 | 59 |
60 | 61 |
62 |
63 |
64 |

Copyright © Arsenii Semenov

65 |
66 |
67 |
68 |
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/webapp/resources/js/contact_me.js: -------------------------------------------------------------------------------- 1 | /* 2 | Jquery Validation using jqBootstrapValidation 3 | example is taken from jqBootstrapValidation docs 4 | */ 5 | $(function() { 6 | 7 | $("#contactForm input,#contactForm textarea").jqBootstrapValidation({ 8 | preventSubmit: true, 9 | submitError: function($form, event, errors) { 10 | // something to have when submit produces an error ? 11 | // Not decided if I need it yet 12 | }, 13 | submitSuccess: function($form, event) { 14 | event.preventDefault(); // prevent default submit behaviour 15 | // get values from FORM 16 | var name = $("input#name").val(); 17 | var phone = $("input#phone").val(); 18 | var email = $("input#email").val(); 19 | var message = $("textarea#message").val(); 20 | var firstName = name; // For Success/Failure Message 21 | // Check for white space in name for Success/Fail message 22 | if (firstName.indexOf(' ') >= 0) { 23 | firstName = name.split(' ').slice(0, -1).join(' '); 24 | } 25 | $.ajax({ 26 | url: "./bin/contact_me.php", 27 | type: "POST", 28 | data: { 29 | name: name, 30 | phone: phone, 31 | email: email, 32 | message: message 33 | }, 34 | cache: false, 35 | success: function() { 36 | // Success message 37 | $('#success').html("
"); 38 | $('#success > .alert-success').html(""); 40 | $('#success > .alert-success') 41 | .append("Your message has been sent. "); 42 | $('#success > .alert-success') 43 | .append('
'); 44 | 45 | //clear all fields 46 | $('#contactForm').trigger("reset"); 47 | }, 48 | error: function() { 49 | // Fail message 50 | $('#success').html("
"); 51 | $('#success > .alert-danger').html(""); 53 | $('#success > .alert-danger').append("Sorry " + firstName + " it seems that my mail server is not responding... Could you please email me directly to .alert-danger').append('
'); 55 | //clear all fields 56 | $('#contactForm').trigger("reset"); 57 | }, 58 | }) 59 | }, 60 | filter: function() { 61 | return $(this).is(":visible"); 62 | }, 63 | }); 64 | 65 | $("a[data-toggle=\"tab\"]").click(function(e) { 66 | e.preventDefault(); 67 | $(this).tab("show"); 68 | }); 69 | }); 70 | 71 | 72 | /*When clicking on Full hide fail/success boxes */ 73 | $('#name').focus(function() { 74 | $('#success').html(''); 75 | }); 76 | -------------------------------------------------------------------------------- /target/spring-mvc-app/resources/js/contact_me.js: -------------------------------------------------------------------------------- 1 | /* 2 | Jquery Validation using jqBootstrapValidation 3 | example is taken from jqBootstrapValidation docs 4 | */ 5 | $(function() { 6 | 7 | $("#contactForm input,#contactForm textarea").jqBootstrapValidation({ 8 | preventSubmit: true, 9 | submitError: function($form, event, errors) { 10 | // something to have when submit produces an error ? 11 | // Not decided if I need it yet 12 | }, 13 | submitSuccess: function($form, event) { 14 | event.preventDefault(); // prevent default submit behaviour 15 | // get values from FORM 16 | var name = $("input#name").val(); 17 | var phone = $("input#phone").val(); 18 | var email = $("input#email").val(); 19 | var message = $("textarea#message").val(); 20 | var firstName = name; // For Success/Failure Message 21 | // Check for white space in name for Success/Fail message 22 | if (firstName.indexOf(' ') >= 0) { 23 | firstName = name.split(' ').slice(0, -1).join(' '); 24 | } 25 | $.ajax({ 26 | url: "./bin/contact_me.php", 27 | type: "POST", 28 | data: { 29 | name: name, 30 | phone: phone, 31 | email: email, 32 | message: message 33 | }, 34 | cache: false, 35 | success: function() { 36 | // Success message 37 | $('#success').html("
"); 38 | $('#success > .alert-success').html(""); 40 | $('#success > .alert-success') 41 | .append("Your message has been sent. "); 42 | $('#success > .alert-success') 43 | .append('
'); 44 | 45 | //clear all fields 46 | $('#contactForm').trigger("reset"); 47 | }, 48 | error: function() { 49 | // Fail message 50 | $('#success').html("
'); 55 | //clear all fields 56 | $('#contactForm').trigger("reset"); 57 | }, 58 | }) 59 | }, 60 | filter: function() { 61 | return $(this).is(":visible"); 62 | }, 63 | }); 64 | 65 | $("a[data-toggle=\"tab\"]").click(function(e) { 66 | e.preventDefault(); 67 | $(this).tab("show"); 68 | }); 69 | }); 70 | 71 | 72 | /*When clicking on Full hide fail/success boxes */ 73 | $('#name').focus(function() { 74 | $('#success').html(''); 75 | }); 76 | -------------------------------------------------------------------------------- /src/main/java/com/arseniisemenov/springapp/controllers/DataController.java: -------------------------------------------------------------------------------- 1 | package com.arseniisemenov.springapp.controllers; 2 | 3 | import com.arseniisemenov.springapp.models.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.servlet.ModelAndView; 11 | import org.springframework.web.servlet.view.RedirectView; 12 | 13 | import java.util.List; 14 | 15 | @Controller 16 | public class DataController { 17 | @Autowired 18 | DBController dbController; 19 | 20 | @RequestMapping(value = {"/", "/index"}, method = RequestMethod.GET) 21 | public ModelAndView getUsers() { 22 | List users = dbController.queryAllUsers(); 23 | return new ModelAndView("index", "users", users); 24 | } 25 | 26 | @RequestMapping(value = "/user/{id}", method = RequestMethod.GET) 27 | public ModelAndView getUser(@PathVariable(value="id") int id) { 28 | User user = dbController.queryUser(id); 29 | return new ModelAndView("user/user", "user", user); 30 | } 31 | 32 | @RequestMapping(value = "/create", method = RequestMethod.GET) 33 | public String getCreateView() { 34 | return "create/create"; 35 | } 36 | @RequestMapping(value = "/create", method = RequestMethod.POST) 37 | public RedirectView createUser( 38 | @RequestParam String name, 39 | @RequestParam String phone, 40 | @RequestParam String email, 41 | @RequestParam String blog, 42 | @RequestParam String note 43 | ) { 44 | User user = new User(); 45 | user.setName(name); 46 | user.setPhone(phone); 47 | user.setEmail(email); 48 | user.setBlog(blog); 49 | user.setNote(note); 50 | 51 | dbController.addUser(user); 52 | return new RedirectView("/"); 53 | } 54 | 55 | @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) 56 | public ModelAndView getEditView(@PathVariable(value="id") int id) { 57 | User user = dbController.queryUser(id); 58 | return new ModelAndView("edit/edit", "user", user); 59 | } 60 | @RequestMapping(value = "/update/{id}", method = RequestMethod.POST) 61 | public RedirectView updateUser( 62 | @PathVariable(value="id") int id, 63 | @RequestParam String name, 64 | @RequestParam String phone, 65 | @RequestParam String email, 66 | @RequestParam String blog, 67 | @RequestParam String note 68 | ) { 69 | User user = new User(); 70 | user.setName(name); 71 | user.setPhone(phone); 72 | user.setEmail(email); 73 | user.setBlog(blog); 74 | user.setNote(note); 75 | user.setId(id); 76 | 77 | dbController.updateUser(user); 78 | return new RedirectView("/"); 79 | } 80 | 81 | @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) 82 | public RedirectView deleteUser(@PathVariable(value="id") int id) { 83 | dbController.deleteUser(id); 84 | return new RedirectView("/"); 85 | } 86 | 87 | @RequestMapping(value = "/find", method = RequestMethod.GET) 88 | public ModelAndView findUsers(@RequestParam("name") String name) { 89 | List users = dbController.findUsers(name); 90 | return new ModelAndView("index", "users", users); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/arseniisemenov/springapp/controllers/DBController.java: -------------------------------------------------------------------------------- 1 | package com.arseniisemenov.springapp.controllers; 2 | 3 | import com.arseniisemenov.springapp.models.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.jdbc.core.PreparedStatementCreator; 6 | import org.springframework.jdbc.core.RowMapper; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | import javax.annotation.PostConstruct; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.Connection; 13 | import java.sql.PreparedStatement; 14 | import java.sql.ResultSet; 15 | import java.sql.SQLException; 16 | import java.util.List; 17 | 18 | @Repository 19 | public class DBController { 20 | @Autowired 21 | DataSource dataSource; 22 | 23 | private JdbcTemplate jdbcTemplate; 24 | 25 | @PostConstruct 26 | public void init() { 27 | System.out.println("DBController initialize: " + dataSource); 28 | jdbcTemplate = new JdbcTemplate(dataSource); 29 | } 30 | 31 | public List queryAllUsers() { 32 | final String query = "SELECT * FROM USER ORDER BY ID"; 33 | List users = this.jdbcTemplate.query(query, new UserMapper()); 34 | return users; 35 | } 36 | 37 | public User queryUser(int id) { 38 | final String query = "SELECT * FROM USER WHERE ID LIKE ?"; 39 | User user = this.jdbcTemplate.queryForObject(query, new Object[]{id}, new UserMapper()); 40 | return user; 41 | } 42 | 43 | public boolean addUser(final User user) { 44 | final String query = "INSERT INTO USER (NAME, PHONE, EMAIL, BLOG, NOTE) VALUES(?, ?, ?, ?, ?)"; 45 | jdbcTemplate.update(new PreparedStatementCreator() { 46 | @Override 47 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { 48 | PreparedStatement preparedStatement = con.prepareStatement(query); 49 | preparedStatement.setString(1, user.getName()); 50 | preparedStatement.setString(2, user.getPhone()); 51 | preparedStatement.setString(3, user.getEmail()); 52 | preparedStatement.setString(4, user.getBlog()); 53 | preparedStatement.setString(5, user.getNote()); 54 | return preparedStatement; 55 | } 56 | }); 57 | return true; 58 | } 59 | 60 | public boolean updateUser(final User user) { 61 | final String query = "UPDATE USER SET NAME = ?, PHONE = ?, EMAIL = ?, BLOG = ?, NOTE = ? WHERE ID LIKE ?"; 62 | jdbcTemplate.update(new PreparedStatementCreator() { 63 | @Override 64 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { 65 | PreparedStatement preparedStatement = con.prepareStatement(query); 66 | preparedStatement.setString(1, user.getName()); 67 | preparedStatement.setString(2, user.getPhone()); 68 | preparedStatement.setString(3, user.getEmail()); 69 | preparedStatement.setString(4, user.getBlog()); 70 | preparedStatement.setString(5, user.getNote()); 71 | preparedStatement.setInt(6, user.getId()); 72 | return preparedStatement; 73 | } 74 | }); 75 | return true; 76 | } 77 | 78 | public boolean deleteUser(int id) { 79 | final String query = "DELETE FROM USER WHERE ID LIKE ?"; 80 | int result = jdbcTemplate.update(query, new Object[]{id}); 81 | if(result > 0) { 82 | return true; 83 | } 84 | return false; 85 | } 86 | 87 | public List findUsers(String name) { 88 | final String query = "SELECT * FROM USER WHERE NAME LIKE ?"; 89 | List users = this.jdbcTemplate.query(query, new Object[]{name}, new UserMapper()); 90 | return users; 91 | } 92 | } 93 | 94 | 95 | 96 | class UserMapper implements RowMapper { 97 | @Override 98 | public User mapRow(ResultSet resultSet, int rowNum) throws SQLException { 99 | User user = new User(); 100 | user.setId(resultSet.getInt("ID")); 101 | user.setName(resultSet.getString("NAME")); 102 | user.setPhone(resultSet.getString("PHONE")); 103 | user.setEmail(resultSet.getString("EMAIL")); 104 | user.setBlog(resultSet.getString("BLOG")); 105 | user.setNote(resultSet.getString("NOTE")); 106 | return user; 107 | } 108 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.arseniisemenov 8 | spring-mvc-app 9 | 1.0-SNAPSHOT 10 | war 11 | 12 | spring-mvc-app Maven Webapp 13 | 14 | http://www.example.com 15 | 16 | 17 | UTF-8 18 | 1.7 19 | 1.7 20 | 5.3.20 21 | 22 | 23 | 24 | 25 | junit 26 | junit 27 | 4.11 28 | test 29 | 30 | 31 | 32 | 33 | org.springframework 34 | spring-core 35 | ${spring.version} 36 | 37 | 38 | 39 | 40 | org.springframework 41 | spring-context 42 | ${spring.version} 43 | 44 | 45 | 46 | 47 | org.springframework 48 | spring-web 49 | ${spring.version} 50 | 51 | 52 | 53 | 54 | org.springframework 55 | spring-webmvc 56 | ${spring.version} 57 | 58 | 59 | 60 | javax.servlet.jsp 61 | jsp-api 62 | 2.2 63 | 64 | 65 | 66 | javax.servlet 67 | jstl 68 | 1.2 69 | 70 | 71 | 72 | javax.servlet 73 | javax.servlet-api 74 | 4.0.1 75 | provided 76 | 77 | 78 | 79 | javax.annotation 80 | javax.annotation-api 81 | 1.3.2 82 | 83 | 84 | 85 | org.hsqldb 86 | hsqldb 87 | 2.3.3 88 | 89 | 90 | 91 | 92 | org.springframework 93 | spring-jdbc 94 | 4.2.4.RELEASE 95 | 96 | 97 | 98 | 99 | spring-mvc-app 100 | 101 | 102 | 103 | maven-clean-plugin 104 | 3.1.0 105 | 106 | 107 | 108 | maven-resources-plugin 109 | 3.0.2 110 | 111 | 112 | maven-compiler-plugin 113 | 3.8.0 114 | 115 | 116 | maven-surefire-plugin 117 | 2.22.1 118 | 119 | 120 | maven-war-plugin 121 | 3.2.2 122 | 123 | 124 | maven-install-plugin 125 | 2.5.2 126 | 127 | 128 | maven-deploy-plugin 129 | 2.8.2 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/main/webapp/resources/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.6 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under the MIT license 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>2)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.6",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.6",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.6",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));return a>this.$items.length-1||0>a?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.6",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.6",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),c.isInStateTrue()?void 0:(clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide())},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;(e||!/destroy|hide/.test(b))&&(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.6",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.6",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.6",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /target/spring-mvc-app/resources/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.6 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under the MIT license 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>2)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.6",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.6",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.6",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));return a>this.$items.length-1||0>a?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.6",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.6",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),c.isInStateTrue()?void 0:(clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide())},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;(e||!/destroy|hide/.test(b))&&(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.6",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.6",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.6",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /src/main/webapp/resources/js/jqBootstrapValidation.js: -------------------------------------------------------------------------------- 1 | /* jqBootstrapValidation 2 | * A plugin for automating validation on Twitter Bootstrap formatted forms. 3 | * 4 | * v1.3.6 5 | * 6 | * License: MIT - see LICENSE file 7 | * 8 | * http://ReactiveRaven.github.com/jqBootstrapValidation/ 9 | */ 10 | 11 | (function( $ ){ 12 | 13 | var createdElements = []; 14 | 15 | var defaults = { 16 | options: { 17 | prependExistingHelpBlock: false, 18 | sniffHtml: true, // sniff for 'required', 'maxlength', etc 19 | preventSubmit: true, // stop the form submit event from firing if validation fails 20 | submitError: false, // function called if there is an error when trying to submit 21 | submitSuccess: false, // function called just before a successful submit event is sent to the server 22 | semanticallyStrict: false, // set to true to tidy up generated HTML output 23 | autoAdd: { 24 | helpBlocks: true 25 | }, 26 | filter: function () { 27 | // return $(this).is(":visible"); // only validate elements you can see 28 | return true; // validate everything 29 | } 30 | }, 31 | methods: { 32 | init : function( options ) { 33 | 34 | var settings = $.extend(true, {}, defaults); 35 | 36 | settings.options = $.extend(true, settings.options, options); 37 | 38 | var $siblingElements = this; 39 | 40 | var uniqueForms = $.unique( 41 | $siblingElements.map( function () { 42 | return $(this).parents("form")[0]; 43 | }).toArray() 44 | ); 45 | 46 | $(uniqueForms).bind("submit", function (e) { 47 | var $form = $(this); 48 | var warningsFound = 0; 49 | var $inputs = $form.find("input,textarea,select").not("[type=submit],[type=image]").filter(settings.options.filter); 50 | $inputs.trigger("submit.validation").trigger("validationLostFocus.validation"); 51 | 52 | $inputs.each(function (i, el) { 53 | var $this = $(el), 54 | $controlGroup = $this.parents(".control-group").first(); 55 | if ( 56 | $controlGroup.hasClass("has-warning") 57 | ) { 58 | $controlGroup.removeClass("has-warning").addClass("has-error"); 59 | warningsFound++; 60 | } 61 | }); 62 | 63 | $inputs.trigger("validationLostFocus.validation"); 64 | 65 | if (warningsFound) { 66 | if (settings.options.preventSubmit) { 67 | e.preventDefault(); 68 | } 69 | $form.addClass("has-error"); 70 | if ($.isFunction(settings.options.submitError)) { 71 | settings.options.submitError($form, e, $inputs.jqBootstrapValidation("collectErrors", true)); 72 | } 73 | } else { 74 | $form.removeClass("has-error"); 75 | if ($.isFunction(settings.options.submitSuccess)) { 76 | settings.options.submitSuccess($form, e); 77 | } 78 | } 79 | }); 80 | 81 | return this.each(function(){ 82 | 83 | // Get references to everything we're interested in 84 | var $this = $(this), 85 | $controlGroup = $this.parents(".control-group").first(), 86 | $helpBlock = $controlGroup.find(".help-block").first(), 87 | $form = $this.parents("form").first(), 88 | validatorNames = []; 89 | 90 | // create message container if not exists 91 | if (!$helpBlock.length && settings.options.autoAdd && settings.options.autoAdd.helpBlocks) { 92 | $helpBlock = $('
'); 93 | $controlGroup.find('.controls').append($helpBlock); 94 | createdElements.push($helpBlock[0]); 95 | } 96 | 97 | // ============================================================= 98 | // SNIFF HTML FOR VALIDATORS 99 | // ============================================================= 100 | 101 | // *snort sniff snuffle* 102 | 103 | if (settings.options.sniffHtml) { 104 | var message = ""; 105 | // --------------------------------------------------------- 106 | // PATTERN 107 | // --------------------------------------------------------- 108 | if ($this.attr("pattern") !== undefined) { 109 | message = "Not in the expected format"; 110 | if ($this.data("validationPatternMessage")) { 111 | message = $this.data("validationPatternMessage"); 112 | } 113 | $this.data("validationPatternMessage", message); 114 | $this.data("validationPatternRegex", $this.attr("pattern")); 115 | } 116 | // --------------------------------------------------------- 117 | // MAX 118 | // --------------------------------------------------------- 119 | if ($this.attr("max") !== undefined || $this.attr("aria-valuemax") !== undefined) { 120 | var max = ($this.attr("max") !== undefined ? $this.attr("max") : $this.attr("aria-valuemax")); 121 | message = "Too high: Maximum of '" + max + "'"; 122 | if ($this.data("validationMaxMessage")) { 123 | message = $this.data("validationMaxMessage"); 124 | } 125 | $this.data("validationMaxMessage", message); 126 | $this.data("validationMaxMax", max); 127 | } 128 | // --------------------------------------------------------- 129 | // MIN 130 | // --------------------------------------------------------- 131 | if ($this.attr("min") !== undefined || $this.attr("aria-valuemin") !== undefined) { 132 | var min = ($this.attr("min") !== undefined ? $this.attr("min") : $this.attr("aria-valuemin")); 133 | message = "Too low: Minimum of '" + min + "'"; 134 | if ($this.data("validationMinMessage")) { 135 | message = $this.data("validationMinMessage"); 136 | } 137 | $this.data("validationMinMessage", message); 138 | $this.data("validationMinMin", min); 139 | } 140 | // --------------------------------------------------------- 141 | // MAXLENGTH 142 | // --------------------------------------------------------- 143 | if ($this.attr("maxlength") !== undefined) { 144 | message = "Too long: Maximum of '" + $this.attr("maxlength") + "' characters"; 145 | if ($this.data("validationMaxlengthMessage")) { 146 | message = $this.data("validationMaxlengthMessage"); 147 | } 148 | $this.data("validationMaxlengthMessage", message); 149 | $this.data("validationMaxlengthMaxlength", $this.attr("maxlength")); 150 | } 151 | // --------------------------------------------------------- 152 | // MINLENGTH 153 | // --------------------------------------------------------- 154 | if ($this.attr("minlength") !== undefined) { 155 | message = "Too short: Minimum of '" + $this.attr("minlength") + "' characters"; 156 | if ($this.data("validationMinlengthMessage")) { 157 | message = $this.data("validationMinlengthMessage"); 158 | } 159 | $this.data("validationMinlengthMessage", message); 160 | $this.data("validationMinlengthMinlength", $this.attr("minlength")); 161 | } 162 | // --------------------------------------------------------- 163 | // REQUIRED 164 | // --------------------------------------------------------- 165 | if ($this.attr("required") !== undefined || $this.attr("aria-required") !== undefined) { 166 | message = settings.builtInValidators.required.message; 167 | if ($this.data("validationRequiredMessage")) { 168 | message = $this.data("validationRequiredMessage"); 169 | } 170 | $this.data("validationRequiredMessage", message); 171 | } 172 | // --------------------------------------------------------- 173 | // NUMBER 174 | // --------------------------------------------------------- 175 | if ($this.attr("type") !== undefined && $this.attr("type").toLowerCase() === "number") { 176 | message = settings.builtInValidators.number.message; 177 | if ($this.data("validationNumberMessage")) { 178 | message = $this.data("validationNumberMessage"); 179 | } 180 | $this.data("validationNumberMessage", message); 181 | } 182 | // --------------------------------------------------------- 183 | // EMAIL 184 | // --------------------------------------------------------- 185 | if ($this.attr("type") !== undefined && $this.attr("type").toLowerCase() === "email") { 186 | message = "Not a valid email address"; 187 | if ($this.data("validationValidemailMessage")) { 188 | message = $this.data("validationValidemailMessage"); 189 | } else if ($this.data("validationEmailMessage")) { 190 | message = $this.data("validationEmailMessage"); 191 | } 192 | $this.data("validationValidemailMessage", message); 193 | } 194 | // --------------------------------------------------------- 195 | // MINCHECKED 196 | // --------------------------------------------------------- 197 | if ($this.attr("minchecked") !== undefined) { 198 | message = "Not enough options checked; Minimum of '" + $this.attr("minchecked") + "' required"; 199 | if ($this.data("validationMincheckedMessage")) { 200 | message = $this.data("validationMincheckedMessage"); 201 | } 202 | $this.data("validationMincheckedMessage", message); 203 | $this.data("validationMincheckedMinchecked", $this.attr("minchecked")); 204 | } 205 | // --------------------------------------------------------- 206 | // MAXCHECKED 207 | // --------------------------------------------------------- 208 | if ($this.attr("maxchecked") !== undefined) { 209 | message = "Too many options checked; Maximum of '" + $this.attr("maxchecked") + "' required"; 210 | if ($this.data("validationMaxcheckedMessage")) { 211 | message = $this.data("validationMaxcheckedMessage"); 212 | } 213 | $this.data("validationMaxcheckedMessage", message); 214 | $this.data("validationMaxcheckedMaxchecked", $this.attr("maxchecked")); 215 | } 216 | } 217 | 218 | // ============================================================= 219 | // COLLECT VALIDATOR NAMES 220 | // ============================================================= 221 | 222 | // Get named validators 223 | if ($this.data("validation") !== undefined) { 224 | validatorNames = $this.data("validation").split(","); 225 | } 226 | 227 | // Get extra ones defined on the element's data attributes 228 | $.each($this.data(), function (i, el) { 229 | var parts = i.replace(/([A-Z])/g, ",$1").split(","); 230 | if (parts[0] === "validation" && parts[1]) { 231 | validatorNames.push(parts[1]); 232 | } 233 | }); 234 | 235 | // ============================================================= 236 | // NORMALISE VALIDATOR NAMES 237 | // ============================================================= 238 | 239 | var validatorNamesToInspect = validatorNames; 240 | var newValidatorNamesToInspect = []; 241 | 242 | do // repeatedly expand 'shortcut' validators into their real validators 243 | { 244 | // Uppercase only the first letter of each name 245 | $.each(validatorNames, function (i, el) { 246 | validatorNames[i] = formatValidatorName(el); 247 | }); 248 | 249 | // Remove duplicate validator names 250 | validatorNames = $.unique(validatorNames); 251 | 252 | // Pull out the new validator names from each shortcut 253 | newValidatorNamesToInspect = []; 254 | $.each(validatorNamesToInspect, function(i, el) { 255 | if ($this.data("validation" + el + "Shortcut") !== undefined) { 256 | // Are these custom validators? 257 | // Pull them out! 258 | $.each($this.data("validation" + el + "Shortcut").split(","), function(i2, el2) { 259 | newValidatorNamesToInspect.push(el2); 260 | }); 261 | } else if (settings.builtInValidators[el.toLowerCase()]) { 262 | // Is this a recognised built-in? 263 | // Pull it out! 264 | var validator = settings.builtInValidators[el.toLowerCase()]; 265 | if (validator.type.toLowerCase() === "shortcut") { 266 | $.each(validator.shortcut.split(","), function (i, el) { 267 | el = formatValidatorName(el); 268 | newValidatorNamesToInspect.push(el); 269 | validatorNames.push(el); 270 | }); 271 | } 272 | } 273 | }); 274 | 275 | validatorNamesToInspect = newValidatorNamesToInspect; 276 | 277 | } while (validatorNamesToInspect.length > 0) 278 | 279 | // ============================================================= 280 | // SET UP VALIDATOR ARRAYS 281 | // ============================================================= 282 | 283 | var validators = {}; 284 | 285 | $.each(validatorNames, function (i, el) { 286 | // Set up the 'override' message 287 | var message = $this.data("validation" + el + "Message"); 288 | var hasOverrideMessage = (message !== undefined); 289 | var foundValidator = false; 290 | message = 291 | ( 292 | message 293 | ? message 294 | : "'" + el + "' validation failed " 295 | ) 296 | ; 297 | 298 | $.each( 299 | settings.validatorTypes, 300 | function (validatorType, validatorTemplate) { 301 | if (validators[validatorType] === undefined) { 302 | validators[validatorType] = []; 303 | } 304 | if (!foundValidator && $this.data("validation" + el + formatValidatorName(validatorTemplate.name)) !== undefined) { 305 | validators[validatorType].push( 306 | $.extend( 307 | true, 308 | { 309 | name: formatValidatorName(validatorTemplate.name), 310 | message: message 311 | }, 312 | validatorTemplate.init($this, el) 313 | ) 314 | ); 315 | foundValidator = true; 316 | } 317 | } 318 | ); 319 | 320 | if (!foundValidator && settings.builtInValidators[el.toLowerCase()]) { 321 | 322 | var validator = $.extend(true, {}, settings.builtInValidators[el.toLowerCase()]); 323 | if (hasOverrideMessage) { 324 | validator.message = message; 325 | } 326 | var validatorType = validator.type.toLowerCase(); 327 | 328 | if (validatorType === "shortcut") { 329 | foundValidator = true; 330 | } else { 331 | $.each( 332 | settings.validatorTypes, 333 | function (validatorTemplateType, validatorTemplate) { 334 | if (validators[validatorTemplateType] === undefined) { 335 | validators[validatorTemplateType] = []; 336 | } 337 | if (!foundValidator && validatorType === validatorTemplateType.toLowerCase()) { 338 | $this.data("validation" + el + formatValidatorName(validatorTemplate.name), validator[validatorTemplate.name.toLowerCase()]); 339 | validators[validatorType].push( 340 | $.extend( 341 | validator, 342 | validatorTemplate.init($this, el) 343 | ) 344 | ); 345 | foundValidator = true; 346 | } 347 | } 348 | ); 349 | } 350 | } 351 | 352 | if (! foundValidator) { 353 | $.error("Cannot find validation info for '" + el + "'"); 354 | } 355 | }); 356 | 357 | // ============================================================= 358 | // STORE FALLBACK VALUES 359 | // ============================================================= 360 | 361 | $helpBlock.data( 362 | "original-contents", 363 | ( 364 | $helpBlock.data("original-contents") 365 | ? $helpBlock.data("original-contents") 366 | : $helpBlock.html() 367 | ) 368 | ); 369 | 370 | $helpBlock.data( 371 | "original-role", 372 | ( 373 | $helpBlock.data("original-role") 374 | ? $helpBlock.data("original-role") 375 | : $helpBlock.attr("role") 376 | ) 377 | ); 378 | 379 | $controlGroup.data( 380 | "original-classes", 381 | ( 382 | $controlGroup.data("original-clases") 383 | ? $controlGroup.data("original-classes") 384 | : $controlGroup.attr("class") 385 | ) 386 | ); 387 | 388 | $this.data( 389 | "original-aria-invalid", 390 | ( 391 | $this.data("original-aria-invalid") 392 | ? $this.data("original-aria-invalid") 393 | : $this.attr("aria-invalid") 394 | ) 395 | ); 396 | 397 | // ============================================================= 398 | // VALIDATION 399 | // ============================================================= 400 | 401 | $this.bind( 402 | "validation.validation", 403 | function (event, params) { 404 | 405 | var value = getValue($this); 406 | 407 | // Get a list of the errors to apply 408 | var errorsFound = []; 409 | 410 | $.each(validators, function (validatorType, validatorTypeArray) { 411 | if (value || value.length || (params && params.includeEmpty) || (!!settings.validatorTypes[validatorType].blockSubmit && params && !!params.submitting)) { 412 | $.each(validatorTypeArray, function (i, validator) { 413 | if (settings.validatorTypes[validatorType].validate($this, value, validator)) { 414 | errorsFound.push(validator.message); 415 | } 416 | }); 417 | } 418 | }); 419 | 420 | return errorsFound; 421 | } 422 | ); 423 | 424 | $this.bind( 425 | "getValidators.validation", 426 | function () { 427 | return validators; 428 | } 429 | ); 430 | 431 | // ============================================================= 432 | // WATCH FOR CHANGES 433 | // ============================================================= 434 | $this.bind( 435 | "submit.validation", 436 | function () { 437 | return $this.triggerHandler("change.validation", {submitting: true}); 438 | } 439 | ); 440 | $this.bind( 441 | [ 442 | "keyup", 443 | "focus", 444 | "blur", 445 | "click", 446 | "keydown", 447 | "keypress", 448 | "change" 449 | ].join(".validation ") + ".validation", 450 | function (e, params) { 451 | 452 | var value = getValue($this); 453 | 454 | var errorsFound = []; 455 | 456 | $controlGroup.find("input,textarea,select").each(function (i, el) { 457 | var oldCount = errorsFound.length; 458 | $.each($(el).triggerHandler("validation.validation", params), function (j, message) { 459 | errorsFound.push(message); 460 | }); 461 | if (errorsFound.length > oldCount) { 462 | $(el).attr("aria-invalid", "true"); 463 | } else { 464 | var original = $this.data("original-aria-invalid"); 465 | $(el).attr("aria-invalid", (original !== undefined ? original : false)); 466 | } 467 | }); 468 | 469 | $form.find("input,select,textarea").not($this).not("[name=\"" + $this.attr("name") + "\"]").trigger("validationLostFocus.validation"); 470 | 471 | errorsFound = $.unique(errorsFound.sort()); 472 | 473 | // Were there any errors? 474 | if (errorsFound.length) { 475 | // Better flag it up as a warning. 476 | $controlGroup.removeClass("has-success has-error").addClass("has-warning"); 477 | 478 | // How many errors did we find? 479 | if (settings.options.semanticallyStrict && errorsFound.length === 1) { 480 | // Only one? Being strict? Just output it. 481 | $helpBlock.html(errorsFound[0] + 482 | ( settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : "" )); 483 | } else { 484 | // Multiple? Being sloppy? Glue them together into an UL. 485 | $helpBlock.html("
  • " + errorsFound.join("
  • ") + "
" + 486 | ( settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : "" )); 487 | } 488 | } else { 489 | $controlGroup.removeClass("has-warning has-error has-success"); 490 | if (value.length > 0) { 491 | $controlGroup.addClass("has-success"); 492 | } 493 | $helpBlock.html($helpBlock.data("original-contents")); 494 | } 495 | 496 | if (e.type === "blur") { 497 | $controlGroup.removeClass("has-success"); 498 | } 499 | } 500 | ); 501 | $this.bind("validationLostFocus.validation", function () { 502 | $controlGroup.removeClass("has-success"); 503 | }); 504 | }); 505 | }, 506 | destroy : function( ) { 507 | 508 | return this.each( 509 | function() { 510 | 511 | var 512 | $this = $(this), 513 | $controlGroup = $this.parents(".control-group").first(), 514 | $helpBlock = $controlGroup.find(".help-block").first(); 515 | 516 | // remove our events 517 | $this.unbind('.validation'); // events are namespaced. 518 | // reset help text 519 | $helpBlock.html($helpBlock.data("original-contents")); 520 | // reset classes 521 | $controlGroup.attr("class", $controlGroup.data("original-classes")); 522 | // reset aria 523 | $this.attr("aria-invalid", $this.data("original-aria-invalid")); 524 | // reset role 525 | $helpBlock.attr("role", $this.data("original-role")); 526 | // remove all elements we created 527 | if (createdElements.indexOf($helpBlock[0]) > -1) { 528 | $helpBlock.remove(); 529 | } 530 | 531 | } 532 | ); 533 | 534 | }, 535 | collectErrors : function(includeEmpty) { 536 | 537 | var errorMessages = {}; 538 | this.each(function (i, el) { 539 | var $el = $(el); 540 | var name = $el.attr("name"); 541 | var errors = $el.triggerHandler("validation.validation", {includeEmpty: true}); 542 | errorMessages[name] = $.extend(true, errors, errorMessages[name]); 543 | }); 544 | 545 | $.each(errorMessages, function (i, el) { 546 | if (el.length === 0) { 547 | delete errorMessages[i]; 548 | } 549 | }); 550 | 551 | return errorMessages; 552 | 553 | }, 554 | hasErrors: function() { 555 | 556 | var errorMessages = []; 557 | 558 | this.each(function (i, el) { 559 | errorMessages = errorMessages.concat( 560 | $(el).triggerHandler("getValidators.validation") ? $(el).triggerHandler("validation.validation", {submitting: true}) : [] 561 | ); 562 | }); 563 | 564 | return (errorMessages.length > 0); 565 | }, 566 | override : function (newDefaults) { 567 | defaults = $.extend(true, defaults, newDefaults); 568 | } 569 | }, 570 | validatorTypes: { 571 | callback: { 572 | name: "callback", 573 | init: function ($this, name) { 574 | return { 575 | validatorName: name, 576 | callback: $this.data("validation" + name + "Callback"), 577 | lastValue: $this.val(), 578 | lastValid: true, 579 | lastFinished: true 580 | }; 581 | }, 582 | validate: function ($this, value, validator) { 583 | if (validator.lastValue === value && validator.lastFinished) { 584 | return !validator.lastValid; 585 | } 586 | 587 | if (validator.lastFinished === true) 588 | { 589 | validator.lastValue = value; 590 | validator.lastValid = true; 591 | validator.lastFinished = false; 592 | 593 | var rrjqbvValidator = validator; 594 | var rrjqbvThis = $this; 595 | executeFunctionByName( 596 | validator.callback, 597 | window, 598 | $this, 599 | value, 600 | function (data) { 601 | if (rrjqbvValidator.lastValue === data.value) { 602 | rrjqbvValidator.lastValid = data.valid; 603 | if (data.message) { 604 | rrjqbvValidator.message = data.message; 605 | } 606 | rrjqbvValidator.lastFinished = true; 607 | rrjqbvThis.data("validation" + rrjqbvValidator.validatorName + "Message", rrjqbvValidator.message); 608 | // Timeout is set to avoid problems with the events being considered 'already fired' 609 | setTimeout(function () { 610 | rrjqbvThis.trigger("change.validation"); 611 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 612 | } 613 | } 614 | ); 615 | } 616 | 617 | return false; 618 | 619 | } 620 | }, 621 | ajax: { 622 | name: "ajax", 623 | init: function ($this, name) { 624 | return { 625 | validatorName: name, 626 | url: $this.data("validation" + name + "Ajax"), 627 | lastValue: $this.val(), 628 | lastValid: true, 629 | lastFinished: true 630 | }; 631 | }, 632 | validate: function ($this, value, validator) { 633 | if (""+validator.lastValue === ""+value && validator.lastFinished === true) { 634 | return validator.lastValid === false; 635 | } 636 | 637 | if (validator.lastFinished === true) 638 | { 639 | validator.lastValue = value; 640 | validator.lastValid = true; 641 | validator.lastFinished = false; 642 | $.ajax({ 643 | url: validator.url, 644 | data: "value=" + value + "&field=" + $this.attr("name"), 645 | dataType: "json", 646 | success: function (data) { 647 | if (""+validator.lastValue === ""+data.value) { 648 | validator.lastValid = !!(data.valid); 649 | if (data.message) { 650 | validator.message = data.message; 651 | } 652 | validator.lastFinished = true; 653 | $this.data("validation" + validator.validatorName + "Message", validator.message); 654 | // Timeout is set to avoid problems with the events being considered 'already fired' 655 | setTimeout(function () { 656 | $this.trigger("change.validation"); 657 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 658 | } 659 | }, 660 | failure: function () { 661 | validator.lastValid = true; 662 | validator.message = "ajax call failed"; 663 | validator.lastFinished = true; 664 | $this.data("validation" + validator.validatorName + "Message", validator.message); 665 | // Timeout is set to avoid problems with the events being considered 'already fired' 666 | setTimeout(function () { 667 | $this.trigger("change.validation"); 668 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 669 | } 670 | }); 671 | } 672 | 673 | return false; 674 | 675 | } 676 | }, 677 | regex: { 678 | name: "regex", 679 | init: function ($this, name) { 680 | return {regex: regexFromString($this.data("validation" + name + "Regex"))}; 681 | }, 682 | validate: function ($this, value, validator) { 683 | return (!validator.regex.test(value) && ! validator.negative) 684 | || (validator.regex.test(value) && validator.negative); 685 | } 686 | }, 687 | required: { 688 | name: "required", 689 | init: function ($this, name) { 690 | return {}; 691 | }, 692 | validate: function ($this, value, validator) { 693 | return !!(value.length === 0 && ! validator.negative) 694 | || !!(value.length > 0 && validator.negative); 695 | }, 696 | blockSubmit: true 697 | }, 698 | match: { 699 | name: "match", 700 | init: function ($this, name) { 701 | var element = $this.parents("form").first().find("[name=\"" + $this.data("validation" + name + "Match") + "\"]").first(); 702 | element.bind("validation.validation", function () { 703 | $this.trigger("change.validation", {submitting: true}); 704 | }); 705 | return {"element": element}; 706 | }, 707 | validate: function ($this, value, validator) { 708 | return (value !== validator.element.val() && ! validator.negative) 709 | || (value === validator.element.val() && validator.negative); 710 | }, 711 | blockSubmit: true 712 | }, 713 | max: { 714 | name: "max", 715 | init: function ($this, name) { 716 | return {max: $this.data("validation" + name + "Max")}; 717 | }, 718 | validate: function ($this, value, validator) { 719 | return (parseFloat(value, 10) > parseFloat(validator.max, 10) && ! validator.negative) 720 | || (parseFloat(value, 10) <= parseFloat(validator.max, 10) && validator.negative); 721 | } 722 | }, 723 | min: { 724 | name: "min", 725 | init: function ($this, name) { 726 | return {min: $this.data("validation" + name + "Min")}; 727 | }, 728 | validate: function ($this, value, validator) { 729 | return (parseFloat(value) < parseFloat(validator.min) && ! validator.negative) 730 | || (parseFloat(value) >= parseFloat(validator.min) && validator.negative); 731 | } 732 | }, 733 | maxlength: { 734 | name: "maxlength", 735 | init: function ($this, name) { 736 | return {maxlength: $this.data("validation" + name + "Maxlength")}; 737 | }, 738 | validate: function ($this, value, validator) { 739 | return ((value.length > validator.maxlength) && ! validator.negative) 740 | || ((value.length <= validator.maxlength) && validator.negative); 741 | } 742 | }, 743 | minlength: { 744 | name: "minlength", 745 | init: function ($this, name) { 746 | return {minlength: $this.data("validation" + name + "Minlength")}; 747 | }, 748 | validate: function ($this, value, validator) { 749 | return ((value.length < validator.minlength) && ! validator.negative) 750 | || ((value.length >= validator.minlength) && validator.negative); 751 | } 752 | }, 753 | maxchecked: { 754 | name: "maxchecked", 755 | init: function ($this, name) { 756 | var elements = $this.parents("form").first().find("[name=\"" + $this.attr("name") + "\"]"); 757 | elements.bind("click.validation", function () { 758 | $this.trigger("change.validation", {includeEmpty: true}); 759 | }); 760 | return {maxchecked: $this.data("validation" + name + "Maxchecked"), elements: elements}; 761 | }, 762 | validate: function ($this, value, validator) { 763 | return (validator.elements.filter(":checked").length > validator.maxchecked && ! validator.negative) 764 | || (validator.elements.filter(":checked").length <= validator.maxchecked && validator.negative); 765 | }, 766 | blockSubmit: true 767 | }, 768 | minchecked: { 769 | name: "minchecked", 770 | init: function ($this, name) { 771 | var elements = $this.parents("form").first().find("[name=\"" + $this.attr("name") + "\"]"); 772 | elements.bind("click.validation", function () { 773 | $this.trigger("change.validation", {includeEmpty: true}); 774 | }); 775 | return {minchecked: $this.data("validation" + name + "Minchecked"), elements: elements}; 776 | }, 777 | validate: function ($this, value, validator) { 778 | return (validator.elements.filter(":checked").length < validator.minchecked && ! validator.negative) 779 | || (validator.elements.filter(":checked").length >= validator.minchecked && validator.negative); 780 | }, 781 | blockSubmit: true 782 | } 783 | }, 784 | builtInValidators: { 785 | email: { 786 | name: "Email", 787 | type: "shortcut", 788 | shortcut: "validemail" 789 | }, 790 | validemail: { 791 | name: "Validemail", 792 | type: "regex", 793 | regex: "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\.[A-Za-z]{2,4}", 794 | message: "Not a valid email address" 795 | }, 796 | passwordagain: { 797 | name: "Passwordagain", 798 | type: "match", 799 | match: "password", 800 | message: "Does not match the given password" 801 | }, 802 | positive: { 803 | name: "Positive", 804 | type: "shortcut", 805 | shortcut: "number,positivenumber" 806 | }, 807 | negative: { 808 | name: "Negative", 809 | type: "shortcut", 810 | shortcut: "number,negativenumber" 811 | }, 812 | number: { 813 | name: "Number", 814 | type: "regex", 815 | regex: "([+-]?\\\d+(\\\.\\\d*)?([eE][+-]?[0-9]+)?)?", 816 | message: "Must be a number" 817 | }, 818 | integer: { 819 | name: "Integer", 820 | type: "regex", 821 | regex: "[+-]?\\\d+", 822 | message: "No decimal places allowed" 823 | }, 824 | positivenumber: { 825 | name: "Positivenumber", 826 | type: "min", 827 | min: 0, 828 | message: "Must be a positive number" 829 | }, 830 | negativenumber: { 831 | name: "Negativenumber", 832 | type: "max", 833 | max: 0, 834 | message: "Must be a negative number" 835 | }, 836 | required: { 837 | name: "Required", 838 | type: "required", 839 | message: "This is required" 840 | }, 841 | checkone: { 842 | name: "Checkone", 843 | type: "minchecked", 844 | minchecked: 1, 845 | message: "Check at least one option" 846 | } 847 | } 848 | }; 849 | 850 | var formatValidatorName = function (name) { 851 | return name 852 | .toLowerCase() 853 | .replace( 854 | /(^|\s)([a-z])/g , 855 | function(m,p1,p2) { 856 | return p1+p2.toUpperCase(); 857 | } 858 | ) 859 | ; 860 | }; 861 | 862 | var getValue = function ($this) { 863 | // Extract the value we're talking about 864 | var value = $this.val(); 865 | var type = $this.attr("type"); 866 | if (type === "checkbox") { 867 | value = ($this.is(":checked") ? value : ""); 868 | } 869 | if (type === "radio") { 870 | value = ($('input[name="' + $this.attr("name") + '"]:checked').length > 0 ? value : ""); 871 | } 872 | return value; 873 | }; 874 | 875 | function regexFromString(inputstring) { 876 | return new RegExp("^" + inputstring + "$"); 877 | } 878 | 879 | /** 880 | * Thanks to Jason Bunting via StackOverflow.com 881 | * 882 | * http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string#answer-359910 883 | * Short link: http://tinyurl.com/executeFunctionByName 884 | **/ 885 | function executeFunctionByName(functionName, context /*, args*/) { 886 | var args = Array.prototype.slice.call(arguments).splice(2); 887 | var namespaces = functionName.split("."); 888 | var func = namespaces.pop(); 889 | for(var i = 0; i < namespaces.length; i++) { 890 | context = context[namespaces[i]]; 891 | } 892 | return context[func].apply(this, args); 893 | } 894 | 895 | $.fn.jqBootstrapValidation = function( method ) { 896 | 897 | if ( defaults.methods[method] ) { 898 | return defaults.methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); 899 | } else if ( typeof method === 'object' || ! method ) { 900 | return defaults.methods.init.apply( this, arguments ); 901 | } else { 902 | $.error( 'Method ' + method + ' does not exist on jQuery.jqBootstrapValidation' ); 903 | return null; 904 | } 905 | 906 | }; 907 | 908 | $.jqBootstrapValidation = function (options) { 909 | $(":input").not("[type=image],[type=submit]").jqBootstrapValidation.apply(this,arguments); 910 | }; 911 | 912 | })( jQuery ); 913 | -------------------------------------------------------------------------------- /target/spring-mvc-app/resources/js/jqBootstrapValidation.js: -------------------------------------------------------------------------------- 1 | /* jqBootstrapValidation 2 | * A plugin for automating validation on Twitter Bootstrap formatted forms. 3 | * 4 | * v1.3.6 5 | * 6 | * License: MIT - see LICENSE file 7 | * 8 | * http://ReactiveRaven.github.com/jqBootstrapValidation/ 9 | */ 10 | 11 | (function( $ ){ 12 | 13 | var createdElements = []; 14 | 15 | var defaults = { 16 | options: { 17 | prependExistingHelpBlock: false, 18 | sniffHtml: true, // sniff for 'required', 'maxlength', etc 19 | preventSubmit: true, // stop the form submit event from firing if validation fails 20 | submitError: false, // function called if there is an error when trying to submit 21 | submitSuccess: false, // function called just before a successful submit event is sent to the server 22 | semanticallyStrict: false, // set to true to tidy up generated HTML output 23 | autoAdd: { 24 | helpBlocks: true 25 | }, 26 | filter: function () { 27 | // return $(this).is(":visible"); // only validate elements you can see 28 | return true; // validate everything 29 | } 30 | }, 31 | methods: { 32 | init : function( options ) { 33 | 34 | var settings = $.extend(true, {}, defaults); 35 | 36 | settings.options = $.extend(true, settings.options, options); 37 | 38 | var $siblingElements = this; 39 | 40 | var uniqueForms = $.unique( 41 | $siblingElements.map( function () { 42 | return $(this).parents("form")[0]; 43 | }).toArray() 44 | ); 45 | 46 | $(uniqueForms).bind("submit", function (e) { 47 | var $form = $(this); 48 | var warningsFound = 0; 49 | var $inputs = $form.find("input,textarea,select").not("[type=submit],[type=image]").filter(settings.options.filter); 50 | $inputs.trigger("submit.validation").trigger("validationLostFocus.validation"); 51 | 52 | $inputs.each(function (i, el) { 53 | var $this = $(el), 54 | $controlGroup = $this.parents(".control-group").first(); 55 | if ( 56 | $controlGroup.hasClass("has-warning") 57 | ) { 58 | $controlGroup.removeClass("has-warning").addClass("has-error"); 59 | warningsFound++; 60 | } 61 | }); 62 | 63 | $inputs.trigger("validationLostFocus.validation"); 64 | 65 | if (warningsFound) { 66 | if (settings.options.preventSubmit) { 67 | e.preventDefault(); 68 | } 69 | $form.addClass("has-error"); 70 | if ($.isFunction(settings.options.submitError)) { 71 | settings.options.submitError($form, e, $inputs.jqBootstrapValidation("collectErrors", true)); 72 | } 73 | } else { 74 | $form.removeClass("has-error"); 75 | if ($.isFunction(settings.options.submitSuccess)) { 76 | settings.options.submitSuccess($form, e); 77 | } 78 | } 79 | }); 80 | 81 | return this.each(function(){ 82 | 83 | // Get references to everything we're interested in 84 | var $this = $(this), 85 | $controlGroup = $this.parents(".control-group").first(), 86 | $helpBlock = $controlGroup.find(".help-block").first(), 87 | $form = $this.parents("form").first(), 88 | validatorNames = []; 89 | 90 | // create message container if not exists 91 | if (!$helpBlock.length && settings.options.autoAdd && settings.options.autoAdd.helpBlocks) { 92 | $helpBlock = $('
'); 93 | $controlGroup.find('.controls').append($helpBlock); 94 | createdElements.push($helpBlock[0]); 95 | } 96 | 97 | // ============================================================= 98 | // SNIFF HTML FOR VALIDATORS 99 | // ============================================================= 100 | 101 | // *snort sniff snuffle* 102 | 103 | if (settings.options.sniffHtml) { 104 | var message = ""; 105 | // --------------------------------------------------------- 106 | // PATTERN 107 | // --------------------------------------------------------- 108 | if ($this.attr("pattern") !== undefined) { 109 | message = "Not in the expected format"; 110 | if ($this.data("validationPatternMessage")) { 111 | message = $this.data("validationPatternMessage"); 112 | } 113 | $this.data("validationPatternMessage", message); 114 | $this.data("validationPatternRegex", $this.attr("pattern")); 115 | } 116 | // --------------------------------------------------------- 117 | // MAX 118 | // --------------------------------------------------------- 119 | if ($this.attr("max") !== undefined || $this.attr("aria-valuemax") !== undefined) { 120 | var max = ($this.attr("max") !== undefined ? $this.attr("max") : $this.attr("aria-valuemax")); 121 | message = "Too high: Maximum of '" + max + "'"; 122 | if ($this.data("validationMaxMessage")) { 123 | message = $this.data("validationMaxMessage"); 124 | } 125 | $this.data("validationMaxMessage", message); 126 | $this.data("validationMaxMax", max); 127 | } 128 | // --------------------------------------------------------- 129 | // MIN 130 | // --------------------------------------------------------- 131 | if ($this.attr("min") !== undefined || $this.attr("aria-valuemin") !== undefined) { 132 | var min = ($this.attr("min") !== undefined ? $this.attr("min") : $this.attr("aria-valuemin")); 133 | message = "Too low: Minimum of '" + min + "'"; 134 | if ($this.data("validationMinMessage")) { 135 | message = $this.data("validationMinMessage"); 136 | } 137 | $this.data("validationMinMessage", message); 138 | $this.data("validationMinMin", min); 139 | } 140 | // --------------------------------------------------------- 141 | // MAXLENGTH 142 | // --------------------------------------------------------- 143 | if ($this.attr("maxlength") !== undefined) { 144 | message = "Too long: Maximum of '" + $this.attr("maxlength") + "' characters"; 145 | if ($this.data("validationMaxlengthMessage")) { 146 | message = $this.data("validationMaxlengthMessage"); 147 | } 148 | $this.data("validationMaxlengthMessage", message); 149 | $this.data("validationMaxlengthMaxlength", $this.attr("maxlength")); 150 | } 151 | // --------------------------------------------------------- 152 | // MINLENGTH 153 | // --------------------------------------------------------- 154 | if ($this.attr("minlength") !== undefined) { 155 | message = "Too short: Minimum of '" + $this.attr("minlength") + "' characters"; 156 | if ($this.data("validationMinlengthMessage")) { 157 | message = $this.data("validationMinlengthMessage"); 158 | } 159 | $this.data("validationMinlengthMessage", message); 160 | $this.data("validationMinlengthMinlength", $this.attr("minlength")); 161 | } 162 | // --------------------------------------------------------- 163 | // REQUIRED 164 | // --------------------------------------------------------- 165 | if ($this.attr("required") !== undefined || $this.attr("aria-required") !== undefined) { 166 | message = settings.builtInValidators.required.message; 167 | if ($this.data("validationRequiredMessage")) { 168 | message = $this.data("validationRequiredMessage"); 169 | } 170 | $this.data("validationRequiredMessage", message); 171 | } 172 | // --------------------------------------------------------- 173 | // NUMBER 174 | // --------------------------------------------------------- 175 | if ($this.attr("type") !== undefined && $this.attr("type").toLowerCase() === "number") { 176 | message = settings.builtInValidators.number.message; 177 | if ($this.data("validationNumberMessage")) { 178 | message = $this.data("validationNumberMessage"); 179 | } 180 | $this.data("validationNumberMessage", message); 181 | } 182 | // --------------------------------------------------------- 183 | // EMAIL 184 | // --------------------------------------------------------- 185 | if ($this.attr("type") !== undefined && $this.attr("type").toLowerCase() === "email") { 186 | message = "Not a valid email address"; 187 | if ($this.data("validationValidemailMessage")) { 188 | message = $this.data("validationValidemailMessage"); 189 | } else if ($this.data("validationEmailMessage")) { 190 | message = $this.data("validationEmailMessage"); 191 | } 192 | $this.data("validationValidemailMessage", message); 193 | } 194 | // --------------------------------------------------------- 195 | // MINCHECKED 196 | // --------------------------------------------------------- 197 | if ($this.attr("minchecked") !== undefined) { 198 | message = "Not enough options checked; Minimum of '" + $this.attr("minchecked") + "' required"; 199 | if ($this.data("validationMincheckedMessage")) { 200 | message = $this.data("validationMincheckedMessage"); 201 | } 202 | $this.data("validationMincheckedMessage", message); 203 | $this.data("validationMincheckedMinchecked", $this.attr("minchecked")); 204 | } 205 | // --------------------------------------------------------- 206 | // MAXCHECKED 207 | // --------------------------------------------------------- 208 | if ($this.attr("maxchecked") !== undefined) { 209 | message = "Too many options checked; Maximum of '" + $this.attr("maxchecked") + "' required"; 210 | if ($this.data("validationMaxcheckedMessage")) { 211 | message = $this.data("validationMaxcheckedMessage"); 212 | } 213 | $this.data("validationMaxcheckedMessage", message); 214 | $this.data("validationMaxcheckedMaxchecked", $this.attr("maxchecked")); 215 | } 216 | } 217 | 218 | // ============================================================= 219 | // COLLECT VALIDATOR NAMES 220 | // ============================================================= 221 | 222 | // Get named validators 223 | if ($this.data("validation") !== undefined) { 224 | validatorNames = $this.data("validation").split(","); 225 | } 226 | 227 | // Get extra ones defined on the element's data attributes 228 | $.each($this.data(), function (i, el) { 229 | var parts = i.replace(/([A-Z])/g, ",$1").split(","); 230 | if (parts[0] === "validation" && parts[1]) { 231 | validatorNames.push(parts[1]); 232 | } 233 | }); 234 | 235 | // ============================================================= 236 | // NORMALISE VALIDATOR NAMES 237 | // ============================================================= 238 | 239 | var validatorNamesToInspect = validatorNames; 240 | var newValidatorNamesToInspect = []; 241 | 242 | do // repeatedly expand 'shortcut' validators into their real validators 243 | { 244 | // Uppercase only the first letter of each name 245 | $.each(validatorNames, function (i, el) { 246 | validatorNames[i] = formatValidatorName(el); 247 | }); 248 | 249 | // Remove duplicate validator names 250 | validatorNames = $.unique(validatorNames); 251 | 252 | // Pull out the new validator names from each shortcut 253 | newValidatorNamesToInspect = []; 254 | $.each(validatorNamesToInspect, function(i, el) { 255 | if ($this.data("validation" + el + "Shortcut") !== undefined) { 256 | // Are these custom validators? 257 | // Pull them out! 258 | $.each($this.data("validation" + el + "Shortcut").split(","), function(i2, el2) { 259 | newValidatorNamesToInspect.push(el2); 260 | }); 261 | } else if (settings.builtInValidators[el.toLowerCase()]) { 262 | // Is this a recognised built-in? 263 | // Pull it out! 264 | var validator = settings.builtInValidators[el.toLowerCase()]; 265 | if (validator.type.toLowerCase() === "shortcut") { 266 | $.each(validator.shortcut.split(","), function (i, el) { 267 | el = formatValidatorName(el); 268 | newValidatorNamesToInspect.push(el); 269 | validatorNames.push(el); 270 | }); 271 | } 272 | } 273 | }); 274 | 275 | validatorNamesToInspect = newValidatorNamesToInspect; 276 | 277 | } while (validatorNamesToInspect.length > 0) 278 | 279 | // ============================================================= 280 | // SET UP VALIDATOR ARRAYS 281 | // ============================================================= 282 | 283 | var validators = {}; 284 | 285 | $.each(validatorNames, function (i, el) { 286 | // Set up the 'override' message 287 | var message = $this.data("validation" + el + "Message"); 288 | var hasOverrideMessage = (message !== undefined); 289 | var foundValidator = false; 290 | message = 291 | ( 292 | message 293 | ? message 294 | : "'" + el + "' validation failed " 295 | ) 296 | ; 297 | 298 | $.each( 299 | settings.validatorTypes, 300 | function (validatorType, validatorTemplate) { 301 | if (validators[validatorType] === undefined) { 302 | validators[validatorType] = []; 303 | } 304 | if (!foundValidator && $this.data("validation" + el + formatValidatorName(validatorTemplate.name)) !== undefined) { 305 | validators[validatorType].push( 306 | $.extend( 307 | true, 308 | { 309 | name: formatValidatorName(validatorTemplate.name), 310 | message: message 311 | }, 312 | validatorTemplate.init($this, el) 313 | ) 314 | ); 315 | foundValidator = true; 316 | } 317 | } 318 | ); 319 | 320 | if (!foundValidator && settings.builtInValidators[el.toLowerCase()]) { 321 | 322 | var validator = $.extend(true, {}, settings.builtInValidators[el.toLowerCase()]); 323 | if (hasOverrideMessage) { 324 | validator.message = message; 325 | } 326 | var validatorType = validator.type.toLowerCase(); 327 | 328 | if (validatorType === "shortcut") { 329 | foundValidator = true; 330 | } else { 331 | $.each( 332 | settings.validatorTypes, 333 | function (validatorTemplateType, validatorTemplate) { 334 | if (validators[validatorTemplateType] === undefined) { 335 | validators[validatorTemplateType] = []; 336 | } 337 | if (!foundValidator && validatorType === validatorTemplateType.toLowerCase()) { 338 | $this.data("validation" + el + formatValidatorName(validatorTemplate.name), validator[validatorTemplate.name.toLowerCase()]); 339 | validators[validatorType].push( 340 | $.extend( 341 | validator, 342 | validatorTemplate.init($this, el) 343 | ) 344 | ); 345 | foundValidator = true; 346 | } 347 | } 348 | ); 349 | } 350 | } 351 | 352 | if (! foundValidator) { 353 | $.error("Cannot find validation info for '" + el + "'"); 354 | } 355 | }); 356 | 357 | // ============================================================= 358 | // STORE FALLBACK VALUES 359 | // ============================================================= 360 | 361 | $helpBlock.data( 362 | "original-contents", 363 | ( 364 | $helpBlock.data("original-contents") 365 | ? $helpBlock.data("original-contents") 366 | : $helpBlock.html() 367 | ) 368 | ); 369 | 370 | $helpBlock.data( 371 | "original-role", 372 | ( 373 | $helpBlock.data("original-role") 374 | ? $helpBlock.data("original-role") 375 | : $helpBlock.attr("role") 376 | ) 377 | ); 378 | 379 | $controlGroup.data( 380 | "original-classes", 381 | ( 382 | $controlGroup.data("original-clases") 383 | ? $controlGroup.data("original-classes") 384 | : $controlGroup.attr("class") 385 | ) 386 | ); 387 | 388 | $this.data( 389 | "original-aria-invalid", 390 | ( 391 | $this.data("original-aria-invalid") 392 | ? $this.data("original-aria-invalid") 393 | : $this.attr("aria-invalid") 394 | ) 395 | ); 396 | 397 | // ============================================================= 398 | // VALIDATION 399 | // ============================================================= 400 | 401 | $this.bind( 402 | "validation.validation", 403 | function (event, params) { 404 | 405 | var value = getValue($this); 406 | 407 | // Get a list of the errors to apply 408 | var errorsFound = []; 409 | 410 | $.each(validators, function (validatorType, validatorTypeArray) { 411 | if (value || value.length || (params && params.includeEmpty) || (!!settings.validatorTypes[validatorType].blockSubmit && params && !!params.submitting)) { 412 | $.each(validatorTypeArray, function (i, validator) { 413 | if (settings.validatorTypes[validatorType].validate($this, value, validator)) { 414 | errorsFound.push(validator.message); 415 | } 416 | }); 417 | } 418 | }); 419 | 420 | return errorsFound; 421 | } 422 | ); 423 | 424 | $this.bind( 425 | "getValidators.validation", 426 | function () { 427 | return validators; 428 | } 429 | ); 430 | 431 | // ============================================================= 432 | // WATCH FOR CHANGES 433 | // ============================================================= 434 | $this.bind( 435 | "submit.validation", 436 | function () { 437 | return $this.triggerHandler("change.validation", {submitting: true}); 438 | } 439 | ); 440 | $this.bind( 441 | [ 442 | "keyup", 443 | "focus", 444 | "blur", 445 | "click", 446 | "keydown", 447 | "keypress", 448 | "change" 449 | ].join(".validation ") + ".validation", 450 | function (e, params) { 451 | 452 | var value = getValue($this); 453 | 454 | var errorsFound = []; 455 | 456 | $controlGroup.find("input,textarea,select").each(function (i, el) { 457 | var oldCount = errorsFound.length; 458 | $.each($(el).triggerHandler("validation.validation", params), function (j, message) { 459 | errorsFound.push(message); 460 | }); 461 | if (errorsFound.length > oldCount) { 462 | $(el).attr("aria-invalid", "true"); 463 | } else { 464 | var original = $this.data("original-aria-invalid"); 465 | $(el).attr("aria-invalid", (original !== undefined ? original : false)); 466 | } 467 | }); 468 | 469 | $form.find("input,select,textarea").not($this).not("[name=\"" + $this.attr("name") + "\"]").trigger("validationLostFocus.validation"); 470 | 471 | errorsFound = $.unique(errorsFound.sort()); 472 | 473 | // Were there any errors? 474 | if (errorsFound.length) { 475 | // Better flag it up as a warning. 476 | $controlGroup.removeClass("has-success has-error").addClass("has-warning"); 477 | 478 | // How many errors did we find? 479 | if (settings.options.semanticallyStrict && errorsFound.length === 1) { 480 | // Only one? Being strict? Just output it. 481 | $helpBlock.html(errorsFound[0] + 482 | ( settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : "" )); 483 | } else { 484 | // Multiple? Being sloppy? Glue them together into an UL. 485 | $helpBlock.html("
  • " + errorsFound.join("
  • ") + "
" + 486 | ( settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : "" )); 487 | } 488 | } else { 489 | $controlGroup.removeClass("has-warning has-error has-success"); 490 | if (value.length > 0) { 491 | $controlGroup.addClass("has-success"); 492 | } 493 | $helpBlock.html($helpBlock.data("original-contents")); 494 | } 495 | 496 | if (e.type === "blur") { 497 | $controlGroup.removeClass("has-success"); 498 | } 499 | } 500 | ); 501 | $this.bind("validationLostFocus.validation", function () { 502 | $controlGroup.removeClass("has-success"); 503 | }); 504 | }); 505 | }, 506 | destroy : function( ) { 507 | 508 | return this.each( 509 | function() { 510 | 511 | var 512 | $this = $(this), 513 | $controlGroup = $this.parents(".control-group").first(), 514 | $helpBlock = $controlGroup.find(".help-block").first(); 515 | 516 | // remove our events 517 | $this.unbind('.validation'); // events are namespaced. 518 | // reset help text 519 | $helpBlock.html($helpBlock.data("original-contents")); 520 | // reset classes 521 | $controlGroup.attr("class", $controlGroup.data("original-classes")); 522 | // reset aria 523 | $this.attr("aria-invalid", $this.data("original-aria-invalid")); 524 | // reset role 525 | $helpBlock.attr("role", $this.data("original-role")); 526 | // remove all elements we created 527 | if (createdElements.indexOf($helpBlock[0]) > -1) { 528 | $helpBlock.remove(); 529 | } 530 | 531 | } 532 | ); 533 | 534 | }, 535 | collectErrors : function(includeEmpty) { 536 | 537 | var errorMessages = {}; 538 | this.each(function (i, el) { 539 | var $el = $(el); 540 | var name = $el.attr("name"); 541 | var errors = $el.triggerHandler("validation.validation", {includeEmpty: true}); 542 | errorMessages[name] = $.extend(true, errors, errorMessages[name]); 543 | }); 544 | 545 | $.each(errorMessages, function (i, el) { 546 | if (el.length === 0) { 547 | delete errorMessages[i]; 548 | } 549 | }); 550 | 551 | return errorMessages; 552 | 553 | }, 554 | hasErrors: function() { 555 | 556 | var errorMessages = []; 557 | 558 | this.each(function (i, el) { 559 | errorMessages = errorMessages.concat( 560 | $(el).triggerHandler("getValidators.validation") ? $(el).triggerHandler("validation.validation", {submitting: true}) : [] 561 | ); 562 | }); 563 | 564 | return (errorMessages.length > 0); 565 | }, 566 | override : function (newDefaults) { 567 | defaults = $.extend(true, defaults, newDefaults); 568 | } 569 | }, 570 | validatorTypes: { 571 | callback: { 572 | name: "callback", 573 | init: function ($this, name) { 574 | return { 575 | validatorName: name, 576 | callback: $this.data("validation" + name + "Callback"), 577 | lastValue: $this.val(), 578 | lastValid: true, 579 | lastFinished: true 580 | }; 581 | }, 582 | validate: function ($this, value, validator) { 583 | if (validator.lastValue === value && validator.lastFinished) { 584 | return !validator.lastValid; 585 | } 586 | 587 | if (validator.lastFinished === true) 588 | { 589 | validator.lastValue = value; 590 | validator.lastValid = true; 591 | validator.lastFinished = false; 592 | 593 | var rrjqbvValidator = validator; 594 | var rrjqbvThis = $this; 595 | executeFunctionByName( 596 | validator.callback, 597 | window, 598 | $this, 599 | value, 600 | function (data) { 601 | if (rrjqbvValidator.lastValue === data.value) { 602 | rrjqbvValidator.lastValid = data.valid; 603 | if (data.message) { 604 | rrjqbvValidator.message = data.message; 605 | } 606 | rrjqbvValidator.lastFinished = true; 607 | rrjqbvThis.data("validation" + rrjqbvValidator.validatorName + "Message", rrjqbvValidator.message); 608 | // Timeout is set to avoid problems with the events being considered 'already fired' 609 | setTimeout(function () { 610 | rrjqbvThis.trigger("change.validation"); 611 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 612 | } 613 | } 614 | ); 615 | } 616 | 617 | return false; 618 | 619 | } 620 | }, 621 | ajax: { 622 | name: "ajax", 623 | init: function ($this, name) { 624 | return { 625 | validatorName: name, 626 | url: $this.data("validation" + name + "Ajax"), 627 | lastValue: $this.val(), 628 | lastValid: true, 629 | lastFinished: true 630 | }; 631 | }, 632 | validate: function ($this, value, validator) { 633 | if (""+validator.lastValue === ""+value && validator.lastFinished === true) { 634 | return validator.lastValid === false; 635 | } 636 | 637 | if (validator.lastFinished === true) 638 | { 639 | validator.lastValue = value; 640 | validator.lastValid = true; 641 | validator.lastFinished = false; 642 | $.ajax({ 643 | url: validator.url, 644 | data: "value=" + value + "&field=" + $this.attr("name"), 645 | dataType: "json", 646 | success: function (data) { 647 | if (""+validator.lastValue === ""+data.value) { 648 | validator.lastValid = !!(data.valid); 649 | if (data.message) { 650 | validator.message = data.message; 651 | } 652 | validator.lastFinished = true; 653 | $this.data("validation" + validator.validatorName + "Message", validator.message); 654 | // Timeout is set to avoid problems with the events being considered 'already fired' 655 | setTimeout(function () { 656 | $this.trigger("change.validation"); 657 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 658 | } 659 | }, 660 | failure: function () { 661 | validator.lastValid = true; 662 | validator.message = "ajax call failed"; 663 | validator.lastFinished = true; 664 | $this.data("validation" + validator.validatorName + "Message", validator.message); 665 | // Timeout is set to avoid problems with the events being considered 'already fired' 666 | setTimeout(function () { 667 | $this.trigger("change.validation"); 668 | }, 1); // doesn't need a long timeout, just long enough for the event bubble to burst 669 | } 670 | }); 671 | } 672 | 673 | return false; 674 | 675 | } 676 | }, 677 | regex: { 678 | name: "regex", 679 | init: function ($this, name) { 680 | return {regex: regexFromString($this.data("validation" + name + "Regex"))}; 681 | }, 682 | validate: function ($this, value, validator) { 683 | return (!validator.regex.test(value) && ! validator.negative) 684 | || (validator.regex.test(value) && validator.negative); 685 | } 686 | }, 687 | required: { 688 | name: "required", 689 | init: function ($this, name) { 690 | return {}; 691 | }, 692 | validate: function ($this, value, validator) { 693 | return !!(value.length === 0 && ! validator.negative) 694 | || !!(value.length > 0 && validator.negative); 695 | }, 696 | blockSubmit: true 697 | }, 698 | match: { 699 | name: "match", 700 | init: function ($this, name) { 701 | var element = $this.parents("form").first().find("[name=\"" + $this.data("validation" + name + "Match") + "\"]").first(); 702 | element.bind("validation.validation", function () { 703 | $this.trigger("change.validation", {submitting: true}); 704 | }); 705 | return {"element": element}; 706 | }, 707 | validate: function ($this, value, validator) { 708 | return (value !== validator.element.val() && ! validator.negative) 709 | || (value === validator.element.val() && validator.negative); 710 | }, 711 | blockSubmit: true 712 | }, 713 | max: { 714 | name: "max", 715 | init: function ($this, name) { 716 | return {max: $this.data("validation" + name + "Max")}; 717 | }, 718 | validate: function ($this, value, validator) { 719 | return (parseFloat(value, 10) > parseFloat(validator.max, 10) && ! validator.negative) 720 | || (parseFloat(value, 10) <= parseFloat(validator.max, 10) && validator.negative); 721 | } 722 | }, 723 | min: { 724 | name: "min", 725 | init: function ($this, name) { 726 | return {min: $this.data("validation" + name + "Min")}; 727 | }, 728 | validate: function ($this, value, validator) { 729 | return (parseFloat(value) < parseFloat(validator.min) && ! validator.negative) 730 | || (parseFloat(value) >= parseFloat(validator.min) && validator.negative); 731 | } 732 | }, 733 | maxlength: { 734 | name: "maxlength", 735 | init: function ($this, name) { 736 | return {maxlength: $this.data("validation" + name + "Maxlength")}; 737 | }, 738 | validate: function ($this, value, validator) { 739 | return ((value.length > validator.maxlength) && ! validator.negative) 740 | || ((value.length <= validator.maxlength) && validator.negative); 741 | } 742 | }, 743 | minlength: { 744 | name: "minlength", 745 | init: function ($this, name) { 746 | return {minlength: $this.data("validation" + name + "Minlength")}; 747 | }, 748 | validate: function ($this, value, validator) { 749 | return ((value.length < validator.minlength) && ! validator.negative) 750 | || ((value.length >= validator.minlength) && validator.negative); 751 | } 752 | }, 753 | maxchecked: { 754 | name: "maxchecked", 755 | init: function ($this, name) { 756 | var elements = $this.parents("form").first().find("[name=\"" + $this.attr("name") + "\"]"); 757 | elements.bind("click.validation", function () { 758 | $this.trigger("change.validation", {includeEmpty: true}); 759 | }); 760 | return {maxchecked: $this.data("validation" + name + "Maxchecked"), elements: elements}; 761 | }, 762 | validate: function ($this, value, validator) { 763 | return (validator.elements.filter(":checked").length > validator.maxchecked && ! validator.negative) 764 | || (validator.elements.filter(":checked").length <= validator.maxchecked && validator.negative); 765 | }, 766 | blockSubmit: true 767 | }, 768 | minchecked: { 769 | name: "minchecked", 770 | init: function ($this, name) { 771 | var elements = $this.parents("form").first().find("[name=\"" + $this.attr("name") + "\"]"); 772 | elements.bind("click.validation", function () { 773 | $this.trigger("change.validation", {includeEmpty: true}); 774 | }); 775 | return {minchecked: $this.data("validation" + name + "Minchecked"), elements: elements}; 776 | }, 777 | validate: function ($this, value, validator) { 778 | return (validator.elements.filter(":checked").length < validator.minchecked && ! validator.negative) 779 | || (validator.elements.filter(":checked").length >= validator.minchecked && validator.negative); 780 | }, 781 | blockSubmit: true 782 | } 783 | }, 784 | builtInValidators: { 785 | email: { 786 | name: "Email", 787 | type: "shortcut", 788 | shortcut: "validemail" 789 | }, 790 | validemail: { 791 | name: "Validemail", 792 | type: "regex", 793 | regex: "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\.[A-Za-z]{2,4}", 794 | message: "Not a valid email address" 795 | }, 796 | passwordagain: { 797 | name: "Passwordagain", 798 | type: "match", 799 | match: "password", 800 | message: "Does not match the given password" 801 | }, 802 | positive: { 803 | name: "Positive", 804 | type: "shortcut", 805 | shortcut: "number,positivenumber" 806 | }, 807 | negative: { 808 | name: "Negative", 809 | type: "shortcut", 810 | shortcut: "number,negativenumber" 811 | }, 812 | number: { 813 | name: "Number", 814 | type: "regex", 815 | regex: "([+-]?\\\d+(\\\.\\\d*)?([eE][+-]?[0-9]+)?)?", 816 | message: "Must be a number" 817 | }, 818 | integer: { 819 | name: "Integer", 820 | type: "regex", 821 | regex: "[+-]?\\\d+", 822 | message: "No decimal places allowed" 823 | }, 824 | positivenumber: { 825 | name: "Positivenumber", 826 | type: "min", 827 | min: 0, 828 | message: "Must be a positive number" 829 | }, 830 | negativenumber: { 831 | name: "Negativenumber", 832 | type: "max", 833 | max: 0, 834 | message: "Must be a negative number" 835 | }, 836 | required: { 837 | name: "Required", 838 | type: "required", 839 | message: "This is required" 840 | }, 841 | checkone: { 842 | name: "Checkone", 843 | type: "minchecked", 844 | minchecked: 1, 845 | message: "Check at least one option" 846 | } 847 | } 848 | }; 849 | 850 | var formatValidatorName = function (name) { 851 | return name 852 | .toLowerCase() 853 | .replace( 854 | /(^|\s)([a-z])/g , 855 | function(m,p1,p2) { 856 | return p1+p2.toUpperCase(); 857 | } 858 | ) 859 | ; 860 | }; 861 | 862 | var getValue = function ($this) { 863 | // Extract the value we're talking about 864 | var value = $this.val(); 865 | var type = $this.attr("type"); 866 | if (type === "checkbox") { 867 | value = ($this.is(":checked") ? value : ""); 868 | } 869 | if (type === "radio") { 870 | value = ($('input[name="' + $this.attr("name") + '"]:checked').length > 0 ? value : ""); 871 | } 872 | return value; 873 | }; 874 | 875 | function regexFromString(inputstring) { 876 | return new RegExp("^" + inputstring + "$"); 877 | } 878 | 879 | /** 880 | * Thanks to Jason Bunting via StackOverflow.com 881 | * 882 | * http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string#answer-359910 883 | * Short link: http://tinyurl.com/executeFunctionByName 884 | **/ 885 | function executeFunctionByName(functionName, context /*, args*/) { 886 | var args = Array.prototype.slice.call(arguments).splice(2); 887 | var namespaces = functionName.split("."); 888 | var func = namespaces.pop(); 889 | for(var i = 0; i < namespaces.length; i++) { 890 | context = context[namespaces[i]]; 891 | } 892 | return context[func].apply(this, args); 893 | } 894 | 895 | $.fn.jqBootstrapValidation = function( method ) { 896 | 897 | if ( defaults.methods[method] ) { 898 | return defaults.methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); 899 | } else if ( typeof method === 'object' || ! method ) { 900 | return defaults.methods.init.apply( this, arguments ); 901 | } else { 902 | $.error( 'Method ' + method + ' does not exist on jQuery.jqBootstrapValidation' ); 903 | return null; 904 | } 905 | 906 | }; 907 | 908 | $.jqBootstrapValidation = function (options) { 909 | $(":input").not("[type=image],[type=submit]").jqBootstrapValidation.apply(this,arguments); 910 | }; 911 | 912 | })( jQuery ); 913 | --------------------------------------------------------------------------------