<div class="modal fade" id="knbaseEntryForm" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Новий запис</h5>
<button type="button" class="btn-close" data-coreui-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="new_entry" class="add-new-entry">
@@include("knbase-form.html")
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary submit-form">Створити</button>
<button type="button" class="btn btn-secondary reset-form" data-coreui-dismiss="modal">Відмінити</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", e => {
const knbaseEntryForm = document.getElementById("knbaseEntryForm");
const form = knbaseEntryForm.querySelector(".add-new-entry");
const modal = new coreui.Modal(knbaseEntryForm);
form.validityChecking = function(e){
return validityChecking(this);
}
form.submitting = function(e){
e.preventDefault();
const data = {};
data["type"] = form.querySelector("select.knbase").value;
data["include_to"] = getSwitchersVal(form.querySelector(".bots-multi"));
data["title"] = form.querySelector('[name="title"]').value;
data["content"] = form.querySelector('[name="content"]').value;
data["hlink"] = form.querySelector('[name="hlink"]').value;
data["price"] = form.querySelector('[name="price"]').value;
if(!this.validityChecking()) {
return;
}
doAction("knbase.new_entry", data, resp => {
document.querySelector("table.entries").loadDataFromServer();
});
document.activeElement.blur();
modal.hide();
form.reset();
}
form.addEventListener("submit", e => {
form.submitting(e);
});
knbaseEntryForm.querySelector(".submit-form").addEventListener("click", e => {
form.submitting(e);
});
knbaseEntryForm.querySelector(".reset-form").addEventListener("click", e => {
document.activeElement.blur();
form.reset();
});
});
</script>