-qi_ordered_table_name = qi_ordered_table_collection.klass.to_s.tableize

-qi_ordered_table_model = qi_ordered_table_collection.klass



=render :partial => "qi/qi_ordered_table_head", :locals => {:qi_ordered_table_name => qi_ordered_table_name, :qi_ordered_table_model => qi_ordered_table_model}


-@qi_table_orders = @qi_table_orders || {}

-if current_admin

  -if ap = current_admin.admin_preferences.where(:key => "sort_table_"+qi_ordered_table_name).first
    -qi_ordered_table_personalised = ap.value

  
  -if ap = current_admin.admin_preferences.where(:key => "sort_table_"+qi_ordered_table_name+"_nbr_col").first
    -qi_ordered_table_nbr_col = ap.value
  -else
    -qi_ordered_table_nbr_col = 1

  

-else
  -qi_ordered_table_personalised = session[:qi_sort_string][qi_ordered_table_name]

  -qi_ordered_table_nbr_col = session[:qi_sort_string][qi_ordered_table_name+"_nbr_col"] || 1






%span.qi_ordered_table_column{:onclick => "$(this).next('.qi_ordered_table_sort_select_wrapper').toggle();"}
  =ic :columns
  
  
.qi_ordered_table_sort_select_wrapper{:style => "display:none;"}
  =form_tag request.url, :method => "get",  :onsubmit => "", :remote => false do
    
   
    =hidden_field_tag "qi_sort_string[class]",qi_ordered_table_name 
  
    =hidden_field_tag "qi_sort_string[list]", "", :class => "qi_sort_string"
    .qi_ordered_table_sort_select
      
      -my_keys = []
      -@qi_table_orders[qi_ordered_table_name.to_sym].each do |key, value|
        .qi_order_item{:"data-ref" => "#{key}", :class => "active", :onclick => "$(this).toggleClass('active');"}
          -if value.instance_of? Hash
            =value[:name]
          -else
            =value
          -my_keys << key
      
    
      -qi_ordered_table_collection.klass.qi_table_order.each do |key, value|
        -if !my_keys.include?(key)
          .qi_order_item{:"data-ref" => "#{key}", :onclick => "$(this).toggleClass('active');"}
            -if value.instance_of? Hash
              =value[:name]
            -else
              =value
    %hr{:style => "margin:3px 0;"}
    -if false
      Colonnes fixes :
      =select_tag "qi_sort_string[nbr_colonnes]", options_for_select([0,1,2,3], qi_ordered_table_nbr_col)
    
    
    =link_to "Mettre à jour", "#", :class => "btn btn-primary update_table_order_link"
      

:scss
  .qi_ordered_table_column{
    position:absolute;
    color:rgba(0,0,0,0.2);
    font-size:1.2em;
    padding-top:3px;
    padding-left:10px;
    cursor:pointer;
    
    &:hover{
      color:rgba(0,0,0,0.6);
    }
    
  }

  .qi_ordered_table_sort_select_wrapper{
    background:rgba(white, 0.98);
    box-shadow:0 0 10px rgba(0,0,0,0.2);
    width:auto;
    position:absolute;
    margin-left:15px;
    margin-top:25px;
    z-index:5;
    padding:5px 10px;
    .qi_order_item{
      padding:2px 0;
      cursor:pointer;
      
    }
    .active{
      font-weight:bold;
    }
  }
  
:coffeescript
  $(".update_table_order_link").click ->
    r = []
    $(this).closest('.qi_ordered_table_sort_select_wrapper').find(".qi_order_item").each ->
      if $(this).hasClass("active")
        r.push $(this).data("ref")
    
    
    $(this).closest("form").find(".qi_sort_string").val(r.join(','))
    $.ajax
      type: "GET",
      url: "/",
      data: $(this).closest("form").serialize(),
      success: ->
        location.reload()
        
    
    
    
    
    

  $( ".qi_ordered_table_sort_select" ).sortable
    axis: "y"
    




.qi_pannel.padding.new_table_container
  
  .table-area
    .table-area-inner
  
  
      .freezeTable
        %table.table.table-striped.table-hover.table-bordered.data_table
          %thead.header
            %tr
              -@qi_table_orders[qi_ordered_table_name.to_sym].each do |key, value|
                -if value.instance_of? Hash
                  -if value[:reorder]
                    -sort_name = value[:sort_name] ? value[:sort_name] : key
                  
                    %th=raw sort_link sort_name.to_s, value[:name]
                  -else
                    %th=raw value[:name]
                    
                -else
                  %th=raw value
            
            
              =#sort_link "code", "Code"
              
              
              -if false
                %th
  

          %tbody{:id => "#{qi_ordered_table_name}_rows"}
            =render qi_ordered_table_collection
      
      
    .qi_pagination
      = paginate qi_ordered_table_collection #, :remote => true

:javascript
  resize();
  $('.freezeTable').freezeTable({columnNum:#{qi_ordered_table_nbr_col},fixedNavbar:'#qi_header_wrapper'});
  