Last active
August 29, 2015 14:03
-
-
Save cheesinglee/df4320f45686f53e0874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeStatusIndicator(loan_id){ | |
// this function executes the Kiva API query for a particular loan id, feeds the result through | |
// the actionable model, and returns a green light or red light icon depending on the result. | |
// create DOM object for icon | |
var img = $('<img class="indicator">') ; | |
// Kiva API call | |
var url = "http://api.kivaws.org/v1/loans/" + loan_id + ".json" ; | |
$.get(url,function(data){ | |
// pass response to actionable model | |
var data = data.loans[0] ; | |
var status = predictStatus(data.funded_amount,data.location.country,data.loan_amount,data.sector) ; | |
// create the indicator. use chrome.extension.getURL to resolve path to image resource | |
if (status == "paid"){ | |
img.attr("src",chrome.extension.getURL("images/green_light.png")) ; | |
}else{ | |
img.attr("src",chrome.extension.getURL("images/red_light.png")) ; | |
} | |
img.attr("title","The predicted status for this loan is: " + status.toUpperCase()) ; | |
}) | |
return img ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment