Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/custom.js

627 lines
21 KiB
JavaScript
Raw Normal View History

2018-10-16 16:28:42 +00:00
(function ($, sr) {
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced() {
var obj = this, args = arguments;
function delayed() {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
};
// smartresize
jQuery.fn[sr] = function (fn) {
return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
};
})(jQuery, 'smartresize');
/**
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var CURRENT_URL = window.location.href.split('?')[0],
$BODY = $('body'),
$MENU_TOGGLE = $('#menu_toggle'),
$SIDEBAR_MENU = $('#sidebar-menu'),
$SIDEBAR_FOOTER = $('.sidebar-footer'),
$LEFT_COL = $('.left_col'),
$RIGHT_COL = $('.right_col'),
$NAV_MENU = $('.nav_menu'),
$FOOTER = $('footer');
// Sidebar
$(document).ready(function () {
// TODO: This is some kind of easy fix, maybe we can improve this
var setContentHeight = function () {
// reset height
$RIGHT_COL.css('min-height', $(window).height());
var bodyHeight = $BODY.outerHeight(),
footerHeight = $BODY.hasClass('footer_fixed') ? -10 : $FOOTER.height(),
leftColHeight = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height(),
contentHeight = bodyHeight < leftColHeight ? leftColHeight : bodyHeight;
// normalize content
contentHeight -= $NAV_MENU.height() + footerHeight;
$RIGHT_COL.css('min-height', contentHeight);
};
$SIDEBAR_MENU.find('a').on('click', function (ev) {
var $li = $(this).parent();
if ($li.is('.active')) {
$li.removeClass('active active-sm');
$('ul:first', $li).slideUp(function () {
setContentHeight();
});
} else {
// prevent closing menu if we are on child menu
if (!$li.parent().is('.child_menu')) {
$SIDEBAR_MENU.find('li').removeClass('active active-sm');
$SIDEBAR_MENU.find('li ul').slideUp();
}
$li.addClass('active');
$('ul:first', $li).slideDown(function () {
setContentHeight();
});
}
});
// toggle small or large menu
$MENU_TOGGLE.on('click', function () {
if ($BODY.hasClass('nav-md')) {
$SIDEBAR_MENU.find('li.active ul').hide();
$SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
} else {
$SIDEBAR_MENU.find('li.active-sm ul').show();
$SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
}
$BODY.toggleClass('nav-md nav-sm');
setContentHeight();
});
// check active menu
$SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page');
$SIDEBAR_MENU.find('a').filter(function () {
return this.href == CURRENT_URL;
}).parent('li').addClass('current-page').parents('ul').slideDown(function () {
setContentHeight();
}).parent().addClass('active');
// recompute content when resizing
$(window).smartresize(function () {
setContentHeight();
});
setContentHeight();
// fixed sidebar
if ($.fn.mCustomScrollbar) {
$('.menu_fixed').mCustomScrollbar({
autoHideScrollbar: true,
theme: 'minimal',
mouseWheel: {
preventDefault: true,
deltaFactor: 1000
}
});
}
});
// /Sidebar
// Panel toolbox
$(document).ready(function () {
$('.collapse-link').on('click', function () {
var $BOX_PANEL = $(this).closest('.x_panel'),
$ICON = $(this).find('i'),
$BOX_CONTENT = $BOX_PANEL.find('.x_content');
// fix for some div with hardcoded fix class
if ($BOX_PANEL.attr('style')) {
$BOX_CONTENT.slideToggle(200, function () {
$BOX_PANEL.removeAttr('style');
});
} else {
$BOX_CONTENT.slideToggle(200);
$BOX_PANEL.css('height', 'auto');
}
$ICON.toggleClass('fa-chevron-up fa-chevron-down');
});
$('.close-link').click(function () {
var $BOX_PANEL = $(this).closest('.x_panel');
$BOX_PANEL.remove();
});
});
// /Panel toolbox
// Tooltip
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip({
container: 'body'
});
});
// /Tooltip
// Accordion
$(document).ready(function () {
$(".expand").on("click", function () {
$(this).next().slideToggle(200);
$expand = $(this).find(">:first-child");
if ($expand.text() == "+") {
$expand.text("-");
} else {
$expand.text("+");
}
});
});
function getDate(date) {
let d = date.getDate();
if (d < 10)
d = "0" + d;
let m = date.getMonth() + 1;
if (m < 10)
m = "0" + m;
let y = date.getFullYear();
let h = date.getHours();
if (h < 10)
h = "0" + h;
let mm = date.getMinutes();
if (mm < 10)
mm = "0" + mm;
return d + "." + m + "." + y;
}
$(function () {
let defaultDate;
if ($('#datepicker').val()) {
defaultDate = new Date($('#datepicker').val());
} else {
defaultDate = new Date();
}
$('#datetimepicker').datetimepicker({
format: 'DD.MM.YYYY HH:mm',
stepping: '10',
sideBySide: true,
showTodayButton: true,
icons: {
time: "fa fa-clock-o",
date: "fa fa-calendar",
up: "fa fa-arrow-up",
down: "fa fa-arrow-down"
}
});
$('#datepicker').datetimepicker({
format: 'DD.MM.YYYY',
date: defaultDate,
viewDate: defaultDate,
stepping: '10',
sideBySide: true,
showTodayButton: true,
icons: {
time: "fa fa-clock-o",
date: "fa fa-calendar",
up: "fa fa-arrow-up",
down: "fa fa-arrow-down"
}
});
});
$('select[name=category]').change(function () {
if (this.value == "new-category") {
$('#new-category').show();
} else {
$('#new-category').hide();
}
});
$('#new-category-submit').click(function () {
var name = $('input[name=new-category-name]').val();
var display_name = $('input[name=new-category-display-name]').val();
$.ajax({
url: "/admin/blog/new_category",
2018-10-16 16:28:42 +00:00
type: "POST",
data: {
name: name,
display_name: display_name
},
success: function (data) {
console.log(data);
var duplicates = $('select[name="category"] option[value="' + data + '"]').eq(0);
if (jQuery.isEmptyObject(duplicates)) {
console.log('test');
$('select[name="category"]').append('<option value="' + data + '" selected="">' + display_name + '</option>');
} else {
console.log('kein guter Test');
duplicates.attr('selected', '');
}
}
});
});
$(window).load(function () {
var date = new Date(),
d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear(),
started,
categoryClass;
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function (start, end, allDay) {
$('#fc_create').click();
started = start;
ended = end;
$(".antosubmit").on("click", function () {
var title = $("#title").val();
if (end) {
ended = end;
}
categoryClass = $("#event_type").val();
if (title) {
calendar.fullCalendar('renderEvent', {
title: title,
start: started,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
$('#title').val('');
calendar.fullCalendar('unselect');
$('.antoclose').click();
return false;
});
},
eventClick: function (calEvent, jsEvent, view) {
$('#fc_edit').click();
$('#title2').val(calEvent.title);
categoryClass = $("#event_type").val();
$(".antosubmit2").on("click", function () {
calEvent.title = $("#title2").val();
calendar.fullCalendar('updateEvent', calEvent);
$('.antoclose2').click();
});
calendar.fullCalendar('unselect');
},
editable: true,
events: '/admin/calendar/getAllEvents',
locale: 'de',
eventClick: function () {
alert('Test');
}
});
});
// tinymce.init({
// selector: '.tinymce-textarea',
// plugins: [
// 'image, imagetools, code, media, link, colorpicker, paste, table, textcolor, advlist',
// 'anchor, autolink, autoresize, autosave, charmap, codesample, contextmenu, emoticons, fullscreen, hr',
// 'insertdatetime, layer, preview, searchreplace, textpattern, wordcount, jbimages'
// ],
// toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages media codesample | toc emoticons insertdatetime hr | preview searchreplace',
// textpattern_patterns: [
// {start: '*', end: '*', format: 'italic'},
// {start: '**', end: '**', format: 'bold'},
// {start: '#', format: 'h1'},
// {start: '##', format: 'h2'},
// {start: '###', format: 'h3'},
// {start: '####', format: 'h4'},
// {start: '#####', format: 'h5'},
// {start: '######', format: 'h6'},
// {start: '1. ', cmd: 'InsertOrderedList'},
// {start: '* ', cmd: 'InsertUnorderedList'},
// {start: '- ', cmd: 'InsertUnorderedList'}
// ],
// relative_urls: false,
// content_css: '/assets/css/bootstrap-3.0.0.css,/assets/css/main.css',
// content_style: 'html{padding:0 50px}body{max-width:1170px;}'
// });
$('#title-input').keyup(function () {
var title = $('#title-input').val().toLowerCase();
title = title.replace(/ /g, '-');
title = title.replace(/[^a-z1-9-]/g, '');
$('#url-input').val(encodeURI(title));
});
$('#tags-input').keypress(function (event) {
if (event.keyCode === 13) {
event.preventDefault();
}
});
var deletePost = function (id) {
var row = $("#post-" + id);
$.ajax({
url: "/admin/blog/delete",
2018-10-16 16:28:42 +00:00
data: {
id: id
},
method: 'POST',
beforeSend: function () {
row.children().fadeOut(1000);
row.append('<td id="loader" colspan="12" style="text-align:center"><i class="fa fa-spinner fa-spin"></i></td>');
},
success: function (data) {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#2ecc71');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-check');
setTimeout(function () {
row.fadeOut(1000);
setTimeout(function () {
row.remove();
}, 2000);
}, 2000);
}, 2000);
},
error: function () {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#e74c3c');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-times');
setTimeout(function () {
row.find('#loader').fadeOut(1000);
row.children().fadeIn(1000);
setTimeout(function () {
row.find('#loader').remove();
}, 2000);
}, 2000);
}, 2000);
}
});
};
$('#deleteModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var type = button.data('type');
var title = button.data('title');
var id = button.data('id');
var modal = $(this);
modal.find('.modal-body').html("<div class='alert alert-danger'><b>Durch das Klicken auf den Bestätigungs-Button wird der/die/das " + type + " <b>unwiederruflich</b> gelöscht und kann nicht wiederhergestellt werden!</b></div><p>Diese Aktion kann <b>NICHT</b> rückgängig gemacht werden. Dies wird alle Kommentare, Statistiken, Likes und Inhalte von <b>" + title + "</b> unwiederruflich löschen.</p><p>Bitte gib zur Bestätigung den Titel des Eintrags unter Berücksichtigung der Groß- und Kleinschreibung ein:</p><input class='form-control' id='confirm-delete-input' data-title='" + title + "'>");
modal.find('.modal-footer .btn-red').attr('disabled', '');
$('#confirm-delete-input').keyup(function () {
var removeButton = $('.modal-footer .btn-red', '#deleteModal');
if ($(this).val() == title) {
removeButton.removeAttr('disabled');
switch (type) {
case "Blog-Post":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/blog/deleteFinally", "post")');
2018-10-16 16:28:42 +00:00
break;
case "Projekt":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/projects/delete", "entry")');
2018-10-16 16:28:42 +00:00
break;
case "Projekt-Kategorie":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/projects/delete_category", "category")');
2018-10-16 16:28:42 +00:00
break;
case "Datei":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/files/delete", "file")');
2018-10-16 16:28:42 +00:00
break;
}
removeButton.css('cursor', 'pointer');
} else {
removeButton.attr('disabled', '');
removeButton.removeAttr('onclick');
removeButton.css('cursor', 'auto');
}
});
});
function deletePostFinally(id, url, selector) {
var row = $("#" + selector + "-" + id);
console.log(row);
$.ajax({
url: url,
method: 'POST',
data: {
id: id
},
beforeSend: function () {
$('#deleteModal').modal('hide');
row.children().fadeOut(1000);
row.append('<td id="loader" colspan="12" style="text-align:center"><i class="fa fa-spinner fa-spin"></i></td>');
},
success: function (data) {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#2ecc71');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-check');
setTimeout(function () {
row.fadeOut(1000);
setTimeout(function () {
row.remove();
}, 2000);
}, 2000);
}, 2000);
},
error: function (data) {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#e74c3c');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-times');
setTimeout(function () {
row.find('#loader').fadeOut(1000);
row.children().fadeIn(1000);
setTimeout(function () {
row.find('#loader').remove();
}, 2000);
}, 2000);
}, 2000);
}
});
}
function restorePost(id) {
var row = $("#post-" + id);
$.ajax({
url: "/admin/blog/restore",
2018-10-16 16:28:42 +00:00
data: {
id: id
},
method: 'POST',
beforeSend: function () {
row.children().fadeOut(1000);
row.append('<td id="loader" colspan="12" style="text-align:center"><i class="fa fa-spinner fa-spin"></i></td>');
},
success: function (data) {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#2ecc71');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-check');
setTimeout(function () {
row.fadeOut(1000);
setTimeout(function () {
row.remove();
}, 2000);
}, 2000);
}, 2000);
},
error: function () {
setTimeout(function () {
row.find('#loader').delay(1000).css('background-color', '#e74c3c');
row.find('#loader').delay(1000).css('color', '#fff');
row.find('#loader .fa').delay(1000).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-times');
setTimeout(function () {
row.find('#loader').fadeOut(1000);
row.children().fadeIn(1000);
setTimeout(function () {
row.find('#loader').remove();
}, 2000);
}, 2000);
}, 2000);
}
});
}
$(window).load(function () {
imageUploadSwitch();
});
function imageUploadSwitch() {
if ($('#imageUrl').is(':checked')) {
$('.image-upload').hide();
$('.image-url').show();
} else {
$('.image-url').hide();
$('.image-upload').show();
}
}
function fillSecond() {
$('#second-form input[name="title"]').val($('#title').html());
$('#second-form input[name="description"]').val($('#description').html());
}
$(".table").DataTable({
language: {
"sEmptyTable": "Keine Daten in der Tabelle vorhanden",
"sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen",
"sInfoEmpty": "0 bis 0 von 0 Einträgen",
"sInfoFiltered": "(gefiltert von _MAX_ Einträgen)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "_MENU_ Einträge anzeigen",
"sLoadingRecords": "Wird geladen...",
"sProcessing": "Bitte warten...",
"sSearch": "Suchen",
"sZeroRecords": "Keine Einträge vorhanden.",
"oPaginate": {
"sFirst": "Erste",
"sPrevious": "Zurück",
"sNext": "Nächste",
"sLast": "Letzte"
},
"oAria": {
"sSortAscending": ": aktivieren, um Spalte aufsteigend zu sortieren",
"sSortDescending": ": aktivieren, um Spalte absteigend zu sortieren"
},
select: {
rows: {
_: '%d Zeilen ausgewählt',
0: 'Zum Auswählen auf eine Zeile klicken',
1: '1 Zeile ausgewählt'
}
}
}
});
function loadNotificationsAsync() {
$.ajax({
url: '/Main/getNotifications',
2018-10-16 16:28:42 +00:00
method: 'post',
success: (data) => {
console.log(data);
if (data.status === 'success') {
for (let notification of data.notifications) {
$('#notificationMenu').append(`
<li>
<a href="${notification.link}" target="_blank">
<span class="image"><img src="${notification.image}" alt="${notification.sender}"/></span>
<span>
<span>${notification.sender}</span>
<span class="time">${notification.time}</span>
</span>
<span class="message">${notification.message}</span>
</a>
</li>`);
}
if(data.notifications.length > 0) {
$('#notificationCount').text(data.notifications.length);
}
}
},
error: (data) => {
// TODO: Fallback hinzufügen
}
})
}
loadNotificationsAsync();