]> git.openstreetmap.org Git - rails.git/blob - app/models/map_bug.rb
Escape javascript in output
[rails.git] / app / models / map_bug.rb
1 class MapBug < ActiveRecord::Base
2   include GeoRecord
3
4   set_table_name 'map_bugs'
5
6   validates_presence_of :id, :on => :update
7   validates_uniqueness_of :id
8   validates_numericality_of :latitude, :only_integer => true
9   validates_numericality_of :longitude, :only_integer => true
10   validates_presence_of :date_created
11   validates_presence_of :last_changed
12   validates_inclusion_of :status, :in => [ "open", "closed", "hidden" ]
13
14   has_many :map_bug_comment, :foreign_key => :bug_id, :order => :date_created, :conditions => { :visible => true } 
15
16
17   def self.create_bug(lat, lon)
18         bug = MapBug.new(:lat => lat, :lon => lon);
19         raise OSM::APIBadUserInput.new("The node is outside this world") unless bug.in_world?
20         bug.date_created = Time.now.getutc
21         bug.last_changed = Time.now.getutc
22         bug.status = "open";
23         return bug;
24   end
25
26   def close_bug
27         self.status = "closed"
28         self.last_changed = Time.now.getutc
29         self.save;
30   end
31
32   def flatten_comment ( separator_char )
33         resp = ""
34         comment_no = 1
35         self.map_bug_comment.each do |comment|
36         resp += (comment_no == 1 ? "" : separator_char)
37                 resp += comment.comment if comment.comment
38                 resp += " [ " 
39                 resp += comment.commenter_name if comment.commenter_name
40                 resp += " " + comment.date_created.to_s + " ]"
41                 comment_no += 1
42         end
43
44         return resp
45
46   end
47
48 end