Rework geolocation status display so you can actually tell what it's doing and whether a location will be posted.

Goes in along with the file attachment info, below the notice box. Still needs to be generalized to work with multiple forms.
This commit is contained in:
Brion Vibber 2011-03-03 15:21:27 -08:00
parent 5a404ee713
commit 6f73b2870b
2 changed files with 83 additions and 27 deletions

View File

@ -375,29 +375,7 @@ var SN = { // StatusNet
.addClass(SN.C.S.Disabled) .addClass(SN.C.S.Disabled)
.attr(SN.C.S.Disabled, SN.C.S.Disabled); .attr(SN.C.S.Disabled, SN.C.S.Disabled);
SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val(); SN.U.normalizeGeoData(form);
SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val();
SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val();
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked');
cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
if (cookieValue !== null && cookieValue != 'disabled') {
cookieValue = JSON.parse(cookieValue);
SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat).val();
SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon).val();
if ($('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS)) {
SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS).val();
SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID).val();
}
}
if (cookieValue == 'disabled') {
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
}
else {
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
}
return true; return true;
}, },
@ -501,6 +479,35 @@ var SN = { // StatusNet
}); });
}, },
normalizeGeoData: function(form) {
SN.C.I.NoticeDataGeo.NLat = form.find('[name=lat]').val();
SN.C.I.NoticeDataGeo.NLon = form.find('[name=lon]').val();
SN.C.I.NoticeDataGeo.NLNS = form.find('[name=location_ns]').val();
SN.C.I.NoticeDataGeo.NLID = form.find('[name=location_id]').val();
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked'); // @fixme
var cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
if (cookieValue !== null && cookieValue != 'disabled') {
cookieValue = JSON.parse(cookieValue);
SN.C.I.NoticeDataGeo.NLat = form.find('[name=lat]').val(cookieValue.NLat).val();
SN.C.I.NoticeDataGeo.NLon = form.find('[name=lon]').val(cookieValue.NLon).val();
if (cookieValue.NLNS) {
SN.C.I.NoticeDataGeo.NLNS = form.find('[name=location_ns]').val(cookieValue.NLNS).val();
SN.C.I.NoticeDataGeo.NLID = form.find('[name=location_id]').val(cookieValue.NLID).val();
} else {
form.find('[name=location_ns]').val('');
form.find('[name=location_id]').val('');
}
}
if (cookieValue == 'disabled') {
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
}
else {
SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
}
},
/** /**
* Fetch an XML DOM from an XHR's response data. * Fetch an XML DOM from an XHR's response data.
* *
@ -1026,6 +1033,7 @@ var SN = { // StatusNet
* *
*/ */
NoticeLocationAttach: function() { NoticeLocationAttach: function() {
// @fixme this should not be tied to the main notice form, as there may be multiple notice forms...
var NLat = $('#'+SN.C.S.NoticeLat).val(); var NLat = $('#'+SN.C.S.NoticeLat).val();
var NLon = $('#'+SN.C.S.NoticeLon).val(); var NLon = $('#'+SN.C.S.NoticeLon).val();
var NLNS = $('#'+SN.C.S.NoticeLocationNs).val(); var NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
@ -1033,7 +1041,7 @@ var SN = { // StatusNet
var NLN = $('#'+SN.C.S.NoticeGeoName).text(); var NLN = $('#'+SN.C.S.NoticeGeoName).text();
var NDGe = $('#'+SN.C.S.NoticeDataGeo); var NDGe = $('#'+SN.C.S.NoticeDataGeo);
function removeNoticeDataGeo() { function removeNoticeDataGeo(error) {
$('label[for='+SN.C.S.NoticeDataGeo+']') $('label[for='+SN.C.S.NoticeDataGeo+']')
.attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text())) .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()))
.removeClass('checked'); .removeClass('checked');
@ -1045,9 +1053,17 @@ var SN = { // StatusNet
$('#'+SN.C.S.NoticeDataGeo).attr('checked', false); $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
$.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' }); $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
if (error) {
$('.geo_status_wrapper').removeClass('success').addClass('error');
$('.geo_status_wrapper .geo_status').text(error);
} else {
$('.geo_status_wrapper').remove();
}
} }
function getJSONgeocodeURL(geocodeURL, data) { function getJSONgeocodeURL(geocodeURL, data) {
SN.U.NoticeGeoStatus('Looking up place name...');
$.getJSON(geocodeURL, data, function(location) { $.getJSON(geocodeURL, data, function(location) {
var lns, lid; var lns, lid;
@ -1068,6 +1084,7 @@ var SN = { // StatusNet
NLN_text = location.name; NLN_text = location.name;
} }
SN.U.NoticeGeoStatus(NLN_text, data.lat, data.lon, location.url);
$('label[for='+SN.C.S.NoticeDataGeo+']') $('label[for='+SN.C.S.NoticeDataGeo+']')
.attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')'); .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')');
@ -1114,6 +1131,7 @@ var SN = { // StatusNet
if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') { if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
if (navigator.geolocation) { if (navigator.geolocation) {
SN.U.NoticeGeoStatus('Requesting location from browser...');
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
function(position) { function(position) {
$('#'+SN.C.S.NoticeLat).val(position.coords.latitude); $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
@ -1131,10 +1149,11 @@ var SN = { // StatusNet
function(error) { function(error) {
switch(error.code) { switch(error.code) {
case error.PERMISSION_DENIED: case error.PERMISSION_DENIED:
removeNoticeDataGeo(); removeNoticeDataGeo('Location permission denied.');
break; break;
case error.TIMEOUT: case error.TIMEOUT:
$('#'+SN.C.S.NoticeDataGeo).attr('checked', false); //$('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
removeNoticeDataGeo('Location lookup timeout.');
break; break;
} }
}, },
@ -1170,6 +1189,7 @@ var SN = { // StatusNet
$('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID); $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID);
$('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG); $('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG);
SN.U.NoticeGeoStatus(cookieValue.NLN, cookieValue.NLat, cookieValue.NLon, cookieValue.NLNU);
$('label[for='+SN.C.S.NoticeDataGeo+']') $('label[for='+SN.C.S.NoticeDataGeo+']')
.attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')') .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
.addClass('checked'); .addClass('checked');
@ -1182,6 +1202,42 @@ var SN = { // StatusNet
} }
}, },
/**
* Create or update a geolocation status widget in this notice posting form.
*
* @param {String} status
* @param {String} lat (optional)
* @param {String} lon (optional)
* @param {String} url (optional)
*/
NoticeGeoStatus: function(status, lat, lon, url)
{
var form = $('#form_notice');
var wrapper = form.find('.geo_status_wrapper');
if (wrapper.length == 0) {
wrapper = $('<div class="'+SN.C.S.Success+' geo_status_wrapper"><button class="close" style="float:right">&#215;</button><div class="geo_status"></div></div>');
wrapper.find('button.close').click(function() {
$('#'+SN.C.S.NoticeDataGeo).removeAttr('checked').change();
});
form.append(wrapper);
}
var label;
if (url) {
label = $('<a></a>').attr('href', url);
} else {
label = $('<span></span>');
}
label.text(status);
if (lat || lon) {
var latlon = lat + ';' + lon;
label.attr('title', latlon);
if (!status) {
label.text(latlon)
}
}
wrapper.find('.geo_status').empty().append(label);
},
/** /**
* Setup function -- DOES NOT trigger actions immediately. * Setup function -- DOES NOT trigger actions immediately.
* *

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long