Last active
December 24, 2015 07:49
-
-
Save AndyObtiva/6766826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectPartsController < ApplicationController | |
before_filter :authenticate_user!, :authorize_project | |
STEPS = ['basic_info', 'detail', 'document_content', 'preview'] | |
def edit | |
if wizard_step_project.editable? | |
if step.present? | |
render step | |
else | |
render "#{Rails.root.to_s}/public/404.html", :layout => false, :status => 404 | |
end | |
else | |
redirect_to :back, :alert => I18n.t("project.#{@project.status}_editable_error") | |
end | |
end | |
def update | |
if wizard_step_project.update_attributes(params[:project]) | |
if next_step && params[:commit].downcase.include?('continue') | |
redirect_to edit_project_project_part_path(wizard_step_project, next_step) | |
else | |
redirect_to project_path(@project) | |
end | |
else | |
render step, :error => "Please complete all required fields" | |
end | |
end | |
private | |
def authorize_project | |
@project = wizard_step_project | |
if @project.user_id != current_user.id && !current_user.is_admin? | |
render(:file => "#{Rails.root.to_s}/public/403.html", :layout => false, :status => 403) | |
end | |
end | |
def wizard_step_project | |
project_class = "Project::#{step.camelcase}".constantize rescue Project | |
project_class.find(params[:project_id]) | |
end | |
def step | |
STEPS.find {|a_step| a_step == params[:id].to_s.downcase} | |
end | |
def next_step | |
current_step_index = STEPS.index(step) | |
next_step = STEPS[current_step_index+1] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment