# -*- encoding : utf-8 -*-
class Admin::PagesController < ApplicationController
   before_filter :auth_admin

  layout false
def edit
  @page = Page.find(params[:id])
  @admin = true
  
  end

  def update
  end
  
  def copy_lang
    @lang_from = LangSite.find(params[:lang_from])
    @lang_to = LangSite.find(params[:lang_to])
    
    
    @page = Page.find(params[:id])
    
    @bloc_from = @page.blocks.find_by_lang_site_id(@lang_from.id)
    @bloc_to = @page.blocks.find_by_lang_site_id(@lang_to.id)
    
    if @bloc_to.portlets.order(:position).last
      i = @bloc_to.portlets.order(:position).last.position.to_i
    else
      i = 0
    end
    @bloc_from.portlets.order(:position).each do |portlet|
      i = i + 1
      new_p = portlet.dup
      new_p.position = i
      new_p.save
      @bloc_to.portlets << new_p
    end
    
    redirect_to edit_admin_menu_item_path(:id => @page.menu_item, :lang => @lang_to.slug)
    
  end

end
