Module: Ezframe::SubPageKit::Edit

Defined in:
lib/ezframe/sub_page_kit.rb

Instance Method Summary collapse

Instance Method Details

#act_after_cancelObject



159
160
161
# File 'lib/ezframe/sub_page_kit.rb', line 159

def act_after_cancel
  return public_detail_post
end

#act_after_editObject



154
155
156
157
# 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) ⇒ Object


新規データ追加欄



113
114
115
116
117
# 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_elementObject



150
151
152
# File 'lib/ezframe/sub_page_kit.rb', line 150

def edit_inject_element
  return "#{@class_snake}_show"
end

#make_edit_form(command = :edit) ⇒ Object

編集フォームの生成



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 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) ⇒ Object



141
142
143
144
145
146
147
148
# 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_postObject

新規データ登録



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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_postObject

データ編集受信



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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