Sha256: 62eaef4dd011d5070e4a984a1f14722565f3422817d4221f424ff6a4b8e92055

Contents?: true

Size: 1.62 KB

Versions: 46

Compression:

Stored size: 1.62 KB

Contents

OAT  = Wco::OfficeActionTemplate
OATT = Wco::OfficeActionTemplateTie

class Wco::OfficeActionTemplatesController < Wco::ApplicationController

  before_action :set_lists

  def edit
    @oat = OAT.find params[:id]
    @oat.ties.push Wco::OfficeActionTemplateTie.new
    authorize! :edit, @oat
  end

  def index
    authorize! :index, OAT
    @oats = OAT.all
    @new_oat = OAT.new
    @new_oat.ties.push Wco::OfficeActionTemplateTie.new
  end

  def new
    @oat = OAT.new
    @oat.ties.push Wco::OfficeActionTemplateTie.new
    authorize! :new, @oat
  end

  def show
    @oat = OAT.find params[:id]
    authorize! :show, @oat
  end

  def update
    params[:oat][:ties_attributes].permit!
    if params[:id]
      @oat = OAT.find params[:id]
    else
      @oat = OAT.new
    end
    authorize! :upsert, @oat

    if params[:oat][:ties_attributes]
      params[:oat][:ties_attributes].each do |k, v|
        if !v[:next_office_action_template_id].present?
          params[:oat][:ties_attributes].delete( k )
        end
        if v[:to_delete] == "1"
          OATT.find( v[:id] ).delete
          params[:oat][:ties_attributes].delete( k )
        end
      end
    end

    if @oat.update params[:oat].permit!
      flash_notice @oat
    else
      flash_alert @oat
    end
    redirect_to action: :index
  end

  ##
  ## private
  ##
  private

  def set_lists
    @from_types_list = [ nil, 'Wco::Gallery', 'Wco::Tag' ]
    @from_type = params[:from_type]
    @from_ids_list = []
    if @from_type.present?
      @from_ids_list = @from_type.constantize.list
    end
    @publishers_list = Wco::Publisher.list

    @oats_list = OAT.list
  end


end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
wco_models-3.1.0.85 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.83 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.82 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.81 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.80 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.79 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.78 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.77 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.76 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.75 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.74 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.73 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.72 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.71 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.70 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.69 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.67 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.66 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.65 app/controllers/wco/office_action_templates_controller.rb
wco_models-3.1.0.64 app/controllers/wco/office_action_templates_controller.rb