class Api::DropdownsController < ApiController
  
  def state_cities

    @state = State.find(params[:id])
    @cities = {}
    
    @state.cities.each do |c|
      @cities[c.id] = c.name
    end

    respond_to do |format|
      format.json { render json: @cities, callback: params[:callback] }
    end

  end
  
  def product_product_brand_product_presentations
    
    @product = Product.find(params[:product_id])
    @product_presentations = {}
    
    @product.product_presentations_by_product_brand(params[:id]).each do |product_presentation|
      @product_presentations[product_presentation.id] = product_presentation.name      
    end    
    
    respond_to do |format|
      format.json { render json: @product_presentations, callback: params[:callback] }
    end
  end
  
  def fetch_model_records

    return unless ['Page'].include?(params[:id])

    @records = {}
    params[:id].constantize.all.each do |record|
      @records[record.id] = record.name
    end    
    
    respond_to do |format|
      format.json { render json: @records, callback: params[:callback] }
    end
  end

  def information_standard_document_categories

    @document_categories = {}
    DocumentCategory.where(institution_id: params[:institution_id], information_standard_id: params[:id]).each do |document_category|
      @document_categories[document_category.id] = document_category.name
    end

    respond_to do |format|
      format.json { render json: @document_categories, callback: params[:callback] }
    end
  end
end