class Test::ElevensController < ApplicationController
  before_action :set_test_eleven, only: [:show, :edit, :update, :destroy]
  respond_to :html, :js

  def index
    limit = 10
    page = params[:page] ? params[:page].to_i : 0

    @test_elevens = Test::Eleven.retrieve(page, limit)

    @next_link = url_for(Test::Eleven.params_to_retrieve(page, limit, 'next'))
    @prev_link = url_for(Test::Eleven.params_to_retrieve(page, limit, 'previous'))
    @reload_link = url_for(Test::Eleven.params_to_retrieve(page, limit, 'reload'))
    more_params = Test::Eleven.params_to_retrieve(page, limit, 'next')
    more_params[:show_more] = 't' 
    @more_link = url_for(more_params)

    #better way to reload or show more.
    respond_to do |format|
      format.html { render "test/elevens/html/index" }
      format.js { render "test/elevens/js/index" }
    end
  end

  def show
    respond_to do |format|
      format.html { render "test/elevens/html/show" }
      format.js { render "test/elevens/js/show" }
    end
  end

  def new
    @test_eleven = Test::Eleven.new
    respond_to do |format|
      format.html { render "test/elevens/html/new" }
      format.js { render "test/elevens/js/new" }
    end
  end

  def edit
    respond_to do |format|
      format.html { render "test/elevens/html/edit" }
      format.js { render "test/elevens/js/edit" }
    end
  end

  def create
    @test_eleven = Test::Eleven.new(test_eleven_params)
    @identifier = @test_eleven.identifier('new')
    @test_eleven.save
    respond_to do |format|
      format.html { render "test/elevens/html/create" }
      format.js { render "test/elevens/js/create" }
    end
  end

  def update
    @test_eleven.update(test_eleven_params)
    if request.format.html?
      redirect_to test_eleven_path(@test_eleven)
    else
      if test_eleven_params.size > 1
        render :update_full
      else
        @attribute = test_eleven_params.first[0].to_s
        render :update_attr
      end
    end
    respond_to do |format|
      format.html { render "test/elevens/html/update" }
      format.js { render "test/elevens/js/update" }
    end
  end

  def destroy
    @identifier = @test_eleven.identifier('id')
    @test_eleven.destroy
    respond_to do |format|
      format.html { }
      format.js { render "test/elevens/js/destroy" }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_test_eleven
      id = params[:id] ? params[:id] : params[:test_eleven_id]
      @test_eleven = Test::Eleven.find(id)
    end

    # Only allow a trusted parameter "white list" through.
    def test_eleven_params
      params.require(:test_eleven).permit(:name, :something, :else, :account_id, :status)
    end
end
