Class: ODDB::Html::View::Drugs::FeedbackForm

Inherits:
HtmlGrid::Form
  • Object
show all
Includes:
HtmlGrid::ErrorMessage, HtmlGrid::InfoMessage
Defined in:
lib/oddb/html/view/drugs/feedback.rb

Constant Summary collapse

COMPONENTS =
{
  [0,0] => :name,
  [0,1] => :email,
  [0,4] => :message,
}
CSS_MAP =
{ 
  [0,4] => 'top', 
}
COLSPAN_MAP =
{
  [1,0] => 2,
  [1,1] => 2,
  [1,4] => 2,
  [1,13] => 2,
}
CSS_CLASS =
'composite top'
LABELS =
true
LOOKANDFEEL_MAP =
{
  :message => :feedback_message,
}
EVENT =
:update
LEGACY_INTERFACE =
false
SYMBOL_MAP =
{
  :email_public => HtmlGrid::LabelText,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.componentsObject



95
96
97
# File 'lib/oddb/html/view/drugs/feedback.rb', line 95

def components
  @components ||= {}
end

.css_mapObject



98
99
100
# File 'lib/oddb/html/view/drugs/feedback.rb', line 98

def css_map
  @css_map ||= {}
end

.radio(ypos, key) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/oddb/html/view/drugs/feedback.rb', line 81

def radio ypos, key
  key = key.to_sym
  truekey = "#{key}_true"
  falsekey = "#{key}_false"
  components.update( [0, ypos] => key, 
                     [1, ypos, 0] => truekey.to_sym,
                     [2, ypos, 1] => truekey,
                     [1, ypos + 1, 0] => falsekey.to_sym,
                     [2, ypos + 1, 1] => falsekey)
  css_map.update( [1, ypos] => 'radio', [1, ypos + 1] => 'radio')
  symbol_map.store(key, HtmlGrid::LabelText)
  define_method(truekey) { |model| radio_true(key) }
  define_method(falsekey) { |model| radio_false(key) }
end

.symbol_mapObject



101
102
103
# File 'lib/oddb/html/view/drugs/feedback.rb', line 101

def symbol_map
  @symbol_map ||= {}
end

Instance Method Details

#captcha(model) ⇒ Object



153
154
155
156
# File 'lib/oddb/html/view/drugs/feedback.rb', line 153

def captcha(model)
  name = "captcha[#{challenge.id}]"
  HtmlGrid::InputText.new(name, model, @session, self)
end

#captcha_image(model) ⇒ Object



157
158
159
160
161
# File 'lib/oddb/html/view/drugs/feedback.rb', line 157

def captcha_image(model)
  img = HtmlGrid::Image.new(:file, challenge, @session, self)
  img.attributes["src"] = File.join('', 'captcha', challenge.file)
  img
end

#challengeObject



150
151
152
# File 'lib/oddb/html/view/drugs/feedback.rb', line 150

def challenge
  @challenge ||= @lookandfeel.generate_challenge
end

#email_public_false(model) ⇒ Object



162
163
164
# File 'lib/oddb/html/view/drugs/feedback.rb', line 162

def email_public_false(model)
  radio_false(:email_public)
end

#email_public_true(model) ⇒ Object



165
166
167
# File 'lib/oddb/html/view/drugs/feedback.rb', line 165

def email_public_true(model)
  radio_true(:email_public)
end

#initObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/oddb/html/view/drugs/feedback.rb', line 136

def init
  components.update self.class.components
  symbol_map.update self.class.symbol_map
  css_map.update self.class.css_map
  if(@session.passed_turing_test?)
    components.update([1,13]=>:submit)
  else
    components.update([0,13]=>:captcha, [1,14]=>:captcha_image, [1,15]=>:submit)
    colspan_map.update([1,14]=>2, [1,15]=>2)
  end
  super
  error_message
  info_message
end

#message(model) ⇒ Object



187
188
189
190
191
192
193
194
# File 'lib/oddb/html/view/drugs/feedback.rb', line 187

def message(model)
  input = HtmlGrid::Textarea.new(:message, model, @session, self)
  input.set_attribute('wrap', true)
  js = "if(this.value.length > 400) { (this.value = this.value.substr(0,400))}" 
  input.set_attribute('onKeypress', js)
  input.label = true
  input
end

#radio_false(false_key) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/oddb/html/view/drugs/feedback.rb', line 177

def radio_false(false_key)
  radio = HtmlGrid::InputRadio.new(false_key, model, @session, self)
  if(model.send(false_key).eql?(false) \
     || @session.user_input(false_key).eql?(false))
    radio.set_attribute('checked', true)
  end
  radio.value = '0'
  radio.label = false
  radio
end

#radio_true(true_key) ⇒ Object



168
169
170
171
172
173
174
175
176
# File 'lib/oddb/html/view/drugs/feedback.rb', line 168

def radio_true(true_key)
  radio = HtmlGrid::InputRadio.new(true_key, model, @session, self)
  if(model.send(true_key) || @session.user_input(true_key))
    radio.set_attribute('checked', true)
  end
  radio.value = '1'
  radio.label = false
  radio
end