Class: Ezframe::SubEditor
- Includes:
- EditorCommon
- Defined in:
- lib/ezframe/sub_editor.rb
Overview
各顧客に関連づいた情報の編集を一般化したクラス
Instance Attribute Summary
Attributes inherited from PageBase
Instance Method Summary collapse
- #act_after_cancel ⇒ Object
- #act_after_edit ⇒ Object
-
#area_for_create(extra_buttons = nil) ⇒ Object
——————————————————————————————————– 新規データ追加欄.
-
#button_for_detail_box(data) ⇒ Object
詳細ページ用ボタン.
-
#button_for_index_line(data) ⇒ Object
一覧ページ用ボタン.
- #edit_inject_element ⇒ Object
- #get_parent_id ⇒ Object
- #init_vars ⇒ Object
-
#list_for_index ⇒ Object
一覧ページ用のデータリスト生成.
-
#make_detail_line(column) ⇒ Object
詳細表示欄の一行を生成.
-
#make_edit_form(command = :edit) ⇒ Object
編集フォームの生成.
- #make_edit_line(column) ⇒ Object
-
#make_index_column(key) ⇒ Object
一覧表示の1カラムを生成.
-
#make_index_line(target_keys, data) ⇒ Object
一覧表示の1行を生成.
-
#make_index_page ⇒ Object
一覧表の生成.
-
#public_create_post ⇒ Object
新規データ登録.
- #public_default_post ⇒ Object
-
#public_delete_post ⇒ Object
削除ボタン押下時の処理.
-
#public_detail_post ⇒ Object
データ詳細表示.
-
#public_edit_post ⇒ Object
データ編集受信.
Methods included from EditorCommon
#get_id, #make_cancel_button, #make_create_button, #make_delete_button, #make_edit_button, #show_label_edit, #show_label_view, #show_message_page, #update_value
Methods inherited from PageBase
#initialize, #login?, #make_base_url, #parse_json_body, #session, #set_request, #show_base_template, #user, #warden
Constructor Details
This class inherits a constructor from Ezframe::PageBase
Instance Method Details
#act_after_cancel ⇒ Object
114 115 116 |
# File 'lib/ezframe/sub_editor.rb', line 114 def act_after_cancel return public_detail_post end |
#act_after_edit ⇒ Object
109 110 111 112 |
# File 'lib/ezframe/sub_editor.rb', line 109 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
新規データ追加欄
185 186 187 188 189 |
# File 'lib/ezframe/sub_editor.rb', line 185 def area_for_create( = nil) = [:event] = "on=click:url=#{make_base_url}/create" return Ht.div(id: "#{@class_snake}-create-area", child: [ , ].compact) end |
#button_for_detail_box(data) ⇒ Object
詳細ページ用ボタン
175 176 177 178 179 180 181 |
# File 'lib/ezframe/sub_editor.rb', line 175 def (data) = [Ht.(class: %w[btn right], event: "on=click:url=#{make_base_url(data[:id])}/edit", child: [Ht.icon("edit"), Message[:edit_button_label]]) ] if .push() end return Ht.div(class: %w[button-box], child: ) end |
#button_for_index_line(data) ⇒ Object
一覧ページ用ボタン
170 171 172 |
# File 'lib/ezframe/sub_editor.rb', line 170 def (data) Ht.(class: %w[btn right], event: "on=click:url=#{make_base_url(data[:id])}/edit", child: [Ht.icon("edit"), Message[:edit_button_label]]) end |
#edit_inject_element ⇒ Object
105 106 107 |
# File 'lib/ezframe/sub_editor.rb', line 105 def edit_inject_element return "#{@class_snake}_show" end |
#get_parent_id ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ezframe/sub_editor.rb', line 14 def get_parent_id params = @request.env["url_params"] unless params EzLog.info "[WARN] no url_params" return nil end return params[@parent_key.to_sym] end |
#init_vars ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/ezframe/sub_editor.rb', line 6 def init_vars super @sort_key = :id # @parent_key = :customer @event = @parsed_body[:event] if @parsed_body # @use_detail_box = true end |
#list_for_index ⇒ Object
一覧ページ用のデータリスト生成
165 166 167 |
# File 'lib/ezframe/sub_editor.rb', line 165 def list_for_index return @column_set.dataset.where(@parent_key.to_sym => get_parent_id, deleted_at: nil).order(@sort_key).all end |
#make_detail_line(column) ⇒ Object
詳細表示欄の一行を生成
96 97 98 99 100 101 102 103 |
# File 'lib/ezframe/sub_editor.rb', line 96 def make_detail_line(column) view = column.view if view view = Ht.pre(view) if view.index("\n") return Ht.p([Ht.small(column.label), view]) end return nil end |
#make_edit_form(command = :edit) ⇒ Object
編集フォームの生成
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ezframe/sub_editor.rb', line 192 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" = Ht.(id: "#{@class_snake}-#{command}-finish-button", class: %w[btn], child: [Ht.icon("check"), Message[:edit_finish_button_label]], event: event) = ("on=click:url=#{make_base_url(@id)}/#{command}:cancel=true:with=form") list.push(Ht.p(class: %w[edit-finish-buttons], child: [, ])) return Ht.form(list) end |
#make_edit_line(column) ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'lib/ezframe/sub_editor.rb', line 213 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 |
#make_index_column(key) ⇒ Object
一覧表示の1カラムを生成
159 160 161 162 |
# File 'lib/ezframe/sub_editor.rb', line 159 def make_index_column(key) column = @column_set[key.to_sym] return column.view(force: true) end |
#make_index_line(target_keys, data) ⇒ Object
一覧表示の1行を生成
152 153 154 155 156 |
# File 'lib/ezframe/sub_editor.rb', line 152 def make_index_line(target_keys, data) @column_set.clear @column_set.set_values(data, from_db: true) return target_keys.map { |key| make_index_column(key) } end |
#make_index_page ⇒ Object
一覧表の生成
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ezframe/sub_editor.rb', line 119 def make_index_page list = list_for_index target_keys = @index_keys unless target_keys target_keys = @column_set.keys.select {|k| !@column_set[k].no_view?} end # 項目名欄の生成 if @table_labels thead = Ht.thead(Ht.tr(@table_labels.map {|label| Ht.th(label)})) else thead = Ht.thead(Ht.tr(target_keys.map {|key| if @column_set[key].respond_to?(:label) Ht.th(@column_set[key].label(force: true)) else nil end })).compact end tr_a = list.map do |data| view_a = make_index_line(target_keys, data) td_a = view_a.map {|view| Ht.td(view)} Ht.tr(id: "tr-#{@class_snake}-#{data[:id]}", child: td_a, event: "on=click:url=#{make_base_url(data[:id])}/detail") end tbody = Ht.tbody(tr_a) return [ area_for_create, Ht.table(id: "enable_datatable_#{@class_snake}", child: [thead, tbody], ezload: "command=enable_datatable:target=#enable_datatable_#{@class_snake}"), Ht.div(id: edit_inject_element), ] end |
#public_create_post ⇒ Object
新規データ登録
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ezframe/sub_editor.rb', line 28 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_default_post ⇒ Object
23 24 25 |
# File 'lib/ezframe/sub_editor.rb', line 23 def public_default_post return { inject: "##{@class_snake}_tab", body: Html.convert(make_index_page) } end |
#public_delete_post ⇒ Object
削除ボタン押下時の処理
88 89 90 91 92 93 |
# File 'lib/ezframe/sub_editor.rb', line 88 def public_delete_post @id = get_id dataset = DB.dataset(@column_set.name) DB.delete(dataset, @id) return public_default_post end |
#public_detail_post ⇒ Object
データ詳細表示
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ezframe/sub_editor.rb', line 70 def public_detail_post @id = get_id data = @column_set.set_from_db(@id) target_keys = @show_keys || @column_set.keys.select { |key| !@column_set[key].attribute[:no_view] } line_a = [] target_keys.each do |key| column = @column_set[key] v = make_detail_line(column) line_a.push(v) if v end table = Ht.div(line_a) collection = Materialize::Collection.new # 詳細表示用のblockを追加 collection.push(Ht.div(class: "detail-box", child: [(data), table])) return { inject: "##{edit_inject_element}", body: Html.convert(collection.to_h) } end |
#public_edit_post ⇒ Object
データ編集受信
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ezframe/sub_editor.rb', line 46 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 |