# -*- encoding : utf-8 -*-
class Portlet::ArticleindexsContentsController < ApplicationController
  layout "admin"

  def new
    @articleindexs_content = ArticleindexsContent.new()

    respond_to do |format|
      format.html {
        if request.xhr?
          render :layout => false
        end
      }
      format.js { render :template => "portlet/shared/new" }
    end
  end

  def create
    @articleindexs_content = ArticleindexsContent.new(params.require(:articleindexs_content).permit!)

    respond_to do |format|
      if @articleindexs_content.save
        
        
        @portlet = Portlet.create(:content => @articleindexs_content)
        
        
        
        
        format.html { redirect_to([:admin, @portlet.block.blockable], :notice => 'Elément ajouté avec succès.') }
        format.js { render :template => "portlet/shared/create" }
      else
        format.html { render :action => "new" }
        format.js { render :template => "portlet/shared/new" }
      end
    end
  end

  def edit
    @articleindexs_content = ArticleindexsContent.find(params[:id])
    @portlet = Portlet.find(params[:portlet_id])
    respond_to do |format|
      format.html {
        if request.xhr?
          render :template => "portlet/shared/edit", :layout => false
        end
      }
      format.js { render :template => "portlet/shared/edit" }
    end
  end
  
  



  def show


  end

  def update
    @articleindexs_content = ArticleindexsContent.find(params[:id])
    @portlet = @articleindexs_content.portlet
    
    respond_to do |format|
          if @articleindexs_content.update_attributes(params.require(:articleindexs_content).permit!)
        if @portlet.block and @portlet.block.blockable
          @portlet.block.blockable.updated_at = Time.now
          @portlet.block.blockable.save
          if @portlet.block.blockable_type == "Page"

            #to_my_log("[Page_"+@portlet.block.blockable.id.to_s+"] "+"Modification de la page "+@portlet.block.blockable.title.to_s+" (modification d'un portlet)")
          end
        end
    
            format.html { redirect_to([:admin, @portlet.block.blockable], :notice => 'Titre mis à jour.') }
        format.js { render :template => "portlet/shared/update" }
          else
            format.html { render :action => "portlet/shared/edit" } 
        format.js { render :template => "portlet/shared/edit" }
          end

    end
  end

  def destroy
    @portlet = Portlet.find(params[:portlet_id])
    @articleindexs_content = ArticleindexsContent.find(params[:id])
    @articleindexs_content.destroy
    
  
    
    respond_to do |format|
      format.html {}
      format.js { render :template => "portlet/shared/destroy" }
    end
  end

 
end
