Sha256: 245b201503c7eea570f65abc6c8c91e05931be05f031d6801a3d62ac8568bab3

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

module Scrivito

class ClientConfig < Struct.new(:obj, :editing_context, :lookup_context)
  def to_json
    config = {}
    config[:editing_context] = editing_context_config
    config[:i18n] = i18n_config
    config[:obj] = obj_config
    config.to_json
  end

  private

  def editing_context_config
    {
      display_mode: editing_context.display_mode,

      selected_workspace: {
        id: editing_context.selected_workspace.id,
        title: editing_context.selected_workspace.title
      },

      visible_workspace: {
        id: editing_context.visible_workspace.id,
        title: editing_context.visible_workspace.title
      }
    }
  end

  def i18n_config
    {locale: I18n.locale}
  end

  def obj_config
    if obj
      {current_page: {
        id: obj.id,
        obj_class_name: obj.obj_class_name,
        has_children: obj.children.any?,
        has_conflict: obj.has_conflict?,
        has_details_view: obj_has_details_view?,
        modification: obj_modification,
      }}
    end
  end

  def obj_has_details_view?
    lookup_context.find(obj.details_view_path).present?
  rescue ActionView::MissingTemplate
    false
  end

  def obj_modification
    if editing_context.comparison.active?
      editing_context.comparison.modification(obj)
    else
      obj.modification
    end
  end
end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrivito_sdk-0.14.0 lib/scrivito/client_config.rb
scrivito_sdk-0.13.0 lib/scrivito/client_config.rb
scrivito_sdk-0.12.0 lib/scrivito/client_config.rb