Permalink
Browse files

added js method to update feed when available

  • Loading branch information...
1 parent 69380d6 commit 74e3d8969ed0817aaf01b6ebf9d14efa2873c356 @andrewxhill andrewxhill committed Jun 14, 2012
Showing with 27 additions and 1 deletion.
  1. +2 −1 app/assets/javascripts/application.js
  2. +25 −0 app/assets/javascripts/plugins.js
View
3 app/assets/javascripts/application.js
@@ -187,7 +187,8 @@ $(function(){
Filter.calcFiltersPosition();
}
}
-
+ updateFeed({countryCode: countryCode,n: 4});
+
if ($("div[data-load]").length > 0) {
addCircle("forest", "bars", { legendUnit: "m", countryCode: countryCode, width: 300, title: "Height", subtitle:"Tree height distribution", legend:"with {{n}} tall trees", hoverColor: "#427C8D", color: "#75ADB5", unit: "km<sup>2</sup>" });
addCircle("forma", "lines", { countryCode: countryCode, width: 300, title: "FORMA", subtitle:"Forest clearing alerts", legend:"In the last month", hoverColor: "#F2B357", color: "#F2B357" });
View
25 app/assets/javascripts/plugins.js
@@ -931,6 +931,31 @@ var Timeline = (function() {
})();
+function updateFeed(options) {
+ var
+ countryCode = options.countryCode || 'MYS',
+ n = options.n || 4;
+ var url = "https://wri-01.cartodb.com/api/v2/sql?q=SELECT%20to_char(gfw2_forma_datecode.date,%20'dd,%20FMMonth,%20yyyy')%20as%20date,alerts%20FROM%20gfw2_forma_graphs,gfw2_forma_datecode%20WHERE%20gfw2_forma_datecode.n%20=%20gfw2_forma_graphs.date%20AND%20iso%20=%20'"+countryCode+"'%20order%20by%20gfw2_forma_datecode.date%20desc%20LIMIT%20"+n;
+ $.ajax({
+ dataType: "jsonp",
+ jsonpCallback:'iwcallback',
+ url: url,
+ success: function(json) {
+ if (0<json.rows.length){
+ $('.alerts ul').html("");
+ }
+ for (var i=0; i<json.rows.length; i++){
+ $('.alerts ul').append(
+ $('<li></li>')
+ .append(
+ $('<span></span>').addClass('data').html(json.rows[i].date))
+ .append(
+ $('<span></span>').addClass('count').html(json.rows[i].alerts+' Alerts'))
+ );
+ }
+ }
+ });
+}
function addCircle(id, type, options) {
var

0 comments on commit 74e3d89

Please sign in to comment.