class ApplicationController < ActionController::Base include Localization include UserSystem include ApplicationHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::PrototypeHelper include ActionView::Helpers::ScriptaculousHelper include UrlForFix layout :determine_layout helper :user before_filter :store_detour_from_params before_filter :authenticate_user before_filter :populate_layout def initialize @application_title = l :backlog @application_description = l :backlog_description end def self.in_place_edit_for(object, attribute, options = {}) define_method("set_#{object}_#{attribute}") do @item = object.to_s.camelize.constantize.find(params[:id]) @item.update_attribute(attribute, params[:value]) render :text => @item.send(attribute).to_s end end private def determine_layout if request.accepts.find {|mt| mt == 'xml'} 'wap' else # Firefox # # # # # # nokia N80 # # # # # # # # SonyEricson K810i # # # # # # # # # # 'mwrt002' end end def detour_to(options) store_detour(params) redirect_to(options) end def rjs_detour_to(options) store_detour(params, request.post?) rjs_redirect_to(options) end def rjs_redirect_to(options) @options = options render :template => 'redirect', :layout => false end def store_detour(options, post = false) options[:request_method] = :post if post if session[:detours] && session[:detours].last == options logger.debug "duplicate detour: #{options}" return end logger.debug "adding detour: #{options}" session[:detours] ||= [] session[:detours] << options end def store_detour_from_params if params[:detour] store_detour(params[:detour]) end if params[:return_from_detour] && session[:detours] pop_detour end end def back_or_redirect_to(options) if session[:detours] detour = pop_detour post = detour.delete(:request_method) == :post if post redirect_to_post(detour) else redirect_to detour end else redirect_to options end end def pop_detour detours = session[:detours] return nil unless detours detour = detours.pop logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more" if detours.empty? session[:detours] = nil end detour end private :pop_detour def populate_shortcuts @shortcuts = [ {:key => 'Alt-N', :function => :new_task, :options => {:controller => 'tasks', :action => 'new', :period_id => (@period ? @period.id : (@backlog && @backlog.periods.first ? @backlog.periods.first.id : nil))}}, {:key => 'Alt-Shift-N', :function => :new_period, :options => {:controller => 'periods', :action => 'new'}}, {:key => 'Alt-Ctrl-N', :function => :new_backlog, :options => {:controller => 'backlogs', :action => 'new'}}, {:key => 'Alt-Ctrl-G', :function => :new_group, :options => {:controller => 'groups', :action => :new}}, {:key => "Alt-#{l :up}", :function => :up}, {:key => "Alt-#{l :down}", :function => :down}, {:key => "Alt-Shift-#{l :left}", :function => :move_to_top}, {:key => "Alt-Shift-#{l :right}", :function => :move_to_bottom}, {:key => 'Alt-X', :function => :complete}, {:key => 'Alt-Q', :function => :reopen}, ] end def populate_layout return true if request.path_parameters[:action] =~ /_no_layout$/ populate_shortcuts # TODO (uwe): This does not scale! #periods = Period.find(:all).select {|period| period.active_or_future?(true) && period.party.includes?(user)} periods = Period.find_active_or_future(true) @sidebars = periods.sort_by {|p| p.required_speed}.reverse.map do |period| content = '
    ' period.tasks.select {|task| task.in_list? }[0...5].map do |task| "
  • #{task.description}
  • " end.each do |period_link| content << "#{period_link}" end content << "
\n" content << drop_receiving_element("sidebar_#{period.id}", :url => with_detour({:action => "move_task_to_period", :period_id => period.id, :layout => false}), :accept => "tasks", :loading => "", :complete => "", :hoverclass => 'highlight') { :id => period.id, :title => "#{period.party.name}##{period.position} (#{'%0.1f' % period.required_speed})", :options => {:controller => 'periods', :action => :show, :id => period}, :content => content } end started_tasks = Task.find_started if not started_tasks.empty? links = started_tasks.map do |task| "
  • 'tasks', :action => :list_started, :id => task.id}\">#{task.description}
  • " end @sidebars.unshift({ :title => l(:started_tasks), :options => {:controller => 'tasks', :action => :list_started}, :content => "
      #{links}" }) end end private def user_id session[:user_id] end def user User.find_by_id(user_id) if user_id end def redirect_to_post(options) url = url_for options render :text => < false
      EOF end end