#64 delete conference refactor

This commit is contained in:
Nightblade73 2019-04-22 21:46:42 +04:00
parent 2767403128
commit 53cc777734
6 changed files with 33 additions and 21 deletions

View File

@ -6,7 +6,6 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -68,6 +67,12 @@ public class ConferenceController {
} }
} }
@PostMapping(value = "/conferences", params = "deleteConference")
public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException {
conferenceService.delete(conferenceId);
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
}
@PostMapping(value = "/conference", params = "save") @PostMapping(value = "/conference", params = "save")
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
filterEmptyDeadlines(conferenceDto); filterEmptyDeadlines(conferenceDto);
@ -76,13 +81,6 @@ public class ConferenceController {
} }
conferenceService.save(conferenceDto); conferenceService.save(conferenceDto);
return String.format(REDIRECT_TO, CONFERENCES_PAGE); return String.format(REDIRECT_TO, CONFERENCES_PAGE);
}
@GetMapping("/delete/{conference-id}")
public String delete(@PathVariable("conference-id") Integer conferenceId) throws IOException {
conferenceService.delete(conferenceId);
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
} }
@PostMapping(value = "/conference", params = "addDeadline") @PostMapping(value = "/conference", params = "addDeadline")

View File

@ -0,0 +1,7 @@
package ru.ulstu.paper.error;
public class PaperConferenceRelationExistException extends RuntimeException {
public PaperConferenceRelationExistException(String message) {
super(message);
}
}

View File

@ -2,7 +2,7 @@ body {
min-width: 400px; min-width: 400px;
} }
.conference-row .col:hover { .conference-row .d-flex:hover {
background-color: #f3f3f3; background-color: #f3f3f3;
border-radius: .25rem; border-radius: .25rem;
} }
@ -15,10 +15,14 @@ body {
margin-bottom: 10px; margin-bottom: 10px;
} }
.conference-row .col .text-decoration { .conference-row .d-flex .text-decoration {
text-decoration: none; text-decoration: none;
} }
.conference-row .d-flex {
margin: 0 15px;
}
.form-group textarea { .form-group textarea {
min-height: 206px; min-height: 206px;

View File

@ -1,7 +1,6 @@
$(document).ready(function () { $(document).ready(function () {
$('input[data-confirm]').click(function(ev) {
$('a[data-confirm]').click(function(ev) { var value = $(this).attr('value');
var href = $(this).attr('href');
if (!$('#dataConfirmModal').length) { if (!$('#dataConfirmModal').length) {
$('#modalDelete').append('<div class="modal fade" id="dataConfirmModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"\n' + $('#modalDelete').append('<div class="modal fade" id="dataConfirmModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"\n' +
' >\n' + ' >\n' +
@ -14,7 +13,7 @@ $(document).ready(function () {
' </div>\n' + ' </div>\n' +
' <div class="modal-footer">\n' + ' <div class="modal-footer">\n' +
' <a class="btn btn-primary" id="dataConfirmOK">Да</a>'+ ' <button type="submit" name="deleteConference" class="btn btn-primary" id="deleteConference">Да</button>'+
' <button class="btn primary" data-dismiss="modal" aria-hidden="true">Нет</button>'+ ' <button class="btn primary" data-dismiss="modal" aria-hidden="true">Нет</button>'+
' </div>\n' + ' </div>\n' +
' </div>\n' + ' </div>\n' +
@ -22,7 +21,7 @@ $(document).ready(function () {
' </div>'); ' </div>');
} }
$('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm'));
$('#dataConfirmOK').attr('href', href); $('#deleteConference').attr('value', value);
$('#dataConfirmModal').modal({show:true}); $('#dataConfirmModal').modal({show:true});
return false; return false;
}); });

View File

@ -8,7 +8,7 @@
<body> <body>
<div layout:fragment="content"> <div layout:fragment="content">
<form id="conferences-form" method="post" th:action="@{'/conferences/conferences'}"> <form id="conferences-form" method="post">
<section id="conferences"> <section id="conferences">
<div class="container"> <div class="container">
<div class="row" id="conference-list"> <div class="row" id="conference-list">
@ -20,6 +20,7 @@
<hr/> <hr/>
<div class="row"> <div class="row">
<div class="col-md-9 col-sm-12"> <div class="col-md-9 col-sm-12">
<!--<input type="hidden" th:field="${filteredConferences}"/>-->
<th:block th:each="conference : ${filteredConferences.conferences}"> <th:block th:each="conference : ${filteredConferences.conferences}">
<div th:replace="conferences/fragments/confLineFragment :: confLine(conference=${conference})"/> <div th:replace="conferences/fragments/confLineFragment :: confLine(conference=${conference})"/>
</th:block> </th:block>

View File

@ -5,16 +5,19 @@
</head> </head>
<body> <body>
<div th:fragment="confLine (conference)" class="row text-left conference-row h3" style="background-color: white;"> <div th:fragment="confLine (conference)" class="row text-left conference-row h3" style="background-color: white;">
<div class="col d-flex justify-content-between"> <div class="d-flex justify-content-between w-100">
<a th:href="@{'conference?id='+${conference.id}}" class="w-100 text-decoration"> <a th:href="@{'conference?id='+${conference.id}}" class="w-100 text-decoration">
<span class="h5" th:text="${conference.title}"/> <span class="h5" th:text="${conference.title}"/>
<span class="text-muted h6 float-right m-2" th:text="${conference.datesString}"/> <span class="text-muted h6 float-right m-2" th:text="${conference.datesString}"/>
</a> </a>
<input class="id-class" type="hidden" th:value="${conference.id}"/> <input class="id-class" type="hidden" th:value="${conference.id}"/>
<a class="remove-paper pull-right m-auto" th:href="@{'/conferences/delete/'+${conference.id}}" <input type="submit" class="icon icon-delete grey-border"
data-confirm="Удалить конференцию?"> alt="Удалить" th:value="${conference.id}"
<i class="fa fa-trash" aria-hidden="true"></i> data-confirm="Удалить конференцию?"/>
</a> <!--<a class="remove-paper pull-right m-auto" th:href="@{'/conferences/delete/'+${conference.id}}"-->
<!--data-confirm="Удалить конференцию?">-->
<!--<i class="fa fa-trash" aria-hidden="true"></i>-->
<!--</a>-->
</div> </div>
</div> </div>