Skip to content

Instantly share code, notes, and snippets.

@snize
Created June 5, 2013 02:11
Show Gist options
  • Save snize/5711162 to your computer and use it in GitHub Desktop.
Save snize/5711162 to your computer and use it in GitHub Desktop.
if (Meteor.isClient) {
Template.template_main.results = function () {
return Session.get("recentUsage") || [];
}
Template.template_sidebar.events = {
'change .radio': function () {
var plant = this.key;
Meteor.call('latestPowerUsage', plant);
}
}
Template.template_sidebar.plants = [
{"key": "hokkaido", "name": "北海道"},
{"key": "tohoku", "name": "東北"},
{"key": "tokyo", "name": "東京"},
{"key": "chubu", "name": "中部"},
{"key": "kansai", "name": "関西"},
{"key": "kyushu", "name": "九州"}
];
Meteor.startup(function () {
var plant = "tokyo";
$("input[value='" + plant + "']").attr('checked', 'checked');
Meteor.call('latestPowerUsage', plant);
});
Meteor.methods({
latestPowerUsage: function (plant) {
var url = 'http://setsuden.yahooapis.jp/v1/Setsuden/latestPowerUsage?'
+ [
'appid=hogehoge',
'output=json',
'area=' + plant,
'callback=?'
].join('&');
$.getJSON(url, function (data, status) {
Session.set("recentUsage", data.ElectricPowerUsage);
}
);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment