Add city/country to event during creation/change.

This commit is contained in:
Hike Danakian 2013-07-22 19:57:50 -07:00
Родитель c50b360286
Коммит 24d0a7a644
3 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -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>