<% root = Section.root.first root.full_path = root.name @sections = [] @sections << root @sections += root.all_children_with_name @sections.each {|s| s.full_path = "/" + s.full_path unless s == root } @block.attachment_file_path = @block.attachment.file_path if @block.attachment_file_path.blank? && !@block.new_record? %> <% content_for :html_head do %> <% javascript_tag do %> jQuery(function($) { <% if @block.new_record? %> var sectionIdPathMap = <%= @sections.inject({}){|map, sec| map[sec.id.to_s] = sec.path.sub(/\/$/,''); map}.to_json %> $('#file_block_attachment_file, #file_block_attachment_section_id').change(function(){ $('#file_block_attachment_file_path').val(sectionIdPathMap[$('#file_block_attachment_section_id').val()]+'/'+$.cms.sanitizeFileName($('#file_block_attachment_file').val())) }) <% end %> }); <% end %> <% end %> <%= f.cms_text_field :name %> <%= f.cms_file_field :attachment_file, :label => "File" %> <%= f.cms_drop_down :attachment_section_id, @sections.map{|s| [s.full_path, s.id]}, :label => "Section" %> <%= f.cms_text_field :attachment_file_path, :label => "Path" %> <%= f.cms_tag_list %>