main.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var navigationMenuEdited = false;
  2. //CHARGEMENT DE LA PAGE SETTING
  3. function init_setting_global_navigation(){
  4. /*switch($.urlParam('page')){
  5. default:
  6. break;
  7. }*/
  8. window.onbeforeunload = function(e){
  9. if(!navigationMenuEdited) return e=null;
  10. return 'Vous n\'avez pas sauvgardé certaines modifications sur le menu, êtes vous sûr de vouloir quitter la page?';
  11. };
  12. navigation_tree_search();
  13. $( ".navigation-tree-list" ).sortable({
  14. placeholder: "navigation-item-placeholder",
  15. handle: ".navigation-item-header",
  16. cancel: ".not-editable",
  17. distance : 15,
  18. update : function(){
  19. navigationMenuEdited = true;
  20. },
  21. grid: [ 50, 1 ],
  22. sort: function(event,ui){
  23. var leftLimit = ui.item.hasClass('navigation-line-child') ? -20: 15;
  24. if(ui.position.left < leftLimit){
  25. ui.helper.css('left',leftLimit+'px');
  26. }
  27. if(ui.position.left >65 ){
  28. left = 65;
  29. ui.helper.css('left',left+'px');
  30. }
  31. if(ui.item.index()==1){
  32. ui.helper.css('left',leftLimit+'px');
  33. }
  34. },
  35. stop: function(event,ui){
  36. if(ui.position.left>15){
  37. if(!ui.item.hasClass('navigation-line-child')) navigationMenuEdited = true;
  38. ui.item.addClass('navigation-line-child');
  39. }else{
  40. if(ui.item.hasClass('navigation-line-child')) navigationMenuEdited = true;
  41. ui.item.removeClass('navigation-line-child');
  42. }
  43. },
  44. helper: "clone",
  45. opacity: 0.8
  46. });
  47. $( ".navigation-tree > u" ).disableSelection();
  48. }
  49. //CHARGEMENT DE LA PAGE
  50. /*
  51. function init_plugin_navigation(){
  52. switch($.urlParam('page')){
  53. default:
  54. break;
  55. }
  56. }
  57. */
  58. /** Editeur d'arborescence **/
  59. //Enregistrement des configurations
  60. function navigation_setting_save(){
  61. var items = [];
  62. var lastParentIndex = 0;
  63. $('.navigation-line:visible').each(function(i,element){
  64. var line = $(element);
  65. var item = {};
  66. item.label = line.find('.item-label').val();
  67. item.visibility = line.find('input.item-visibility').val();
  68. item.url = line.find('.item-url').val();
  69. item.icon = line.find('.item-icon').val();
  70. item.target = line.find('[name="item-target"]:checked').val();
  71. if(line.hasClass('navigation-line-child')){
  72. items[lastParentIndex].childs.push(item);
  73. }else{
  74. lastParentIndex = items.length;
  75. item.childs = [];
  76. items.push(item);
  77. }
  78. });
  79. $.action({
  80. action : 'navigation_setting_save',
  81. fields : $('#navigation-setting-form').toJson(),
  82. items : items,
  83. menu : $('#navigation-menu').val()
  84. },function(){
  85. navigationMenuEdited = false;
  86. $.message('success','Enregistré');
  87. });
  88. }
  89. function navigation_tree_search(callback){
  90. var menu = $('#navigation-menu').val();
  91. if(!menu || menu=='') return;
  92. $.action({
  93. action : 'navigation_tree_search',
  94. menu : menu
  95. },function(r){
  96. $('.navigation-tree > ul > li:visible').remove();
  97. for(var key in r.rows){
  98. var line = r.rows[key];
  99. navigation_tree_add(line);
  100. if(line.childs){
  101. for(var key2 in line.childs){
  102. navigation_tree_add(line.childs[key2]);
  103. }
  104. }
  105. }
  106. $('.navigation-line [name="item-target"]').each(function(){
  107. var input = $(this);
  108. if(input.attr('data-value')==input.val()) input.prop('checked', true);
  109. });
  110. init_components();
  111. });
  112. }
  113. function navigation_tree_new(element){
  114. var data = {
  115. label : 'Sans titre',
  116. icon : 'far fa-bookmark',
  117. url : '',
  118. labelType : 'non définis'
  119. };
  120. if(element){
  121. data = $(element).closest('.list-group-item').data();
  122. data.target = 'redirect';
  123. $.message('info','Lien "'+data.label+'" ajouté au menu');
  124. }
  125. var line = navigation_tree_add(data);
  126. $('.navigation-line .navigation-item-form').addClass('hidden');
  127. line.find('.navigation-item-form').removeClass('hidden');
  128. init_components();
  129. line.find('.item-label').select();
  130. }
  131. function navigation_tree_add(data){
  132. var tpl = $('.navigation-line:hidden').get(0).outerHTML;
  133. tpl = tpl.replace('data-type="user-tpl"','data-type="user"');
  134. var line = $(Mustache.render(tpl,data));
  135. line.removeClass('hidden');
  136. $('.navigation-tree > ul').append(line);
  137. line.find('[name="item-target"][value="'+data.target+'"]').prop('checked',true);
  138. line.find('.item-label').keyup(function(){
  139. navigationMenuEdited = true;
  140. line.find('.navigation-item-label').text($(this).val());
  141. });
  142. line.find('.item-url').keyup(function(){
  143. navigationMenuEdited = true;
  144. line.find('.navigation-item-url').text($(this).val());
  145. });
  146. line.find('[name="item-target"]').click(function(){
  147. navigationMenuEdited = true;
  148. line.find('.navigation-item-type span').text($(this).parent().text());
  149. });
  150. line.find('.item-icon').change(function(){
  151. navigationMenuEdited = true;
  152. line.find('.navigation-item-icon i').attr('class',$(this).val());
  153. });
  154. return line;
  155. }
  156. function navigation_tree_toggle(element){
  157. var line = $(element).closest('.navigation-line');
  158. $('.navigation-item-form',line).toggleClass('hidden');
  159. }
  160. function navigation_tree_remove(element){
  161. if(!confirm('Êtes-vous sûr de vouloir supprimer cet élement?')) return;
  162. navigationMenuEdited = true;
  163. $(element).closest('.navigation-line').remove()
  164. }