306 lines
16 KiB
HTML
306 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en"
|
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
|
<head>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container" layout:fragment="content">
|
|
|
|
<section id="paper">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-lg-12 text-center">
|
|
<h2 class="section-heading text-uppercase">Редактирование статьи</h2>
|
|
<div th:replace="papers/fragments/paperNavigationFragment"/>
|
|
</div>
|
|
</div>
|
|
<hr/>
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<form id="paper-form" method="post" th:action="@{'/papers/paper?id='+ *{id == null ? '' : id} + ''}"
|
|
th:object="${paperDto}">
|
|
<div class="row">
|
|
<div class="col-md-7 col-sm-12">
|
|
<input type="hidden" name="id" th:field="*{id}"/>
|
|
<div class="form-group">
|
|
<label for="title">Название:</label>
|
|
<input class="form-control" id="title" type="text"
|
|
placeholder="Название статьи"
|
|
th:field="*{title}"/>
|
|
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
|
|
class="alert alert-danger">Incorrect title</p>
|
|
<p class="help-block text-danger"></p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="status">Статус:</label>
|
|
<select class="form-control" th:field="*{status}" id="status">
|
|
<option th:each="status : ${allStatuses}" th:value="${status}"
|
|
th:text="${status.statusName}">Status
|
|
</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="comment">Комментарий:</label>
|
|
<textarea class="form-control" rows="5" id="comment"
|
|
th:field="*{comment}"></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Дедлайны:</label>
|
|
<div class="row" th:each="deadline, rowStat : *{deadlines}">
|
|
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
|
<div class="col-6">
|
|
<input type="date" class="form-control" name="deadline"
|
|
th:field="*{deadlines[__${rowStat.index}__].date}"/>
|
|
</div>
|
|
<div class="col-4">
|
|
<input class="form-control" type="text" placeholder="Описание"
|
|
th:field="*{deadlines[__${rowStat.index}__].description}"/>
|
|
</div>
|
|
<div class="col-2">
|
|
<a class="btn btn-danger float-right"
|
|
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
|
|
$('#deadlines${rowStat.index}\\.date').val('');
|
|
$('#addDeadline').click();|"><span
|
|
aria-hidden="true"><i class="fa fa-times"/></span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
|
class="alert alert-danger">Incorrect title</p>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary"
|
|
value="Добавить
|
|
дедлайн"/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Авторы:</label>
|
|
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
|
title="-- Выберите авторов --"
|
|
th:field="*{authorIds}">
|
|
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
|
th:text="${author.lastName}">Status
|
|
</option>
|
|
</select>
|
|
<p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
|
|
class="alert alert-danger">Incorrect title</p>
|
|
</div>
|
|
|
|
<div class="form-group" id="files-list">
|
|
<label>Файлы:</label>
|
|
<th:block th:each="file, rowStat : *{files}">
|
|
<div class="row" th:id="|files${rowStat.index}|"
|
|
th:style="${file.deleteFlag} ? 'display: none;' :''">
|
|
<input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/>
|
|
<input type="hidden" th:field="*{files[__${rowStat.index}__].deleteFlag}"/>
|
|
<input type="hidden" th:field="*{files[__${rowStat.index}__].name}"/>
|
|
<input type="hidden" th:field="*{files[__${rowStat.index}__].tmpFileName}"/>
|
|
<div class="col-2">
|
|
<a class="btn btn-danger float-right"
|
|
th:onclick="|$('#files${rowStat.index}\\.deleteFlag').val('true'); $('#files${rowStat.index}').hide(); |">
|
|
<span aria-hidden="true"><i class="fa fa-times"/></span>
|
|
</a>
|
|
</div>
|
|
<div class="col-10" th:if="${file.id==null}">
|
|
<a th:onclick="|downloadFile('${file.tmpFileName}',null,'${file.name}') |"
|
|
href="javascript:void(0)"
|
|
th:text="*{files[__${rowStat.index}__].name}">
|
|
</a>
|
|
</div>
|
|
<div class="col-10" th:unless="${file.id==null}">
|
|
<a th:onclick="|downloadFile(null,${file.id},'${file.name}') |"
|
|
href="javascript:void(0)"
|
|
th:text="*{files[__${rowStat.index}__].name}">
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</th:block>
|
|
|
|
</div>
|
|
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input" id="locked"
|
|
th:field="*{locked}"/>
|
|
<label class="form-check-label" for="locked">Заблокирована</label>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="loader">Загрузить статью:</label>
|
|
<div id="loader">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 offset-md-1 col-sm-12 offset-sm-0">
|
|
<div class="form-group">
|
|
<div class="row">
|
|
<div class="col">
|
|
<h6 class="my-0">Дата создания:</h6>
|
|
</div>
|
|
<div class="col">
|
|
<small class="text-muted"
|
|
th:text="${paperDto.createDate == null ? '' : #dates.format(paperDto.createDate, 'dd.MM.yyyy HH:mm')}">
|
|
text
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="row">
|
|
<div class="col">
|
|
<h6 class="my-0">Дата изменения:</h6>
|
|
</div>
|
|
<div class="col">
|
|
<small class="text-muted"
|
|
th:text="${paperDto.updateDate == null ? '' : #dates.format(paperDto.updateDate, 'dd.MM.yyyy HH:mm')}">
|
|
text
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<button id="pingButton" class="btn btn-primary text-uppercase"
|
|
type="button">
|
|
Ping авторам
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="clearfix"></div>
|
|
<div class="col-lg-12">
|
|
<div class="form-group">
|
|
<button id="sendMessageButton" name="save"
|
|
class="btn btn-success text-uppercase"
|
|
type="submit">
|
|
Сохранить
|
|
</button>
|
|
<a id="cancelButton" class="btn btn-default text-uppercase"
|
|
href="/papers/papers">
|
|
Отмена
|
|
</a>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<script type="text/javascript" src="/js/file-loader.js"></script>
|
|
<script>
|
|
/*<![CDATA[*/
|
|
$(document).ready(function () {
|
|
new FileLoader({
|
|
div: "loader",
|
|
url: urlFileUpload,
|
|
maxSize: -1,
|
|
extensions: [],
|
|
callback: function (response) {
|
|
showFeedbackMessage("Файл успешно загружен");
|
|
console.debug(response);
|
|
|
|
addNewFile(response);
|
|
}
|
|
});
|
|
$('.selectpicker').selectpicker();
|
|
});
|
|
/*]]>*/
|
|
function addNewFile(fileNames) {
|
|
var filesList = $("#files-list");
|
|
var fileNumber = $("#files-list div.row").length;
|
|
|
|
var newFileRow = $("<div/>")
|
|
.attr("id", 'files' + fileNumber)
|
|
.addClass("row");
|
|
|
|
var idInput = $("<input/>")
|
|
.attr("type", "hidden")
|
|
.attr("id", "files" + fileNumber + ".id")
|
|
.attr("value", '')
|
|
.attr("name", "files[" + fileNumber + "].id");
|
|
newFileRow.append(idInput);
|
|
|
|
var flagInput = $("<input/>")
|
|
.attr("type", "hidden")
|
|
.attr("id", "files" + fileNumber + ".deleteFlag")
|
|
.attr("value", "false")
|
|
.attr("name", "files[" + fileNumber + "].deleteFlag");
|
|
newFileRow.append(flagInput);
|
|
|
|
var nameInput = $("<input/>")
|
|
.attr("type", "hidden")
|
|
.attr("id", "files" + fileNumber + ".name")
|
|
.attr("value", fileNames[1])
|
|
.attr("name", "files[" + fileNumber + "].name");
|
|
newFileRow.append(nameInput);
|
|
|
|
var tmpFileNameInput = $("<input/>")
|
|
.attr("type", "hidden")
|
|
.attr("id", "files" + fileNumber + ".tmpFileName")
|
|
.attr("value", fileNames[0])
|
|
.attr("name", "files[" + fileNumber + "].tmpFileName");
|
|
newFileRow.append(tmpFileNameInput);
|
|
|
|
var nextDiv = $("<div/>")
|
|
.addClass("col-2");
|
|
|
|
var nextA = $("<a/>")
|
|
.addClass("btn btn-danger float-right")
|
|
.attr("onclick", "$('#files" + fileNumber + "\\\\.deleteFlag').val('true'); $('#files" + fileNumber + "').hide();")
|
|
.append(($("<span/>").attr("aria-hidden", "true")).append($("<i/>").addClass("fa fa-times")))
|
|
;
|
|
nextDiv.append(nextA)
|
|
newFileRow.append(nextDiv);
|
|
|
|
var nameDiv = $("<div/>")
|
|
.addClass("col-10")
|
|
.append($("<a/>").text(fileNames[1])
|
|
.attr("href", 'javascript:void(0)')
|
|
.attr("onclick", "downloadFile('" + fileNames[0] + "',null,'" + fileNames[1] + "')"));
|
|
newFileRow.append(nameDiv);
|
|
|
|
$("#files-list").append(newFileRow);
|
|
|
|
}
|
|
|
|
function downloadFile(tmpName, fileId, downloadName) {
|
|
let xhr = new XMLHttpRequest();
|
|
if (fileId != null) xhr.open('GET', urlFileDownload + fileId);
|
|
if (tmpName != null) xhr.open('GET', urlFileDownloadTmp + tmpName);
|
|
xhr.responseType = 'blob';
|
|
|
|
var formData = new FormData();
|
|
if (fileId != null) formData.append("file-id", fileId);
|
|
if (tmpName != null) formData.append("tmp-file-name", tmpName);
|
|
|
|
xhr.send(formData);
|
|
|
|
xhr.onload = function () {
|
|
if (this.status == 200) {
|
|
console.debug(this.response);
|
|
var blob = new Blob([this.response], {type: '*'});
|
|
let a = document.createElement("a");
|
|
a.style = "display: none";
|
|
document.body.appendChild(a);
|
|
let url = window.URL.createObjectURL(blob);
|
|
a.href = url;
|
|
a.download = downloadName;
|
|
a.click();
|
|
window.URL.revokeObjectURL(url);
|
|
} else {
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|