Projet

Général

Profil

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

Serghei Mihai (congés, retour 15/05), 18 septembre 2019 16:25

Télécharger (7,46 ko)

Voir les différences:

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

 static/includes/_wcs.scss                     |  56 +++++++
 .../forms/widgets/map--nearby-list.html       | 149 +++++++++++++++++-
 2 files changed, 203 insertions(+), 2 deletions(-)
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
	}
778
	a {
779
		&.marker-counter {
780
			background: $button-background;
781
			padding: 5px 10px;
782
			color: white;
783
			min-width: 0.5em;
784
			border-radius: 3px;
785
		}
786
		&.plus1 {
787
			transition: all ease 0.2s;
788
			&:hover {
789
				background: lighten($primary-color, 10);
790
			}
791
		}
792
	}
793
}
794

  
795
div.leaflet-div-icon {
796
	padding: 3px;
797
	border-radius: 3px;
798
	display: flex;
799
	justify-content: space-around;
800
	a {
801
		line-height: 1em;
802
	}
803
}
804

  
805
.signalements-thanks ~ div.buttons {
806
	div.submit-button, div.previous-button {
807
		display: none;
808
	}
809
	div.cancel-button button {
810
		text-indent: -9999px;
811
		line-height: 0;
812
		&::after {
813
			text-indent: 0;
814
			line-height: initial;
815
			display: block;
816
			content: 'Continuer';
817
		}
818
	}
819
}
templates/qommon/forms/widgets/map--nearby-list.html
1 1
{% extends "qommon/forms/widgets/map.html" %}
2
{% block  widget-control %}
3
{{ block.super }}
2
{% load qommon l10n %}
3

  
4
{% block widget-title %}
4 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
              <span class="problem-title">{{ formdata.var.problem_title }}</span>
33
              <span class="problem-summary">{{ formdata.var.problem_summary }}</span>
34
              <span class="problem-datetime">Signalé le {{ formdata.receipt_date }}</span>
35
              <a class="plus1 pk-button" href="#" data-plus1-url="{{formdata.api_url}}hooks/plus1/">+1</a>
36
      </div>
37
  {% endfor %}
38
{% endwith %}
39
{% endwith %}
40
</div>
41

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

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

  
78
      if (geojson_data) {
79
        var geo_json = L.geoJson(geojson_data,
80
          {
81
            pointToLayer: function (feature, latlng) {
82
              marker = L.divIcon({
83
                                  iconAnchor: [0, 0],
84
                                  popupAnchor: [5, -45],
85
                                  html: '<a href="#nearby-' + feature.properties.counter + '" class="demand-map-marker">' +
86
                                         feature.properties.counter + '</a>'
87
                                 });
88
              return L.marker(latlng, {icon: marker});
89
            }
90
          });
91
        geo_json.addTo(map);
92
        $(map).trigger('moveend');
93
      }
94

  
95
      $('a.plus1').on('click', function() {
96
        var plus1_url = $(this).data('plus1-url');
97
        var $dialog = null;
98
        $dialog = $('<div id="plus1-dialog">'
99
                    + '{% if user.is_authenticated %}<p>Vous allez confirmer le signalement.'
100
                    + 'Vous pouvez également décider de recevoir un message une fois celui-ci pris en charge.</p>'
101
                    + '<label><input type="checkbox">Recevoir un message</input></label>'
102
                    + '{% else %}<p>Vous allez confirmer le signalement.</p>{% endif %}'
103
                    + '</div>');
104
        $dialog.dialog({
105
          modal: true,
106
          buttons: [
107
                    {text: 'Annuler',
108
                     'class': 'cancel-button',
109
                     click: function() {
110
                       $(this).dialog('destroy');
111
                     }
112
                    },
113
                    {text: 'Confirmer',
114
                     click: function() {
115
                       var checked = ($(this).find('[type=checkbox]:checked').length > 0);
116
                       $.ajax({
117
                         url: plus1_url,
118
                         data: JSON.stringify({'checked': checked}),
119
                         type: 'POST',
120
                         contentType: 'application/json; charset=utf-8',
121
                         dataType: 'json',
122
                         success: function(resp) {
123
                           $dialog.dialog('destroy');
124
                           $map_widget.parent().find('[type=hidden]').val('0;0');
125
                           $('div.buttons button[name=submit]').click();
126
                         }
127
                       });
128
                     }
129
                    }
130
                   ],
131
          close: function() {}
132
        });
133
        return false;
134
      });
135
    });
136
  }
137
})
138
</script>
139

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

  
148
{% endblock %}
149

  
5
-