class PlansController

Public Instance Methods

answer() click to toggle source
# File app/controllers/plans_controller.rb, line 142
def answer
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.readable_by(current_user.id) then
                respond_to do |format|
                        format.json { render json: @plan.answer(params[:q_id], false).to_json(:include => :options) }
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
delete_recent_locks() click to toggle source
# File app/controllers/plans_controller.rb, line 74
def delete_recent_locks
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.editable_by(current_user.id) then
                respond_to do |format|
                        if @plan.delete_recent_locks(current_user.id)
                                format.html { render action: "edit" }
                                format.json { head :no_content }
                        else
                                format.html { render action: "edit" }
                                format.json { render json: @plan.errors, status: :unprocessable_entity }
                        end
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
edit() click to toggle source

GET /plans/1/edit

# File app/controllers/plans_controller.rb, line 6
    def edit
            @plan = Plan.find(params[:id])
    
   
if !user_signed_in? then
  respond_to do |format|
                            format.html { redirect_to edit_user_registration_path }
                    end
            elsif !@plan.readable_by(current_user.id) then
                    respond_to do |format|
                            format.html { redirect_to projects_url, notice: "This account does not have access to that plan." }
                    end
            end
    end
export() click to toggle source
# File app/controllers/plans_controller.rb, line 164
def export
        @plan = Plan.find(params[:id])

        if user_signed_in? && @plan.readable_by(current_user.id) then
                @exported_plan = ExportedPlan.new.tap do |ep|
                        ep.plan = @plan
                        ep.user = current_user
                        ep.format = request.format.try(:symbol)
                        plan_settings = @plan.settings(:export)

                        Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value|
                                ep.settings(:export).send("#{key}=", plan_settings.send(key))
                        end
                end

                @exported_plan.save! # FIXME: handle invalid request types without erroring?

                file_name = @exported_plan.project_name

                respond_to do |format|
        format.html
        format.xml
        format.json
        format.csv  { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" }
        format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" }
                        format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""}
        format.pdf do
            @formatting = @plan.settings(:export).formatting
            render pdf: file_name,
                                 margin: @formatting[:margin],
                                 footer: {
                                   center:    t('helpers.plan.export.pdf.generated_by'),
                                   font_size: 8,
                                   spacing:   (@formatting[:margin][:bottom] / 2) - 4,
                                   right:     '[page] of [topage]'
                                 }
                  end
                end
        elsif !user_signed_in? then
       respond_to do |format|
                        format.html { redirect_to edit_user_registration_path }
                end
        elsif !@plan.editable_by(current_user.id) then
                respond_to do |format|
                        format.html { redirect_to projects_url, notice: "This account does not have access to that plan." }
                end
        end
end
lock_section() click to toggle source
# File app/controllers/plans_controller.rb, line 108
def lock_section
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.editable_by(current_user.id) then
                respond_to do |format|
                        if @plan.lock_section(params[:section_id], current_user.id)
                                format.html { render action: "edit" }
                                format.json { head :no_content }
                        else
                                format.html { render action: "edit" }
                                format.json { render json: @plan.errors, status: :unprocessable_entity }
                        end
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
locked() click to toggle source
# File app/controllers/plans_controller.rb, line 63
def locked
        @plan = Plan.find(params[:id])
        if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then
                respond_to do |format|
                        format.json { render json: @plan.locked(params[:section_id],current_user.id) }
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
section_answers() click to toggle source
# File app/controllers/plans_controller.rb, line 52
def section_answers
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.readable_by(current_user.id) then
                respond_to do |format|
                        format.json { render json: @plan.section_answers(params[:section_id]) }
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
status() click to toggle source

GET /status/1.json

# File app/controllers/plans_controller.rb, line 41
def status
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.readable_by(current_user.id) then
                respond_to do |format|
                        format.json { render json: @plan.status }
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
unlock_all_sections() click to toggle source
# File app/controllers/plans_controller.rb, line 91
def unlock_all_sections
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.editable_by(current_user.id) then
                respond_to do |format|
                        if @plan.unlock_all_sections(current_user.id)
                                format.html { render action: "edit" }
                                format.json { head :no_content }
                        else
                                format.html { render action: "edit" }
                                format.json { render json: @plan.errors, status: :unprocessable_entity }
                        end
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
unlock_section() click to toggle source
# File app/controllers/plans_controller.rb, line 125
def unlock_section
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.editable_by(current_user.id) then
                respond_to do |format|
                        if @plan.unlock_section(params[:section_id], current_user.id)
                                format.html { render action: "edit" }
                                format.json { head :no_content }
                        else
                                format.html { render action: "edit" }
                                format.json { render json: @plan.errors, status: :unprocessable_entity }
                        end
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end
update() click to toggle source

PUT /plans/1 PUT /plans/1.json

# File app/controllers/plans_controller.rb, line 23
def update
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.editable_by(current_user.id) then
                respond_to do |format|
                if @plan.update_attributes(params[:plan])
                        format.html { redirect_to @plan, notice: 'Plan was successfully updated.' }
                        format.json { head :no_content }
                else
                        format.html { render action: "edit" }
                        format.json { render json: @plan.errors, status: :unprocessable_entity }
                end
        end
else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
warning() click to toggle source
# File app/controllers/plans_controller.rb, line 153
def warning
        @plan = Plan.find(params[:id])
        if user_signed_in? && @plan.readable_by(current_user.id) then
                respond_to do |format|
                        format.json { render json: @plan.warning(params[:option_id]) }
                end
        else
                render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
        end
end