Class: Interview::View
- Defined in:
- lib/interview/controls/view.rb
Instance Attribute Summary collapse
-
#assoc_method ⇒ Object
readonly
Returns the value of attribute assoc_method.
-
#assoc_object ⇒ Object
readonly
Returns the value of attribute assoc_object.
-
#auto_title_for ⇒ Object
Returns the value of attribute auto_title_for.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#object ⇒ Object
Returns the value of attribute object.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Control
Instance Method Summary collapse
- #build(b) ⇒ Object
- #nested_form ⇒ Object
-
#singular_title ⇒ Object
todo: Überdenken.
- #tooltip ⇒ Object
Methods inherited from Control
#ancestors, #build_child, #build_with_params, #find_attribute, #find_attribute!, #initialize, #set_attributes, #set_defaults
Constructor Details
This class inherits a constructor from Interview::Control
Instance Attribute Details
#assoc_method ⇒ Object (readonly)
Returns the value of attribute assoc_method.
5 6 7 |
# File 'lib/interview/controls/view.rb', line 5 def assoc_method @assoc_method end |
#assoc_object ⇒ Object (readonly)
Returns the value of attribute assoc_object.
5 6 7 |
# File 'lib/interview/controls/view.rb', line 5 def assoc_object @assoc_object end |
#auto_title_for ⇒ Object
Returns the value of attribute auto_title_for.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def auto_title_for @auto_title_for end |
#filter ⇒ Object
Returns the value of attribute filter.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def filter @filter end |
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def object @object end |
#objects ⇒ Object
Returns the value of attribute objects.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def objects @objects end |
#scope ⇒ Object
Returns the value of attribute scope.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def scope @scope end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/interview/controls/view.rb', line 4 def title @title end |
Instance Method Details
#build(b) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/interview/controls/view.rb', line 54 def build(b) tmp_object = @object tmp_objects = @objects if @object.is_a? String # if Object::const_defined?(@object.camelcase) # todo: Überdenken! # @object = @object.camelcase.constantize.new # else @assoc_object = @parent.find_attribute! :object @object = @object.split('.').inject(@assoc_object, :send) # end elsif @object.is_a? Proc @assoc_object = @parent.find_attribute! :object @object = @object.call(@assoc_object, self) elsif @object.is_a? Class @object = @object.new elsif @object.nil? @object = find_attribute! :object end if @objects.is_a? String @assoc_object = find_attribute! :object @assoc_method = @objects @objects = @assoc_method.split('.').inject(@assoc_object, :send) # @objects = @assoc_object.send @assoc_method @objects = @objects.send @scope if @scope @object = @objects.klass.new @scope = nil @filter = { "#{assoc_object.class.name.underscore}_id" => assoc_object.id } end if Object.const_defined? 'Gretel' and parent.nil? model_name = @object.class.lookup_ancestors.last.model_name case h.action_name when 'index' h. model_name.plural.to_sym when 'show' h. model_name.singular.to_sym, @object when 'new' h. "new_#{model_name.singular}".to_sym, @object when 'edit' h. "edit_#{model_name.singular}".to_sym, @object end end yield if block_given? @object = tmp_object @objects = tmp_objects end |
#nested_form ⇒ Object
7 8 9 |
# File 'lib/interview/controls/view.rb', line 7 def nested_form return siblings.find { |sib| sib.is_a? Interview::NestedForm } end |
#singular_title ⇒ Object
todo: Überdenken
31 32 33 34 35 36 37 38 39 |
# File 'lib/interview/controls/view.rb', line 31 def singular_title # todo: Überdenken if @auto_title_for if @assoc_object return @assoc_object.class.human_attribute_name(@assoc_method.to_s.singularize) else return @object.class.human_name end end end |
#tooltip ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/interview/controls/view.rb', line 41 def tooltip defaults = @object.class.lookup_ancestors.map do |klass| klass.name.underscore.to_sym end defaults << '' = { :scope => [@object.class.i18n_scope, :model_tooltips], :default => defaults } return I18n.translate(defaults.shift, ) # return h.t("activerecord.model_tooltips.#{@object.class.name.underscore}", default: '') # todo: tooltip von Elternelement verwenden, falls nicht vorhanden. end |