-
Notifications
You must be signed in to change notification settings - Fork 2
/
meetings_filter.js
188 lines (159 loc) · 5.02 KB
/
meetings_filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function initTopicFilter(tag) {
var $li = $('#id_tags-' + tag + '-li'),
$btn = $('#id_tags-' + tag + '-btn'),
$chk = $('#id_tags-' + tag);
if ($li.length !== 1)
console.error('The check box must be inside of a list item.');
if ($btn.length !== 1)
console.error('The check box should have a link to go with it.');
$btn.click(function() {
if ($chk.is(':checked')) {
$chk.removeAttr('checked');
} else {
$chk.attr('checked', 'checked');
}
$chk.trigger('change');
});
$chk.change(function() {
if ($chk.is(':checked')) {
$li.addClass('active');
} else {
$li.removeClass('active');
}
});
}
function initAllTopicsFilter() {
var $li = $('#id_all_tags-li'),
$btn = $('#id_all_tags-btn'),
$chk = $('input[name="tags"]'),
$form = $('#id_filter_form');
$btn.click(function() {
$chk.removeAttr('checked');
$chk.trigger('change');
});
$chk.change(function() {
if ($chk.filter(':checked').length > 0) {
$li.removeClass('active');
} else {
$li.addClass('active');
}
});
}
/**
* The widget that goes with these methods is in floppyforms/meetings_bbmap.html
*/
function initGeoBoundsMap(map, value, fieldid, provider) {
var n, e, s, w,
// Which map provider are we using, Google or Leaflet
isG = (google && google.maps && provider === google.maps),
isL = !isG;
if (value) {
var splitVal = value.split(',');
n = parseFloat(splitVal[0]);
e = parseFloat(splitVal[1]);
s = parseFloat(splitVal[2]);
w = parseFloat(splitVal[3]);
} else {
n = 75;
e = 0;
s = -75;
w = 359.999;
}
if (isL) {
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution}),
mapBounds;
mapBounds = new L.LatLngBounds(new L.LatLng(n, e), new L.LatLng(s, w));
map.fitBounds(mapBounds);
map.addLayer(cloudmade);
map.on('moveend', function(evt) {
setGeoFilterValues(map, fieldid, L);
});
} else if (isG) {
var G = provider,
mapBounds;
mapBounds = new G.LatLngBounds(new G.LatLng(s, w), new G.LatLng(n, e));
map.fitBounds(mapBounds);
google.maps.event.addListener(map, 'bounds_changed', function() {
setGeoFilterValues(map, fieldid, G);
});
}
}
function toggleGeoBoundsMap(map, fieldid, provider) {
var geofilter = $('#' + fieldid + '-enable').is(':checked');
if (geofilter) {
$('#' + fieldid + '-map-container').css({position: 'static'});
} else {
// If we hide the map, it won't load it's tiles (if we're using Google), so
// let's just move it far off the page.
$('#' + fieldid + '-map-container').css({position:'absolute', left: -10000});
}
// As soon as the map has bounds, update the filter value.
var _setGeoFilterValues = function(map, fieldid, provider) {
if (map.getBounds()) {
setGeoFilterValues(map, fieldid, provider);
} else {
setTimeout(function() {
_setGeoFilterValues(map, fieldid, provider)
}, 100);
}
};
_setGeoFilterValues(map, fieldid, provider);
}
function setGeoFilterValues(map, fieldid, provider) {
var geofilter = $('#' + fieldid + '-enable').is(':checked'),
// Which map provider are we using, Google or Leaflet
isG = (google && google.maps && provider === google.maps),
isL = !isG;
if (geofilter) {
var mb = map.getBounds(),
n, e, s, w;
if (isL) {
n = mb._northEast.lat;
e = mb._northEast.lng;
s = mb._southWest.lat;
w = mb._southWest.lng;
} else if (isG) {
n = mb.getNorthEast().lat();
e = mb.getNorthEast().lng();
s = mb.getSouthWest().lat();
w = mb.getSouthWest().lng();
}
bbox = n + ',' + e + ',' + s + ',' + w;
$('#' + fieldid).val(bbox).change();
} else {
$('#' + fieldid).removeAttr('value').change();
}
}
function togglePlaceFilterVisibility() {
if ($('#id_place-filter-wrapper').css('position') == 'static')
hidePlaceFilter();
else
$('#id_place-filter-wrapper').css({position: 'static'});
}
function toggleTimeFilterVisibility() {
$('#id_time-filter-wrapper').slideToggle();
}
function toggleTopicsFilterVisibility() {
$('#id_topics-filter-wrapper').slideToggle();
}
function hidePlaceFilter() {
$('#id_place-filter-wrapper').css({position:'absolute', left: -10000});
}
function hideTimeFilter() {
$('#id_time-filter-wrapper').hide();
}
function hideMeetingListUpdateAlert() {
$('#id_loading-meetings-alert').slideUp();
}
function updateMeetingList(filterTimeout) {
$('#id_loading-meetings-alert').slideDown();
// When a filter form input changes, submit the form. Wait a
// bit before submitting, in case the user is making quick
// changes in succession.
clearTimeout(filterTimeout);
return setTimeout(function() {
$('#id_filter_form').submit();
}, 1000);
}