templates/Page/pages.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block localstyle %}
  3.     body{overflow-y:hidden}
  4. {% endblock %}
  5. {% block appmenu %}
  6.     <div id="menupage" class="d-flex align-items-center">
  7.         {% for page in pagesadmin %} 
  8.             {% set forcereload=true %}
  9.             {% if page.pagecategory.id==1 %}
  10.                 {% set forcereload=page.toreload %}
  11.             {% endif %}
  12.             {% set usage="portal" %}
  13.             {% if loop.first %} {% set usage="accueil" %} {%endif %}
  14.             {% if entity.id is defined and page.id==entity.id %}
  15.                 <div id="menupage-{{page.id}}" class="active nav-link" style="cursor:pointer">
  16.                     <a onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','{{usage}}','{{forcereload}}',null,'{{page.name}}')">
  17.                         {% if page.fonticon %}
  18.                             <i class="{{ page.fonticon }} fa-faw"></i>&nbsp;
  19.                         {% endif %}                    
  20.                         {{ page.name }}
  21.                     </a>
  22.                 </div>
  23.             {% else %}
  24.                 <div id="menupage-{{page.id}}" class="nav-link">
  25.                     <a style="cursor:pointer" onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','portal','{{forcereload}}',null,'{{page.name}}')">
  26.                         {% if page.fonticon %}
  27.                             <i class="{{ page.fonticon }} fa-faw"></i>&nbsp;
  28.                         {% endif %}                       
  29.                         {{ page.name }}
  30.                     </a>
  31.                 </div>
  32.             {% endif %}
  33.         {% endfor %}
  34.     </div>
  35.     <div id="menuuser" class="d-flex align-items-center">
  36.         {% for page in pagesuser %}
  37.             {% set forcereload=true %}
  38.             {% if page.pagecategory.id==1 %}
  39.                 {% set forcereload=page.toreload %}
  40.             {% endif %}
  41.             
  42.             {% if entity.id is defined and page.id==entity.id %}
  43.                 <div id="menupage-{{page.id}}" class="active nav-link" style="cursor:pointer">
  44.                     <a onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','user','{{forcereload}}',null,'{{page.name}}')">
  45.                         {% if page.fonticon %}
  46.                             <i class="{{ page.fonticon }} fa-faw"></i>
  47.                         {% else %}
  48.                             <i class="fa fa-user fa-fw"></i>
  49.                         {% endif %}
  50.                         {{ page.name }}
  51.                     </a>
  52.                 </div>
  53.             {% else %}
  54.                 <div id="menupage-{{page.id}}" class="nav-link">
  55.                     <a style="cursor:pointer" onClick="showPage({{ page.id }},{{ page.pagecategory.id }},'{{ page.canupdate }}','user','{{forcereload}}',null,'{{page.name}}')">
  56.                         {% if page.fonticon %}
  57.                             <i class="{{ page.fonticon }} fa-faw"></i>
  58.                         {% else %}
  59.                             <i class="fa fa-user fa-fw"></i>
  60.                         {% endif %}
  61.                         {{ page.name }}
  62.                     </a>
  63.                 </div>
  64.             {% endif %}
  65.         {% endfor %}
  66.     </div>
  67.     <div id="menugroup" class="d-flex align-items-center">
  68.         <!-- On regroupe l'ensemble des pages si plus de x groupes -->
  69.         {% set nbgroupregrouped=5 %}
  70.         {% if groupsshared|length > nbgroupregrouped %} 
  71.             <div id="pagesshared" class="nav-link">
  72.                 <a id="menugrouppages" style='cursor:pointer' data-bs-toggle='modal' data-bs-target='#selgrouppages'>
  73.                     <i class="fa fa-users fa-fw"></i>&nbsp;Mes Groupes
  74.                     <span class="caret"></span>
  75.                 </a>    
  76.             </div>
  77.         {% else %}
  78.             {% set inmenu=true %}
  79.             {{ include('Page/menugroupe.html.twig') }}
  80.         {% endif %}
  81.     </div>
  82.     <div id="menuaction" class="ms-auto d-flex align-items-center">
  83.         <a id="menuname" style="cursor:pointer;font-size:80%" href=""></a>
  84.         {% if canadd %}
  85.             <a id="menusubmit" style="cursor:pointer" onclick="submitPage()" title='Ajouter une page'><i class='fa fa-plus fa-fw'></i></a>
  86.         {% endif %}
  87.         <a id="menuupdate" style="cursor:pointer;display:none" onclick="updatePage()" title='Modifier une page'><i class='fa fa-file fa-fw'></i></a>
  88.         <a id="menushare" style="cursor:pointer;display:none" onclick="sharePage()" title='Partager une page'><i class='fa fa-share-alt fa-fw'></i></a>
  89.         <a id="menudelete" style="cursor:pointer;display:none" onclick="deletePage()" title='Supprimer une page'><i class='fa fa-trash fa-fw'></i></a>
  90.         <a id="menubookmark" style="cursor:pointer;display:none" onclick="bookmarkPage()" title="Faire de cette page votre page d'accueil"><i class='fa fa-heart fa-fw'></i></a>
  91.         <a id="menuwidgetuser" style='cursor:pointer;display:none' data-bs-toggle='modal' data-bs-target='#selwidgetuser' title='Ajouter un widget'><i class='fa fa-cubes fa-fw'></i></a>
  92.         <a id="menuwidgetgroup" style='cursor:pointer;display:none' data-bs-toggle='modal' data-bs-target='#selwidgetgroup' title='Ajouter un widget'><i class='fa fa-cubes fa-fw'></i></a>
  93.     </div> 
  94. {% endblock %}
  95. {% block pagewrapper %}
  96.     <div id="pagecontainer">  
  97.         {% if activate_widonlyoffice %}
  98.             <iframe src="{{ widonlyoffice_url }}/sso/login" style="display:none"></iframe>
  99.         {% endif %}
  100.         {% set nbgroupregrouped=5 %}
  101.         {% if groupsshared|length > nbgroupregrouped %} 
  102.             <div id="selgrouppages" class="modal fade bs-item-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  103.                 <div class="modal-dialog modal-lg">
  104.                     <div class="modal-content">
  105.                         <div class="modal-header">
  106.                             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  107.                             <h4 class="modal-title">MES GROUPES</h4>
  108.                         </div>
  109.                         <div class="modal-body">
  110.                             <a onclick="$('#selgrouppages').modal('hide');" class="btn btn-secondary" style="margin-bottom:15px">
  111.                                 Annuler
  112.                             </a>
  113.                             {% set inmenu=false %}
  114.                             {{ include('Page/menugroupe.html.twig') }}
  115.                         </div>
  116.                     </div>
  117.                 </div>
  118.             </div>    
  119.         {%endif%}
  120.         <div id="selwidgetuser" class="modal fade bs-item-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  121.             <div class="modal-dialog modal-lg">
  122.                 <div class="modal-content">
  123.                     <div class="modal-header">
  124.                         <h4 class="modal-title">SELECTIONNER UN WIDGET</h4>
  125.                         <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  126.                     </div>
  127.                     <div class="modal-body">
  128.                         <div class="form-group row clearfix">
  129.                             <div class="col-md-12" style="margin-bottom:15px">
  130.                                 <a onclick="$('#selwidgetuser').modal('hide');" class="btn btn-secondary">
  131.                                     Annuler
  132.                                 </a>
  133.                             </div>  
  134.                             <div class="dataTable_wrapper col-md-12">
  135.                             <table id="dataTables" class="table table-bordered table-striped table-hover">  
  136.                                 <thead>
  137.                                 <tr>
  138.                                     <th class="no-sort" width="20%">#</th>
  139.                                     <th>Nom</th>
  140.                                     <th class="no-sort">Description</th>
  141.                                 </tr>
  142.                                 </thead>
  143.                                 <tbody>
  144.                                     {% for widget in widgetsuser %}
  145.                                         <tr>
  146.                                             <td>
  147.                                                 <a onClick="selWidget({{ widget.id }})" style="cursor:pointer;">
  148.                                                     <img id="widgettype-{{ widget.id }}" class="grid-item-img" height="40" src="{{ asset(widget.icon.label) }}" style="padding:2px">
  149.                                                 </a>
  150.                                             </td>
  151.                                             <td>{{ widget.name }}</td>
  152.                                             <td>{{ widget.description }}</td>
  153.                                         </tr>
  154.                                     {% endfor %}  
  155.                                 </tbody>
  156.                             </table>
  157.                             </div>
  158.                         </div>
  159.                     </div>
  160.                 </div>
  161.             </div>
  162.         </div>   
  163.         <div id="selwidgetgroup" class="modal" tabindex="-1">
  164.             <div class="modal-dialog modal-lg">
  165.                 <div class="modal-content">
  166.                     <div class="modal-header">
  167.                         <h4 class="modal-title">SELECTIONNER UN WIDGET</h4>
  168.                         <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  169.                     </div>
  170.                     <div class="modal-body">
  171.                         <div class="form-group row clearfix">
  172.                             <div class="col-md-12" style="margin-bottom:15px">
  173.                                 <a onclick="$('#selwidgetgroup').modal('hide');" class="btn btn-secondary">
  174.                                     Annuler
  175.                                 </a>
  176.                             </div>  
  177.                             <div class="dataTable_wrapper col-md-12">
  178.                             <table id="dataTables" class="table table-bordered table-striped table-hover">  
  179.                                 <thead>
  180.                                 <tr>
  181.                                     <th class="no-sort" width="20%">#</th>
  182.                                     <th>Nom</th>
  183.                                     <th class="no-sort">Description</th>
  184.                                 </tr>
  185.                                 </thead>
  186.                                 <tbody>
  187.                                     {% for widget in widgetsgroup %}
  188.                                         <tr>
  189.                                             <td >
  190.                                                 <a onClick="selWidget({{ widget.id }})" style="cursor:pointer;">
  191.                                                     <img id="widgettype-{{ widget.id }}" class="grid-item-img" height="40" src="{{ asset(widget.icon.label) }}" style="padding:2px">
  192.                                                 </a>
  193.                                             </td>
  194.                                             <td>{{ widget.name }}</td>
  195.                                             <td>{{ widget.description }}</td>
  196.                                         </tr>
  197.                                     {% endfor %}  
  198.                                 </tbody>
  199.                             </table>
  200.                             </div>
  201.                         </div>
  202.                     </div>
  203.                 </div>
  204.             </div>
  205.         </div>  
  206.         {%if app.user %}
  207.             <a id="refreshcounter" data-event=""></a>
  208.         {% endif %}
  209.     </div>
  210. {% endblock %}
  211. {% block localjavascript %}
  212.     var idpage;
  213.     pagebookmark="{{app.session.get("pagebookmark")}}";
  214.     $('document').ready(function(){
  215.         {% if gotoroute is empty %}
  216.             {% for page in pagesadmin %} 
  217.                 {% if page.id==entity.id %}
  218.                     {% set usage="portal" %}
  219.                     {% if loop.first %} {% set usage="accueil" %} {%endif %}                
  220.                     showPage({{ page.id }}, {{ page.pagecategory.id }},'{{ page.canupdate }}','{{usage}}',false,null,'{{page.name}}');
  221.                 {% endif %}
  222.             {% endfor %}
  223.             
  224.             {% for page in pagesuser %} 
  225.                 {% if page.id==entity.id %}
  226.                     showPage({{ page.id }}, {{ page.pagecategory.id }},'{{ page.canupdate }}','user',false,null,'{{page.name}}');
  227.                 {% endif %}
  228.             {% endfor %}      
  229.             
  230.             {% for groupshared in groupsshared %}
  231.                 {% for page in groupshared.pagesshared %}
  232.                     {% if page.id==entity.id %}
  233.                         showPage({{ page.id }}, {{ page.pagecategory.id }},'{{ page.canupdate }}','group',true,{{groupshared.id}},'{{page.name}}');
  234.                     {% endif %}
  235.                 {% endfor %}       
  236.             {% endfor %}
  237.         {% else %}
  238.             var url="{{ path(gotoroute,{id:gotoid}) }}";
  239.             showGoto(url);   
  240.         {% endif %}
  241.         // Rendre les pages user déplacable
  242.         $("#menuuser").sortable({
  243.             axis: "x",
  244.             forcePlaceholderSize: true,
  245.             placeholder: "placeholder",
  246.             items: "> div",
  247.             update:  function( event, ui ) {
  248.                 $('#menuuser div').each(function(order) {
  249.                     var idpage=$(this).attr('id').replace("menupage-","");
  250.                     $.ajax({
  251.                         method: "POST",
  252.                         url: "{{ path('app_portal_'~access~'_page_order') }}",
  253.                         data: {
  254.                             id:idpage,
  255.                             order:order
  256.                         }
  257.                     });
  258.                 });     
  259.             }
  260.         }); 
  261.         // Initialisation du tableau des widgets selectionnable à la création
  262.         $('.table').DataTable({
  263.             columnDefs: [ { "targets": 'no-sort', "orderable": false }, { "targets": 0, "className": "text-center" } ],
  264.             responsive: true,
  265.             iDisplayLength: 10,
  266.             order: [[ 1, "asc" ]],
  267.         }); 
  268.         {% if app.user and app.session.get("timerefreshnotif") > 0%}
  269.         setInterval(function(){
  270.             loadmsgCounter()
  271.         }, {{(app.session.get("timerefreshnotif")*1000)}});
  272.         {% endif %}
  273.     });
  274.     // Affichage des frames associés aux items de bureau
  275.     function showFrameitem(id,url,forcereload) {
  276.         $(".pageframereload").remove();
  277.         $(".pageframe").hide();
  278.         // Si force le rechargement et frame existante on la détruit
  279.         if(forcereload&&$("#frameitem-"+id).length)
  280.             $("#frameitem-"+id).remove();
  281.         // Si la frame en cours existe déjà on l'affiche
  282.         if($("#frameitem-"+id).length)
  283.             $("#frameitem-"+id).show();         
  284.         // Sinon on la génère
  285.         else {
  286.             var myclass="";
  287.             if(forcereload) myclass="pageframereload";
  288.             $("#pagecontainer").append("<iframe onload='this.contentWindow.focus()' id='frameitem-"+id+"' class='pageframe "+myclass+"' src='"+url+"' style='border:none; width:100%'></iframe>");
  289.         }
  290.         
  291.         resize();
  292.     }
  293.     // Affichages des pages
  294.     function showPage(id,catid,canupdate,usage,forcereload,groupid,pagename) {
  295.         // Sauvegarder la page en cours
  296.         idpage=id;   
  297.         // Cacher toutes les pages
  298.         $(".pageframereload").remove();
  299.         $(".pageframe").hide();
  300.         // Rendre actif le page en cours dans le menu
  301.         $("#menu .nav-link").removeClass("active");
  302.         $(".dropdown-toggle").removeClass("dropdownactive");
  303.         $("#menupage-"+id).addClass("active");
  304.         $('a[data-group="'+groupid+'"][data-toggle="dropdown"]').addClass("dropdownactive");
  305.         
  306.         var url="{{ path('app_portal_user_page_view',{id:'xx',usage:'yy','group':'zz'}) }}";
  307.         url=url.replace('xx',id);
  308.         url=url.replace('yy',usage);
  309.         url=url.replace('zz',groupid);
  310.         passurl="{{ path('app_core_home',{id:'xx'}) }}";
  311.         passurl=passurl.replace('xx',id);
  312.         history.pushState('data to be passed', 'Title of the page', passurl);
  313.         // Si force le rechargement et frame existante on la détruit
  314.         if(forcereload&&$("#page-"+id).length)
  315.             $("#page-"+id).remove();
  316.         // Si la frame en cours existe déjà on l'affiche
  317.         if($("#page-"+id).length)
  318.             $("#page-"+id).show();
  319.         // Sinon on la génère
  320.         else {
  321.             var myclass="";
  322.             if(forcereload) myclass="pageframereload";
  323.             $("#pagecontainer").append("<iframe onload='this.contentWindow.focus()' id='page-"+id+"' data-category='"+catid+"' class='pageframe "+myclass+"' src='"+url+"' style='border:none; width:100%'></iframe>");    
  324.         }
  325.         // Détruire le badge associé car normalement de fait on a lu les notif
  326.         if(usage=="group") {
  327.             $("#badge-"+groupid).remove()
  328.         }
  329.         // Nom de la page
  330.         console.log(pagename);
  331.         $("#menuname").html(pagename);
  332.         // Cacher les actions possibles sur la page
  333.         $("#menuupdate").hide();
  334.         $("#menushare").hide();
  335.         $("#menudelete").hide();
  336.         $("#menubookmark").hide();
  337.         $("#menuwidgetuser").hide();
  338.         $("#menuwidgetgroup").hide();
  339.         if(canupdate) {
  340.             $("#menuupdate").show();
  341.             $("#menushare").show();
  342.             $("#menudelete").show();
  343.         }
  344.         {% if app.user %}
  345.             
  346.             if(id==pagebookmark) {
  347.                 $("#menubookmark").css("color","red");
  348.                 $("#menubookmark").attr("title","Ne plus faire de cette page votre page d'accueil")
  349.             }
  350.             else {
  351.                 $("#menubookmark").css("color","");
  352.                 $("#menubookmark").attr("title","Faire de cette page votre page d'accueil")
  353.             }
  354.             $("#menubookmark").show();
  355.         {% endif %}
  356.         // Si page de type widget on affiche la selection des widgets à insérer
  357.         if($("#page-"+id).data('category')==2&&canupdate) {
  358.             if(usage=="user") $("#menuwidgetuser").show();    
  359.             if(usage=="group") $("#menuwidgetgroup").show();    
  360.         }
  361.         // On resize les frame
  362.         resize();
  363.         // Mettre le focus dans la frame
  364.         //$("#page-"+id).contentWindow.focus();
  365.     }
  366.     // Affichages des pages
  367.     function showGoto(url) {
  368.         $("#pagecontainer").append("<iframe onload='this.contentWindow.focus()' id='goto' class='pageframe pageframereload' src='"+url+"' style='border:none; width:100%'></iframe>");    
  369.         // On resize les frame
  370.         resize();
  371.     }
  372.     function submitPage() {
  373.         var url="{{ path('app_portal_'~access~'_page_submit') }}";
  374.         $(location).attr('href',url);
  375.     }  
  376.     function updatePage() {
  377.         if($("#page-"+idpage).length) {
  378.             var url="{{ path('app_portal_'~access~'_page_update',{id:'xx'}) }}";
  379.             url=url.replace('xx',idpage);
  380.             $(location).attr('href',url);
  381.         }
  382.     }    
  383.     function sharePage() {
  384.         if($("#page-"+idpage).length) {
  385.             var url="{{ path('app_portal_'~access~'_page_share',{id:'xx'}) }}";
  386.             url=url.replace('xx',idpage);
  387.             $(location).attr('href',url);
  388.         }
  389.     } 
  390.     function deletePage() {
  391.         if($("#page-"+idpage).length) {
  392.             if (confirm('Êtes-vous sûr de vouloir supprimer ?')) {
  393.                 var url="{{ path('app_portal_'~access~'_page_delete',{id:'xx'}) }}";
  394.                 url=url.replace('xx',idpage);
  395.                 $(location).attr('href',url);
  396.             }
  397.         }
  398.     }  
  399.     function bookmarkPage() {
  400.         {% if app.user %}
  401.             if($("#page-"+idpage).length) {
  402.                 if(pagebookmark==idpage)
  403.                     confirmtext="Votre page d'accueil redevient l'accueil général de {{ app.session.get("appname") }}.";
  404.                 else
  405.                     confirmtext="Cette page sera votre page d'acueil à l'ouverture de {{ app.session.get("appname") }}, vous pourrez à tout moment changer de page d'accueil.";
  406.                if (confirm(confirmtext)) {
  407.                     $.ajax({
  408.                         method: "POST",
  409.                         url: "{{ path('app_core_user_preference') }}",
  410.                         data: {
  411.                             id:0,
  412.                             key:'pagebookmark',
  413.                             value: idpage
  414.                         },
  415.                         success: function() {
  416.                             if(pagebookmark==idpage) {
  417.                                 pagebookmark="";
  418.                                 $("#menubookmark").css("color","");
  419.                                 $("#menubookmark").attr("title","Faire de cette page votre page d'accueil")
  420.                             }
  421.                             else {
  422.                                 pagebookmark=idpage;
  423.                                 $("#menubookmark").css("color","red");
  424.                                 $("#menubookmark").attr("title","Ne plus faire de cette page votre page d'accueil")
  425.                             }
  426.                         }            
  427.                     });
  428.                 }
  429.             }
  430.         {% endif %}   
  431.     }  
  432.     // Création d'un widget selectionné
  433.     function selWidget(idwidgettype) {
  434.         var url="{{ path('app_portal_user_pagewidget_widget_sumbit',{idpage:'yy',idwidgettype:'xx'})}}";
  435.         url=url.replace('xx',idwidgettype);
  436.         url=url.replace('yy',idpage);
  437.         $(location).attr('href', url);
  438.     };      
  439.     function loadmsgCounter() {      
  440.         $.ajax({
  441.             method: "POST",
  442.             url: "{{ path('app_portal_user_page_ajax_msgcounter') }}",
  443.             success: function(data) {
  444.                 $.each(data, function(group, counter) {
  445.                     menu=$("a[data-group='"+group+"']");
  446.                     if(menu.length) {
  447.                         if(menu.children(".badge").length) {
  448.                             if(counter==0) 
  449.                                 menu.remove();
  450.                             else
  451.                                 menu.children(".badge").html(counter);
  452.                         }
  453.                         else if(counter>0)
  454.                             menu.append('<span id="badge-' + group + '" class="badge bg-secondary ms-1">' + counter + '</span>');
  455.                     }                    
  456.                 });  
  457.             } 
  458.         });
  459.     }
  460. {% endblock %}