main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. $(function(){
  2. navigation_menuitem_search();
  3. })
  4. //CHARGEMENT DE LA PAGE
  5. function init_plugin_navigation(){
  6. switch($.urlParam('page')){
  7. default:
  8. break;
  9. }
  10. }
  11. //Enregistrement des configurations
  12. function navigation_setting_save(){
  13. $.action({
  14. action : 'navigation_setting_save',
  15. fields : $('#navigation-setting-form').toJson()
  16. },function(){
  17. $.message('success','Enregistré');
  18. });
  19. }
  20. /** MENUITEM **/
  21. //Récuperation d'une liste de menuitem dans le tableau #menuitems
  22. function navigation_menuitem_search(callback){
  23. $.action({
  24. action : 'navigation_menuitem_search'
  25. },function(r){
  26. $('.navigation-template-item:visible').remove();
  27. for(var k in r.rows){
  28. navigation_menuitem_add(r.rows[k]);
  29. }
  30. });
  31. }
  32. //Ajout ou modification d'élément menuitem
  33. function navigation_menuitem_save(){
  34. var data = $('#menuitem-form').toJson();
  35. $.action(data,function(r){
  36. $('#menuitem-form').attr('data-id','');
  37. navigation_menuitem_search();
  38. $('#quickform-modal').modal('hide');
  39. $.message('success', 'Enregistré');
  40. });
  41. }
  42. //Récuperation ou edition d'élément menuitem
  43. function navigation_menuitem_edit(element,event){
  44. /*var line = $(element).closest('tr');
  45. $.action({action:'navigation_menuitem_edit',id:line.attr('data-id')},function(r){
  46. $.setForm('#menuitem-form',r);
  47. $('#menuitem-form').attr('data-id',r.id);
  48. });*/
  49. var idMenu = $(element).attr('data-id');
  50. var modal = $('#quickform-modal');
  51. modal.find('#quickform-modal-label').text('Édition de menu');
  52. modal.find('.modal-body').load('plugin/navigation/page.quick.item.php',{
  53. id: idMenu
  54. },function(){
  55. var modalFooter = modal.find('.modal-footer');
  56. var closeBtn = modalFooter.find('[data-dismiss="modal"]');
  57. modalFooter.text('').append(closeBtn);
  58. modalFooter.append('<div onclick="navigation_menuitem_save();" class="btn btn-success save-menu"><i class="fas fa-check"></i> Enregistrer</div>');
  59. if(idMenu){
  60. modalFooter.addClass('modal-footer-margin-auto');
  61. modalFooter.prepend('<div onclick="navigation_menuitem_delete();" class="btn btn-danger delete-menu mr-auto"><i class="fas fa-times"></i> Supprimer</div>');
  62. } else {
  63. modalFooter.removeClass('modal-footer-margin-auto');
  64. }
  65. init_components(modal);
  66. });
  67. modal.modal('show');
  68. if(!event)return;
  69. event.preventDefault();
  70. event.stopPropagation();
  71. }
  72. //Récuperation ou edition d'élément menuitem
  73. function navigation_navigation_edit(element){
  74. $('.navigation-plus-button,.navigation-validate-button,.navigation-edit-item-button').show();
  75. $('.navigation-edit-button').hide();
  76. $('.navigation-menu').sortable({
  77. items: 'li:not(.pointer)',
  78. placeholder: "navigation-sortable-placeholder",
  79. axis: "x",
  80. cursor: "move",
  81. stop : function(e, ui){
  82. var sort = [];
  83. $('.navigation-template-item:visible').each(function(i,element){
  84. sort.push($(this).attr('data-id'));
  85. });
  86. $.action({
  87. action : 'navigation_menuitem_move',
  88. sort : sort
  89. });
  90. },
  91. //handle: ".navigation-template-item"
  92. });
  93. }
  94. function navigation_menuitem_add(data){
  95. if(!data) data = {};
  96. var data = $.extend({
  97. label : 'Nouveau menu',
  98. icon : 'user',
  99. },data);
  100. var tpl = $('.navigation-template-item.hide').get(0).outerHTML;
  101. var item = $(Mustache.render(tpl,data));
  102. item.removeClass('hide');
  103. $('.navigation-template-item.hide').before(item);
  104. }
  105. function navigation_navigation_save(){
  106. $('.navigation-plus-button,.navigation-edit-item-button,.navigation-validate-button').hide();
  107. $('.navigation-edit-button').show();
  108. $('.navigation-menu').sortable("disable");
  109. }
  110. //Suppression d'élement menuitem
  111. function navigation_menuitem_delete(element){
  112. if(!confirm('Êtes vous sûr de vouloir supprimer ce menu ?')) return;
  113. var line = $(element).closest('tr');
  114. $.action({
  115. action : 'navigation_menuitem_delete',
  116. id : $('#menuitem-form').attr('data-id')
  117. },function(r){
  118. line.remove();
  119. $('#menuitem-form').attr('data-id','');
  120. navigation_menuitem_search();
  121. $('#quickform-modal').modal('hide');
  122. $.message('info', 'Menu supprimé');
  123. });
  124. }