Skip to content

Commit

Permalink
Improved user notif layout
Browse files Browse the repository at this point in the history
  • Loading branch information
okeen committed Sep 2, 2011
1 parent 2b11af1 commit 4a042b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
41 changes: 34 additions & 7 deletions app/models/notification_type.rb
Expand Up @@ -7,11 +7,11 @@ class NotificationType < ActiveRecord::Base
def self.create_all_notification_types
NotificationType.create(:name => "new_player")
NotificationType.create(:name => "new_team")
NotificationType.create(:name => "team_accepted")
NotificationType.create(:name => "team_confirmed")
NotificationType.create(:name => "new_game")
NotificationType.create(:name => "game_accepted")
NotificationType.create(:name => "game__confirmed")
NotificationType.create(:name => "new_result")
NotificationType.create(:name => "result_accepted")
NotificationType.create(:name => "result_confirmed")
end
create_all_notification_types if self.all.blank?;

Expand All @@ -36,9 +36,9 @@ def NotificationType.NEW_TEAM
}
end

def NotificationType.TEAM_ACCEPTED
def NotificationType.TEAM_CONFIRMED
{
:notification_type_id => NotificationType.named("team_accepted").first.id,
:notification_type_id => NotificationType.named("team_confirmed").first.id,
:params => {
:title => "Team Joined",
:message => "You have joined a new team"
Expand All @@ -50,10 +50,37 @@ def NotificationType.NEW_GAME
{
:notification_type_id => NotificationType.named("new_game").first.id,
:params => {
:title => "Team Joined",
:message => "You have joined a new team"
:title => "Game Request",
:message => "You have received a game offer"
}
}
end

def NotificationType.GAME_CONFIRMED
{
:notification_type_id => NotificationType.named("game_confirmed").first.id,
:params => {
:title => "Game confirmed",
:message => "You have a new confirmed game"
}
}
end
def NotificationType.NEW_RESULT
{
:notification_type_id => NotificationType.named("new_result").first.id,
:params => {
:title => "Result confirmation request",
:message => "You have received a request to confirm the result"
}
}
end
def NotificationType.RESULT_CONFIRMED
{
:notification_type_id => NotificationType.named("result_confirmed").first.id,
:params => {
:title => "Result confirmed",
:message => ""
}
}
end
end
3 changes: 3 additions & 0 deletions app/models/result.rb
Expand Up @@ -33,6 +33,9 @@ def winner
def on_confirm
game.update_attribute :winner_team_id, winner.id
Stat.update_all_for_game(game)
notification= NotificationType.RESULT_CONFIRMED
notification[:params][:name] = self.name
notifications.create notification
end

def as_json(options={})
Expand Down
6 changes: 3 additions & 3 deletions public/javascripts/session.js
Expand Up @@ -23,15 +23,15 @@ $(function() {
$.when( $.ajax("/notifications.json")).then(function(data, status){
$("#notifications_button").addClass("with_notifications");
this.set({"notifications": data});
var urgentNotifications = _(data).find(function(notif){
var urgentNotifications = _(data).select(function(notif){
return notif.params.urgent == true;
});
for (var i=0; i<urgentNotifications.length; i++)
$.gritter.add({
title: data[i].params.title,
title: urgentNotifications[i].params.title,
class_name: "under_panel_notifications",
sticky: true,
text: data[i].params.message
text: urgentNotifications[i].params.message
});

}.bind(this));
Expand Down

0 comments on commit 4a042b7

Please sign in to comment.