gluttonberg/lib/gluttonberg/helpers/admin.rb
def asset_browser(*args)
        bound = bound?(*args)
        if bound
          opts = args.length > 1 ? args.last : {}
          # do something clever to get the current obj, hence the fieldname
          rel = "#{current_form_context.instance_variable_get(:@name)}_#{args.first}"
          asset_id = current_form_context.send(:control_value, args.first)
        else
          opts = args.first
          rel = opts[:id]
          asset_id = opts[:value]
        end
        # Find the asset so we can get the name
        asset_name, indicator = unless asset_id.nil?
          asset = Gluttonberg::Asset.get(asset_id, :fields => [:name, :category])
          if asset
            [asset.name, asset.category]
          else
            ["Asset missing!", "missing"]
          end
        else
          ["Nothing selected", "default"]
        end
        # Output it all
        link_contents = "<strong class=\"#{indicator}\">#{asset_name}</strong>"
        link_contents << link_to("Browse", url(:gluttonberg_asset_browser), :class => "buttonGrey", :rel => rel)
        output = ""
        output << tag(:label, opts[:label]) if opts[:label]
        output << tag(:p, link_contents, :class => "assetBrowserLink")
        output << (bound ? hidden_field(args.first, opts) : hidden_field(opts))
        
      end
# Generates a link which launches the asset browser
# This method operates in bound or unbound mode.
#
# In bound mode method accepts two arguments, the first argument must be the models
# relationship field to accept the asset (as a symbol) as per merbs bound form controls.
# The second argument is the options hash.
#
# In unbound mode the method accepts one argument an options hash.
#
# The options hash accepts the following parameters:
#
#   The following are required in unbound mode, not used in bound mode:
#     :id = This is the id to use for the generated hidden field to store the selected assets id.
#     :value = The id of the currently selected asset. ode)
#
#   The following are optional in either mode:
#     < any option accepted by hidden_field() method >
#
# Example (unbound):
#   asset_browser(
#       :value => content.asset_id,
#       :id => "page_image_#{content.id}",
#       :name => "gluttonberg::page_localization[contents][#{content.association_name}][#{content.id}][asset_id]"
#   )
#
# Example (bound):
#   asset_browser(:thumbnail_id, :label => "Thumbnail")
#
Generates a link which launches the asset browser
This method operates in bound or unbound mode.

In bound mode method accepts two arguments, the first argument must be the models
relationship field to accept the asset (as a symbol) as per merbs bound form controls.
The second argument is the options hash.

In unbound mode the method accepts one argument an options hash.

The options hash accepts the following parameters.

The following are required in unbound mode, not used in bound mode:
:id = This is the id to use for the generated hidden field to store the selected assets id.
:value = The id of the currently selected asset. ode)

The following are optional in either mode:
< any option accepted by hidden_field() method >




Generates a link which launches the asset browser This method operates in bound or unbound mode . In bound mode method accepts two arguments the first argument must be the models relationship field to accept the asset ( as a symbol ) as per merbs bound form controls . The second argument is the options hash . In unbound mode the method accepts one argument an options hash . The options hash accepts the following parameters . The following are required in unbound mode not used in bound mode : : id = This is the id to use for the generated hidden field to store the selected assets id . : value = The id of the currently selected asset . ode ) The following are optional in either mode : < any option accepted by hidden_field () method >
def asset_browser(*args)
        bound = bound?(*args)
        if bound
          opts = args.length > 1 ? args.last : {}
          rel = "#{current_form_context.instance_variable_get(:@name)}_#{args.first}"
          asset_id = current_form_context.send(:control_value, args.first)
        else
          opts = args.first
          rel = opts[:id]
          asset_id = opts[:value]
        end
        asset_name, indicator = unless asset_id.nil?
          asset = Gluttonberg::Asset.get(asset_id, :fields => [:name, :category])
          if asset
            [asset.name, asset.category]
          else
            ["Asset missing!", "missing"]
          end
        else
          ["Nothing selected", "default"]
        end
        link_contents = "<strong class=\"#{indicator}\">#{asset_name}</strong>"
        link_contents << link_to("Browse", url(:gluttonberg_asset_browser), :class => "buttonGrey", :rel => rel)
        output = ""
        output << tag(:label, opts[:label]) if opts[:label]
        output << tag(:p, link_contents, :class => "assetBrowserLink")
        output << (bound ? hidden_field(args.first, opts) : hidden_field(opts))
      end
def asset_browser ( * args ) bound = bound? ( * args ) if bound opts = args . length > 1 ? args . last : { } rel = "#{current_form_context.instance_variable_get(:@name)}_#{args.first}" asset_id = current_form_context . send ( :control_value , args . first ) else opts = args . first rel = opts [ :id ] asset_id = opts [ :value ] end asset_name , indicator = unless asset_id . nil? asset = Gluttonberg :: Asset . get ( asset_id , :fields => [ :name , :category ] ) if asset [ asset . name , asset . category ] else [ "Asset missing!" , "missing" ] end else [ "Nothing selected" , "default" ] end link_contents = "<strong class=\"#{indicator}\">#{asset_name}</strong>" link_contents << link_to ( "Browse" , url ( :gluttonberg_asset_browser ) , :class => "buttonGrey" , :rel => rel ) output = "" output << tag ( :label , opts [ :label ] ) if opts [ :label ] output << tag ( :p , link_contents , :class => "assetBrowserLink" ) output << ( bound ? hidden_field ( args . first , opts ) : hidden_field ( opts ) ) end
Generates a link which launches the asset browser
This method operates in bound or unbound mode.
Generates a link which launches the asset browser This method operates in bound or unbound mode .
# do something clever to get the current obj, hence the fieldname # Find the asset so we can get the name # Output it all
args