class AdminController < ApplicationController before_filter :login_required def index render :action => 'newgroup' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) end end def newgroup end def new_websites session[:project_cat] = "websites" session[:project_image_url] ||= {} if Parent.find_by_cat_name("websites").nil? then @category = Parent.new(:cat_name => 'websites') @category.save render :action => 'newgroup' else @category = Parent.find_by_cat_name("websites") render :action => 'list' end end def new_user_interface session[:project_cat] = "user_interface" session[:project_image_url] ||= {} if Parent.find_by_cat_name("user_interface").nil? then @category = Parent.new(:cat_name => 'user_interface') @category.save render :action => 'newgroup' else @category = Parent.find_by_cat_name("user_interface") render :action => 'list' end end def new_misc session[:project_cat] = "misc" session[:project_image_url] ||= {} if Parent.find_by_cat_name("misc").nil? then @category = Parent.new(:cat_name => 'misc') @category.save render :action => 'newgroup' else @category = Parent.find_by_cat_name("misc") render :action => 'list' end end def new_branding session[:project_cat] = "branding" session[:project_image_url] ||= {} if Parent.find_by_cat_name("branding").nil? then @category = Parent.new(:cat_name => 'branding') @category.save render :action => 'newgroup' else @category = Parent.find_by_cat_name("branding") render :action => 'list' end end def new_client_say session[:project_cat] = "client_say" if Parent.find_by_cat_name("client_say").nil? then @category = Parent.new(:cat_name => 'client_say') @category.save render :action => 'newgroup' else @category = Parent.find_by_cat_name("client_say") render :action => 'list' end end def show if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @project = @category.brandings.find(params[:id]) elsif @category.cat_name == "client_say" then @project = @category.client_says.find(params[:id]) else @project = @category.projects.find(params[:id]) end end end def add product_id = params[:id] session[:project_image_url] = product_id render :nothing => true end def new if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/branding/works") @img_folder = "branding" @category.brandings.new() elsif @category.cat_name == "client_say" then # @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/clients/works") # @img_folder = "clients" elsif @category.cat_name == "misc" then @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/misc/works") @img_folder = "misc" elsif @category.cat_name == "websites" then @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/web/works") @img_folder = "web" elsif @category.cat_name == "user_interface" then @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/interface/works") @img_folder = "interface" end end end def create if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then branding_c = @category.brandings.create(params[:project]) branding_c.image_url = "/images/"+branding_c.image_url elsif @category.cat_name == "client_say" then @category.client_says.create(params[:project]) else project_c = @category.projects.create(params[:project]) project_c.image_url = "/images/"+project_c.image_url end if @category.save if project_c.nil? == false then project_c.save elsif branding_c..nil? == false then branding_c.save end flash[:notice] = 'Project was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end end def edit if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @project = @category.brandings.find(params[:id]) @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/branding/works") @img_folder = "branding" elsif @category.cat_name == "client_say" then @project = @category.client_says.find(params[:id]) @all_files = "" @img_folder = "clients" elsif @category.cat_name == "misc" then @project = @category.projects.find(params[:id]) @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/misc/works") @img_folder = "misc" elsif @category.cat_name == "websites" then @project = @category.projects.find(params[:id]) @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/web/works") @img_folder = "web" elsif @category.cat_name == "user_interface" then @project = @category.projects.find(params[:id]) @all_files = Dir.entries("/home/saydigi/saydigitaldesign/public/images/interface/works") @img_folder = "interface" end end end def update if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @project = @category.brandings.find(params[:id]) elsif @category.cat_name == "client_say" then @project = @category.client_says.find(params[:id]) else @project = @category.projects.find(params[:id]) end if @project.update_attributes(@params[:project]) flash[:notice] = 'Project was successfully updated.' redirect_to :action => 'show', :id => @project, :cat_name => @category.id else render :action => 'edit', :cat_name => @category.id end end end def destroy if session[:project_cat].nil? then redirect_to :action => 'index' else @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @category.brandings.find(params[:id]).destroy elsif @category.cat_name == "client_say" then @category.client_says.find(params[:id]).destroy else @category.projects.find(params[:id]).destroy end redirect_to :action => 'list' end end def sort @category = Parent.find_by_cat_name(session[:project_cat]) if @category.cat_name == "branding" then @category.brandings.each do |project_item| project_item.position = params['listtable' ].index(project_item.id.to_s) + 1 project_item.save end elsif @category.cat_name == "client_say" then @category.client_says.each do |project_item| project_item.position = params['listtable' ].index(project_item.id.to_s) + 1 project_item.save end else @category.projects.each do |project_item| project_item.position = params['listtable' ].index(project_item.id.to_s) + 1 project_item.save end end @parent.projects.each do |project_item| project_item.position = params['listtable' ].index(project_item.id.to_s) + 1 project_item.save end render :nothing => true end end