Skip to content

Commit

Permalink
Profile edition bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
eprochasson committed Jul 19, 2013
1 parent 31e15e7 commit 904a6c3
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 24 deletions.
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Complete Lexicon...

Subscription process + email validation.
Check input security (not too long, invalid characters, injection...).
Fix Bug in Profile page.
Fix Bug in Profile page.

Find a way to factorize some client code.
6 changes: 5 additions & 1 deletion client/css/less/map.lessimport
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#googlemap{
height: 500px;
height: 400px;
width: 500px;
margin: 0 auto;
img {
max-width: none;
}
}

span#geocoding_target{
font-weight: bold;
}
9 changes: 7 additions & 2 deletions client/helpers/lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ Meteor.i18nMessages.question = {
dob: 'Date of Birth',
dob_help: 'Select your date of birth',
find_your_location: 'Let us determine your location',
pick_on_the_map: 'Pick your location on a map'

pick_on_the_map: 'Point your location on a map',
location_help: "We don't want to know your precise address! Just help you locate people near you",
gender: "Gender",
geocoding: "Your current location",
unknown: "Unknown :(",
male: "Male",
female: "Female"
};

Meteor.i18nMessages.messages = {
Expand Down
11 changes: 6 additions & 5 deletions client/views/includes/form/form_fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="controls">
<select id="{{domid}}" data-validate='{{validation}}' data-id="{{docid}}">
{{#each options}}
<option value="{{value}}">{{Lex text}}</option>
<option value="{{value}}">{{#if text}}{{Lex text}}{{/if}}</option>
{{/each}}
</select>
</div>
Expand All @@ -42,12 +42,13 @@
<a class="btn btn-success geolocalisation" href="#">{{Lex 'question.find_your_location'}}</a>
<a class="btn btn-info show_map" role="button" href="#map" data-toggle="modal">{{Lex 'question.pick_on_the_map'}}</a>

<input type="hidden" name="{{name}}" id="{{domid}}" value="{{value}}" />
<input type="hidden" name="{{name}}" id="{{domid}}" value="{{value}}" data-id="{{docid}}" />

<div id="map" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Pick your location on the map</h3>
<h3>Point your location on the map</h3>
<p>{{Lex help}}</p>
</div>
<div class="modal-body">
<div id="googlemap">{{> loading}}</div>
Expand All @@ -63,7 +64,7 @@ <h3>Pick your location on the map</h3>

<template name="form_geocoding">
<div class="control-group">
<input type="hidden" name="{{name}}" value="{{value}}" id="{{domid}}" />
Your current location:<span id="geocoding_target">{{#if value}}{{value}}{{else}}unknown :({{/if}}</span>
<input type="hidden" name="{{name}}" value="{{value}}" id="{{domid}}" data-id="{{docid}}" />
{{Lex label}}:<span id="geocoding_target">{{#if value}}{{value}}{{else}}{{Lex 'question.unknown'}}{{/if}}</span>
</div>
</template>
28 changes: 20 additions & 8 deletions client/views/includes/form/form_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Template.form_field_datepicker.helpers({
Template.form_field_text.helpers({
'value' : function(){ return getInputValue(this); }
});
Template.form_location.helpers({
'value' : function(){ return getInputValue(this); }
});
Template.form_geocoding.helpers({
'value' : function(){ return getInputValue(this); }
});

Template.form_field_dropdown.helpers({
'value' : function(){ return getInputValue(this); },
'options': function(){
Expand Down Expand Up @@ -76,8 +83,6 @@ Template.form_location.events({
var center = getInputValue(this);
var isPointing = false, marker, initPosition;



if(!center){
center = Meteor.GMap.defaultLocation;

Expand All @@ -95,11 +100,9 @@ Template.form_location.events({

function updateMarkerPosition(latlng){
if(isPointing){
console.log('updating marker position, poiting');
marker.setPosition(latlng);
updatePosition(latlng);
} else {
console.log('moving marker');
marker = new google.maps.Marker({
map:map,
draggable:true,
Expand All @@ -109,7 +112,6 @@ Template.form_location.events({
updatePosition(latlng);

google.maps.event.addListener(marker, 'dragend', function(){
console.log('updating marker position, draging');
updatePosition(marker.getPosition());
});
isPointing = true;
Expand Down Expand Up @@ -138,6 +140,7 @@ Template.form_location.events({
}
}

// Make sure to only initialize once, 1. once gmap is loaded 2. once the modal is fully shown.
window.gmapcallback = function(){
$('#map').on('shown',function(){
if(!window.maploaded){
Expand All @@ -147,10 +150,8 @@ Template.form_location.events({
})
};

// Load the gmap script, call previous function on success.
load_gmap('gmapcallback');



},
'click .save_change': function(e){
if($('.save_change').hasClass('disabled')){
Expand All @@ -160,6 +161,7 @@ Template.form_location.events({
$('#location').val(window.mapposition.jb+','+window.mapposition.kb);
$('#map').modal('hide');

// Get a humanly readable location
reverseGeodecode(window.mapposition, function(err, res){
if(err){
Errors.notification("Oops, we were unable to determine your location");
Expand All @@ -174,6 +176,16 @@ Template.form_location.events({
'click .geolocalisation': function(){
function success(location){
$('#location').val(location.latitude+";"+location.longitude);
// Get a humanly readable location
reverseGeodecode(window.mapposition, function(err, res){
if(err){
Errors.notification("Oops, we were unable to determine your location");
} else {
$('#geocoding_target').html(res);
$('#geocoding').val(res);
}
});

Errors.notification('Got it!', 'center');
}

Expand Down
12 changes: 8 additions & 4 deletions client/views/profile_creation/profile_creation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

<h5>Yo, blablabla</h5>

{{{makeQuestion 'name'}}}
{{{makeQuestion 'gender'}}}
<form id="profile_creation">
{{{makeQuestion 'name'}}}
{{{makeQuestion 'gender'}}}

{{{makeQuestion 'location'}}}
{{{makeQuestion 'geocoding'}}}
{{{makeQuestion 'location'}}}
{{{makeQuestion 'geocoding'}}}

<button class="btn btn-submit">{{Lex 'default.save'}}</button>
</form>

</template>
62 changes: 62 additions & 0 deletions client/views/profile_creation/profile_creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var validateControlGroup = function(input){
_.each($(input).find('input, select'), function(self){
Meteor.call('validate_input', $(self).val(), $(self).data('id'), $(self).data('validate'), function(err, res){
if(err){
$(input).addClass('error');
$(input).removeClass('success');
if($(input).find('.help-inline')){
$(input).find('.help-inline').html(__(err.reason));
}
ok = false;
} else {
$(input).removeClass('error');
$(input).addClass('success');
if($(input).find('.help-inline')){
$(input).find('.help-inline').html('Ok!');
}
}
});
});
};


Template.profile_creation.events = {
'submit form': function(e){
e.preventDefault();
var res = {};

// validate all input
_.each($('form .control-group'),function(input){
validateControlGroup(input);
});

var values = {};
var docid;
_.each($('form input, form select'), function(input){
docid = $(input).data('id');
if(docid){
values[docid] = $(input).val();
}
});

Meteor.call('update_profile', values);
},
'blur form input': function(e){
e.preventDefault();
var element = e.target;
var parent = $(element).parents(".control-group");

_.each($(parent), function(input){
validateControlGroup(input);
})
},
'change form select': function(e){
e.preventDefault();
var element = e.target;
var parent = $(element).parents(".control-group");

_.each($(parent), function(input){
validateControlGroup(input);
})
}
};
28 changes: 28 additions & 0 deletions server/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

if(Questions.find().count() == 0){
Questions.insert({
name: 'name',
Expand Down Expand Up @@ -45,6 +46,33 @@ if(Questions.find().count() == 0){
sortorder: 3,
required: true
});
Questions.insert({
"domid": "geocoding",
"label": "question.geocoding",
"name": "geocoding",
"required": false,
"sortorder": 3,
"tpl": "form_geocoding",
"validation": [

],
"value": null
});
Questions.insert({
"domid": "location",
"help": "question.location_help",
"label": "question.location",
"name": "location",
"required": true,
"sortorder": 3,
"tpl": "form_location",
"validation": [

],
"value": null
});


}
if(Meteor.users.find({}).count() <= 4){
// Meteor.users.insert({
Expand Down
7 changes: 4 additions & 3 deletions server/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ Meteor.methods({
if(typeof Meteor.FormsValidation[method] == 'function'){
if(!(Meteor.FormsValidation[method])(validation, val)){
valid = false;
} else {
// All good, let's input
cleaned[question.name] = val;
}
} else {
valid = false;
}
});
if(valid){
// All good, let's input
cleaned[question.name] = val;
}
}
} else {
valid = false;
Expand Down

0 comments on commit 904a6c3

Please sign in to comment.