Add city/country to event during creation/change.
This commit is contained in:
Родитель
c50b360286
Коммит
24d0a7a644
|
@ -7,6 +7,7 @@ module.exports = function(init) {
|
|||
util = require('../util'),
|
||||
fs = require('fs'),
|
||||
crypto = require('crypto'),
|
||||
mapquest = require('mapquest'),
|
||||
express = require('express');
|
||||
|
||||
function md5(data) {
|
||||
|
@ -48,6 +49,7 @@ module.exports = function(init) {
|
|||
var allowed = util.sans(SAFE_FIELDS, ['id', 'featured', 'picture']).concat('organizer');
|
||||
|
||||
Event.create(event, allowed).success(picture_handler(picture, function (event) {
|
||||
geocode_filler(event);
|
||||
res.reply(201, 'Event created', { event: event_output_filter(event) },
|
||||
{ location: event.uri() });
|
||||
})).error(function(err) {
|
||||
|
@ -83,6 +85,7 @@ module.exports = function(init) {
|
|||
allowed.push('featured');
|
||||
|
||||
event.updateAttributes(changes, allowed).success(picture_handler(picture, function (event) {
|
||||
geocode_filler(event);
|
||||
res.reply(200, 'Event modified', { event: event_output_filter(event) })
|
||||
})).error(function(err) {
|
||||
res.reply(400, 'Invalid Event changes', { error: err });
|
||||
|
@ -136,6 +139,18 @@ module.exports = function(init) {
|
|||
}
|
||||
};
|
||||
|
||||
function geocode_filler(event) {
|
||||
mapquest.reverse({
|
||||
latitude: event.latitude,
|
||||
longitude: event.longitude
|
||||
}, function(err, loc) {
|
||||
event.updateAttributes({
|
||||
city: loc.adminArea5,
|
||||
country: loc.adminArea1
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function picture_handler(picture, cb) {
|
||||
return function(event) {
|
||||
if (picture)
|
||||
|
|
|
@ -61,8 +61,9 @@ function ($, google, forms) {
|
|||
var place = autocomplete.getPlace();
|
||||
var loc = { latitude: place.geometry.location.lat(),
|
||||
longitude: place.geometry.location.lng() };
|
||||
for (var k in loc)
|
||||
Object.keys(loc).forEach(function(k) {
|
||||
$editForm.find('input[name="'+k+'"]').val(loc[k]);
|
||||
});
|
||||
});
|
||||
|
||||
navigator.idSSO.app.onlogin = function(assert) {
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
<input id="event_address" name="address" type="text" {{ tabIndex() }} />
|
||||
</span>
|
||||
|
||||
<input name="latitude" type="hidden" />
|
||||
<input name="latitude" type="hidden" />
|
||||
<input name="longitude" type="hidden" />
|
||||
|
||||
<label for="event_registerLink"> Event Link </label>
|
||||
|
|
Загрузка…
Ссылка в новой задаче