lib/ezframe/editor.rb in ezframe-0.0.4 vs lib/ezframe/editor.rb in ezframe-0.1.0

- old
+ new

@@ -11,12 +11,12 @@ unless @column_set raise "[ERROR] no such column set: #{@target}" end @dataset = @column_set.dataset end - if @json - @event = @json[:event] || {} + if @parsed_body + @event = @parsed_body[:event] || {} @target_id = @event[@target] end @auth = false init_vars end @@ -32,57 +32,57 @@ @target.downcase! @target = @target.to_sym return @target end - def public_login_page - flash_area = "" - mylog "public_login_page: #{@request}" - if @request - mylog "flash=#{@request.env['x-rack.flash']}" - flash_area = Ht.div(class: %w[teal], child: @request['env']['x-rack.flash'].error) - end - form = Ht.multi_div([ %w[container], %w[row]], - Ht.form(class: "col s6 offset-s3", action: "/#{@target}/login", method: "post", child: [ - Materialize.input(type: "text", name: "account", label: "User ID"), - Materialize.input(type: "password", name: "password", label: "Password"), - Ht.button(type: "submit", class: %w[btn], child: "login") - ])) - common_page(title: "Login", body: Html.convert(Materialize.convert([flash_area, form]))) - end +# def public_login_get +# flash_area = "" +# mylog "public_login_get: #{@request}" +# if @request +# mylog "flash=#{@request.env['x-rack.flash']}" +# flash_area = Ht.div(class: %w[teal], child: @request['env']['x-rack.flash'].error) +# end +# form = Ht.multi_div([ %w[container], %w[row]], +# Ht.form(class: "col s6 offset-s3", action: "/#{@target}/login", method: "post", child: [ +# Materialize.input(type: "text", name: "account", label: "User ID"), +# Materialize.input(type: "password", name: "password", label: "Password"), +# Ht.button(type: "submit", class: %w[btn], child: "login") +# ])) +# show_base_template(title: "Login", body: Html.convert(Materialize.convert([flash_area, form]))) +# end - def public_login_post - mylog "public_login_post: #{@params.inspect}, #{@json}" - warden.authenticate - public_index_page - end +# def public_login_post +# mylog "public_login_post: #{@params.inspect}, #{@parsed_body}" +# warden.authenticate +# public_index_get +# end #-------------------------------------------------------------------------------------------------------- # add new parts - def public_new_page + def public_create_get matrix = @column_set.map do |column| [column.label, column.form] end - matrix.push([Ht.button(child: "送信", class: %w[btn], event: "on=click:branch=add_new:url=/#{@target}/new:with=form")]) + matrix.push([Ht.button(child: Message[:create_finish_button_label], class: %w[btn], event: "on=click:url=/#{@target}/create:with=form")]) tb = Ht::Table.new(matrix) layout = main_layout(left: sidenav, center: Ht.form(child: tb.to_h)) - common_page(title: "新規登録", body: Html.convert(Materialize.convert(layout))) + show_base_template(title: Message[:create_page_title], body: Html.convert(Materialize.convert(layout))) end - def public_new_post + def public_create_post @column_set.values = @event[:form] - @column_set[:id].value = @target_id = @column_set.save + @column_set[:id].value = @target_id = @column_set.create { redirect: "/#{@target}/detail?id=#{@target_id}" } end #-------------------------------------------------------------------------------------------------------- # index parts - def public_index_page + def public_index_get data_a = @dataset.all htb = make_index_table(data_a) layout = index_layout(left: sidenav, center: Ht.form(child: htb)) - common_page(title: "データ一覧", body: Html.convert(Materialize.convert(layout))) + show_base_template(title: Message[:index_page_title], body: Html.convert(Materialize.convert(layout))) end def make_index_table(data_a) column_header = [:id, :name, :email, :zipcode, :prefecture] @column_set.each { |col| col.attribute.delete(:hidden) } @@ -97,42 +97,42 @@ table = PageKit::IndexTable.new(column_header: column_header, column_set: @column_set, add_checkbox: :id, decorate_column: a_element) table.make_table(data_a) end - alias_method :public_default_page, :public_index_page + alias_method :public_default_get, :public_index_get #-------------------------------------------------------------------------------------------------------- # search parts def public_search_post - mylog "public_search_post: #{@json.inspect}" + mylog "public_search_post: #{@parsed_body.inspect}" word = @event[:form][:word] pattern = "%#{word}%" data_a = @dataset.where(Sequel.|(Sequel.like(:name_kana, pattern), Sequel.like(:name, pattern))).all make_index_table(data_a) end #-------------------------------------------------------------------------------------------------------- # detail parts - def public_detail_page - mylog "pubilc_detail_page: #{@request.params.inspect}" + def public_detail_get + mylog "pubilc_detail_get: #{@request.params.inspect}" @target_id ||= @request.params["id"] data = @column_set.set_from_db(@target_id) - return common_page(title: "no data", body: "no customer data: #{@target_id}") unless data - common_page(title: "データ一覧", body: Html.convert(make_detail_page)) + return show_base_template(title: "no data", body: "no customer data: #{@target_id}") unless data + show_base_template(title: Message[:index_page_title], body: Html.convert(make_detail_get)) end - def make_detail_page + def make_detail_get layout = main_layout( left: sidenav, center: detail_table ) @request.env['rack.session'][@target] = @target_id - layout[:event] = "on=load:branch=set_global@target=#{@target_id}" + layout[:event] = "on=load:command=set_global@target=#{@target_id}" Materialize.convert(layout) end def public_detail_post - mylog "public_detail_post: #{@request.params.inspect}: #{@json}" - if @json[:global] - @target_id ||= @json[:global][@target] + mylog "public_detail_post: #{@request.params.inspect}: #{@parsed_body}" + if @parsed_body[:global] + @target_id ||= @parsed_body[:global][@target] end @column_set.set_from_db(@target_id) case @event[:branch] when "update_value" update_value