Class: Gambit::Server::Game::EventForm

Inherits:
Object
  • Object
show all
Includes:
Viewable
Defined in:
lib/gambit/server/game/eventform.rb

Instance Method Summary collapse

Methods included from Viewable

append_features, #view

Constructor Details

#initialize(url, intro, hidden, &init) ⇒ EventForm

Returns a new instance of EventForm.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gambit/server/game/eventform.rb', line 69

def initialize( url, intro, hidden, &init )
  @url           = url
  @intro         = intro
  
  @elements      = Array.new
  @hidden_fields = Array.new
  submit("Submit")
  reset("Reset")
  
  @element_style = :dl
  
  hidden.each { |(name, value)| hidden(name, value) }
  self.instance_eval(&init)
end

Instance Method Details

#checks(group, names, options = Hash.new) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gambit/server/game/eventform.rb', line 84

def checks( group, names, options = Hash.new )
  tags = ""
  names.each do |name|
    tags << " <input type=\"checkbox\" " +
                     "id=\"#{name}\" " +
                     "name=\"#{group}\" value=\"#{name}\"" +
                     "#{htmlify(options[name])} />" +
            "<label for=\"#{name}\">" +
            "#{name.capitalize.tr("_", " ")}</label>"
  end
  @elements << tags.strip
end

#document(name, default_text = nil, options = Hash.new) ⇒ Object



97
98
99
100
101
# File 'lib/gambit/server/game/eventform.rb', line 97

def document( name, default_text = nil, options = Hash.new )
  @elements << "<textarea id=\"#{name}\" name=\"#{name}\"" +
                          "#{htmlify(options)}>" +
               "#{default_text || ''}</textarea>"
end

#hidden(name, value) ⇒ Object



103
104
105
106
107
# File 'lib/gambit/server/game/eventform.rb', line 103

def hidden( name, value )
  @hidden_fields << "<input type=\"hidden\" " +
                            "name=\"#{name}\" " +
                            "value=\"#{value}\" />"
end

#html(tags) ⇒ Object



109
110
111
112
113
# File 'lib/gambit/server/game/eventform.rb', line 109

def html( tags )
  @element_style = :p
  
  @elements << tags
end


115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/gambit/server/game/eventform.rb', line 115

def menu( name, values, options = Hash.new,
                        menu_options = Hash.new )
  tags = "<select id=\"#{name}\" name=\"#{name}\"" +
                 "#{htmlify(menu_options)}>"
  tags << values.map do |value|
    "<option value=\"#{value}\"" +
    "#{htmlify(options[value])}>" +
    "#{value.capitalize.tr("_", " ")}</option>"
  end.join
  tags << "</select>"
  @elements << tags.strip
end

#password(name, options = Hash.new) ⇒ Object



128
129
130
131
132
# File 'lib/gambit/server/game/eventform.rb', line 128

def password( name, options = Hash.new )
  @elements << "<input type=\"password\" " +
                       "id=\"#{name}\" name=\"#{name}\"" +
                       "#{htmlify(options)} />"
end

#radios(group, names, options = Hash.new) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/gambit/server/game/eventform.rb', line 134

def radios( group, names, options = Hash.new )
  tags = ""
  names.each do |name|
    tags << " <input type=\"radio\" " +
                     "id=\"#{name}\" " +
                     "name=\"#{group}\" value=\"#{name}\"" +
                     "#{htmlify(options[name])} />" +
            "<label for=\"#{name}\">" +
            "#{name.capitalize.tr("_", " ")}</label>"
  end
  @elements << tags.strip
end

#reset(name, options = Hash.new) ⇒ Object



147
148
149
150
# File 'lib/gambit/server/game/eventform.rb', line 147

def reset( name, options = Hash.new )
  @reset = "<input type=\"reset\" value=\"#{name}\"" +
                   "#{htmlify(options)} />"
end

#submit(name, options = Hash.new) ⇒ Object



152
153
154
155
# File 'lib/gambit/server/game/eventform.rb', line 152

def submit( name, options = Hash.new )
  @submit = "<input type=\"submit\" value=\"#{name}\"" +
                    "#{htmlify(options)} />"
end

#text(name, options = Hash.new) ⇒ Object



157
158
159
160
161
# File 'lib/gambit/server/game/eventform.rb', line 157

def text( name, options = Hash.new )
  @elements << "<input type=\"text\" " +
                       "id=\"#{name}\" name=\"#{name}\"" +
                       "#{htmlify(options)} />"
end