module Ezframe::SubPageKit::Edit

Public Instance Methods

act_after_cancel() click to toggle source
# File lib/ezframe/sub_page_kit.rb, line 159
def act_after_cancel
  return public_detail_post
end
act_after_edit() click to toggle source
# File lib/ezframe/sub_page_kit.rb, line 154
def act_after_edit
  return [public_default_post, public_detail_post]
  # return { inject: edit_inject_element, body: Html.convert(make_index_line(@column_set.get_hash(:value))) }
end
area_for_create(extra_buttons = nil) click to toggle source
# File lib/ezframe/sub_page_kit.rb, line 113
def area_for_create(extra_buttons = nil)
  create_button = make_create_button
  create_button[:ezevent] = "on=click:url=#{make_base_url}/create"
  return Ht.div(id: "#{@class_snake}-create-area", child: [create_button, extra_buttons].compact)
end
edit_inject_element() click to toggle source
# File lib/ezframe/sub_page_kit.rb, line 150
def edit_inject_element
  return "#{@class_snake}_show"
end
make_edit_form(command = :edit) click to toggle source

編集フォームの生成

# File lib/ezframe/sub_page_kit.rb, line 120
def make_edit_form(command = :edit)
  @id ||= get_id
  if command == :edit && !@id
    EzLog.error "make_edit_form: @id is not defined"
  end
  target_keys = @edit_keys || @column_set.keys
  list = target_keys.map do |colkey|
    column = @column_set[colkey.to_sym]
    unless column
      EzLog.error("undefined column entry: #{colkey}")
      next
    end
    make_edit_line(column)
  end.compact
  event = "on=click:url=#{make_base_url(@id)}/#{command}:with=form"
  send_button = Ht.button(id: "#{@class_snake}-#{command}-finish-button", class: %w[btn], child: [Ht.icon("check"), Message[:edit_finish_button_label]], ezevent: event)
  cancel_button = make_cancel_button("on=click:url=#{make_base_url(@id)}/#{command}:cancel=true:with=form")
  list.push(Ht.p(class: %w[edit-finish-buttons], child: [send_button, cancel_button]))
  return make_form("#{make_base_url}/edit", list)
end
make_edit_line(column) click to toggle source
# File lib/ezframe/sub_page_kit.rb, line 141
def make_edit_line(column)
  form = column.form
  if form
    return Ht.p(class: %w[form-line], child: [Ht.small(column.label), form])
  else
    return nil
  end
end
public_create_post() click to toggle source

新規データ登録

# File lib/ezframe/sub_page_kit.rb, line 69
def public_create_post
  @form = @event[:form]
  # EzLog.debug("public_create_post: form=#{@form}")
  unless @form
    { inject: "##{@class_snake}-create-area", body: Html.convert(make_edit_form(:create)) }
  else
    # 値の保存
    @column_set.clear
    form_values = @form
    form_values.update(@env["url_params"])
    # @column_set.values = form_values
    @column_set[:id].value = @id = @column_set.create(form_values)
    # return { redirect: "#{make_base_url}/#{@id}" }
    return public_default_post
  end
end
public_edit_post() click to toggle source

データ編集受信

# File lib/ezframe/sub_page_kit.rb, line 87
def public_edit_post
  @id ||= get_id
  unless @event[:form]
    data = @column_set.set_from_db(@id)
    # データが空ならエラーページ
    return { inject: "##{edit_inject_element}", body: "データがありません: #{@id}" } unless data
    # フォームの表示
    form = make_edit_form
    found_a = Ht.search(form, tag: "input")
    found_a.each { |h| h.add_class("#{@class_snake}-edit-box") if h[:size] }
    return { inject: "##{edit_inject_element}", body: Html.convert(form) }
  else
    if @event[:cancel]
      # キャンセルの場合
      data = @column_set.set_from_db(@id)
      return act_after_cancel
    else
      # 値を保存
      @column_set.update(@id, @event[:form])
    end
    return act_after_edit
  end
end