Handle multiple notification objects correctly

This commit is contained in:
Michael Sofaer 2011-06-08 13:17:39 -07:00 committed by Michael Sofaer & Raphael Sofaer
parent d6ba3c970c
commit 2c4a75f6a6
2 changed files with 16 additions and 4 deletions

View file

@ -13,3 +13,4 @@
= link_to("", "#", :class => "object") = link_to("", "#", :class => "object")
%br %br
%time

View file

@ -42,20 +42,31 @@
"success":function(data){ "success":function(data){
$("#notifications_overlay").show(); $("#notifications_overlay").show();
var hash = eval("(" + data + ")"); var hash = eval("(" + data + ")");
var notifications_element = $("#notifications_overlay .notifications");
var day_element_template = $("#notifications_overlay .day_group").clone();
day_element_template.find(".notifications_for_day").empty();
var stream_element_template = $("#notifications_overlay .stream_element").clone();
notifications_element.empty();
$.each(hash["group_days"], function(day){ $.each(hash["group_days"], function(day){
$("#notifications_overlay .month").text(day.split(" ")[0]) var day_element = day_element_template.clone();
$("#notifications_overlay .day").text(day.split(" ")[1]) day_element.find(".month").text(day.split(" ")[0])
day_element.find(".day").text(day.split(" ")[1])
var notifications_for_day = hash["group_days"][day] var notifications_for_day = hash["group_days"][day]
console.log(notifications_for_day); var notifications_for_day_element = day_element.find('.notifications_for_day');
$.each(notifications_for_day, function(i, notification_hash){ $.each(notifications_for_day, function(i, notification_hash){
$.each(notification_hash, function(notification_type, notification){ $.each(notification_hash, function(notification_type, notification){
var stream_element = stream_element_template.clone();
console.log(notification_type); console.log(notification_type);
console.log(notification); console.log(notification);
$("#notifications_overlay .actor"). stream_element.find(".actor").
text(notification["actors"][0]["name"]). text(notification["actors"][0]["name"]).
attr("href", notification["actors"][0]["url"]); attr("href", notification["actors"][0]["url"]);
console.log(notification["created_at"]);
stream_element.find('time').text(notification["created_at"]);
notifications_for_day_element.append(stream_element);
}); });
}); });
notifications_element.append(day_element);
}) })
} }
}); });