# encoding: utf-8 # Methods added to this helper will be available to all templates in the application. module ApplicationHelper def ican?(*args) begin # if CanCan plugin installed can?(*args) rescue true end end def icannot?(*args) begin # if CanCan plugin installed cannot?(*args) rescue false end end def url(v) if v =~ /http:/ return "#{v}" else return v end end def show(objet,attribut) aslib= eval "#{objet.class.name}.human_attribute_name(attribut)" begin if attribut.split('.').size==2 return ("
  • "+objet.send( attribut.split('.').first).send( attribut.split('.').second).to_s+"
  • ").html_safe else return ("
  • "+url(objet.send(attribut).to_s)+"
  • ").html_safe end rescue return ("
  • ?
  • ").html_safe end end def model_name(model) begin eval("#{model}.model_name.human") rescue model.humanize end end def titre_action (action,model) txt=model_name(model) ("
    "+t("views.generic.#{action}", :model=>txt)+"
    ").html_safe end def titre_show(objet, lib) model=objet.class begin txt=eval("#{model}.model_name.human") rescue txt= model.model_name end ("

    #{txt} : #{lib} #{link_to_image_edit(objet)} #{link_to_image_delete(objet)}

    ").html_safe end def link_to_image_edit(objet) if can? :edit,objet.class link_to ' Edit'.html_safe, eval("edit_#{objet.class.to_s.underscore.gsub('/','_')}_path(objet)"), class: 'btn btn-default' end # can? :edit,objet.class end def link_to_image_add(objet) if ican? :create,objet.class # link_to image_add,eval("new_#{objet.class.to_s.underscore}_path(objet)"),:id=>'add' link_to ' Add'.html_safe, eval("new_#{objet.class.to_s.underscore.gsub('/','_')}_path(objet)"), class: 'btn btn-default' end end def link_to_image_delete(objet) if ican? :destroy, objet.class link_to(image_delete, objet, :confirm => 'Are you sure?', :method => :delete, :id=>'delete') end end # -------------------------------------------------------------------------------- # Création de la barre de titre à associé au tableau # -------------------------------------------------------------------------------- def titre(titre, model=nil, search=true, add=true, action='search',addlink=nil) s=form_tag('javascript:void(0)' ) # s="#{titre}" s="" if add==true if addlink==nil t="new_"+model.singularize.underscore.gsub('/','_') + "_path(:fournisseur_id=>params[:fournisseur_id], :rfq_id=>params[:rfq_id], :client_id=>params[:client_id])" else t=addlink end # s<'add') if ican?(:create, eval(model.camelcase)) s<<"
    " s< Add".html_safe, eval(t), class: 'btn btn-default') end if search # s<<" "+image_tag("aslon_scaffold/grid-split.gif", :border=>0, :style=>"vertical-align:middle") s<< text_field_tag( :search, nil, {:size=>20,:class=>'form-control',:placeholder=>"Search"}) s<<"" s<< image_tag("aslon_scaffold/indicator.gif", :style=>"vertical-align:middle", :border => 0, :id => "spiner",:style => "display:none;" ) end if search cond=":type=>'simle'" # s<< observe_field(:search, # :frequency=>1, # :update=>"ajaxw", # :before=>"Element.show('spiner')", # :success=>"Element.hide('spiner')", # :url=>{ :controller=>model.underscore.pluralize, # :action=>action, # :method => 'get', # :only_path=>false, # :type=>params[:type], # :status=>params[:status], # :fournisseur_id=>params[:fournisseur_id], # :rfq_id=>params[:rfq_id], # :client_id=>params[:client_id] # }, # :with=>"'search='+encodeURIComponent(value)") url= url_for(:action => 'search', :controller => model.underscore.pluralize) s<< "" end return s.html_safe end # -------------------------------------------------------------------------------- # Création d'un tableau # -------------------------------------------------------------------------------- def table(model, table, h, actions) sel='' sel='&type='+params[:type] if params[:type] sel+='&status='+params[:status] if params[:status] wp=will_paginate(table) # info_titre_tableau=page_entries_info(table) info_titre_tableau="" s=''.force_encoding('utf-8') # -------------------------------------------------------------------- s<<"" # -------------------------------------------------------------------- # intitulé des colonnes # -------------------------------------------------------------------- h.each do |value| img='aslon_scaffold/sort_desc.gif' sens='DESC' if params[:order]==value && params[:sens]=='DESC' sens='ASC' img='aslon_scaffold/sort_desc.gif' end if params[:order]==value && params[:sens]=='ASC' sens='DESC' img='aslon_scaffold/sort_asc.gif' end hlib=eval("#{model.gsub('_','/').camelize}.human_attribute_name(value)") # sorting doesn't work with search if request.env['QUERY_STRING'] != "method=get" && !value.include?('.') s<<"" else # s<< "" s<< "" end end s<<'' s<<'' # -------------------------------------------------------------------- # bas du tableau # -------------------------------------------------------------------- s<< " " s<<'' # -------------------------------------------------------------------- # lignes du tableau # -------------------------------------------------------------------- i=1 script="".force_encoding('utf-8') for aLine in table id='' c_id='' # ------------- création id de la ligne -------------------------- h.each do |lib| begin v=eval("aLine."+"#{lib}").to_s rescue v='nil' end id<" else s<<"" end i+=1 # ---------------------------------------------------------------- cp=0 h.each do |lib| local= I18n.locale begin v=url(eval("aLine."+"#{lib}").to_s) rescue v='nil' end s<<"" premiere_colonne=v t=model.singularize.downcase + "_url(aLine)" if cp==0 s<<("" end cp+=1 end s<<'' end s<<'' s<<"
    #{info_titre_tableau}
    " s<< hlib s<<" "+image_tag(img, :border=>0, :style=>"vertical-align:middle") if (img) s<<""+l(key)+""+hlib+"
    #{info_titre_tableau}   #{wp}
    " ) premiere_colonne= link_to(v, eval(t),:id=>'show') else s<<('") end s<< premiere_colonne lik= url_for( eval(t)) # script << "" # script << "" # script << "" script << "" if cp==0 s<<" " else s<<" 
    " s<" # script << "" # script << "" script << "" if cp==0 s<<" " else s<<" " end cp+=1 end s<<'' end s<<"" s<<'' s<