255 lines
8.1 KiB
JavaScript
Executable File
255 lines
8.1 KiB
JavaScript
Executable File
/* ----------------------------------------------------------------------
|
|
02.04.2023
|
|
Удалялка страниц
|
|
---------------------------------------------------------------------- */
|
|
$(".del_page").click(function(event) {
|
|
var id=$(this).data('id');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=deletePage&id=" + id
|
|
});
|
|
$("#tr_pages_" + id).addClass("hidden");
|
|
})
|
|
|
|
/* ----------------------------------------------------------------------
|
|
02.04.2023
|
|
Удалялка категории
|
|
---------------------------------------------------------------------- */
|
|
$(".del_cat").click(function(event) {
|
|
var id=$(this).data('id');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=deleteCategory&id=" + id
|
|
});
|
|
$("#tr_cat_" + id).addClass("hidden");
|
|
})
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
12.12.2022
|
|
Создаем новую категорию
|
|
---------------------------------------------------------------------- */
|
|
$("#createNewCategory").click(function(event) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=createNewCategory&title=" + $("#categoryTitle").val() + "&category=" + $("#parentCategory").val()
|
|
});
|
|
|
|
setTimeout(function(){location.reload();}, 1000);
|
|
})
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
07.10.2022
|
|
Сохраняем реквизиты категории
|
|
---------------------------------------------------------------------- */
|
|
|
|
$("#saveMeta").click(function(event) {
|
|
var title = $("#title").val();
|
|
//var txt = $("#editarea").val();
|
|
txt=tinyMCE.get('editarea').getContent();
|
|
// alert(txt);
|
|
var keywords = $("#keywords").val();
|
|
var description = $("#description").val();
|
|
var category = $("#category").val();
|
|
var id = $("#id").val();
|
|
var status = $("#status").val();//!!!
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=changeCategory&id=" + id + "&keywords=" + keywords + "&description=" + description + "&category=" + category + "&title=" + title + "&status=" + status + "&txt=" + txt
|
|
});
|
|
$("#div-log p").css({'color':'gray'});
|
|
$("#div-log").prepend("<p style='color: green;'>Изменения сохранены</p>");
|
|
})
|
|
|
|
|
|
$("#showDivNewCat").click(function(event) {
|
|
$("#divNewCat").removeClass("hidden");
|
|
})
|
|
|
|
$("#cancelNewSaveMeta").click(function(event) {
|
|
$("#divNewCat").addClass("hidden");
|
|
})
|
|
|
|
//кнопка удаления в модальном окошке
|
|
$("#del").click(function(event) {
|
|
$.ajax({ type: "POST", url: '/act/page_all', data: "act=del_page&id=" + $('#tmp').val() });
|
|
$('tr#' + $('#tmp').val()).hide('2000');
|
|
$('#exampleModal').modal('hide');
|
|
})
|
|
|
|
// Кнопка удаления в модальном окошке
|
|
$(".del_page_in_modal").click(function(event) {
|
|
var id = $('#del_id').val();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=del_page&id=" + id
|
|
});
|
|
|
|
//
|
|
$("#tr_cat_" + id).hide(1000);
|
|
$("#btn_close_del").click();
|
|
})
|
|
|
|
//кнопка добавления категории
|
|
$("#btn-add-new-cat").click(function(event) {
|
|
var input_new_cat = $('#input_new_cat').val();
|
|
var parent_id = $('#input_parrent').val();
|
|
var input_new_cat_description = $('#input_new_cat_description').val();
|
|
var input_new_cat_keywords = $('#input_new_cat_keywords').val();
|
|
var input_new_cat_edit_id = $('#input_new_cat_edit_id').val();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/act/page_all',
|
|
data: "act=new_cat&input_new_cat=" + input_new_cat + "&parent_id=" + parent_id + "&input_new_cat_description=" + input_new_cat_description + "&input_new_cat_keywords=" + input_new_cat_keywords + "&input_new_cat_edit_id=" + input_new_cat_edit_id
|
|
});
|
|
setTimeout(function() {
|
|
location.reload();
|
|
}, 1500);
|
|
})
|
|
|
|
//Быстрое редактирование категорий в модальном окне, пересмотреть концепцию
|
|
$(".qe").click(function(event) {
|
|
//Придаем заголовок
|
|
$("#modal_label_edit").text("Редактирование категории");
|
|
var id = $(this).data('id');
|
|
var parent_id = $("#parent_id").val();
|
|
$("#input_new_cat").val($("#qe_b_title_" + id).text());
|
|
$("#input_new_cat_description").val($("#qe_b_desc_" + id).text());
|
|
$("#input_new_cat_keywords").val($("#qe_b_keywords_" + id).text());
|
|
$("#input_new_cat_edit_id").val(id);
|
|
$("#input_parrent").val(parent_id);
|
|
|
|
})
|
|
|
|
//Кнопка создания категории
|
|
$("#btn_new_cat").click(function(event) {
|
|
//Придаем заголовок
|
|
$("#modal_label_edit").text("Создать категорию");
|
|
var id = $(this).data('id');
|
|
var parent_id = $("#parent_id").val();
|
|
$("#input_new_cat").val("");
|
|
$("#input_new_cat_description").val("");
|
|
$("#input_new_cat_keywords").val("");
|
|
$("#input_new_cat_edit_id").val("");
|
|
$("#input_parrent").val(parent_id);
|
|
|
|
})
|
|
|
|
|
|
|
|
/* -- uploader -- */
|
|
|
|
// ************************ Drag and drop ***************** //
|
|
let dropArea = document.getElementById("drop-area")
|
|
|
|
// Prevent default drag behaviors
|
|
;
|
|
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, preventDefaults, false)
|
|
document.body.addEventListener(eventName, preventDefaults, false)
|
|
})
|
|
|
|
// Highlight drop area when item is dragged over it
|
|
;
|
|
['dragenter', 'dragover'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, highlight, false)
|
|
})
|
|
|
|
;
|
|
['dragleave', 'drop'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, unhighlight, false)
|
|
})
|
|
|
|
// Handle dropped files
|
|
dropArea.addEventListener('drop', handleDrop, false)
|
|
|
|
function preventDefaults(e) {
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
}
|
|
|
|
function highlight(e) {
|
|
dropArea.classList.add('highlight')
|
|
}
|
|
|
|
function unhighlight(e) {
|
|
dropArea.classList.remove('active')
|
|
}
|
|
|
|
function handleDrop(e) {
|
|
var dt = e.dataTransfer
|
|
var files = dt.files
|
|
|
|
handleFiles(files)
|
|
}
|
|
|
|
let uploadProgress = []
|
|
let progressBar = document.getElementById('progress-bar')
|
|
|
|
function initializeProgress(numFiles) {
|
|
progressBar.value = 0
|
|
uploadProgress = []
|
|
|
|
for (let i = numFiles; i > 0; i--) {
|
|
uploadProgress.push(0)
|
|
}
|
|
}
|
|
|
|
function updateProgress(fileNumber, percent) {
|
|
uploadProgress[fileNumber] = percent
|
|
let total = uploadProgress.reduce((tot, curr) => tot + curr, 0) / uploadProgress.length
|
|
console.debug('update', fileNumber, percent, total)
|
|
progressBar.value = total
|
|
}
|
|
|
|
function handleFiles(files) {
|
|
files = [...files]
|
|
initializeProgress(files.length)
|
|
files.forEach(uploadFile)
|
|
files.forEach(previewFile)
|
|
}
|
|
|
|
function previewFile(file) {
|
|
let reader = new FileReader()
|
|
reader.readAsDataURL(file)
|
|
reader.onloadend = function() {
|
|
let img = document.createElement('img')
|
|
img.src = reader.result
|
|
document.getElementById('gallery').appendChild(img)
|
|
}
|
|
}
|
|
|
|
function uploadFile(file, i) {
|
|
var url = '/act/page_all'
|
|
var xhr = new XMLHttpRequest()
|
|
var formData = new FormData()
|
|
xhr.open('POST', url, true)
|
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
|
|
|
// Update progress (can be used to show progress indicator)
|
|
xhr.upload.addEventListener("progress", function(e) {
|
|
updateProgress(i, (e.loaded * 100.0 / e.total) || 100)
|
|
})
|
|
|
|
xhr.addEventListener('readystatechange', function(e) {
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
updateProgress(i, 100) // <- Add this
|
|
} else if (xhr.readyState == 4 && xhr.status != 200) {
|
|
// Error. Inform the user
|
|
}
|
|
})
|
|
|
|
formData.append('upload_preset', 'ujpu6gyk')
|
|
formData.append('act', 'foto_upload')
|
|
formData.append('file', file)
|
|
xhr.send(formData)
|
|
} |