Projet

Général

Profil

0001-forms-decorate-nearby-field-33680.patch

Serghei Mihai, 22 septembre 2019 21:42

Télécharger (7,67 ko)

Voir les différences:

Subject: [PATCH] forms: decorate "nearby" field (#33680)

 static/includes/_wcs.scss                     |  62 +++++++
 .../qommon/forms/widgets/nearby-list.html     | 153 ++++++++++++++++++
 2 files changed, 215 insertions(+)
 create mode 100644 templates/qommon/forms/widgets/nearby-list.html
static/includes/_wcs.scss
761 761
		}
762 762
	}
763 763
}
764

  
765
div#nearby-list {
766
	> div {
767
		margin: 5px auto;
768
		display: flex;
769
		align-items: center;
770
		align-content: center;
771
		justify-content: space-between;
772
		border: $widget-border;
773
		padding: 5px;
774
	}
775
	span {
776
		margin: 0 5px;
777
		&.problem-digest {
778
			width: 60%;
779
		}
780
		&.problem-datetime {
781
			width: 20%;
782
			@media screen and (max-width: $mobile-limit) {
783
				width: 30%;
784
			}
785
		}
786
	}
787
	a {
788
		&.marker-counter {
789
			background: $button-background;
790
			padding: 5px 10px;
791
			color: $button-color;
792
			min-width: 0.5em;
793
			max-width: 1em;
794
			border-radius: 3px;
795
		}
796
	}
797
}
798

  
799
div.leaflet-div-icon {
800
	padding: 3px;
801
	border-radius: 3px;
802
	display: flex;
803
	display: -ms-flexbox;
804
	justify-content: space-around;
805
	-ms-justify-content: space-around;
806
	a {
807
		line-height: 1em;
808
	}
809
}
810

  
811
.signalements-thanks ~ div.buttons {
812
	div.submit-button, div.previous-button {
813
		display: none;
814
	}
815
	div.cancel-button button {
816
		text-indent: -9999px;
817
		line-height: 0;
818
		&::after {
819
			text-indent: 0;
820
			line-height: initial;
821
			display: block;
822
			content: 'Continuer';
823
		}
824
	}
825
}
templates/qommon/forms/widgets/nearby-list.html
1
{% extends "qommon/forms/widgets/map.html" %}
2
{% load qommon l10n %}
3

  
4
{% block widget-title %}
5
{% endblock %}
6

  
7
{% block widget-content %}
8
{% if form %}
9
<input type="hidden" name="{{widget.name}}$latlng">
10
<div id="map-{{widget.name}}" class="qommon-map"
11
  data-readonly="true"
12
  {% for key, value in widget.map_attributes.items %}{{key}}="{{value}}" {% endfor %}
13
  {% localize off %}
14
  data-init-lat="{{ form_var_carte_lat }}"
15
  data-init-lng="{{ form_var_carte_lon }}"
16
  {% endlocalize %}
17
></div>
18
{% block list-header %}
19
  <h3>Si votre signalement ne figure pas dans la liste ci-dessous, continuez</h3>
20
{% endblock %}
21
<div id="nearby-list">
22
  {% with distance=form_option_distance|default:100|add:50 %}
23
  {% with demands=form.objects.pending|distance_filter:distance %}
24
  {% for formdata in demands %}
25
      <div data-id="{{formdata.number}}"
26
           {% localize off %}
27
           data-geoloc-lat="{{formdata.geoloc.base.lat}}"
28
           data-geoloc-lon="{{formdata.geoloc.base.lon}}"
29
           {% endlocalize %}
30
           >
31
              <a class="marker-counter" name="nearby-{{forloop.counter}}">{{forloop.counter}}</a>
32
              {% block problem-digest %}
33
              <span class="problem-digest">{{ formdata.digest }}</span>
34
              {% endblock %}
35
              <span class="problem-datetime">Signalé le {{ formdata.receipt_date }}</span>
36
              {% if activate_plus1_action == "True" %}
37
              <a class="plus1 pk-button" href="#" data-plus1-url="{{formdata.api_url}}hooks/plus1/">+1</a>
38
              {% endif %}
39
      </div>
40
  {% endfor %}
41
{% endwith %}
42
{% endwith %}
43
</div>
44

  
45
<script type="text/javascript">
46
$(function() {
47
  if ($('#nearby-list').length) {
48
    $(document).on('wcs:maps-ready', function() {
49
      var $map_widget = $('.qommon-map');
50
      var map = $map_widget[0].leaflet_map;
51
      var geojson_data = Array();
52
      $('#nearby-list div[data-id]').each(function(idx, elem) {
53
        var feature = {
54
          type: 'Feature',
55
          properties: {
56
            id: $(elem).data('id'),
57
            counter: $(elem).find('.marker-counter').text()
58
          },
59
          geometry: {
60
            type: 'Point',
61
            coordinates: [$(elem).data('geoloc-lon'), $(elem).data('geoloc-lat')]
62
          }
63
        };
64
        geojson_data.push(feature);
65
      });
66

  
67
      $(map).on('zoomend moveend', function() {
68
        /* filter display of nearby items to match the displayed map area */
69
        var nearby_list = $('#nearby-list');
70
        nearby_list.find('> div').hide();
71
        map.eachLayer(function(layer){
72
          if (layer instanceof L.Marker && map.getBounds().contains(layer.getLatLng())) {
73
            if (layer.feature && layer.feature.properties.id) {
74
              nearby_list.find('[data-id="' + layer.feature.properties.id + '"]').show();
75
              return;
76
            }
77
          }
78
        });
79
      });
80

  
81
      if (geojson_data) {
82
        var geo_json = L.geoJson(geojson_data,
83
          {
84
            pointToLayer: function (feature, latlng) {
85
              marker = L.divIcon({
86
                                  iconAnchor: [0, 0],
87
                                  popupAnchor: [5, -45],
88
                                  html: '<a href="#nearby-' + feature.properties.counter + '" class="demand-map-marker">' +
89
                                         feature.properties.counter + '</a>'
90
                                 });
91
              return L.marker(latlng, {icon: marker});
92
            }
93
          });
94
        geo_json.addTo(map);
95
        $(map).trigger('moveend');
96
      }
97
      {% if activate_plus1_action == "True" %}
98
      $('a.plus1').on('click', function() {
99
        var plus1_url = $(this).data('plus1-url');
100
        var $dialog = null;
101
        $dialog = $('<div id="plus1-dialog">'
102
                    + '{% if user.is_authenticated %}<p>Vous allez confirmer le signalement.'
103
                    + 'Vous pouvez également décider de recevoir un message une fois celui-ci pris en charge.</p>'
104
                    + '<label><input type="checkbox">Recevoir un message</input></label>'
105
                    + '{% else %}<p>Vous allez confirmer le signalement.</p>{% endif %}'
106
                    + '</div>');
107
        $dialog.dialog({
108
          modal: true,
109
          buttons: [
110
                    {text: 'Annuler',
111
                     'class': 'cancel-button',
112
                     click: function() {
113
                       $(this).dialog('destroy');
114
                     }
115
                    },
116
                    {text: 'Confirmer',
117
                     click: function() {
118
                       var checked = ($(this).find('[type=checkbox]:checked').length > 0);
119
                       $.ajax({
120
                         url: plus1_url,
121
                         data: JSON.stringify({'checked': checked}),
122
                         type: 'POST',
123
                         contentType: 'application/json; charset=utf-8',
124
                         dataType: 'json',
125
                         success: function(resp) {
126
                           $dialog.dialog('destroy');
127
                           $map_widget.parent().find('[type=hidden]').val('0;0');
128
                           $('div.buttons button[name=submit]').click();
129
                         }
130
                       });
131
                     }
132
                    }
133
                   ],
134
          close: function() {}
135
        });
136
        return false;
137
      });
138
      {% endif %}
139
    });
140
  }
141
})
142
</script>
143

  
144
{% else %} {# no form, this is the admin preview #}
145
<div class="infonotice">
146
  {% block preview-impossible %}
147
  Signalements à proximité, prévisualisation impossible.
148
  {% endblock %}
149
</div>
150
{% endif %}
151

  
152
{% endblock %}
153

  
0
-