forked from bofh/fetsite
AutoCommit Fre Aug 7 00:03:02 CEST 2015
This commit is contained in:
@@ -10,4 +10,11 @@ class Survey::Choice < ActiveRecord::Base
|
||||
def html
|
||||
content_tag("i","", class: self.icon ) + self.text
|
||||
end
|
||||
def attributes_for_copy
|
||||
self.attributes.select{|k,v| ["text","sort", "picture", "icon"].include?(k)}
|
||||
end
|
||||
def copy_from_template
|
||||
cpy = Survey::Choice.new(self.attributes_for_copy)
|
||||
cpy.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
class Survey::Question < ActiveRecord::Base
|
||||
attr_accessible :text, :title, :typ, :choice_ids
|
||||
attr_accessible :text, :title, :typ, :choice_ids, :parent_type, :parent_id
|
||||
belongs_to :parent, polymorphic: true
|
||||
has_many :choices, dependent: :destroy
|
||||
has_many :answers, through: :choices
|
||||
include IsCommentable
|
||||
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
||||
FLAG_CONFIRM={"delete"=> "Sicher loeschen?"}
|
||||
scope :templates, ->{ where(flag_template:true)}
|
||||
scope :templates, ->{ where(flag_template: true)}
|
||||
acts_as_flagable
|
||||
def attributes_for_copy
|
||||
self.attributes
|
||||
|
||||
def copy_from_template_for(parent)
|
||||
unless self.flag_template
|
||||
return nil
|
||||
else
|
||||
cpy = Survey::Question.new(self.attributes_for_copy)
|
||||
cpy.parent=parent
|
||||
cpy.save
|
||||
self.choices.each do |c|
|
||||
cpy.choices << c.copy_from_template
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def attributes_for_copy
|
||||
self.attributes.select{|k,v| ["title","text","typ"].include?(k)}
|
||||
end
|
||||
|
||||
def add_yesno_choices
|
||||
c=Survey::Choice.new(title: "Ja")
|
||||
c.save
|
||||
|
||||
Reference in New Issue
Block a user