class Qwik::TableForm

Public Class Methods

gen_input(name, value=nil, size=nil, maxsize=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 111
def self.gen_input(name, value=nil, size=nil, maxsize=nil)
  attr = {:name=>name}
  attr[:value] = value if value
  attr[:size] = size if size
  attr[:maxsize] = maxsize if maxsize
  return [:input, attr]
end
gen_input_password(n, v=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 119
def self.gen_input_password(n, v=nil)
  attr = {:type=>'password', :name=>n}
  attr[:value] = v if v
  return [:input, attr]
end
gen_select(n, *aa) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 125
def self.gen_select(n, *aa)
  return [:select, {:name=>n}] + aa.map {|a| [:option, {:name=>a}, a] }
end
gen_submit(v=nil, n=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 129
def self.gen_submit(v=nil, n=nil)
  attr = {:type=>'submit'}
  attr[:value] = v if v
  attr[:name] = n if n
  return [:input, attr]
end
gen_textarea(name, cols=nil, rows=nil, msg=nil) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 136
def self.gen_textarea(name, cols=nil, rows=nil, msg=nil)
  msg ||= ''
  msg.gsub!(/\\n/, "\n")
  attr = {:name=>name}
  attr[:cols] = cols if cols
  attr[:rows] = rows if rows
  return [:textarea, attr, msg]
end
generate(action, dest, str, pagename) click to toggle source
# File vendor/qwik/lib/qwik/act-tableform.rb, line 37
def self.generate(action, dest, str, pagename)
  table = [:table, {:class=>'form'}]

  str.each {|line|
    line.chomp!

    ar = line.split(/\|/)
    ar.shift

    case ar.length
    when 1
      table << [:tr, [:td, {:colspan=>2, :class=>'msg'}, ar.shift]]

    when 2
      midashi = ar.shift
      td = []
      nakami = ar.shift
      nakami.sub!(/^\{\{/, "")
      nakami.sub!(/\}\}$/, "")

      if /^([^\(\)]+)\((.*)\)$/ =~ nakami
        cmd, args = $1, $2
        aa = args.split(/,/)

        case cmd
        when 'input'
          td << gen_input(*aa)

        when 'select'
          td << gen_select(*aa)

        when 'textarea'
          name, w, h, msg = aa
          msg = '' if !msg
          msg.gsub!(/\\n/, "\n")
          td << gen_textarea(name, w, h, msg)

        when 'submit'
          su = gen_submit(*aa)
          su.attr[:class] = 'submit'
          td << su

        when 'show'
          td << [:span, action.show(*aa)]

        when 'ring_show'
          td << [:span, action.plg_ring_show(*aa)]

        when 'member_user'
         #td << [:span, action.plg_member_user]
          td << [:span, action.req_user]

        end
      else
        td << [:span, nakami]
      end
      etd = [:td, {:class=>'nakami'}, td]
      etr = [:tr, [:td, {:class=>'midashi'}, midashi], etd]
      table << etr
    else
      table << [:tr, ar.to_s] #debug
    end
  }

  action = "#{pagename.to_s.escape}.html"
  action = "#{dest.to_s.escape}.html" if dest && ! dest.empty?

  div = [:div, {:class=>'form'},
    [:form, {:method=>'POST', :action=>action},
      [:input, {:type=>'hidden', :name=>'page', :value=>pagename.escape}],
      table]]
  return div
end