Module: Card::Set::All::NestEditor::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod023-edit/all/nest_editor.rb

Constant Summary collapse

NEST_OPTIONS =
%i[view title show hide wrap help variant size params].freeze

Instance Method Summary collapse

Instance Method Details

#apply_dataObject



64
65
66
67
68
69
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 64

def apply_data
  data = { "data-tinymce-id": tinymce_id }
  data["data-nest-start".to_sym] = params[:nest_start] if params[:nest_start].present?
  data["data-nest-size".to_sym] = edit_nest.raw.size if params[:edit_nest].present?
  data
end

#default_nest_editor_item_optionsObject



71
72
73
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 71

def default_nest_editor_item_options
  [[:view, default_item_view]]
end

#edit_nestObject



56
57
58
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 56

def edit_nest
  @edit_nest ||= NestParser.new params[:edit_nest], default_nest_view, default_item_view
end

#empty_nest_name_alert(show) ⇒ Object



43
44
45
46
47
48
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 43

def empty_nest_name_alert show
  alert :warning, false, false,
        class: "mb-0 _empty-nest-name-alert #{'d-none' unless show}" do
    "nest name required" # LOCALIZE
  end
end


50
51
52
53
54
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 50

def modal_nest_editor
  wrap_with :modal do
    haml :nest_editor, nest_editor_mode: "modal"
  end
end

#nest_editor_tabsObject



23
24
25
26
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 23

def nest_editor_tabs
  static_tabs({ rules: nest_rules_tab, options: haml_partial(:options) },
              :options, "tabs")
end

#nest_option_name_disabled(selected, level) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 94

def nest_option_name_disabled selected, level
  disabled = if level == 0
               edit_nest.options
             else
               edit_nest.item_options[level - 1] || default_nest_editor_item_options
             end

  disabled = disabled&.map(&:first)
  disabled&.delete selected if selected
  disabled
end

#nest_option_name_select(selected = nil, level = 0) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 75

def nest_option_name_select selected=nil, level=0
  classes = "form-control form-control-sm _nest-option-name"
  classes += " _new-row" unless selected
  select_tag "nest_option_name_#{unique_id}",
             nest_option_name_select_options(selected, level),
             class: classes, id: nil
  # id: nil ensures that select2 generates its own unique identifier
  # that ensures that we can clone this tag without breaking select2
end

#nest_option_name_select_options(selected, level) ⇒ Object



85
86
87
88
89
90
91
92
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 85

def nest_option_name_select_options selected, level
  options = selected ? [] : ["--"]
  options += NEST_OPTIONS
  options_for_select(
    options, disabled: nest_option_name_disabled(selected, level),
             selected: selected
  )
end

#nest_option_value_select(value = nil) ⇒ Object



106
107
108
109
110
111
112
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 106

def nest_option_value_select value=nil
  # select_tag "nest_option_value_#{unique_id}"
  text_field_tag "value", value,
                 class: "_nest-option-value form-control form-control-sm",
                 disabled: !value,
                 id: nil
end

#nest_rules_editorObject



35
36
37
38
39
40
41
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 35

def nest_rules_editor
  if edit_nest.name.blank?
     :div, "", class: "card-slot" # placeholder
  else
    nest([edit_nest.name, :right], view: :nest_rules)
  end
end

#nest_rules_tabObject



28
29
30
31
32
33
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 28

def nest_rules_tab
  [
    empty_nest_name_alert(edit_nest.name.blank?),
    nest_rules_editor
  ]
end

#tinymce_idObject



60
61
62
# File 'tmpsets/set/mod023-edit/all/nest_editor.rb', line 60

def tinymce_id
  params[:tinymce_id]
end