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("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 # #// # #
# # # #
# #
# # Browse #
#
# #
def thumbnail_upload_field(aOptions) ensure_css aOptions[:label] ||= "Upload Image" method = (aOptions.delete(:method) || :attachment) method_file = (method.to_s + '_file').to_sym _attachment = object.send(method) result = cms_file_field(method_file.to_sym, aOptions) + '
' underscore_id = object_name underscore_id += '_'+options[:index].to_s if options[:index] underscore_id += '_'+method_file.to_s 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_file.to_s,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("
") template.concat(content) template.concat("
") end def text_display_field(aField,aOptions={}) template.concat('
') if aOptions[:label] label aField, aOptions[:label] else label aField end template.concat("
#{object.send(aField.to_sym)}
") template.concat("
#{aOptions[:instructions]}
") if aOptions[:instructions] template.concat("
") # Fixes issue with bad line wrapping template.concat("
") end end