From 65d153cb0a8c63abcd405f0f55f16bde8acc7945 Mon Sep 17 00:00:00 2001 From: Mariusz Lusiak Date: Wed, 25 Nov 2009 00:40:48 +0100 Subject: [PATCH] Enable game_slots start/finish modifications --- app/controllers/game_slots_controller.rb | 26 + app/controllers/tournaments_controller.rb | 4 +- app/helpers/game_slots_helper.rb | 38 ++ app/helpers/tournaments_helper.rb | 15 - app/views/layouts/application.html.erb | 1 + .../layouts/tournament/game_slots.html.erb | 17 - app/views/tournaments/_game_slot.html.erb | 3 +- app/views/tournaments/_game_slots.html.erb | 4 +- app/views/tournaments/schedule.html.erb | 2 +- config/environment.rb | 3 + config/routes.rb | 5 +- public/blank_iframe.html | 2 + .../images/calendar_date_select/calendar.gif | Bin 0 -> 581 bytes .../calendar_date_select.js | 443 ++++++++++++++++++ .../calendar_date_select/format_american.js | 34 ++ .../calendar_date_select/format_db.js | 27 ++ .../calendar_date_select/format_euro_24hr.js | 7 + .../format_euro_24hr_ymd.js | 7 + .../calendar_date_select/format_finnish.js | 32 ++ .../format_hyphen_ampm.js | 37 ++ .../calendar_date_select/format_iso_date.js | 46 ++ .../calendar_date_select/format_italian.js | 24 + .../calendar_date_select/locale/de.js | 11 + .../calendar_date_select/locale/fi.js | 10 + .../calendar_date_select/locale/fr.js | 10 + .../calendar_date_select/locale/pl.js | 11 + .../calendar_date_select/locale/pt.js | 11 + .../calendar_date_select/locale/ru.js | 10 + .../stylesheets/calendar_date_select/blue.css | 130 +++++ .../calendar_date_select/default.css | 135 ++++++ .../calendar_date_select/plain.css | 128 +++++ .../stylesheets/calendar_date_select/red.css | 135 ++++++ .../calendar_date_select/silver.css | 133 ++++++ 33 files changed, 1463 insertions(+), 38 deletions(-) delete mode 100644 app/views/layouts/tournament/game_slots.html.erb create mode 100644 public/blank_iframe.html create mode 100644 public/images/calendar_date_select/calendar.gif create mode 100644 public/javascripts/calendar_date_select/calendar_date_select.js create mode 100644 public/javascripts/calendar_date_select/format_american.js create mode 100644 public/javascripts/calendar_date_select/format_db.js create mode 100644 public/javascripts/calendar_date_select/format_euro_24hr.js create mode 100644 public/javascripts/calendar_date_select/format_euro_24hr_ymd.js create mode 100644 public/javascripts/calendar_date_select/format_finnish.js create mode 100644 public/javascripts/calendar_date_select/format_hyphen_ampm.js create mode 100644 public/javascripts/calendar_date_select/format_iso_date.js create mode 100644 public/javascripts/calendar_date_select/format_italian.js create mode 100644 public/javascripts/calendar_date_select/locale/de.js create mode 100644 public/javascripts/calendar_date_select/locale/fi.js create mode 100644 public/javascripts/calendar_date_select/locale/fr.js create mode 100644 public/javascripts/calendar_date_select/locale/pl.js create mode 100644 public/javascripts/calendar_date_select/locale/pt.js create mode 100644 public/javascripts/calendar_date_select/locale/ru.js create mode 100644 public/stylesheets/calendar_date_select/blue.css create mode 100644 public/stylesheets/calendar_date_select/default.css create mode 100644 public/stylesheets/calendar_date_select/plain.css create mode 100644 public/stylesheets/calendar_date_select/red.css create mode 100644 public/stylesheets/calendar_date_select/silver.css diff --git a/app/controllers/game_slots_controller.rb b/app/controllers/game_slots_controller.rb index f3f2e50..a704777 100644 --- a/app/controllers/game_slots_controller.rb +++ b/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 diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 8df04fa..94a0789 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -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 }) @@ -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 }) diff --git a/app/helpers/game_slots_helper.rb b/app/helpers/game_slots_helper.rb index f9d978c..d4f2e0c 100644 --- a/app/helpers/game_slots_helper.rb +++ b/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 diff --git a/app/helpers/tournaments_helper.rb b/app/helpers/tournaments_helper.rb index 00ecbab..26581ee 100644 --- a/app/helpers/tournaments_helper.rb +++ b/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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b718e9b..cb392b4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,7 @@ Menedżer Turniejów Piłkarskich <%= javascript_include_tag :defaults %> <%= stylesheet_link_tag('application') %> + <%= calendar_date_select_includes "silver", :locale => 'pl' %>