<commit_before>require 'factory_girl_rails'

class CallsController < ApplicationController

  def index
    @calls = Call.where(status: :open)
    respond_to do |format|
      format.html
      format.fragment { render "index", formats: ['html'], layout: false }
    end
  end

  def new
    organ = Organ.find params[:organ_id]
    @call  = organ.calls.build
    @form_path = calls_path
    @form_title = t "calls.new.title"
    respond_to do |format|
      format.fragment
    end
  end

  def create # create a new call for applications
    call_params = params[:call] || {}
    call = FactoryGirl.create :call, call_params.merge(organ: Organ.find(params[:organ_id]))

    respond_to do |format|
      format.json { render json: call.to_json }
      format.html { redirect_to action: :show, id: call._id }
    end
  end

  def show # return a single call for applications
    @call = Call.find(params[:id])
    respond_to do |format|
      format.html
      format.json { render :json => @call }
      format.fragment { render "show", formats: ['html'], layout: false }
      format.pdf { render pdf: @call.file_name, encoding: 'utf-8', layout: true }
    end
  end

  def edit # form for modifing an existing call
    @call = Call.find(params[:id])
    @form_path = call_path
    @form_title = t "calls.edit.title"
    respond_to do |format|
      format.fragment { render "new" }
    end
  end

  def update
    call = Call.find params[:id]

    updated_call = params[:call]
    if updated_call
      call.update_attributes!(updated_call)
    else
      call.set_selected! params[:selected_as], params[:deputy] || params[:member]
      call.organ.add_members_from_applications params[:selected_as]
      status = params[:status]
      unless status.nil?
        call.status = status.first.first.to_sym
      end
      call.save!
    end
    respond_to do |format|
      format.html { redirect_to call_path(id: call._id) }
      format.json { render :json => call }
    end
  end

  def destroy # delete an call
  end

end<commit_msg>Fix redirecting to organ if editing call from organ page<commit_after>require 'factory_girl_rails'

class CallsController < ApplicationController

  def index
    @calls = Call.where(status: :open)
    respond_to do |format|
      format.html
      format.fragment { render "index", formats: ['html'], layout: false }
    end
  end

  def new
    organ = Organ.find params[:organ_id]
    @call  = organ.calls.build
    @form_path = calls_path
    @form_title = t "calls.new.title"
    respond_to do |format|
      format.fragment
    end
  end

  def create # create a new call for applications
    call_params = params[:call] || {}
    call = FactoryGirl.create :call, call_params.merge(organ: Organ.find(params[:organ_id]))

    respond_to do |format|
      format.json { render json: call.to_json }
      format.html { redirect_to action: :show, id: call._id }
    end
  end

  def show # return a single call for applications
    @call = Call.find(params[:id])
    respond_to do |format|
      format.html
      format.json { render :json => @call }
      format.fragment { render "show", formats: ['html'], layout: false }
      format.pdf { render pdf: @call.file_name, encoding: 'utf-8', layout: true }
    end
  end

  def edit # form for modifing an existing call
    @call = Call.find(params[:id])
    @form_path = call_path
    @form_title = t "calls.edit.title"
    respond_to do |format|
      format.fragment { render "new" }
    end
  end

  def update
    call = Call.find params[:id]

    updated_call = params[:call]
    if updated_call
      call.update_attributes!(updated_call)
    else
      call.set_selected! params[:selected_as], params[:deputy] || params[:member]
      call.organ.add_members_from_applications params[:selected_as]
      status = params[:status]
      unless status.nil?
        call.status = status.first.first.to_sym
      end
      call.save!
    end
    respond_to do |format|
      format.html {
        if updated_call
          redirect_to call_path(id: call._id)
        else
          redirect_to organ_path(id: call.organ._id)
        end
      }
      format.json { render :json => call }
    end
  end

  def destroy # delete an call
  end

end
{'fraction_non_alphanumeric': 0.10361104555109747, 'fraction_numerical': 0.0004720320981826764, 'mean_word_length': 2.740511915269197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5918428', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1311, 'n_words': 365}