Class: Ezframe::DataEditor
Instance Attribute Summary
Attributes inherited from PageBase
Instance Method Summary collapse
-
#make_edit_form(command = :edit) ⇒ Object
編集フォームの生成.
-
#make_index_table(data_a) ⇒ Object
一覧テーブルの生成.
-
#public_create_get ⇒ Object
新規登録フォーム表示.
-
#public_create_post ⇒ Object
新規登録受信.
-
#public_default_get ⇒ Object
一覧ページ生成.
-
#public_edit_post ⇒ Object
データ編集受信.
-
#public_search_post ⇒ Object
——————————————————————————————————– 検索.
-
#show_detail_page ⇒ Object
詳細表示.
Methods inherited from PageBase
#init_vars, #initialize, #login?, #make_base_url, #parse_json_body, #set_request, #show_base_template, #user, #warden
Constructor Details
This class inherits a constructor from Ezframe::PageBase
Instance Method Details
#make_edit_form(command = :edit) ⇒ Object
編集フォームの生成
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ezframe/editor.rb', line 82 def make_edit_form(command = :edit) @id = get_id table = [] matrix = @column_set.map do |column| form = column.form table.push Ht.p([ Ht.small_text(column.label), form ]) if form end = Ht.(child: Message[:edit_finish_button_label], class: %w[btn], event: "on=click:url=#{make_base_url(@id)}/#{command}:with=form") table.push() return Ht.table(Ht.tr(table)) end |
#make_index_table(data_a) ⇒ Object
一覧テーブルの生成
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ezframe/editor.rb', line 19 def make_index_table(data_a) # @column_set.each { |col| col.attribute.delete(:hidden) } idx_keys = @index_keys || @column_set.keys puts "idx_keys=#{idx_keys.inspect}" a_element = Proc.new { |key, id, text| if key.to_s.index("_name") Ht.a(href: "#{make_base_url(id)}", child: text) else text end } tr_a = data_a.map do |data| @column_set.clear @column_set.values = data line = idx_keys.map do |key| view = @column_set[key].view Ht.td(Ht.a(href: "#{make_base_url(data[:id])}", child: view)) end Ht.tr(line) end th_a = idx_keys.map {|key| Ht.th(@column_set[key.to_sym].label) } thead = Ht.thead(Ht.tr(th_a)) tbody = Ht.tbody(tr_a) table_id = "enable_datatable_#{@class_snake}" return Ht.table(id: table_id, class: %w[enable_datatable], child: [ thead, tbody ], event: "on=load:command=enable_datatable:target=##{table_id}:size=10") end |
#public_create_get ⇒ Object
新規登録フォーム表示
47 48 49 50 51 52 |
# File 'lib/ezframe/editor.rb', line 47 def public_create_get @column_set.clear table = make_edit_form(:create) layout = main_layout(center: Ht.form(child: table), type: 2) show_base_template(title: Message[:parent_create_page_title], body: Html.convert(layout)) end |
#public_create_post ⇒ Object
新規登録受信
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ezframe/editor.rb', line 55 def public_create_post unless @event[:form] { inject: "#center-panel", body: Ht.form(child: make_edit_form(:create)) } else # 値の保存 @column_set.clear @column_set.values = @event[:form] @column_set[:id].value = id = @column_set.create return { redirect: make_base_url(id) } end end |
#public_default_get ⇒ Object
一覧ページ生成
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ezframe/editor.rb', line 6 def public_default_get id = get_id if id return show_detail_page else data_a = @dataset.all htb = make_index_table(data_a) layout = index_layout(center: Ht.form(child: htb)) return show_base_template(title: Message[:index_page_title], body: Html.convert(layout)) end end |
#public_edit_post ⇒ Object
データ編集受信
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ezframe/editor.rb', line 68 def public_edit_post id = get_id unless @event[:form] data = @column_set.set_from_db(id) return ("no data", "data is not defined: #{id}") unless data { inject: "#center-panel", body: Html.convert(Ht.form(make_edit_form)) } else # 値を保存 @column_set.update(id, @event[:form]) { redirect: make_base_url(id) } end end |
#public_search_post ⇒ Object
検索
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ezframe/editor.rb', line 96 def public_search_post mylog "public_search_post: #{@parsed_body.inspect}" sch_keys = @search_keys || @column_set.keys word = @params["word"] pattern = "%#{word}%" pattern_a = sch_keys.map {|key| Sequel.like(key, pattern) } data_a = @dataset.where(Sequel.|(*pattern_a)).all puts data_a.inspect layout = index_layout(center: make_index_table(data_a)) show_base_template(title: Message[:search_result_page_title], body: Html.convert(layout)) end |
#show_detail_page ⇒ Object
詳細表示
109 110 111 112 113 114 115 116 117 |
# File 'lib/ezframe/editor.rb', line 109 def show_detail_page mylog "show_detail_page: #{@request.params.inspect}" id = get_id(@class_snake) unless @column_set.set_from_db(id) return ("no data", "data is not defined: #{id}") end layout = main_layout(center: make_detail_table) return show_base_template(title: Message[:detail_page_title], body: Html.convert(layout)) end |