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 :store_cookies_from_params before_filter :populate_layout def initialize @application_title = l :backlog @application_description = l :backlog_description @sidebar = Sidebar.new(self) 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 def render_to_string(*args) super 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 return false if session[:detours].nil? detour = pop_detour post = detour.delete(:request_method) == :post if post redirect_to_post(detour) else redirect_to detour end return true end def back_or_redirect_to(options) back or redirect_to options 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 def store_cookies_from_params if params[:cookies] params[:cookies].each_pair do |key, value| logger.info "Storing cookie #{key.inspect}=#{value.inspect}" #cookies[key] = {:value => value, :expires => 1.year.from_now} session[key] = value logger.info "Stored cookie #{key.inspect}=#{session[key].inspect}" end end end 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-Shift-D', :function => :daily_work_sheet, :options => {:controller => 'works', :action => :daily_work_sheet}}, {:key => 'Alt-Shift-W', :function => :weekly_work_sheet, :options => {:controller => 'works', :action => :weekly_work_sheet}}, ] end def populate_layout return true if request.path_parameters[:action] =~ /_no_layout$/ populate_shortcuts end 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