Module: Ezframe::PageKit::Edit

Included in:
SinglePageEditor
Defined in:
lib/ezframe/single_page_kit.rb

Instance Method Summary collapse

Instance Method Details

#act_after_cancelObject

キャンセル時の表示



145
146
147
# File 'lib/ezframe/single_page_kit.rb', line 145

def act_after_cancel
  return public_detail_post
end

#act_after_editObject

編集完了後の表示



140
141
142
# File 'lib/ezframe/single_page_kit.rb', line 140

def act_after_edit
  return [public_default_post, public_detail_post]
end

#make_edit_form(command = :edit) ⇒ Object

編集フォームの生成



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ezframe/single_page_kit.rb', line 121

def make_edit_form(command = :edit)
  @id ||= get_id
  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
    form = column.form
    Ht.p(class: %w[form-line], child: [Ht.small(column.label), form]) if form
  end
  send_button = Ht.button(id: "#{@class_snake}-#{command}-finish-button", class: %w[btn], child: [Ht.icon("check"), Message[:edit_finish_button_label]], ezevent: "on=click:url=#{make_base_url(@id)}/#{command}:with=form")
  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

#public_create_postObject

新規データ登録



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ezframe/single_page_kit.rb', line 73

def public_create_post
  @form = @event[:form]
  EzLog.debug("public_create_post: event=#{@event}")
  if @event[:cancel]
    return { inject: "##{@dom_id[:create]}", body: Html.convert(make_index_top) }
  elsif !@form
    return { inject: "##{@dom_id[:create]}", 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_postObject

データ編集受信



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ezframe/single_page_kit.rb', line 93

def public_edit_post
  @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 @event[:form]
    data = @column_set.set_from_db(@id)
    return show_message_page("no data", "data is not defined: #{@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: "##{@dom_id[:detail]}", 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