Sha256: 1270611f110db85f4348790d8d3623848c815f82738100bf440cf13f11240f1e

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

class ::Admin::LocatorsController < ::Admin::BaseController
  authorize_resource

  before_filter :find_files, only: [:show, :edit, :update]
  before_filter :find_file, only: [:edit, :update]

  def edit
    @locale_hash = YAML.load_file(@file)
  end

  def update
    if Locator.save(@file, {params[:edit_locale_name] => params[:locale_hash]})
      flash[:notice] = I18n.t('flash.admin.locators.updated')
      redirect_to admin_locators_path
    else
      flash[:error] = I18n.t('flash.admin.locators.update_error')
      redirect_to edit_admin_locators_path(filename: params[:filename])
    end
  end

  def prepare
    result = Locator.instance.prepare_files
    if !result
      flash[:error] = 'Failed to prepare locale files'
    elsif result[:message]
      flash[:error] = result[:message]
    else
      flash[:notice] = I18n.t('flash.admin.locators.prepared')
    end
    redirect_to admin_locators_path
  end

  def reload
    I18n.reload!
    Locator.reload_checker.expire
    flash[:notice] = I18n.t('flash.admin.locators.restart')
    redirect_to admin_locators_path
  end

  protected

  def collection
    []
  end

  def settings
    {}
  end

  def action_items
    []
  end

  def find_files
    @files = Locator.find_files
  end

  def find_file
    @file = @files.detect{|path| File.basename(path) == params[:filename]}
    raise "File #{params[:filename]} not found" unless @file
  end

  def resource
    Locator.instance
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ab_admin-0.3.6 app/controllers/admin/locators_controller.rb
ab_admin-0.3.5 app/controllers/admin/locators_controller.rb
ab_admin-0.3.4 app/controllers/admin/locators_controller.rb
ab_admin-0.3.3 app/controllers/admin/locators_controller.rb
ab_admin-0.3.2 app/controllers/admin/locators_controller.rb
ab_admin-0.3.1 app/controllers/admin/locators_controller.rb
ab_admin-0.3.0 app/controllers/admin/locators_controller.rb