From fcb86a5091a481ba82a1c27609deff32342bf4fc Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Fri, 24 Sep 2021 15:43:46 +0200
Subject: [PATCH] braine-l-alleud: get actualities from plone (#56545)

---
 static/braine-l-alleud/config.json            | 18 +++++------
 .../combo/json/actualites.html                | 30 ++++++++-----------
 2 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/static/braine-l-alleud/config.json b/static/braine-l-alleud/config.json
index 62f89707e..c6ed1d46e 100644
--- a/static/braine-l-alleud/config.json
+++ b/static/braine-l-alleud/config.json
@@ -33,34 +33,32 @@
                   "extra-css-classes" : "no-borders",
                   "label" : "Intertitre avec image",
                   "template" : "combo/cells/page-intertitle.html"
                }
             }
          },
          "JSON_CELL_TYPES.update" : {
             "actualites" : {
-               "additional-data" : [
-                  {
-                     "cache_duration" : 60,
-                     "key" : "actus",
-                     "url" : "{{ json.data|get:slug|get:'href' }}"
-                  }
-               ],
                "cache_duration" : 60,
                "force_async" : false,
                "form" : [
                   {
-                     "label" : "Identifiant du type d’actualités",
+                     "label" : "Identifiant du connecteur Plone REST API",
+                     "type" : "string",
+                     "varname" : "connector"
+                  },
+                  {
+                     "label" : "Identifiant de la requête",
                      "type" : "string",
-                     "varname" : "slug"
+                     "varname" : "query"
                   }
                ],
                "name" : "Actualités",
-               "url" : "{{ braine_actualites_json_url }}"
+               "url" : "{{ passerelle_url }}plone-restapi/{{ connector }}/q/{{ query }}/"
             },
             "deliberations-communales": {
                "cache_duration" : 360,
                "force_async" : false,
                "name" : "Délibérations communales",
                "url" : "{{ braine_deliberations_communales_json_url }}"
             }
          }
diff --git a/templates/variants/braine-l-alleud/combo/json/actualites.html b/templates/variants/braine-l-alleud/combo/json/actualites.html
index 44a626de0..fd5992132 100644
--- a/templates/variants/braine-l-alleud/combo/json/actualites.html
+++ b/templates/variants/braine-l-alleud/combo/json/actualites.html
@@ -1,28 +1,27 @@
 {% load dashboard thumbnail %}
 {% if not in_dashboard %}
-{% with actualites=json.data|get:slug %}
 <div class="dashboard-settings">
 <div class="dashboard-meta">
-<h2>{{actualites.label}}</h2>
-<div>{{actualites.description}}</div>
+<h2>{{json.meta.label}}</h2>
+<div>{{json.meta.description}}</div>
 </div>
 <div class="dashboard-switch">
   {% with tile=cell|as_dashboard_cell:request.user %}
-  <input type="checkbox" id="actualites-id-{{slug}}"
+  <input type="checkbox" id="actualites-id-{{connector}}{{query}}"
       data-add-tile-url="{% url 'combo-dashboard-add-tile' cell_reference=cell.get_reference %}"
       {% if tile %}
       checked
       data-remove-tile-url="{% url 'combo-dashboard-remove-tile' cell_reference=tile.cell.get_reference %}"
       {% endif %}
     >
   {% endwith %}
   <script>
-  $('#actualites-id-{{slug}}').on('change', function() {
+  $('#actualites-id-{{connector}}{{query}}').on('change', function() {
     if ($(this).is(':checked')) {
       var $checkbox = $(this);
       $.ajax({
         url: $(this).data('add-tile-url'),
         success: function(data) {
           $checkbox.data('remove-tile-url', data.cell_data.remove_url);
           $('h1#logo').addClass('dashboard-change').on('animationend', function() { $('h1#logo').removeClass('dashboard-change')});
         }
@@ -32,35 +31,31 @@
         url: $(this).data('remove-tile-url'),
         success: function(data) {}
       });
     }
   });
   </script>
 </div>
 </div>
-{% endwith %}
 {% else %}
-{% with actualites=json.data|get:slug %}
-{% if actus.data %}
-<button hidden class="newsitem-category" data-slug="{{ slug }}">{{actualites.label}}</button>
-{% endif %}
-{% for actu in actus.data %}
-<div class="newsitem" data-slug="{{ slug }}" data-date="{{ actu.date }}">
-{% thumbnail actu.image "160x160" crop="50% 25%" as im %}
+<button hidden class="newsitem-category" data-slug="{{connector}}-{{query}}">{{json.meta.label}}</button>
+{% for actu in json.data %}
+<div class="newsitem" data-slug="{{connector}}-{{query}}" data-date="{{ actu.created }}">
+{% thumbnail actu.image.download "160x160" crop="50% 25%" as im %}
 <img src="{{ im.url }}" alt="" />
 {% endthumbnail %}
 <div>
-<h3><a href="{{actu.href}}">{{actu.title}}</a></h3>
-<h4>{{actualites.label}} - {{ actu.date|parse_date|date:"d/m/Y" }}</h4>
-<p>{{actu.description}}</p>
+<h3><a href="{{actu.portal_id}}">{{actu.title}}</a></h3>
+<h4>{{json.meta.label}} - {{ actu.created|slice:19|parse_date|date:"d/m/Y" }}</h4>
+<p>{{actu.text|safe|escape}}</p>
 </div>
 </div>
 {% endfor %}
-{% if actus.data %}
+{% if json.data %}
 <script>
 jQuery.fn.order = function(asc, fn) { // via https://jsfiddle.net/mindplay/H2mrp/
     fn = fn || function (el) {
         return $(el).text().replace(/^\s+|\s+$/g, '');
     };
     var T = asc !== false ? 1 : -1,
         F = asc !== false ? -1 : 1;
     this.sort(function (a, b) {
@@ -81,10 +76,9 @@ if ($newsitems.length == 0) {
   $newsitems.appendTo($('.dashboard-cell > div'));
 }
 $('.newsitem').detach().appendTo($newsitems);
 $('.newsitem-category').detach().attr('hidden', null).appendTo($newsitems.find('.categories'));
 $('.newsitem-category').order(true);
 $('.newsitem').order(false, function(el) { return $(el).data('date'); });
 </script>
 {% endif %}
-{% endwith %}
 {% endif %}
-- 
2.30.2

