AutoCommit Fre Aug 7 00:03:02 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-07 00:03:02 +02:00
parent 73f364e620
commit c6222cdc23
2 changed files with 28 additions and 6 deletions

View File

@@ -10,4 +10,11 @@ class Survey::Choice < ActiveRecord::Base
def html def html
content_tag("i","", class: self.icon ) + self.text content_tag("i","", class: self.icon ) + self.text
end 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

View File

@@ -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