Cms::FormBuilder.class_eval do
attr_reader :template
# ensure the related css is included
def ensure_css
template.content_for :html_head do
template.stylesheet_link_tag("for_bcms_tools.css")
end
end
def remove_check_box()
"#{check_box('_destroy')} Remove ?"
end
def jquery_escape(aString)
# from http://samuelsjoberg.com/archive/2009/09/escape-jquery-selectors
# return str.replace(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/g, "\\$1");
aString.gsub(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/) {|c| '\\\\'+c}
end
# standard original file upload
#
#//
#
#
#
#
#
#
#
#
#
#
#
#
#
#
def thumbnail_upload_field(aOptions)
ensure_css
aOptions[:label] ||= "Upload Image"
result = cms_file_field(:attachment_file, aOptions) + ' '
method = 'attachment_file'
underscore_id = object_name+'_'+options[:index].to_s+'_'+method
underscore_id_esc = jquery_escape(underscore_id)
underscore_id_nobrac = underscore_id.gsub('[','_').gsub(']','')
template.content_for :html_head do
template.javascript_tag do
<<-EOS
jQuery(function($) {
$('input#mock_#{underscore_id_esc}') // "
else
''
end
result = result.sub('',''+thumbnail)
result = result.gsub(object_name+'_'+method,underscore_id)
result = StringUtils.split3(result,/
'+remove_check_box()+'
' + result unless aOptions[:remove_check_box]==false || object.new_record?
return result
end
# surround child fields with an appropriate div
# usage :
#<% f.child_fields do %>
# <% f.fields_for( :stock_images_attributes, img, :index => i ) do |image_form| %>
# <%= image_form.cms_text_field :name, :label => "name (short)" %>
# <%= image_form.cms_text_field :caption, :label => 'caption' %>
# <% end %>
#<% end %>
def child_fields(aClass='child_fields', &block)
content = template.capture(&block)
template.concat("