188 lines
6.8 KiB
JavaScript
188 lines
6.8 KiB
JavaScript
|
|
/**
|
|
* Theme: Minton Admin Template
|
|
* Author: Coderthemes
|
|
* Nestable Component
|
|
*/
|
|
|
|
!function($) {
|
|
"use strict";
|
|
|
|
var Nestable = function() {};
|
|
|
|
Nestable.prototype.updateOutput = function (e) {
|
|
var list = e.length ? e : $(e.target),
|
|
output = list.data('output');
|
|
if (window.JSON) {
|
|
output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
|
|
} else {
|
|
output.val('JSON browser support required for this demo.');
|
|
}
|
|
},
|
|
//init
|
|
Nestable.prototype.init = function() {
|
|
// activate Nestable for list 1
|
|
|
|
/* if(!$('#nestable_list_check').length && !$('#nestable_list_1').length){
|
|
return;
|
|
}
|
|
*/
|
|
if($('#nestable_list_1').length){
|
|
$('#nestable_list_1').nestable({
|
|
group: 1,
|
|
maxDepth: 2,
|
|
protectRoot: true,
|
|
}).on('change', this.updateOutput);
|
|
|
|
// activate Nestable for list 2
|
|
$('#nestable_list_2').nestable({
|
|
group: 1,
|
|
maxDepth: 2,
|
|
protectRoot: true,
|
|
}).on('change', this.updateOutput);
|
|
|
|
// output initial serialised data
|
|
this.updateOutput($('#nestable_list_1').data('output', $('#nestable_list_1_output')));
|
|
this.updateOutput($('#nestable_list_2').data('output', $('#nestable_list_2_output')));
|
|
}
|
|
if($('#nestable_list_check').length){
|
|
$('#nestable_list_check').nestable({
|
|
group: 1,
|
|
maxDepth: 2,
|
|
protectRoot: true,
|
|
});
|
|
}
|
|
|
|
$(".nestable_update_btn").on('click', function (e) {
|
|
e.preventDefault();
|
|
$.Nestable.updateNavigatonItem(e, $(this));
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#nestable_list_menu a').on('click', function (e) {
|
|
var action = $(this).data('action');
|
|
if (action === 'expand-all') {
|
|
$('#nestable_list_1').nestable('expandAll');
|
|
}
|
|
if (action === 'collapse-all') {
|
|
$('#nestable_list_1').nestable('collapseAll');
|
|
}
|
|
});
|
|
$('.nestable_list_menu_save').on('click', function(e){
|
|
var target = $(e.target),
|
|
save = target.data('save');
|
|
if(save == 'navigation-structure'){
|
|
$.Nestable.saveNavigatonStructure()
|
|
}
|
|
});
|
|
$('.nestable_list_make_hidden').on('click', function(e){
|
|
e.preventDefault();
|
|
var $i = $(this).find('i');
|
|
if($i.hasClass('fa-eye-slash')){
|
|
$i.removeClass('fa-eye-slash');
|
|
$i.removeClass('text-danger');
|
|
$i.addClass('fa-eye');
|
|
$i.addClass('text-primary');
|
|
$(this).parents('.dd-item').data('hidden', 0);
|
|
}else{
|
|
$i.removeClass('fa-eye');
|
|
$i.removeClass('text-primary');
|
|
$i.addClass('fa-eye-slash');
|
|
$i.addClass('text-danger');
|
|
$(this).parents('.dd-item').data('hidden', 1);
|
|
}
|
|
});
|
|
},
|
|
|
|
Nestable.prototype.updateNavigatonItem = function(e, $this){
|
|
|
|
var $url = $this.data('url');
|
|
var $data = {action:$this.data('action'), target:$this.data('target'), id:$this.data('id'), '_token': $('meta[name=csrf-token]').attr('content') };
|
|
$.post($url, $data, 'json')
|
|
.done(function(data){
|
|
//console.log(data);
|
|
if (data.success === 'update-tag-active' || data.success === 'update-category-active') {
|
|
if(data.active === true){
|
|
$this.find('i').addClass('fa-eye').addClass('text-success').removeClass('fa-eye-slash').removeClass('text-danger');
|
|
}
|
|
if(data.active === false){
|
|
$this.find('i').addClass('fa-eye-slash').addClass('text-danger').removeClass('fa-eye').removeClass('text-success');
|
|
}
|
|
$.growl({
|
|
title: 'Gespeichert',
|
|
message: 'Änderung gespeichert',
|
|
location: 'tr'
|
|
});
|
|
|
|
}else{
|
|
$.growl.error({
|
|
title: 'Error',
|
|
message: 'Änderungen konnten nicht gespeichert werden.',
|
|
location: 'tr'
|
|
});
|
|
}
|
|
})
|
|
.fail( function(xhr, textStatus, errorThrown) {
|
|
console.log("fail");
|
|
console.log(xhr);
|
|
console.log(xhr.responseText);
|
|
$.growl.error({
|
|
title: 'Error',
|
|
message: 'Änderungen konnten nicht gespeichert werden.' + xhr.responseText,
|
|
location: 'tr'
|
|
}); })
|
|
.always(function(){
|
|
|
|
});
|
|
},
|
|
|
|
Nestable.prototype.saveNavigatonStructure = function(){
|
|
var $url = $('#nestable_list_1').data('href-save');
|
|
var $data = {'nestable': $('#nestable_list_1').nestable('serialize'), '_token': $('meta[name=csrf-token]').attr('content') };
|
|
$.post($url, $data, 'json')
|
|
.done(function(data){
|
|
//console.log(data);
|
|
if (data.redirect) {
|
|
// data.redirect contains the string URL to redirect to
|
|
window.location.href = data.redirect;
|
|
}
|
|
if(data.success === true){
|
|
$.growl({
|
|
title: 'Gespeichert',
|
|
message: 'Änderung gespeichert',
|
|
location: 'tr'
|
|
});
|
|
}else{
|
|
$.growl.error({
|
|
title: 'Error',
|
|
message: 'Änderungen konnten nicht gespeichert werden.',
|
|
location: 'tr'
|
|
});
|
|
}
|
|
|
|
})
|
|
.fail( function(xhr, textStatus, errorThrown) {
|
|
console.log("fail");
|
|
console.log(xhr);
|
|
console.log(xhr.responseText);
|
|
$.growl.error({
|
|
title: 'Error',
|
|
message: 'Änderungen konnten nicht gespeichert werden.' + xhr.responseText,
|
|
location: 'tr'
|
|
});
|
|
})
|
|
.always(function(){
|
|
|
|
});
|
|
}
|
|
//init
|
|
$.Nestable = new Nestable, $.Nestable.Constructor = Nestable
|
|
}(window.jQuery),
|
|
|
|
//initializing
|
|
function($) {
|
|
"use strict";
|
|
$.Nestable.init()
|
|
}(window.jQuery);
|