var navigationMenuEdited = false; //CHARGEMENT DE LA PAGE SETTING function init_setting_global_navigation(){ /*switch($.urlParam('page')){ default: break; }*/ window.onbeforeunload = function(e){ if(!navigationMenuEdited) return e = null; return "Certaines modifications sur le menu n'ont pas été sauvgardées.\nÊtes-vous sûr de vouloir quitter la page ?"; }; navigation_tree_search(); $( ".navigation-tree-list" ).sortable({ handle: ".navigation-item-header", cancel: ".not-editable", helper: "clone", opacity: 0.8, distance : 15, grid: [ 50, 1 ], update : function(){ navigationMenuEdited = true; }, start: function(e,ui) { draggedItem = $(ui.item[0]); if(draggedItem.hasClass('navigation-line-child')) return; children = []; var borderReached = false; $.each(draggedItem.nextAll('li.navigation-line'), function(i, childLine){ var line = $(childLine); if(borderReached || !line.hasClass('navigation-line-child')) { borderReached = true; return; } children.push(line); line.addClass('hidden'); }); }, sort: function(event,ui){ var leftLimit = ui.item.hasClass('navigation-line-child') ? -20 : 15; if(ui.position.left < leftLimit){ ui.helper.css('left',leftLimit+'px'); } if(ui.position.left > 65){ left = 65; ui.helper.css('left',left+'px'); } if(ui.item.index()==1){ ui.helper.css('left',leftLimit+'px'); } }, stop: function(event,ui){ if(ui.position.left>15){ if(!ui.item.hasClass('navigation-line-child')) navigationMenuEdited = true; ui.item.addClass('navigation-line-child'); }else{ if(ui.item.hasClass('navigation-line-child')) navigationMenuEdited = true; ui.item.removeClass('navigation-line-child'); } if(!children.length) return; $.each(children.reverse(), function(i, row){ $(row).insertAfter(draggedItem).removeClass('hidden'); }); }, // placeholder: "navigation-item-placeholder", placeholder: { element: function(clone, ui) { var placeholderRow = $(''); /** Lié à la feature de drag&drop de plusieurs lignes à la fois **/ if(!clone.hasClass('navigation-line-child')){ var rowNb = 1; var borderReached = false; $.each(clone.nextAll('li.navigation-line'), function(i, childLine){ var line = $(childLine); if(borderReached || !line.hasClass('navigation-line-child')) { borderReached = true; return; } rowNb += 1 }); placeholderRow.css({ height: 'calc(44px * '+rowNb+')', }); } return placeholderRow; }, update: function() { return; } } }); $(".navigation-tree > ul").disableSelection(); } //CHARGEMENT DE LA PAGE /* function init_plugin_navigation(){ switch($.urlParam('page')){ default: break; } } */ /** Editeur d'arborescence **/ //Enregistrement des configurations function navigation_setting_save(){ var items = []; var lastParentIndex = 0; $('.navigation-line:not(.hidden)').each(function(i,element){ var line = $(element); var item = {}; item.label = line.find('.item-label').val(); item.visibility = line.find('input.item-visibility').val(); item.url = line.find('.item-url').val(); item.icon = line.find('.item-icon').val(); item.target = line.find('[name="item-target"]:checked').val(); if(line.hasClass('navigation-line-child')){ items[lastParentIndex].childs.push(item); }else{ lastParentIndex = items.length; item.childs = []; items.push(item); } }); $.action({ action : 'navigation_setting_save', fields : $('#navigation-setting-form').toJson(), items : items, menu : $('#navigation-menu').val() },function(){ navigationMenuEdited = false; $.message('success','Enregistré'); }); } function navigation_tree_search(callback){ var menu = $('#navigation-menu').val(); if(!menu || menu=='') return; $.action({ action : 'navigation_tree_search', menu : menu },function(r){ $('.navigation-tree > ul > li:visible').remove(); for(var key in r.rows){ var line = r.rows[key]; navigation_tree_add(line); if(line.childs){ for(var key2 in line.childs){ navigation_tree_add(line.childs[key2]); } } } $('.navigation-line [name="item-target"]').each(function(){ var input = $(this); if(input.attr('data-value')==input.val()) input.prop('checked', true); }); init_components(); }); } function navigation_tree_new(element){ var data = { label : 'Sans titre', icon : 'far fa-bookmark', url : '', labelType : 'non défini', shortcut: $('#navigation-menu>option:selected').attr('data-slug') == 'shortcut-menu' }; if(element){ data = $(element).closest('.list-group-item').data(); data.target = 'redirect'; $.message('info','Lien "'+data.label+'" ajouté au menu'); } var line = navigation_tree_add(data); $('.navigation-line .navigation-item-form').addClass('hidden'); line.find('.navigation-item-form').removeClass('hidden'); line.find('.navigation-item-toggle').toggleClass('fa-angle-right fa-angle-down'); init_components(); line.find('.item-label').select(); } function navigation_tree_add(data){ var tpl = $('.navigation-line:hidden').get(0).outerHTML; tpl = tpl.replace('data-type="user-tpl"','data-type="user"'); var line = $(Mustache.render(tpl,data)); line.removeClass('hidden'); $('.navigation-tree > ul').append(line); line.find('[name="item-target"][value="'+data.target+'"]').prop('checked',true); line.find('.item-label').keyup(function(){ navigationMenuEdited = true; line.find('.navigation-item-label').text($(this).val()); }); line.find('.item-url').keyup(function(){ navigationMenuEdited = true; line.find('.navigation-item-url').text($(this).val()); }); line.find('[name="item-target"]').click(function(){ navigationMenuEdited = true; line.find('.navigation-item-type span').text($(this).parent().text()); }); line.find('.item-icon').change(function(){ navigationMenuEdited = true; line.find('.navigation-item-icon i').attr('class',$(this).val()); }); return line; } function navigation_tree_toggle(element){ var toggler = $(element); var line = toggler.closest('.navigation-line'); toggler.toggleClass('fa-angle-right fa-angle-down'); $('.navigation-item-form',line).toggleClass('hidden'); } function navigation_tree_remove(element){ if(!confirm('Êtes-vous sûr de vouloir supprimer cet élement de menu ?')) return; navigationMenuEdited = true; $(element).closest('.navigation-line').remove() }