Sha256: ccef07f05abf322388a8428f8b9a8ecc9ca7fb0d591f446c5487beee2c98a3c8

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

#
# For now edit and update actions are for a plugin settings
#
class EasySettingsController < ApplicationController

  before_filter :require_admin, only: [:edit, :update]
  before_filter :find_optional_project
  before_filter :find_plugin, only: [:edit, :update]

  def new
  end

  def create
    if @easy_settings.save
      redirect_to :back
    else
      render :new
    end
  end

  def edit
    @settings = Setting.send("plugin_#{@plugin.id}")
    @easy_settings = EasySettings::FormModel.new(prefix: @plugin.id, project: @project)
  end

  def update
    if params[:settings]
      Setting.send("plugin_#{@plugin.id}=", params[:settings])
    end

    if params[:easy_setting]
      @easy_settings = EasySettings::ParamsWrapper.from_params(params[:easy_setting], project: @project, prefix: @plugin.id)

      if @easy_settings.save
        # All good
      else
        render :edit
        return
      end
    end

    flash[:notice] = l(:notice_successful_update)
    redirect_back_or_default edit_easy_setting_path(@plugin.id)
  end

  private

    def find_optional_project
      @project = Project.find_by(id: params[:project_id]) if params[:project_id].present?
    end

    def find_plugin
      @plugin = Redmine::Plugin.find(params[:id])
      return render_404 unless @plugin.settings.is_a?(Hash)
    rescue Redmine::PluginNotFound
      render_404
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redmine_extensions-0.2.0 app/controllers/easy_settings_controller.rb