Skip to content

Commit

Permalink
Enable game_slots start/finish modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszlusiak committed Nov 24, 2009
1 parent 93e7675 commit 65d153c
Show file tree
Hide file tree
Showing 33 changed files with 1,463 additions and 38 deletions.
26 changes: 26 additions & 0 deletions app/controllers/game_slots_controller.rb
@@ -1,2 +1,28 @@
class GameSlotsController < ApplicationController

def inline_edit
game_slot = GameSlot.find params[:id]
respond_to do |format|
format.js do
render :update do |page|
page.replace_html "game-slot-#{game_slot.id}",
render_game_slot(game_slot, true, false)
end
end
end
end

def update
game_slot = GameSlot.find params[:id]
game_slot.update_attributes params[:game_slot]
respond_to do |format|
format.js do
render :update do |page|
page.replace_html "game-slot-#{game_slot.id}",
render_game_slot(game_slot, false, true)
end
end
end
end

end
4 changes: 2 additions & 2 deletions app/controllers/tournaments_controller.rb
Expand Up @@ -277,7 +277,7 @@ def schedule_game
render :update do |page|
page.replace_html 'game-slots', render(:partial => 'game_slots',
:object => game_slot.tournament.game_slots,
:locals => { :enable_drag_n_drop => true })
:locals => { :enable_drag_n_drop => true, :enable_edit => true })
page.replace_html 'games', render(:partial => 'games',
:object => game_slot.tournament.games.unscheduled,
:locals => { :enable_drag_n_drop => true })
Expand All @@ -296,7 +296,7 @@ def unschedule_game
render :update do |page|
page.replace_html 'game-slots', render(:partial => 'game_slots',
:object => game_slot.tournament.game_slots,
:locals => { :enable_drag_n_drop => true })
:locals => { :enable_drag_n_drop => true, :enable_edit => true })
page.replace_html 'games', render(:partial => 'games',
:object => game_slot.tournament.games.unscheduled,
:locals => { :enable_drag_n_drop => true })
Expand Down
38 changes: 38 additions & 0 deletions app/helpers/game_slots_helper.rb
@@ -1,2 +1,40 @@
module GameSlotsHelper

def render_game_slot(game_slot, edit = false, enable_edit = false)
result = ''
if enable_edit
result += '['
result += link_to_remote('edytuj', :url => inline_edit_game_slot_path(game_slot))
result += '] '
end
if edit
form_elements = ''
form = remote_form_for(game_slot) do |f|
form_elements += f.submit 'Zapisz'
form_elements += f.calendar_date_select(:start)
form_elements += f.calendar_date_select(:end)
end
result += form[0]
result += form_elements
result += form[1]
#result += calendar_date_select_tag("p_date_and_time", game_slot.start,
# :time => true)
#result += ' '
#result += calendar_date_select_tag("p_date_and_time", game_slot.end,
# :time => true)
else
result += game_slot.start.strftime("%Y-%m-%d")
result += ' '
result += game_slot.start.strftime("%H:%M")
result += game_slot.end.strftime("%H:%M")
end
result += ' '
if game_slot.game
result += "#{game_slot.game.home_team.name} - #{game_slot.game.away_team.name}"
else
result += " _ _ _ _ _ - _ _ _ _ _"
end
result
end

end
15 changes: 0 additions & 15 deletions app/helpers/tournaments_helper.rb
@@ -1,20 +1,5 @@
module TournamentsHelper

def render_game_slot(game_slot)
result = ''
result += game_slot.start.strftime("%Y-%m-%d")
result += ' '
result += game_slot.start.strftime("%H:%M")
result += ' '
result += game_slot.end.strftime("%H:%M")
if game_slot.game
result += "#{game_slot.game.home_team.name} - #{game_slot.game.away_team.name}"
else
result += " _ _ _ _ _ - _ _ _ _ _"
end
result
end

def render_game(game)
"#{game.home_team.name} - #{game.away_team.name}"
end
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -7,6 +7,7 @@
<title>Menedżer Turniejów Piłkarskich</title>
<%= javascript_include_tag :defaults %>
<%= stylesheet_link_tag('application') %>
<%= calendar_date_select_includes "silver", :locale => 'pl' %>
</head>
<body>
<div id="header">
Expand Down
17 changes: 0 additions & 17 deletions app/views/layouts/tournament/game_slots.html.erb

This file was deleted.

3 changes: 2 additions & 1 deletion app/views/tournaments/_game_slot.html.erb
@@ -1,6 +1,7 @@
<% enable_drag_n_drop = false unless defined? enable_drag_n_drop %>
<% enable_edit = false unless defined? enable_edit %>
<li id='game-slot-<%= game_slot.id %>' class='game-slot'>
<%= render_game_slot game_slot %>
<%= render_game_slot game_slot, false, enable_edit %>
</li>
<% if enable_drag_n_drop %>
<%= draggable_element("game-slot-#{game_slot.id}", :revert => true) %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/tournaments/_game_slots.html.erb
@@ -1,5 +1,7 @@
<% enable_drag_n_drop = false unless defined? enable_drag_n_drop %>
<% enable_edit = false unless defined? enable_edit %>
<ul>
<%= render :partial => 'game_slot', :collection => game_slots,
:locals => { :enable_drag_n_drop => enable_drag_n_drop } %>
:locals => { :enable_drag_n_drop => enable_drag_n_drop,
:enable_edit => enable_edit } %>
</ul>
2 changes: 1 addition & 1 deletion app/views/tournaments/schedule.html.erb
Expand Up @@ -15,7 +15,7 @@
<div class='row'>
<div id='game-slots'>
<%= render :partial => 'game_slots', :object => @tournament.game_slots,
:locals => { :enable_drag_n_drop => true } %>
:locals => { :enable_drag_n_drop => true, :enable_edit => true } %>
</div>
<div id='games'>
<%= render :partial => 'games', :object => @tournament.games.unscheduled,
Expand Down
3 changes: 3 additions & 0 deletions config/environment.rb
Expand Up @@ -19,6 +19,7 @@
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "calendar_date_select"

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
Expand All @@ -45,3 +46,5 @@
end

end

CalendarDateSelect.format = :iso_date
5 changes: 4 additions & 1 deletion config/routes.rb
Expand Up @@ -5,7 +5,10 @@
:play => :get
}

map.resources :game_slots
map.resources :game_slots,
:member => {
:inline_edit => :post
}

map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
Expand Down
2 changes: 2 additions & 0 deletions public/blank_iframe.html
@@ -0,0 +1,2 @@
<!-- Nothing here; part of the calendar_date_select plugin -->
<html><head></head><body></body></html>
Binary file added public/images/calendar_date_select/calendar.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 65d153c

Please sign in to comment.