require 'localization' require 'user_system' class ApplicationController < ActionController::Base include Localization include UserSystem include ActionView::Helpers::TagHelper include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::PrototypeHelper include ActionView::Helpers::ScriptaculousHelper layout :determine_layout helper :user before_filter :store_detour_from_params before_filter :populate_layout before_filter :authenticate_user 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 store_detour(options) puts "adding detour: #{options}"; STDOUT.flush session[:detours] ||= [] session[:detours] << options end def store_detour_from_params if params[:return_controller] && params[:return_action] store_detour(:controller => params[:return_controller], :action => params[:return_action], :id => params[:return_id]) end if params[:return_from_detour] && session[:detours] pop_detour end end def back_or_redirect_to(options) if session[:detours] detour = pop_detour redirect_to detour else redirect_to options end end def pop_detour detour = session[:detours].pop puts "popped detour: #{detour} #{session[:detours].size} more"; STDOUT.flush if session[:detours].empty? session[:detours] = nil end detour end private :pop_detour def populate_shortcuts @application_title = l :backlog @application_description = l :backlog_description @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-#{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 @period = Period.find(:first, params[:id]) if params[:id] @owner = @period.party if @period populate_shortcuts # TODO (uwe): This does not scale! periods = Period.find(:all).select {|period| period.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}", :update => "spotlight", :url => { :controller => 'tasks', :action => "move_to_period", :period_id => period.id}, :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(user) if not started_tasks.empty? links = started_tasks.map do |task| "
  • 'periods', :action => :show, :id => task.period, :task_id => task.id}\">#{task.description}
  • " end @sidebars.unshift({ :title => l(:started_tasks), :options => {:controller => 'tasks', :action => :list_started}, :content => "
      #{links}" }) end end # def populate_layout # populate_shortcuts # @groups = Group.find(:all, :order => 'name') # @backlogs = Backlog.find(:all, :order => 'name') # @sidebars = @backlogs.map do |backlog| # content = '' # { :title => "#{backlog.name}", # :options => {:controller => 'backlogs', :action => :show, :id => backlog}, # :content => content # } # end # end private def user_id session[:user_id] end def user User.find(user_id) if user_id end end