Sha256: a1465885f1d81e62c9750e3872035824528436c74620b8a6a84ed5b0b660979f

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

module Amalgam
  module Editor::EditorHelper

    def editable_content_tag tag,obj,field,options={},&block
      if can_edit?
        options[:data] = (options[:data] || {}).merge(:type => 'editable')
        options[:data][:mercury] = "full"
        options[:data][:id] = "#{obj.class.to_s.tableize}/#{obj.id.to_s}.#{field.to_s}"
      end
      value = fetch_field(obj,field)
      if value.present?
        content_tag(tag,value.to_s.html_safe,options)
      else
        content_tag(tag,options,&block) if block_given?
      end
    end

    def properties_button(model_or_url,title=nil)
      return unless can_edit?
      title ||= I18n.t('properties_edit')
      url = case url
             when String then "#{model_or_url}?mercury_frame=true"
             else "#{url_for(model_or_url)}?mercury_frame=true"
            end
      button_tag(title, :type=>'button', :data => {:url => url }, :class => 'properties', :style => "display:none")
    end

    private
    def fetch_field obj,field
      list = field.to_s.split(".")
      node_tmp = obj
      while list.present?
        node = list.shift
        return node_tmp[node] if !list.present? || node_tmp[node] == nil
        node_tmp = node_tmp[node]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
amalgam-2.1.4.1 app/helpers/amalgam/editor/editor_helper.rb
amalgam-2.1.4 app/helpers/amalgam/editor/editor_helper.rb
amalgam-2.1.3.1 app/helpers/amalgam/editor/editor_helper.rb
amalgam-2.1.3 app/helpers/amalgam/editor/editor_helper.rb
amalgam-2.1.2 app/helpers/amalgam/editor/editor_helper.rb
amalgam-2.1.1 app/helpers/amalgam/editor/editor_helper.rb