forked from bofh/fetsite
AutoCommit Fre Aug 7 00:03:02 CEST 2015
This commit is contained in:
@@ -5,9 +5,16 @@ class Survey::Choice < ActiveRecord::Base
|
|||||||
include ActionView::Helpers::TagHelper
|
include ActionView::Helpers::TagHelper
|
||||||
mount_uploader :picture, PictureUploader
|
mount_uploader :picture, PictureUploader
|
||||||
def to_s
|
def to_s
|
||||||
self.text
|
self.text
|
||||||
end
|
end
|
||||||
def html
|
def html
|
||||||
content_tag("i","", class: self.icon ) + self.text
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
class Survey::Question < ActiveRecord::Base
|
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
|
belongs_to :parent, polymorphic: true
|
||||||
has_many :choices, dependent: :destroy
|
has_many :choices, dependent: :destroy
|
||||||
has_many :answers, through: :choices
|
has_many :answers, through: :choices
|
||||||
include IsCommentable
|
include IsCommentable
|
||||||
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
||||||
FLAG_CONFIRM={"delete"=> "Sicher loeschen?"}
|
FLAG_CONFIRM={"delete"=> "Sicher loeschen?"}
|
||||||
scope :templates, ->{ where(flag_template:true)}
|
scope :templates, ->{ where(flag_template: true)}
|
||||||
acts_as_flagable
|
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
|
end
|
||||||
|
|
||||||
|
def attributes_for_copy
|
||||||
|
self.attributes.select{|k,v| ["title","text","typ"].include?(k)}
|
||||||
|
end
|
||||||
|
|
||||||
def add_yesno_choices
|
def add_yesno_choices
|
||||||
c=Survey::Choice.new(title: "Ja")
|
c=Survey::Choice.new(title: "Ja")
|
||||||
c.save
|
c.save
|
||||||
|
|||||||
Reference in New Issue
Block a user