class Document < ActiveRecord::Base attr_accessible :name, :parent, :text, :typ, :parent_id, :parent_type belongs_to :parent, :polymorphic => true validate :name, :length=>{minimum:3} validate :text, :presence=>true validate :typ, :presence=>true validate :parent, :presence=>true has_paper_trail TYPS = { 1=>"fet_docs", 10=>"protocol", 11=> "agenda"} def self.new_divid_for(parent) "document_new_parent_" + parent.class.to_s + "_" + parent.id.to_s end def divid "document_"+self.id.to_s end def self.ether EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/home/andreas/www/APIKEY.txt')) end def ether if @ep.nil? @ep=Document.ether end @ep end def is_etherpad? !(etherpadkey.nil? || etherpadkey.empty?) end def move_to_etherpad unless self.is_etherpad? || self.id.nil? self.etherpadkey="document_"+ self.id.to_s self.ep_pad.html = '