123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- 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 class="navigation-item-placeholder"></li>');
- /** 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()
- }
|