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

Extended by:
Card::Set::AbstractFormat
Defined in:
platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb

Instance Method Summary collapse

Instance Method Details

#cancel_create_pathObject

path to redirect to after canceling a new form



183
184
185
186
187
188
189
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 183

def cancel_create_path
  if main?
    path_to_previous
  else
    path view: (voo&.home_view || :unknown)
  end
end

#create_form(form_opts = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 50

def create_form form_opts={}
  with_create_context do
    card_form :create, form_opts do
      create_form_with_alert_guide
    end
  end
end

#create_form_with_alert_guideObject



78
79
80
81
82
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 78

def create_form_with_alert_guide
  wrap_with :div, class: "d-flex justify-content-between" do
    [_render_new_fields, (alert_guide if voo.show?(:guide))]
  end
end

#framed_create_form(form_opts = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 68

def framed_create_form form_opts={}
  form_opts.reverse_merge! success: new_success

  with_create_context do
    frame_and_form :create, form_opts do
      create_form_with_alert_guide
    end
  end
end

#needs_name?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 129

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

#new_form_optsObject



84
85
86
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 84

def new_form_opts
  { "data-main-success": JSON(redirect: true) }
end

#new_in_modal_successObject



104
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 104

def new_in_modal_success; end

#new_in_modal_titleObject



96
97
98
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 96

def new_in_modal_title
  new_name_prompt? ? new_view_title : render_title
end

#new_modal_menuObject



62
63
64
65
66
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 62

def new_modal_menu
  wrap_with_modal_menu do
    [render_close_modal_link, render_board_link]
  end
end

#new_modal_sizeObject



58
59
60
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 58

def new_modal_size
  :large
end

#new_name_formgroupObject



118
119
120
121
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 118

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

#new_name_prompt?Boolean

Returns:

  • (Boolean)


123
124
125
126
127
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 123

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

#new_successObject



100
101
102
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 100

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

#new_type_permitted?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 157

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

#new_type_preset?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 149

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

#new_type_prompt?Boolean

Returns:

  • (Boolean)


143
144
145
146
147
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 143

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)


153
154
155
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 153

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

#new_view_hiddenObject



106
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 106

def new_view_hidden; end

#new_view_nameObject

NAME HANDLING



110
111
112
113
114
115
116
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 110

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

LOCALIZE



89
90
91
92
93
94
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 89

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

#new_view_typeObject

TYPE HANDLING



135
136
137
138
139
140
141
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 135

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_button(args = {}) ⇒ Object



191
192
193
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 191

def standard_create_button args={}
  submit_button args.merge(class: "submit-button create-submit-button")
end

#view: newObject



11
12
13
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 11

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

#view: new_buttonsObject



169
170
171
172
173
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 169

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

#view: new_fieldsObject



30
31
32
33
34
35
36
37
38
39
40
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 30

view :new_fields, perms: :create, unknown: true, cache: :never do
  wrap true, class: "w-100" do
    [
      new_view_hidden,
      new_view_name,
      new_view_type,
      _render_content_formgroups,
      _render(voo.buttons_view || :new_buttons)
    ]
  end
end

#view: new_in_modalObject



15
16
17
18
19
20
21
22
23
24
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 15

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
  voo.buttons_view ||= :new_in_modal_buttons
  wrap do
    create_form "data-slot-selector": "modal-origin",
                "data-slot-error-selector": ".card-slot"
  end
end

#view: new_in_modal_buttonsObject



175
176
177
178
179
180
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 175

view :new_in_modal_buttons do
  class_up "button-form-group", "d-flex"
  button_formgroup do
    [standard_save_and_close_button(text: "Submit"), modal_cancel_button]
  end
end

#view: new_type_formgroupObject



161
162
163
164
165
166
167
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 161

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

#view: simple_newObject



26
27
28
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 26

view :simple_new, perms: :create, unknown: true, wrap: :slot, cache: :never do
  create_form
end

#with_create_contextObject



42
43
44
45
46
47
48
# File 'platypus/tmp/set/gem-defaults/mod011-edit/all/new.rb', line 42

def with_create_context
  with_nest_mode :edit do
    voo.title ||= new_view_title if new_name_prompt?
    voo.show :help
    yield
  end
end