module Ezframe::MainPageKit::Edit

Public Instance Methods

count_errors(validate_result) click to toggle source

validate_resultの中のエラーの数を数える

# File lib/ezframe/main_page_kit.rb, line 170
def count_errors(validate_result)
  return validate_result.count { |k, a| a[1] }
end
edit_cancel_button() click to toggle source
# File lib/ezframe/main_page_kit.rb, line 174
def edit_cancel_button
  Ht.span(class: %w[btn red small waves-effect waves-light switch-button], child: Ht.icon("clear"))
end
exec_completion() click to toggle source

自動入力を行う

# File lib/ezframe/main_page_kit.rb, line 104
def exec_completion
  return nil
end
full_validation(validate_h) click to toggle source

全てのカラムに対してバリデーションを行う

# File lib/ezframe/main_page_kit.rb, line 145
def full_validation(validate_h)
  cmd_a = show_validate_result(validate_h)
  cmd_a.unshift({ reset_error: ".error-box" })
  EzLog.debug("full_validation: full, cmd_a=#{cmd_a}")
  return cmd_a
end
make_create_button(event = nil) click to toggle source
# File lib/ezframe/main_page_kit.rb, line 178
def make_create_button(event = nil)
  event ||= "on=click:command=redirect:url=#{make_base_url}/create"
  return Ht.button(class: %w[btn], child: [Ht.icon("add"), Message[:create_button_label]], ezevent: event)
end
make_edit_form(command = :edit) click to toggle source

編集フォームの生成

# File lib/ezframe/main_page_kit.rb, line 109
def make_edit_form(command = :edit)
  table = []
  matrix = @column_set.map do |column|
    next if column.no_edit?
    form = column.form
    table.push Ht.p([Ht.small(column.label), form]) if form
  end
  send_button = Ht.button(id: "edit-finish-button", child: Message[:edit_finish_button_label], class: %w[btn], ezevent: "on=click:url=#{make_base_url}/#{command}:with=form")
  cancel_button = edit_cancel_button
  cancel_button[:event] = "on=click:command=redirect:url=#{make_base_url}"
  table.push(Ht.p([send_button, cancel_button]))
  return table
end
public_create_get() click to toggle source

新規登録フォーム表示

# File lib/ezframe/main_page_kit.rb, line 49
def public_create_get
  @column_set.clear
  table = make_edit_form(:create)
  layout = main_layout(center: make_form("#{make_base_url}/create", table), type: 2)
  show_base_template(title: Message[:parent_create_page_title], body: Html.convert(layout))
end
public_create_post() click to toggle source

新規登録受信

# File lib/ezframe/main_page_kit.rb, line 57
def public_create_post
  validation = @column_set.validate(@form)
  EzLog.debug("public_create_post: event=#{@event}, form=#{@form}")
  if @event[:branch] == "single_validate"
    EzLog.debug("public_create_post: single validate")
    return single_validation(validation, @event[:target_key] || @form.keys[0])
  end
  unless @form
    url = "#{make_base_url}/create"
    return { inject: "#center-panel", body: Html.convert(make_form(url, make_edit_form(:create))), set_url: url }
  else
    if count_errors(validation) > 0
      cmd_a = full_validation(validation)
      EzLog.debug("public_create_post: cmd_a=#{cmd_a}")
      return cmd_a if cmd_a.length > 0
    end
    # 値の保存
    id = create_data(@form)
    return { redirect: make_base_url(id) }
  end
end
public_edit_post() click to toggle source

データ編集受信

# File lib/ezframe/main_page_kit.rb, line 80
def public_edit_post
  EzLog.debug("public_edit_post: #{@form}")
  @id = get_id
  validation = @column_set.validate(@form)
  if @event[:branch] == "single_validate"
    EzLog.debug("public_edit_post: single validate:event=#{@event}, form=#{@form}")
    return single_validation(validation, @event[:target_key])
  end
  unless @form
    data = @column_set.set_from_db(@id)
    return show_message_page("no data", "data is not defined: #{@id}") unless data
    return { inject: "#center-panel", body: Html.convert(make_form("#{make_base_url}/edit", make_edit_form)) }
  else
    if count_errors(validation) > 0
      cmd_a = full_validation(validation)
      return cmd_a
    end
    # 値を保存
    update_data(@id, @form)
    return { redirect: make_base_url(@id) }
  end
end
show_validate_result(validate_result) click to toggle source

フォームの値の有効性チェックし、ajax用返信ハッシュを生成

# File lib/ezframe/main_page_kit.rb, line 153
def show_validate_result(validate_result)
  cmd_a = []
  validate_result.each do |key, status|
    norm, err = status
    EzLog.debug("norm=#{norm}, err=#{err}")
    if norm
      cmd_a.push({ set_value: "input[name=#{key}]", value: norm })
    end
    if err
      msg = Message[err.to_sym] || err
      cmd_a.push({ set_error: "#error-box-#{key}", value: msg })
    end
  end
  return cmd_a
end
single_validation(validate_h, target_key) click to toggle source

1カラムに対してだけバリデーションを行う。

# File lib/ezframe/main_page_kit.rb, line 124
def single_validation(validate_h, target_key)
  EzLog.debug("single_validation: validate_h=#{validate_h}, target_key=#{target_key}")
  unless target_key
    raise "target_key is empty: #{validate_h}"
    return []
  end
  cmd_a = []
  if validate_h[target_key.to_sym]
    cmd_a = show_validate_result(validate_h)
  end
  if count_errors(validate_h) == 0
    cmd_a.unshift({ reset_error: "#error-box-#{target_key}" })
  end
  comp_a = exec_completion(@form)
  cmd_a += comp_a if comp_a
  EzLog.debug("reset_error: #error-box-#{target_key}")
  EzLog.debug("single_validation: target_key=#{target_key}, validate_h=#{validate_h}, count=#{count_errors(validate_h)}, cmd_a=#{cmd_a}")
  return cmd_a
end