Module: Card::Set::All::New::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod012-card-mod-edit/all/new.rb,
card/tmpsets/set/mod011-card-mod-edit/all/new.rb

Instance Method Summary collapse

Instance Method Details

#cancel_button_new_argsObject

path to redirect to after canceling a new form



181
182
183
184
185
186
187
188
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 181

def cancel_button_new_args
  href = case
         when main?          then path_to_previous
         when voo&.home_view then path(view: voo.home_view)
         else                     path(view: :unknown)
         end
  { href: href }
end

#create_formObject



28
29
30
31
32
33
34
35
36
37
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 28

def create_form
  form_opts = new_in_modal_form_opts.reverse_merge(success: new_in_modal_success)
  buttons = form_opts.delete(:buttons) || _render_new_buttons

  voo.title ||= new_view_title if new_name_prompt?
  voo.show :help
  card_form(:create, form_opts) do
    create_form_with_alert_guide buttons
  end
end

#create_form_with_alert_guide(buttons) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 62

def create_form_with_alert_guide buttons
  wrap_with :div, class: "d-flex justify-content-between" do
    [(wrap_with(:div, class: "w-100") do
      [
        new_view_hidden,
        new_view_name,
        new_view_type,
        _render_content_formgroups,
        buttons
      ]
    end),
     (alert_guide if voo.show?(:guide))]
  end
end

#needs_name?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 126

def needs_name?
  card.name.blank? && !autoname?
end

#new_form_optsObject



84
85
86
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 84

def new_form_opts
  { "main-success" => "REDIRECT" }
end

#new_in_modal_form_optsObject



79
80
81
82
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 79

def new_in_modal_form_opts
  { "data-slot-selector": "modal-origin", "data-slot-error-selector": ".card-slot",
    buttons: _render_new_in_modal_buttons }
end

#new_in_modal_successObject



103
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 103

def new_in_modal_success; end

#new_in_modal_titleObject



95
96
97
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 95

def new_in_modal_title
  new_name_prompt? ? new_view_title : render_title
end

#new_modal_menuObject



43
44
45
46
47
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 43

def new_modal_menu
  wrap_with_modal_menu do
    [close_modal_window, render_bridge_link]
  end
end

#new_modal_sizeObject



39
40
41
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 39

def new_modal_size
  :large
end

#new_name_formgroupObject



115
116
117
118
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 115

def new_name_formgroup
  output _render_name_formgroup,
         hidden_field_tag("name_prompt", true)
end

#new_name_prompt?Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 120

def new_name_prompt?
  voo.visible? :name_formgroup do
    needs_name? || params[:name_prompt]
  end
end

#new_successObject



99
100
101
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 99

def new_success
  card.rule(:thanks) || "_self"
end

#new_type_permitted?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 154

def new_type_permitted?
  Card.new(type_id: card.type_id).ok? :create
end

#new_type_preset?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 146

def new_type_preset?
  params[:type] || voo.type
end

#new_type_prompt?Boolean

Returns:

  • (Boolean)


140
141
142
143
144
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 140

def new_type_prompt?
  voo.visible? :new_type_formgroup do
    !new_type_preset? && new_type_prompt_context? && new_type_permitted?
  end
end

#new_type_prompt_context?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 150

def new_type_prompt_context?
  main? || card.simple? || card.is_template?
end

#new_view_frame_and_form(form_opts = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 49

def new_view_frame_and_form form_opts={}
  buttons = form_opts.delete(:buttons) || _render_new_buttons
  form_opts = form_opts.reverse_merge(success: new_success)

  with_nest_mode :edit do
    voo.title ||= new_view_title if new_name_prompt?
    voo.show :help
    frame_and_form :create, form_opts do
      create_form_with_alert_guide buttons
    end
  end
end

#new_view_hiddenObject



77
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 77

def new_view_hidden; end

#new_view_nameObject

NAME HANDLING



107
108
109
110
111
112
113
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 107

def new_view_name
  if new_name_prompt?
    new_name_formgroup
  elsif !autoname?
    hidden_field_tag "card[name]", card.name
  end
end

#new_view_titleObject



88
89
90
91
92
93
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 88

def new_view_title
  output(
    "New",
    (card.type_name unless card.type_id == Card.default_type_id)
  )
end

#new_view_typeObject

TYPE HANDLING



132
133
134
135
136
137
138
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 132

def new_view_type
  if new_type_prompt?
    _render_new_type_formgroup
  else
    hidden_field_tag "card[type_id]", card.type_id
  end
end

#standard_create_buttonObject



190
191
192
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 190

def standard_create_button
  submit_button class: "submit-button create-submit-button"
end

#view: newObject



11
12
13
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 11

view :new, perms: :create, unknown: true, cache: :never do
  new_view_frame_and_form new_form_opts
end

#view: new_buttonsObject



166
167
168
169
170
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 166

view :new_buttons do
  button_formgroup do
    [standard_create_button, standard_cancel_button(cancel_button_new_args)]
  end
end

#view: new_content_formObject



15
16
17
18
19
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 15

view :new_content_form, wrap: :slot, unknown: true, cache: :never do
  with_nest_mode :edit do
    create_form
  end
end

#view: new_in_modalObject



21
22
23
24
25
26
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 21

view :new_in_modal, perms: :create, unknown: true, cache: :never,
                    wrap: { modal: { footer: "", size: :edit_modal_size,
                                     title: :new_in_modal_title,
                                     menu: :new_modal_menu } } do
  _render_new_content_form
end

#view: new_in_modal_buttonsObject



172
173
174
175
176
177
178
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 172

view :new_in_modal_buttons do
  button_formgroup do
    wrap_with "div", class: "d-flex" do
      [standard_save_and_close_button(text: "Submit"), modal_cancel_button]
    end
  end
end

#view: new_type_formgroupObject



158
159
160
161
162
163
164
# File 'card/tmpsets/set/mod012-card-mod-edit/all/new.rb', line 158

view :new_type_formgroup do
  wrap_type_formgroup do
    type_field class: "type-field live-type-field",
               href: path(view: :new),
               "data-remote" => true
  end
end