Sha256: 56b2655bf45062662fa3204efd4a3f3fd8edc02882ddb1195c872543348db02f

Contents?: true

Size: 1.37 KB

Versions: 13

Compression:

Stored size: 1.37 KB

Contents

format :html do
  view :rule_form, cache: :never, unknown: true do
    @success_view ||= :open
    @rule_context ||= card
    @form_type ||= :overlay

    wrap do
      edit_rule_form @success_view do
        [
          hidden_tags(success: @edit_rule_success),
          haml(:rule_form)
        ].join
      end
    end
  end

  def form_type
    @form_type || :overlay
  end

  def current_rule_form success_view: :overlay_rule, form_type: :overlay
    current_rule_format = subformat current_rule
    current_rule_format.rule_form success_view, card, form_type
  end

  def rule_form success_view, rule_context, form_type=:overlay
    validate_form_type form_type

    @rule_context = rule_context
    @form_type = form_type
    @success_view = success_view

    render_rule_form
  end

  def validate_form_type form_type
    return if form_type.in? %i[overlay modal]

    raise "invalid rule_form type: #{form_type}; has to be overlay or modal"
  end

  def edit_rule_form success_view, &block
    @rule_context ||= card
    @edit_rule_success = edit_rule_success success_view
    action_args = { action: :update, no_mark: true }
    card_form action_args, rule_form_args, &block
  end

  def rule_form_args
    { class: "card-rule-form", "data-slotter-mode": "update-origin" }
  end

  def edit_rule_success view="overlay_rule"
    { mark: @rule_context.name.url_key, view: view }
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
card-mod-rules-0.14.2 set/rule/rule_form.rb
card-mod-rules-0.14.1 set/rule/rule_form.rb
card-mod-rules-0.14.0 set/rule/rule_form.rb
card-mod-rules-0.13.4 set/rule/rule_form.rb
card-mod-rules-0.13.3 set/rule/rule_form.rb
card-mod-rules-0.13.2 set/rule/rule_form.rb
card-mod-rules-0.13.1 set/rule/rule_form.rb
card-mod-rules-0.13.0 set/rule/rule_form.rb
card-mod-rules-0.11.7 set/rule/rule_form.rb
card-mod-rules-0.12.0 set/rule/rule_form.rb
card-mod-rules-0.11.6 set/rule/rule_form.rb
card-mod-rules-0.11.5 set/rule/rule_form.rb
card-mod-rules-0.11.4 set/rule/rule_form.rb