# encoding: utf-8 module AdminHelper def sortable(url) %Q{ }.gsub(/[\n ]+/, ' ').strip.html_safe end def cropable(image_name, x,y,w,h) %Q{ }.gsub(/[\n ]+/, ' ').strip.html_safe end def sortable_columns(column, title = nil) title ||= column.titleize css_class = column == sort_column ? "current #{sort_direction}" : nil direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc" link_to title, {:sort => column, :direction => direction}, {:class => css_class} end def current_url(overwrite={}) url_for :only_path => false, :params => params.merge(overwrite) end def image_sortable(images) sort_url = "sort_admin_#{images.to_s}_path(:auth_token => current_user.authentication_token)" %Q{ }.gsub(/[\n ]+/, ' ').strip.html_safe end def upload_form(parent, image) new_image = image.new undercored_image = image.to_s.underscore form_for [:admin, parent, new_image], :id => "upload_form" do |f| f.file_field :image, multiple: true, name: "#{undercored_image}[image]" end end def upload_script html = '' html << "" return raw html end def uploader(parent, image) html = '' html << "#{upload_form(parent, image)}" html << "#{upload_script}" return raw html end def show_tree(items) html = "" html << "" items.where(:ancestry => nil).order(:position).each do |i| html << children(i) end html << "" return raw(html) end def children(i) html = "" html << "
  • " html <<"
    " html << expand_button(i) if i.has_attribute?("visible") html << visible_button(i) end html <<"#{link_to i.title, [:edit, :admin, i], :class=>'title'}" html << delete_button(i) html << "
    " unless i.children.empty? html << "
      " i.children.order('position').each do |child| html << children(child) end html << "
    " end html << "
  • " return html end def expand_button(i) link_to '', '#', :class=>"expand plus #{'non-display' if i.children.empty?}" end def visible_button(object) link_to [:toggleshow, :admin, object], :remote => true, :class=>"toggleshow" do raw("") end end def delete_button(object) link_to [:admin, object], :class => :del, :confirm => 'Точно удалить?', :method => :delete do raw(" Удалить ") raw(" ") end end def sort_tree(url, maxlevels) %Q{ }.gsub(/[\n ]+/, ' ').strip.html_safe end end