Module: ODDB::State::Feedbacks

Included in:
Drugs::Feedbacks, Migel::Feedbacks
Defined in:
src/state/feedbacks.rb

Defined Under Namespace

Classes: ItemWrapper

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) passed_turing_test (readonly)

Returns the value of attribute passed_turing_test



49
50
51
# File 'src/state/feedbacks.rb', line 49

def passed_turing_test
  @passed_turing_test
end

Instance Method Details

- (Object) init



50
51
52
53
54
55
56
57
58
# File 'src/state/feedbacks.rb', line 50

def init
  @model = ItemWrapper.new(@model)
  @filter = Proc.new { |model| 
    index = @session.user_input(:index).to_i
    model.index = index
    model
  }
  super
end

- (Object) update



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'src/state/feedbacks.rb', line 59

def update
  mandatory = [:name, :email, :show_email, :experience, 
    :recommend, :impression, :helps]
  unless @passed_turing_test
    mandatory.push :captcha
  end
  keys = mandatory + [:message]
  hash = user_input(keys, mandatory)
  if(@passed_turing_test)
    # do nothing
  elsif((candidates = hash[:captcha]) && candidates.any? { |key, word| 
    @session.lookandfeel.captcha.valid_answer? key, word })
    @passed_turing_test = true
  else
    @errors.store(:captcha, create_error('e_failed_turing_test', 
      :captcha, nil))
  end
  unless(error?)
     = @model.current_feedback
    info_key = :feedback_changed
    if(.is_a?(ODDB::Persistence::CreateItem))
      info_key = :feedback_saved
      hash.each { |key, value|
        .carry(key, value)
      }
      hash.store(:item, @model.item)
    end
    
    # store new Feedback
    time = Time.now
    hash.store(:time , time)
    if msg = hash[:message]
      hash[:message] = msg[0,800]
    end
    @model.current_feedback = @session.app.update(@model.current_feedback.pointer,
                                                  hash)
    @session.update_feedback_rss_feed
    @infos = [info_key]

    # in case this was a new feedback, drop a line into a logfile
    if(info_key == :feedback_saved)
      args = {:pointer => @model.item.pointer}
      link = @session.lookandfeel._event_url(:feedbacks, args)
      line = [
        nil, hash[:name], hash[:email], link
      ].join(';')
      LogFile.append('feedback', line, time)
    end
  end
  self
end