Skip to content
Browse files

add wrapper functions for status messages; update stuff accordingly

  • Loading branch information...
1 parent c9a498c commit 04741718fd82205c40135f7ae829c0e158356dba straup committed Jan 2, 2012
Showing with 32 additions and 23 deletions.
  1. +23 −14 www/javascript/photo.geo.js
  2. +9 −9 www/javascript/photo.geo.min.js
View
37 www/javascript/photo.geo.js
@@ -111,7 +111,8 @@ function _photo_geo_context_update_onsubmit(){
});
$("#photo_geo_context").hide();
- $("#photo_geo_status").html("Poking the Flickr API...");
+
+ _photo_geo_status_show("Poking the Flickr API...");
return false;
}
@@ -138,12 +139,11 @@ function _photo_geo_set_context_onsuccess(rsp){
$("#geo_context").html(taken);
var msg = '<p>Success! The geo context for this photo has been updated and is now <strong>' + str_ctx + '</strong>.</p>';
- $("#photo_geo_status").html(msg);
+ _photo_geo_status_show(msg);
setTimeout(function(){
- $("#photo_geo_status").html("");
- $("#photo_geo_status").hide();
+ _photo_geo_status_hide();
$("#photo_geo_context").html(_photo_geo_context_generate_html);
$("#photo_geo_context").show();
@@ -177,12 +177,12 @@ function _photo_geo_corrections_for_placetype(placetype){
'success': _photo_geo_possible_corrections_onsuccess
});
- $("#photo_geo_status").html("Fetching alternate place names...");
+ _photo_geo_status_show("Fetching alternate place names...");
}
function _photo_geo_possible_corrections_onsuccess(rsp){
- $("#photo_geo_status").html("");
+ _photo_geo_status_hide();
if (rsp['stat'] != 'ok'){
$("#photo_geo_status").html("Ack!");
@@ -193,8 +193,6 @@ function _photo_geo_possible_corrections_onsuccess(rsp){
var current_options = $("#new_woeid option");
-console.log(rsp);
-
if (current_options.length){
// delete the last option
@@ -297,13 +295,15 @@ function _photo_geo_corrections_update_onsubmit(){
});
$("#photo_geo_corrections").hide();
- $("#photo_geo_status").html("Poking the Flickr API...");
+ _photo_geo_status_show("Poking the Flickr API...");
return false;
}
function _photo_geo_correct_location_onsuccess(rsp){
+ _photo_geo_status_hide();
+
if (rsp['stat'] != 'ok'){
_photo_geo_flickr_error(rsp);
return;
@@ -330,21 +330,30 @@ function _photo_geo_correct_location_onsuccess(rsp){
$("#geo_placename").html(placename);
$("#photo_geo_status").html("Okay! The place name for your photo has been updated. It is now " + new_placename);
+ $("#photo_geo_status").show();
setTimeout(function(){
- $("#photo_geo_status").html("");
- $("#photo_geo_status").hide();
+ _photo_geo_status_hide();
$("#photo_geo_corrections").html(_photo_geo_corrections_generate_html);
$("#photo_geo_corrections").show();
- $("#photo_geo_corrections_update").submit(_photo_geo_corrections_update_onsubmit);
-
+ $("#photo_geo_corrections_fetch").click(_photo_geo_corrections_fetch_onclick);
}, 2500);
}
function _photo_geo_flickr_error(rsp){
- $("#photo_geo_status").html("Ack! There was a problem calling the Flickr API.");
+ _photo_geo_status_show("Ack! There was a problem calling the Flickr API.");
return;
}
+
+function _photo_geo_status_show(msg){
+ $("#photo_geo_status").html(msg);
+ $("#photo_geo_status").show();
+}
+
+function _photo_geo_status_hide(){
+ $("#photo_geo_status").html("");
+ $("#photo_geo_status").hide();
+}
View
18 www/javascript/photo.geo.min.js
@@ -1,15 +1,15 @@
var photo_geo_ctx_map={0:"in a place that doesn't matter (not defined)",1:"indoors",2:"outdoors"};
function photo_geo_edit_meta(){var a='<div id="modal_geo">';a+='<div id="photo_geo_status"></div>';a+='<div id="photo_geo_context">';a+=_photo_geo_context_generate_html();a+="</div>";a+='<div id="photo_geo_corrections">';a+=_photo_geo_corrections_generate_html();a+="</div>";a+='<div id="photo_geo_close"><a href="#" onclick="$.modal.close(); return false;">close</a></div>';a+="</div>";$.modal(a);$("#photo_geo_context_update").submit(_photo_geo_context_update_onsubmit);$("#photo_geo_corrections_fetch").click(_photo_geo_corrections_fetch_onclick)}
function _photo_geo_context_generate_html(){var a=$("#edit_geo").attr("geo:context"),b="";b+="<h3>Edit the geo context for this photo</h3>";b+='<form id="photo_geo_context_update">';b+="This photo was taken ";b+='<select id="new_geocontext">';for(i in photo_geo_ctx_map){b+='<option value="'+i+'"';if(i==a)b+=' selected="true" disabled="true"';b+=">"+photo_geo_ctx_map[i]+"</option>"}b+="</select>";b+="&#160;";b+='<input type="submit" value="UPDATE" />';b+="</form>";return b}
-function _photo_geo_corrections_generate_html(){var a="",b=$("#geo_placename a").html();a+="<h3>Edit the place name for this photo</h3>";a+="<p>Flickr thinks this photo was taken in <q>";a+=b;a+='</q>. <a href="#" id="photo_geo_corrections_fetch">Fetch the list of alternate place names.</a>';a+="</p>";return a}
-function _photo_geo_context_update_onsubmit(){var a=$("#edit_geo").attr("geo:context"),b=$("#new_geocontext");b=b.val();if(b==a)alert("Hey! There's nothing to update!");else{$.ajax({url:"/api/",type:"POST",data:{method:"flickr.photos.geo.setContext",photo_id:photo_id,context:b},success:_photo_geo_set_context_onsuccess});$("#photo_geo_context").hide();$("#photo_geo_status").html("Poking the Flickr API...");return false}}
-function _photo_geo_set_context_onsuccess(a){if(a.stat!="ok")_photo_geo_flickr_error(a);else{$("#edit_geo").attr("geo:context",a.context);var b=photo_geo_ctx_map[a.context],d="";if(a.context!=0){a=$("#edit_geo").attr("geo:woeid");d='It was taken <a href="'+(places_url+a+"/"+b+"/")+'">'+b+"</a>"}$("#geo_context").html(d);b="<p>Success! The geo context for this photo has been updated and is now <strong>"+b+"</strong>.</p>";$("#photo_geo_status").html(b);setTimeout(function(){$("#photo_geo_status").html("");
-$("#photo_geo_status").hide();$("#photo_geo_context").html(_photo_geo_context_generate_html);$("#photo_geo_context").show();$("#photo_geo_context_update").submit(_photo_geo_context_update_onsubmit)},2500)}}function _photo_geo_corrections_fetch_onclick(){placetype="neighbourhood";$("#photo_geo_corrections_fetch").hide();return _photo_geo_corrections_for_placetype(placetype)}
-function _photo_geo_corrections_for_placetype(a){$.ajax({url:"/api/",type:"GET",data:{method:"flickr.photos.geo.possibleCorrections",photo_id:photo_id,place_type:a},success:_photo_geo_possible_corrections_onsuccess});$("#photo_geo_status").html("Fetching alternate place names...")}
-function _photo_geo_possible_corrections_onsuccess(a){$("#photo_geo_status").html("");if(a.stat!="ok")$("#photo_geo_status").html("Ack!");else{var b=$("#edit_geo").attr("geo:woeid"),d=$("#new_woeid option");console.log(a);if(d.length){$("#new_woeid option:last-child").remove();if(d=a.places.length){for(var c="<option />",e=0;e<d;e++){var f=a.places[e];c+='<option value="'+f.woeid+'"';c+=">"+f.name+"</option>"}if(a.parent_place_type)c+='<option value="-1" geo:placetype="'+a.parent_place_type+'">\u2013\u2013 fetch more place names \u2013\u2013</option>';
+function _photo_geo_corrections_generate_html(){var a="#geo_placename";if(places_is_enabled)a+=" a";a=$(a).html();var b="";b+="<h3>Edit the place name for this photo</h3>";b+="<p>Flickr thinks this photo was taken in <q>";b+=a;b+='</q>. <a href="#" id="photo_geo_corrections_fetch">Fetch the list of alternate place names.</a>';b+="</p>";return b}
+function _photo_geo_context_update_onsubmit(){var a=$("#edit_geo").attr("geo:context"),b=$("#new_geocontext");b=b.val();if(b==a)alert("Hey! There's nothing to update!");else{$.ajax({url:"/api/",type:"POST",data:{method:"flickr.photos.geo.setContext",photo_id:photo_id,context:b},success:_photo_geo_set_context_onsuccess});$("#photo_geo_context").hide();_photo_geo_status_show("Poking the Flickr API...");return false}}
+function _photo_geo_set_context_onsuccess(a){if(a.stat!="ok")_photo_geo_flickr_error(a);else{$("#edit_geo").attr("geo:context",a.context);var b=photo_geo_ctx_map[a.context],d="";if(a.context!=0){a=$("#edit_geo").attr("geo:woeid");d='It was taken <a href="'+(places_url+a+"/"+b+"/")+'">'+b+"</a>"}$("#geo_context").html(d);_photo_geo_status_show("<p>Success! The geo context for this photo has been updated and is now <strong>"+b+"</strong>.</p>");setTimeout(function(){_photo_geo_status_hide();$("#photo_geo_context").html(_photo_geo_context_generate_html);
+$("#photo_geo_context").show();$("#photo_geo_context_update").submit(_photo_geo_context_update_onsubmit)},2500)}}function _photo_geo_corrections_fetch_onclick(){placetype="neighbourhood";$("#photo_geo_corrections_fetch").hide();return _photo_geo_corrections_for_placetype(placetype)}
+function _photo_geo_corrections_for_placetype(a){$.ajax({url:"/api/",type:"GET",data:{method:"flickr.photos.geo.possibleCorrections",photo_id:photo_id,place_type:a},success:_photo_geo_possible_corrections_onsuccess});_photo_geo_status_show("Fetching alternate place names...")}
+function _photo_geo_possible_corrections_onsuccess(a){_photo_geo_status_hide();if(a.stat!="ok")$("#photo_geo_status").html("Ack!");else{var b=$("#edit_geo").attr("geo:woeid");if($("#new_woeid option").length){$("#new_woeid option:last-child").remove();var d=a.places.length;if(d){for(var c="<option />",e=0;e<d;e++){var f=a.places[e];c+='<option value="'+f.woeid+'"';c+=">"+f.name+"</option>"}if(a.parent_place_type)c+='<option value="-1" geo:placetype="'+a.parent_place_type+'">\u2013\u2013 fetch more place names \u2013\u2013</option>';
$("#new_woeid").append(c)}else alert("Hrm. There are no more places to choose from")}else{c='<form id="photo_geo_corrections_update">';c+="It was really taken in ";c+='<select id="new_woeid">';c+="<option />";d=a.places.length;for(e=0;e<d;e++){f=a.places[e];c+='<option value="'+f.woeid+'"';if(f.woeid==b)c+=' disabled="true"';c+=">"+f.name+"</option>"}if(a.parent_place_type)c+='<option value="-1" geo:placetype="'+a.parent_place_type+'">\u2013\u2013 fetch more place names \u2013\u2013</option>';c+=
"</select>";c+="&#160;&#160;";c+='<input type="submit" value="UPDATE" />';c+="</form>";$("#photo_geo_corrections").append(c);$("#photo_geo_corrections_update").submit(_photo_geo_corrections_update_onsubmit)}}}
-function _photo_geo_corrections_update_onsubmit(){var a=$("#new_woeid");a=a.val();if(a==""){alert("Hey! You didn't choose anything.");return false}if(a==-1){a=$("#new_woeid option:last-child").attr("geo:placetype");_photo_geo_corrections_for_placetype(a);return false}$.ajax({url:"/api/",type:"POST",data:{method:"flickr.photos.geo.correctLocation",photo_id:photo_id,woeid:a},success:_photo_geo_correct_location_onsuccess});$("#photo_geo_corrections").hide();$("#photo_geo_status").html("Poking the Flickr API...");
+function _photo_geo_corrections_update_onsubmit(){var a=$("#new_woeid");a=a.val();if(a==""){alert("Hey! You didn't choose anything.");return false}if(a==-1){a=$("#new_woeid option:last-child").attr("geo:placetype");_photo_geo_corrections_for_placetype(a);return false}$.ajax({url:"/api/",type:"POST",data:{method:"flickr.photos.geo.correctLocation",photo_id:photo_id,woeid:a},success:_photo_geo_correct_location_onsuccess});$("#photo_geo_corrections").hide();_photo_geo_status_show("Poking the Flickr API...");
return false}
-function _photo_geo_correct_location_onsuccess(a){if(a.stat!="ok")_photo_geo_flickr_error(a);else{var b=a.place.name;$("#edit_geo").attr("geo:woeid",a.woeid);a='<a href="">'+b+"</a>";$("#geo_placename").html(a);$("#photo_geo_status").html("Okay! The place name for your photo has been updated. It is now "+b);setTimeout(function(){$("#photo_geo_status").html("");$("#photo_geo_status").hide();$("#photo_geo_corrections").html(_photo_geo_corrections_generate_html);$("#photo_geo_corrections").show();$("#photo_geo_corrections_update").submit(_photo_geo_corrections_update_onsubmit)},
-2500)}}function _photo_geo_flickr_error(){$("#photo_geo_status").html("Ack! There was a problem calling the Flickr API.")};
+function _photo_geo_correct_location_onsuccess(a){_photo_geo_status_hide();if(a.stat!="ok")_photo_geo_flickr_error(a);else{var b=a.woeid,d=a.place.name;$("#edit_geo").attr("geo:woeid",a.woeid);placename=b==0?"a place with no name":places_is_enabled?'<a href="'+(places_url+b+"/")+'">'+d+"</a>":d;$("#geo_placename").html(placename);$("#photo_geo_status").html("Okay! The place name for your photo has been updated. It is now "+d);$("#photo_geo_status").show();setTimeout(function(){_photo_geo_status_hide();$("#photo_geo_corrections").html(_photo_geo_corrections_generate_html);
+$("#photo_geo_corrections").show();$("#photo_geo_corrections_fetch").click(_photo_geo_corrections_fetch_onclick)},2500)}}function _photo_geo_flickr_error(){_photo_geo_status_show("Ack! There was a problem calling the Flickr API.")}function _photo_geo_status_show(a){$("#photo_geo_status").html(a);$("#photo_geo_status").show()}function _photo_geo_status_hide(){$("#photo_geo_status").html("");$("#photo_geo_status").hide()};

0 comments on commit 0474171

Please sign in to comment.
Something went wrong with that request. Please try again.