Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31)

Unified Diff: static/browser.js

Issue 738: Started adapting old Browser code to work with GAE backend and XmlHttpRequests instead of JSONP SVN Base: http://wto-informals.googlecode.com/svn/trunk/wto-informals/
Patch Set: Created 5 months, 1 week ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: static/browser.js
===================================================================
--- static/browser.js (revision 5)
+++ static/browser.js (working copy)
@@ -11,8 +11,6 @@
var WTO = {};
-WTO.ALL_MEMBERS = "WTO";
-WTO.BASE_URL = "http://wto-informals.org";
// http://kids.yahoo.com/reference/world-factbook/country/xx--World
// TODO(rae) P2 This should actually be from the same source as our population
// data
@@ -30,7 +28,15 @@
/* Each callback just saves the relevant data. */
function member_callback(members) { WTO.members = members; }
function meeting_callback(meetings) { WTO.meetings = meetings; }
-function group_callback(groups) { WTO.groups = groups; }
+WTO.receiveGroupDetails = function(xmlHttpRequest) {
+ var data = eval(xmlHttpRequest.responseText);
+ WTO.groups = {};
+ // Convert the list of groups to a map by groupname to group
+ for (var i = 0; i < data.length; i++) {
+ WTO.groups[data[i].name] = data[i];
+ }
+ WTO.drawGroups("name");
+}
/* Represents the perspective we've chosen.
@@ -52,7 +58,7 @@
GROUP_ORDERS = {
"members": function(group) {
- return $$.keys(group["members"]).length;
+ return $$.keys(group["members"]).length || 0;
},
"gdp": function(group) {
var pop = 0;
@@ -80,19 +86,19 @@
return trade;
},
"name": function(group) {
- return group["short"];
+ return group["name"];
}
// TODO(rae) P2 implement other ordering functions
// per-cap gdp, trade (need data)
};
function percent(denominator) {
- return function(pop, name) {
- pop = (pop / denominator) * 100;
- if (pop < 1 && pop > 0) {
+ return function(value, name) {
+ value = (value / denominator) * 100;
+ if (value < 1 && value > 0) {
return "[<1%] " + name;
} else {
- return "[" + Math.round(pop) + "%] " + name;
+ return "[" + Math.round(value) + "%] " + name;
}
}
}
@@ -124,9 +130,9 @@
// Cache whatever values we'll use to sort the list
var sortCache = {};
- for (var group in WTO.groups) {
+ for (var name in WTO.groups) {
//TODO(rae) P1 make the assumption about "short" existing more robust
- sortCache[group] = GROUP_ORDERS[order](WTO.groups[group]);
+ sortCache[name] = GROUP_ORDERS[order](WTO.groups[name]);
}
function cacheComparator(left, right) {
@@ -154,23 +160,23 @@
var tags = { "fake": true, "not real": true, "imaginary": true };
for (var i = 0; i < groups.length; i++) {
- var short_ = groups[i];
- var group = WTO.groups[short_];
- var official = group["official"];
+ var group = WTO.groups[groups[i]];
+ var formal = group["formal_name"];
+ var name = group["name"];
var optionE = $$.make("option");
- optionE.value = short_;
- optionE.name = official;
+ optionE.value = name;
+ optionE.name = name;
- var name = short_;
- if (official && official.length < 32) {
- name = official;
+ var display = name;
+ if (formal && formal.length < 32) {
+ display = formal;
}
if (GROUP_FORMATS[order]) {
- optionE.innerHTML = GROUP_FORMATS[order](sortCache[short_], name);
+ optionE.innerHTML = GROUP_FORMATS[order](sortCache[name], display);
} else {
- optionE.innerHTML = name;
+ optionE.innerHTML = display;
}
groupSelectE.appendChild(optionE);
@@ -182,6 +188,7 @@
}
WTO.tagList = $$.keys(tags).sort();
+ WTO.drawTagList();
};
@@ -836,19 +843,23 @@
function init() {
if (GBrowserIsCompatible()) {
WTO.initMap();
+ } else {
+ $$.get("map").innerHTML = "<b>Sorry, this site needs a browser that is supported by Google Maps.</b>";
}
+
+ HttpRequest("/GroupDetails", null, WTO.receiveGroupDetails);
+
WTO.loaded = true;
- WTO.drawGroups("members");
- WTO.drawTagList();
+ //WTO.drawTagList();
- $$.get("tagList").addEventListener("click", WTO.handleTagRemove, false);
+ //$$.get("tagList").addEventListener("click", WTO.handleTagRemove, false);
$$.get("groupOrder").addEventListener("click", WTO.handleGroupOrder, false);
- $$.get("groupList").addEventListener("change", WTO.handleGroupChange, false);
- $$.get("meetings").addEventListener("click", WTO.handleMeetingClick, false);
+ //$$.get("groupList").addEventListener("change", WTO.handleGroupChange, false);
+ //$$.get("meetings").addEventListener("click", WTO.handleMeetingClick, false);
// FIXME handle case where members aren't loaded yet (impossible?)
- WTO.populateGroup(WTO.ALL_MEMBERS);
+ //WTO.populateGroup(WTO.ALL_MEMBERS);
WTO.fixTableWidths();
//$$.get("groupTdiv").addEventListener('click', WTO.handleGroupClick, false);

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338