Commit 0bb5e24a authored by Deep Dey's avatar Deep Dey

initialize

parent 84e843f4
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
**/files/**
*.jpg
*.csv
*.xls
*.xlsx
*.txt
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.10</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>laMartin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>laMartin</name>
<description>LaMartin Student Application</description>
<properties>
<java.version>17</java.version>
<swagger.version>2.9.2</swagger.version>
<swagger-models.version>1.5.21</swagger-models.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger-models.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-schema</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.11.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.LaMartin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LaMartinApplication {
public static void main(String[] args) {
SpringApplication.run(LaMartinApplication.class, args);
}
}
package com.example.LaMartin.Swagger;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
import java.util.List;
@Import(BeanValidatorPluginsConfiguration.class)
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(java.util.Locale.class)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.LaMartin"))
.paths(PathSelectors.any())
.build()
.securityContexts(Lists.newArrayList(securityContext()))
.securitySchemes(Collections.singletonList(apiKey()));
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.any())
.build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope
= new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Collections.singletonList(
new SecurityReference("apikey", authorizationScopes)
);
}
@NotNull
@Contract(" -> new")
private ApiKey apiKey() {
return new ApiKey("apikey", "apikey", "header");
}
}
\ No newline at end of file
package com.example.LaMartin.admission.controller;
import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.common.model.GeneralResponse;
import com.example.LaMartin.constants.AppConstants;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@RestController
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class AdmissionFormController {
@PostMapping(
value = "/admission-form/submit",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "SUCCESS"),
@ApiResponse(code = 400, message = "FAILED"),
@ApiResponse(code = 500, message = "Exception Occurred")
})
@ApiOperation(value = "")
public Object addNewAdmission(
HttpServletRequest request,
@Valid @ModelAttribute AdmissionFormData admissionFormData,
@RequestPart("candidateImage") MultipartFile candidateImage,
@RequestPart("fatherImage") MultipartFile fatherImage,
@RequestPart("motherImage") MultipartFile motherImage
) throws Exception {
return new ResponseEntity<>(
new GeneralResponse(
true,
AppConstants.RESPONSE_SUCCESS_STATUS_CODE,
"Form Submitted Successfully",
null
),
HttpStatus.OK);
}
@GetMapping(
value = "/admission-form/get",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "SUCCESS"),
@ApiResponse(code = 400, message = "FAILED"),
@ApiResponse(code = 500, message = "Exception Occurred")
})
@ApiOperation(value = "")
public Object addNewAdmission(
HttpServletRequest request,
@RequestHeader("apikey") String apiKey
) throws Exception {
return new ResponseEntity<>(
new GeneralResponse(
true,
AppConstants.RESPONSE_SUCCESS_STATUS_CODE,
"Form Submitted Successfully",
null
),
HttpStatus.OK);
}
}
package com.example.LaMartin.admission.dao;
public class AdmissionFormDAOController {
}
package com.example.LaMartin.admission.mapper;
import com.example.LaMartin.admission.model.AdmissionFormData;
import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
public class AdmissionFormMapper implements RowMapper<AdmissionFormData> {
@Override
public AdmissionFormData mapRow(@NotNull ResultSet resultSet, int rowNum) throws SQLException {
return AdmissionFormData
.builder()
.id(resultSet.getLong("id"))
.school(resultSet.getString("school"))
.category(resultSet.getString("category"))
.fullName(resultSet.getString("fullName"))
.admissionClass(resultSet.getString("admissionClass"))
.dateOfBirth(resultSet.getString("dateOfBirth"))
.nationality(resultSet.getString("nationality"))
.religion(resultSet.getString("religion"))
.motherTongue(resultSet.getString("motherTongue"))
.community(resultSet.getString("community"))
.otherChildren(resultSet.getString("otherChildren"))
.maritalStatus(resultSet.getString("maritalStatus"))
.fatherName(resultSet.getString("fatherName"))
.fatherMobile(resultSet.getString("fatherMobile"))
.fatherEmail(resultSet.getString("fatherEmail"))
.fatherNationality(resultSet.getString("fatherNationality"))
.fatherReligion(resultSet.getString("fatherReligion"))
.fatherMotherTongue(resultSet.getString("fatherMotherTongue"))
.fatherCommunity(resultSet.getString("fatherCommunity"))
.fatherSchoolInfo(resultSet.getString("fatherSchoolInfo"))
.fatherCollegeInfo(resultSet.getString("fatherCollegeInfo"))
.fatherUniversityInfo(resultSet.getString("fatherUniversityInfo"))
.fatherProfessionalQualification(resultSet.getString("fatherProfessionalQualification"))
.fatherOccupation(resultSet.getString("fatherOccupation"))
.fatherMonthlyIncome(resultSet.getString("fatherMonthlyIncome"))
.fatherWorkplaceInfo(resultSet.getString("fatherWorkplaceInfo"))
.motherName(resultSet.getString("motherName"))
.motherMobile(resultSet.getString("motherMobile"))
.motherEmail(resultSet.getString("motherEmail"))
.motherNationality(resultSet.getString("motherNationality"))
.motherReligion(resultSet.getString("motherReligion"))
.motherMotherTongue(resultSet.getString("motherMotherTongue"))
.motherCommunity(resultSet.getString("motherCommunity"))
.motherSchoolInfo(resultSet.getString("motherSchoolInfo"))
.motherCollegeInfo(resultSet.getString("motherCollegeInfo"))
.motherUniversityInfo(resultSet.getString("motherUniversityInfo"))
.motherProfessionalQualification(resultSet.getString("motherProfessionalQualification"))
.motherOccupation(resultSet.getString("motherOccupation"))
.motherMonthlyIncome(resultSet.getString("motherMonthlyIncome"))
.motherWorkplaceInfo(resultSet.getString("motherWorkplaceInfo"))
.candidateImageName(resultSet.getString("candidateImageName"))
.fatherImageName(resultSet.getString("fatherImageName"))
.motherImageName(resultSet.getString("motherImageName"))
.build();
}
}
package com.example.LaMartin.admission.model;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@Getter
@Setter
public class AdmissionFormData {
private Long id;
@NotEmpty(message = "School cannot be empty")
private String school;
@NotEmpty(message = "Category cannot be empty")
private String category;
@NotEmpty(message = "Name cannot be empty")
private String fullName;
@NotEmpty(message = "Admission Class cannot be empty")
private String admissionClass;
@NotEmpty(message = "Date of Birth cannot be empty")
private String dateOfBirth;
@NotEmpty(message = "Nationality cannot be empty")
private String nationality;
@NotEmpty(message = "Religion cannot be empty")
private String religion;
@NotEmpty(message = "Mother Tongue cannot be empty")
private String motherTongue;
@NotEmpty(message = "Community cannot be empty")
private String community;
private String otherChildren;
@NotEmpty(message = "Marital Status cannot be empty")
private String maritalStatus;
@NotEmpty(message = "Father Name cannot be empty")
private String fatherName;
@NotEmpty(message = "Father Mobile cannot be empty")
private String fatherMobile;
@NotEmpty(message = "Father Email cannot be empty")
private String fatherEmail;
@NotEmpty(message = "Father Nationality cannot be empty")
private String fatherNationality;
@NotEmpty(message = "Father Religion cannot be empty")
private String fatherReligion;
@NotEmpty(message = "Father Mother Tongue cannot be empty")
private String fatherMotherTongue;
@NotEmpty(message = "Father Community cannot be empty")
private String fatherCommunity;
@NotEmpty(message = "Father School Info cannot be empty")
private String fatherSchoolInfo;
private String fatherCollegeInfo;
private String fatherUniversityInfo;
private String fatherProfessionalQualification;
@NotEmpty(message = "Father Occupation cannot be empty")
private String fatherOccupation;
@NotEmpty(message = "Father Monthly Income cannot be empty")
private String fatherMonthlyIncome;
private String fatherWorkplaceInfo;
@NotEmpty(message = "Mother Name cannot be empty")
private String motherName;
private String motherMobile;
private String motherEmail;
@NotEmpty(message = "Mother Nationality cannot be empty")
private String motherNationality;
@NotEmpty(message = "Mother Religion cannot be empty")
private String motherReligion;
@NotEmpty(message = "Mother Mother Tongue cannot be empty")
private String motherMotherTongue;
@NotEmpty(message = "Mother Community cannot be empty")
private String motherCommunity;
@NotEmpty(message = "Mother School Info cannot be empty")
private String motherSchoolInfo;
private String motherCollegeInfo;
private String motherUniversityInfo;
private String motherProfessionalQualification;
private String motherOccupation;
private String motherMonthlyIncome;
private String motherWorkplaceInfo;
@NotNull(message = "Candidate Image cannot be empty")
private MultipartFile candidateImage;
private String candidateImageName;
@NotNull(message = "Father Image cannot be empty")
private MultipartFile fatherImage;
private String fatherImageName;
@NotNull(message = "Mother Image cannot be empty")
private MultipartFile motherImage;
private String motherImageName;
}
package com.example.LaMartin.admission.validator;
import com.example.LaMartin.admission.model.AdmissionFormData;
import org.jetbrains.annotations.NotNull;
public class AdmissionFormDataValidator {
public boolean validate(@NotNull AdmissionFormData admissionFormData) {
return true;
}
}
package com.example.LaMartin.common.Exception;
import com.example.LaMartin.common.model.GeneralResponse;
import com.example.LaMartin.constants.AppConstants;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import java.util.HashMap;
import java.util.Map;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BindException.class)
public ResponseEntity<?> handleMethodArgumentNotValidException(
@NotNull BindException ex,
WebRequest request
) {
Map<String, String> errors = new HashMap<>();
for (FieldError error : ex.getBindingResult().getFieldErrors()) {
errors.put(error.getField(), error.getDefaultMessage());
}
GeneralResponse errorResponse = new GeneralResponse(
false,
AppConstants.PAYLOAD_NOT_ACCEPTABLE_STATUS_CODE,
"Validation Failed",
errors
);
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_ACCEPTABLE);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleGlobalException(
@NotNull Exception ex,
WebRequest request
) {
GeneralResponse errorResponse = new GeneralResponse(
false,
AppConstants.EXCEPTION_OCCURRED_STATUS_CODE,
ex.getMessage(),
null
);
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
package com.example.LaMartin.common.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class GeneralResponse {
boolean status;
int status_code;
String message;
Object data;
}
package com.example.LaMartin.config;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import java.util.Locale;
@Configuration
@ComponentScan(basePackages = {"com.example.LaMartin"})
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(@NotNull ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/static/**")
.addResourceLocations("/");
registry
.addResourceHandler("/static/**")
.addResourceLocations("/");
}
@Override
public void addCorsMappings(@NotNull CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "TRACE");
}
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(new Locale("en"));
resolver.setCookieName("myLocaleCookie");
resolver.setCookieMaxAge(-1);
return resolver;
}
}
package com.example.LaMartin.constants;
public class AppConstants {
public static final int RESPONSE_RESOURCE_NOT_FOUND_STATUS_CODE = 400;
public static final int RESPONSE_SUCCESS_STATUS_CODE = 200;
public static final int RESPONSE_FAILURE_STATUS_CODE = 201;
public static final int RESPONSE_DUPLICATE_STATUS_CODE = 202;
public static final int PAYLOAD_NOT_ACCEPTABLE_STATUS_CODE=406;
public static final int RESPONSE_HEADER_USER_ID_NOT_FOUND_STATUS_CODE=290;
public static final int RESPONSE_HEADER_PROJECT_ADMIN_USER_ID_NOT_FOUND_STATUS_CODE=291;
public static final int RESPONSE_HEADER_PROJECT_ROLES_NOT_FOUND_STATUS_CODE=292;
public static final int RESPONSE_HEADER_SERVER_KEY_NOT_FOUND_STATUS_CODE=293;
public static final int RESPONSE_SERVER_KEY_AUTHENTICATION_ERROR_STATUS_CODE=294;
public static final int RESPONSE_HEADER_PROJECT_ID_NOT_FOUND_STATUS_CODE=295;
public static final int RESPONSE_HEADER_CATEGORY_NOT_FOUND_STATUS_CODE=296;
public static final int RESPONSE_HEADER_PUBLIC_KEY_NOT_FOUND_STATUS_CODE=297;
public static final int RESPONSE_AUTHENTICATION_ERROR_STATUS_CODE=298;
public static final int EXCEPTION_OCCURRED_STATUS_CODE=500;
}
logging.level.web=DEBUG
#server.error.include-binding-errors=never
#server.error.include-message=always
server.http2.enabled=true
spring.datasource.url=jdbc:postgresql://localhost:5432/webomagic
spring.web.resources.cache.cachecontrol.s-max-age=3600000
spring.datasource.username=postgres
spring.datasource.password=2580
spring.redis.host=localhost
spring.redis.port=6379
\ No newline at end of file
spring.thymeleaf.cache=true
server.http2.enabled=true
spring.datasource.url=jdbc:postgresql://localhost:5432/webomagic
spring.web.resources.cache.cachecontrol.s-max-age=3600000
spring.datasource.username=postgres
spring.datasource.password=2580
spring.redis.host=localhost
spring.redis.port=6379
\ No newline at end of file
server.servlet.context-path=/webomagic-lamartin
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
server.port=8084
logging.level.org.springframework=DEBUG
logging.level.com.example=DEBUG
# application.properties
spring.profiles.active=dev
\ No newline at end of file
This diff is collapsed.
$(document).ready(function () {
//TODO: depending on class it will set the min and max date
$('#dateOfBirth').click(function () {
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var upperLimitDate = new Date(currentYear - 2, 11, 31); // 2 years back, December 31st
var lowerLimitDate = new Date(currentYear - 3, 0, 1); // 4 years back, January 1st
// Format the dates as YYYY-MM-DD strings
var upperLimitDateString = upperLimitDate.toISOString().split('T')[0];
var lowerLimitDateString = lowerLimitDate.toISOString().split('T')[0];
$('#dateOfBirth').attr('max', upperLimitDateString);
$('#dateOfBirth').attr('min', lowerLimitDateString);
});
function readURL(input, previewId) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(previewId).attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
// Bind change events to file inputs for image preview
$('input[name="candidateImage"]').change(function () {
readURL(this, '#candidateImage');
});
$('input[name="fatherImage"]').change(function () {
readURL(this, '#fatherImage');
});
$('input[name="motherImage"]').change(function () {
readURL(this, '#motherImage');
});
$.validator.addMethod(
'regex',
function (value, element, regexpr) {
if (value == '') {
return true;
}
return regexpr.test(value);
},
'Please check your input'
);
$.validator.addMethod(
'extension',
function (value, element, param) {
let fileExtension = value.split('.').pop().toLowerCase();
return this.optional(element) || param.includes(fileExtension);
},
'Please upload a file with a valid extension'
);
$.validator.addMethod(
'fileSize',
function (value, element, param) {
if (element.files.length === 0) {
return true; // No file selected
}
var fileSize = element.files[0].size;
return this.optional(element) || fileSize <= param;
},
'Please upload a file smaller than the specified size'
);
$('#application-form').validate({
rules: {
school: 'required',
category: 'required',
fullName: 'required',
admissionClass: 'required',
dateOfBirth: 'required',
nationality: 'required',
religion: 'required',
motherTongue: 'required',
communty: 'required',
maritalStatus: 'required',
fatherName: 'required',
fatherEmail: 'required',
fatherMobile: {
required: true,
regex: /^[0-9]{10}$/,
},
fatherNationality: 'required',
fatherReligion: 'required',
fatherMotherTongue: 'required',
fatherCommunity: 'required',
fatherSchoolInfo: 'required',
fatherOccupation: 'required',
fatherMonthlyIncome: 'required',
motherName: 'required',
motherMobile: {
regex: /^[0-9]{10}$/,
},
motherNationality: 'required',
motherReligion: 'required',
motherMotherTongue: 'required',
motherCommunity: 'required',
motherSchoolInfo: 'required',
candidateImage: {
required: true,
extension: ['jpg', 'png', 'jpeg', 'svg'],
fileSize: 1 * 1024 * 1024,
},
fatherImage: {
required: true,
extension: ['jpg', 'png', 'jpeg', 'svg'],
fileSize: 1 * 1024 * 1024,
},
motherImage: {
required: true,
extension: ['jpg', 'png', 'jpeg', 'svg'],
fileSize: 1 * 1024 * 1024,
},
},
messages: {
school: 'Please select your school',
category: 'Please specify the category',
fullName: 'Please enter your full name',
admissionClass: 'Please specify the class',
dateOfBirth: 'Please enter the date of birth',
nationality: 'Please enter the nationality',
religion: 'Please enter the religion',
motherTongue: 'Please enter the mother tongue',
communty: 'Please specify the community',
maritalStatus: 'Please choose an option',
fatherName: "Please enter the father's name",
fatherEmail: "Please enter the father's email",
fatherMobile: {
required: "Please enter the father's phone number",
regex: 'Please enter a valid phone number',
},
fatherNationality: "Please enter the father's nationality",
fatherReligion: "Please enter the father's religion",
fatherMotherTongue: "Please enter the father's mother tongue",
fatherCommunity: "Please specify the father's community",
fatherSchoolInfo: "Please enter the father's school name",
fatherOccupation: "Please enter the father's occupation",
fatherMonthlyIncome: "Please enter the father's monthly income",
motherName: "Please enter the mother's name",
motherMobile: {
regex: 'Please enter a valid phone number',
},
motherNationality: "Please enter the mother's nationality",
motherReligion: "Please enter the mother's religion",
motherMotherTongue: "Please enter the mother's mother tongue",
motherCommunity: "Please specify the mother's community",
motherSchoolInfo: "Please enter the mother's school name",
candidateImage: {
required: "Candidate's photo is required",
extension: 'Only jpg, jpeg, png, svg files are allowed.',
fileSize: 'Please upload a file smaller than 1 MB',
},
fatherImage: {
required: "Father's photo is required",
extension: 'Only jpg, jpeg, png, svg files are allowed.',
fileSize: 'Please upload a file smaller than 1 MB',
},
motherImage: {
required: "Mother's photo is required",
extension: 'Only jpg, jpeg, png, svg files are allowed.',
fileSize: 'Please upload a file smaller than 1 MB',
},
},
errorPlacement: function (error, element) {
element.prev('label').addClass('is-invalid');
element.next('.la-invalid-feedback').html(error.html());
},
highlight: function (element) {
$(element).addClass('is-invalid');
},
unhighlight: function (element) {
$(element).removeClass('is-invalid');
$(element).prev('label').removeClass('is-invalid');
$(element).next('.la-invalid-feedback').html('');
},
submitHandler: function (form) {
var formData = new FormData(form);
console.log(formData.get('candidateImage'));
$.ajax({
// TODO: move the url to a constant file
url: 'http://localhost:8084/webomagic-lamartin/admission-form/submit',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (response) {
console.log('Success:', response);
},
error: function (xhr, status, error) {
if (xhr.responseText) {
var errorMessage = JSON.parse(xhr.responseText).message;
console.error('Server Response:', errorMessage);
} else {
console.error('No response from server');
}
},
});
return false;
},
});
});
* {
margin: 0;
padding: 0;
}
body {
font-family: "Poppins", sans-serif;
font-style: normal;
background-color: #f1f1f1;
width: 100%;
height: 100%;
}
.la-body-container {
padding: 0px 100px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.la-header {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
flex-direction: column;
}
.la-header-title {
font-size: 1.8rem;
font-weight: bold;
padding-top: 15px;
}
.la-header-sub-title {
font-size: 1rem;
}
.la-header-sub-title span {
font-weight: bold;
}
.la-form-container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
margin-top: 30px;
}
/* Form */
#application-form {
width: 60%;
padding-bottom: 30px;
}
.form-group {
width: 100%;
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 4px;
font-size: 13px;
color: #706c6c;
}
.form-group label.is-invalid {
color: crimson;
}
.form-group label span {
color: crimson;
font-weight: 600;
}
.form-group .form-control {
width: 100%;
padding: 8px;
box-sizing: border-box;
border: 1px solid #b9b7b7;
outline: none;
}
.form-group .form-control.is-invalid {
border: 1px solid crimson;
color: crimson;
}
.form-group .la-invalid-feedback,
.form-group small {
display: block;
margin-top: 3px;
color: #3c3939;
font-size: 11px;
}
.form-group .la-invalid-feedback {
color: crimson;
}
.form-btn {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.btn {
display: inline-block;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
padding: .355rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
cursor: pointer;
}
.btn-sumbit {
width: 250px;
margin-top: 15px;
color: #fff;
background-color: #007bff;
border-color: #007bff;
}
.btn-sumbit:hover {
color: #fff;
background-color: #0069d9;
border-color: #0062cc;
}
.form-image-group{
display: flex;
justify-content: center;
align-items: center;
width: 100%;
margin-top: 30px;
}
.form-image-group .form-group{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 30%;
padding: 0px 10px;
}
.image-preview {
width: 100px;
height: 100px;
/* border: 1px solid #ddd; */
margin: 10px;
object-fit: cover;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment