Module: Card::Set::All::EditName::HtmlFormat

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

Instance Method Summary collapse

Instance Method Details

#edit_name_buttonsObject



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

def edit_name_buttons
  button_formgroup do
    [rename_and_update_button, rename_button, standard_cancel_button]
  end
end

#edit_name_form(success_view = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 21

def edit_name_form success_view=nil
  card_form({ action: :update, id: card.id },
            # "main-success" => "REDIRECT",
            "data-update-origin": "true",
            success: edit_name_success(success_view)) do
    [hidden_edit_name_fields,
     _render_name_formgroup,
     rename_confirmation_alert,
     edit_name_buttons]
  end
end

#edit_name_success(view = nil) ⇒ Object



33
34
35
36
37
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 33

def edit_name_success view=nil
  success = { id: "_self" }
  success[:view] = view if view
  success
end

#format_rename_effects_and_options(effects, referer_option) ⇒ Object



73
74
75
76
77
78
79
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 73

def format_rename_effects_and_options effects, referer_option
  effects = effects.map { |effect| "<li>#{effect}</li>" }.join
  info = %(<h6>This change will...</h6>)
  info += %(<ul>#{effects}</ul>)
  info += %(<p>#{referer_option}</p>) if referer_option
  info
end

#hidden_edit_name_fieldsObject



39
40
41
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 39

def hidden_edit_name_fields
  hidden_tags old_name: card.name, card: { update_referers: false }
end

#rename_and_update_buttonObject



49
50
51
52
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 49

def rename_and_update_button
  submit_button text: "Rename and Update", disable_with: "Renaming",
                class: "renamer-updater"
end

#rename_buttonObject



54
55
56
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 54

def rename_button
  button_tag "Rename", data: { disable_with: "Renaming" }, class: "renamer"
end

#rename_confirmation_alertObject



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

def rename_confirmation_alert
  msg = "<h5>Are you sure you want to rename <em>#{safe_name}</em>?</h5>"
  msg << rename_effects_and_options
  alert("warning", false, false, class: "hidden-alert") { msg }
end

#rename_descendant_effectObject



81
82
83
84
85
86
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 81

def rename_descendant_effect
  descendants = card.descendants
  return unless descendants.any? # FIXME: count, don't instantiate

  "automatically alter #{descendants.size} related name(s)."
end

#rename_effects_and_optionsObject



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

def rename_effects_and_options
  descendant_effect = rename_descendant_effect
  referer_effect, referer_option = rename_referer_effect_and_option
  effects = [descendant_effect, referer_effect].compact
  return "" if effects.empty?

  format_rename_effects_and_options effects, referer_option
end

#rename_referer_effect_and_optionObject



88
89
90
91
92
93
94
95
96
97
98
# File 'tmpsets/set/mod023-edit/all/edit_name.rb', line 88

def rename_referer_effect_and_option
  referers = card.family_referers
  return unless referers.any? # FIXME: count, don't instantiate

  count = referers.size
  refs = count == 1 ? "reference" : "references"
  effect = "affect at least #{count} #{refs} to \"#{card.name}\""
  effect += hidden_field_tag(:referers, count)
  option = "You may choose to <em>update or ignore</em> the referers."
  [effect, option]
end