bhf 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/app/assets/images/bhf/pictos.png +0 -0
- data/app/assets/images/bhf/pictos_2x.png +0 -0
- data/app/assets/javascripts/bhf/application.js +153 -116
- data/app/assets/javascripts/bhf/classes/ArrayFields.js +1 -1
- data/app/assets/javascripts/bhf/classes/MultipleFields.js +2 -2
- data/app/assets/javascripts/bhf/classes/PlatformHelper.js +6 -11
- data/app/assets/javascripts/bhf/classes/{AjaxEdit.js → QuickEdit.js} +9 -9
- data/app/assets/javascripts/bhf/classes/{AjaxEditStack.js → QuickEditStack.js} +4 -20
- data/app/assets/javascripts/bhf/mootools-core-1.5.0-full-compat.js +1 -0
- data/app/assets/javascripts/bhf/mootools_ujs.js +11 -11
- data/app/assets/stylesheets/bhf/application.css.sass +86 -48
- data/app/controllers/bhf/application_controller.rb +8 -4
- data/app/controllers/bhf/embed_entries_controller.rb +2 -6
- data/app/controllers/bhf/entries_controller.rb +13 -16
- data/app/controllers/bhf/pages_controller.rb +14 -13
- data/app/helpers/bhf/application_helper.rb +6 -6
- data/app/helpers/bhf/entries_helper.rb +4 -2
- data/app/helpers/bhf/pages_helper.rb +0 -4
- data/app/views/bhf/entries/_form.haml +7 -4
- data/app/views/bhf/entries/show.haml +3 -4
- data/app/views/bhf/form/belongs_to/_radio.haml +28 -0
- data/app/views/bhf/form/belongs_to/_select.haml +21 -0
- data/app/views/bhf/form/belongs_to/_static.haml +1 -0
- data/app/views/bhf/{entries/form → form}/column/_array.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_boolean.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_date.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_hash.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_mappin.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_markdown.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_multiple_fields.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_number.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_paperclip.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_password.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_static.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_string.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_text.haml +0 -0
- data/app/views/bhf/{entries/form → form}/column/_wysiwyg.haml +0 -0
- data/app/views/bhf/form/embeds_many/_static.haml +26 -0
- data/app/views/bhf/form/embeds_one/_static.haml +2 -0
- data/app/views/bhf/form/has_and_belongs_to_many/_check_box.haml +22 -0
- data/app/views/bhf/form/has_and_belongs_to_many/_static.haml +1 -0
- data/app/views/bhf/form/has_many/_static.haml +26 -0
- data/app/views/bhf/form/has_one/_static.haml +2 -0
- data/app/views/bhf/helper/_definition_item.haml +1 -1
- data/app/views/bhf/helper/_frontend_edit.haml +1 -1
- data/app/views/bhf/pages/_platform.haml +39 -16
- data/app/views/bhf/{pages/macro → table}/belongs_to/_default.haml +1 -1
- data/app/views/bhf/table/column/_array.haml +1 -0
- data/app/views/bhf/table/column/_boolean.haml +1 -0
- data/app/views/bhf/table/column/_date.haml +1 -0
- data/app/views/bhf/table/column/_extern_link.haml +2 -0
- data/app/views/bhf/table/column/_file.haml +1 -0
- data/app/views/bhf/table/column/_hash.haml +1 -0
- data/app/views/bhf/table/column/_image.haml +1 -0
- data/app/views/bhf/table/column/_number.haml +1 -0
- data/app/views/bhf/table/column/_paperclip.haml +5 -0
- data/app/views/bhf/table/column/_primary_key.haml +1 -0
- data/app/views/bhf/table/column/_string.haml +1 -0
- data/app/views/bhf/table/column/_text.haml +1 -0
- data/app/views/bhf/table/embeds_many/_default.haml +1 -0
- data/app/views/bhf/table/embeds_one/_default.haml +1 -0
- data/app/views/bhf/table/has_and_belongs_to_many/_default.haml +1 -0
- data/app/views/bhf/table/has_many/_default.haml +2 -0
- data/app/views/bhf/{pages/macro → table}/has_one/_default.haml +1 -1
- data/bhf.gemspec +60 -59
- data/config/locales/de.yml +8 -8
- data/config/locales/en.yml +7 -7
- data/lib/bhf.rb +26 -21
- data/lib/bhf/action_view/form_builder.rb +36 -0
- data/lib/bhf/action_view/form_options.rb +30 -0
- data/lib/bhf/active_record/base.rb +58 -0
- data/lib/bhf/mongoid/document.rb +135 -137
- data/lib/bhf/platform/attribute/abstract.rb +52 -0
- data/lib/bhf/platform/attribute/column.rb +78 -0
- data/lib/bhf/platform/attribute/reflection.rb +68 -0
- data/lib/bhf/platform/base.rb +333 -0
- data/lib/bhf/{pagination.rb → platform/pagination.rb} +1 -1
- data/lib/bhf/{settings.rb → settings/base.rb} +14 -11
- data/lib/bhf/settings/platform.rb +20 -0
- data/lib/bhf/settings/yaml_parser.rb +84 -0
- data/lib/rails/generators/bhf/templates/initializer.rb +1 -1
- metadata +58 -57
- data/app/views/bhf/entries/form/belongs_to/_account_scope.haml +0 -2
- data/app/views/bhf/entries/form/belongs_to/_radio.haml +0 -8
- data/app/views/bhf/entries/form/belongs_to/_select.haml +0 -7
- data/app/views/bhf/entries/form/belongs_to/_static.haml +0 -1
- data/app/views/bhf/entries/form/embeds_many/_static.haml +0 -12
- data/app/views/bhf/entries/form/embeds_one/_static.haml +0 -12
- data/app/views/bhf/entries/form/has_and_belongs_to_many/_account_scope.haml +0 -2
- data/app/views/bhf/entries/form/has_and_belongs_to_many/_check_box.haml +0 -5
- data/app/views/bhf/entries/form/has_and_belongs_to_many/_static.haml +0 -1
- data/app/views/bhf/entries/form/has_many/_static.haml +0 -12
- data/app/views/bhf/entries/form/has_one/_account_scope.haml +0 -2
- data/app/views/bhf/entries/form/has_one/_static.haml +0 -9
- data/app/views/bhf/pages/macro/column/_array.haml +0 -1
- data/app/views/bhf/pages/macro/column/_boolean.haml +0 -1
- data/app/views/bhf/pages/macro/column/_date.haml +0 -1
- data/app/views/bhf/pages/macro/column/_extern_link.haml +0 -2
- data/app/views/bhf/pages/macro/column/_file.haml +0 -1
- data/app/views/bhf/pages/macro/column/_hash.haml +0 -1
- data/app/views/bhf/pages/macro/column/_image.haml +0 -2
- data/app/views/bhf/pages/macro/column/_number.haml +0 -1
- data/app/views/bhf/pages/macro/column/_paperclip.haml +0 -6
- data/app/views/bhf/pages/macro/column/_primary_key.haml +0 -1
- data/app/views/bhf/pages/macro/column/_string.haml +0 -1
- data/app/views/bhf/pages/macro/column/_text.haml +0 -1
- data/app/views/bhf/pages/macro/embeds_many/_default.haml +0 -1
- data/app/views/bhf/pages/macro/embeds_one/_default.haml +0 -1
- data/app/views/bhf/pages/macro/has_and_belongs_to_many/_default.haml +0 -1
- data/app/views/bhf/pages/macro/has_many/_default.haml +0 -2
- data/lib/bhf/active_record/active_record.rb +0 -59
- data/lib/bhf/data.rb +0 -169
- data/lib/bhf/form.rb +0 -36
- data/lib/bhf/platform.rb +0 -308
- data/lib/bhf/settings_parser.rb +0 -84
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Bhf::ActionView
|
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
|
3
|
+
include ActionView::Helpers::FormTagHelper
|
|
4
|
+
|
|
5
|
+
def error_label(name, message)
|
|
6
|
+
label name, "#{object.class.human_attribute_name(name)} #{message}"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def field_errors(field)
|
|
10
|
+
object.errors[field.to_sym]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def field_has_errors?(field)
|
|
14
|
+
field_errors(field).any?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil)
|
|
18
|
+
mm = :has_and_belongs_to_many
|
|
19
|
+
bhf_primary_key ||= obj.send(obj.class.bhf_primary_key).to_s
|
|
20
|
+
unless checked
|
|
21
|
+
checked = if params[mm] && params[mm][ref_name]
|
|
22
|
+
params[mm][ref_name][bhf_primary_key] != ''
|
|
23
|
+
else
|
|
24
|
+
object.send(ref_name).include?(obj)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
html = hidden_field_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", '', id: "hidden_#{mm}_#{ref_name}_#{bhf_primary_key}")
|
|
29
|
+
html = html+' '+check_box_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", bhf_primary_key, checked)
|
|
30
|
+
html = html+' '+label_tag("#{mm}_#{ref_name}_#{bhf_primary_key}", obj.to_bhf_s) unless hide_label
|
|
31
|
+
|
|
32
|
+
html
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Bhf::ActionView
|
|
2
|
+
module FormOptions
|
|
3
|
+
|
|
4
|
+
def option_groups_from_collection_for_select_with_html_attrs(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key, html_attrs)
|
|
5
|
+
collection.map do |group|
|
|
6
|
+
option_tags = options_from_collection_for_select_with_html_attrs(
|
|
7
|
+
group.send(group_method), option_key_method, option_value_method, selected_key, html_attrs)
|
|
8
|
+
|
|
9
|
+
content_tag(:optgroup, option_tags, label: group.send(group_label_method))
|
|
10
|
+
end.join.html_safe
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def options_from_collection_for_select_with_html_attrs(collection, value_method, text_method, selected, html_attrs)
|
|
14
|
+
options = collection.map do |element|
|
|
15
|
+
[
|
|
16
|
+
value_for_collection(element, text_method), value_for_collection(element, value_method), option_html_attributes(element),
|
|
17
|
+
html_attrs.call(element)
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
selected, disabled = extract_selected_and_disabled(selected)
|
|
21
|
+
select_deselect = {
|
|
22
|
+
selected: extract_values_from_collection(collection, value_method, selected),
|
|
23
|
+
disabled: extract_values_from_collection(collection, value_method, disabled)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
options_for_select(options, select_deselect)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Bhf::ActiveRecord
|
|
2
|
+
module Base
|
|
3
|
+
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
def to_bhf_s
|
|
7
|
+
return title if self.respond_to? :title
|
|
8
|
+
return name if self.respond_to? :name
|
|
9
|
+
return headline if self.respond_to? :headline
|
|
10
|
+
|
|
11
|
+
if self.respond_to?(:attributes)
|
|
12
|
+
return title if attributes['title']
|
|
13
|
+
return name if attributes['name']
|
|
14
|
+
klass_name = if self.class.respond_to?(:model_name)
|
|
15
|
+
self.class.model_name.human
|
|
16
|
+
else
|
|
17
|
+
self.class.to_s.humanize
|
|
18
|
+
end
|
|
19
|
+
return "#{klass_name} ID: #{send(self.class.primary_key)}" if attributes[self.class.primary_key]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
self.to_s.humanize
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module ClassMethods
|
|
26
|
+
def bhf_default_search(search_params)
|
|
27
|
+
return self if (search_term = search_params[:text]).blank?
|
|
28
|
+
where_statement = []
|
|
29
|
+
columns_hash.each_pair do |name, props|
|
|
30
|
+
is_number = search_term.to_i.to_s == search_term || search_term.to_f.to_s == search_term
|
|
31
|
+
|
|
32
|
+
if props.type == :string || props.type == :text
|
|
33
|
+
where_statement << "LOWER(#{name}) LIKE LOWER('%#{search_term}%')"
|
|
34
|
+
elsif props.type == :integer && is_number
|
|
35
|
+
where_statement << "#{name} = #{search_term.to_i}"
|
|
36
|
+
elsif props.type == :float && is_number
|
|
37
|
+
where_statement << "#{name} = #{search_term.to_f}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
where(where_statement.join(' OR '))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def bhf_attribute_method?(column_name)
|
|
45
|
+
column_names.include?(column_name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def bhf_primary_key
|
|
49
|
+
primary_key
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def bhf_embedded?
|
|
53
|
+
false
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/bhf/mongoid/document.rb
CHANGED
|
@@ -1,165 +1,163 @@
|
|
|
1
|
-
module Bhf
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
extend ActiveSupport::Concern
|
|
1
|
+
module Bhf::Mongoid
|
|
2
|
+
module Document
|
|
3
|
+
|
|
4
|
+
extend ActiveSupport::Concern
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
class Field
|
|
7
|
+
attr_reader :type, :name
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
9
|
+
def initialize(mongoid_field)
|
|
10
|
+
@name = mongoid_field.name
|
|
11
|
+
@type = mongoid_field.type.to_s.downcase.gsub('mongoid::', '').to_sym
|
|
12
|
+
@type = :primary_key if @type == :'bson::objectid'
|
|
15
13
|
end
|
|
14
|
+
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else
|
|
34
|
-
mongoid_field.macro
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_bhf_s
|
|
40
|
-
return title if self.respond_to? :title
|
|
41
|
-
return name if self.respond_to? :name
|
|
42
|
-
|
|
43
|
-
if self.respond_to?(:attributes)
|
|
44
|
-
return title if attributes['title']
|
|
45
|
-
return name if attributes['name']
|
|
46
|
-
klass_name = if self.class.respond_to?(:model_name)
|
|
47
|
-
self.class.model_name.human
|
|
16
|
+
class Reflection
|
|
17
|
+
attr_reader :name, :macro, :klass, :foreign_key
|
|
18
|
+
|
|
19
|
+
def initialize(mongoid_field)
|
|
20
|
+
@name = mongoid_field.name
|
|
21
|
+
@klass = mongoid_field.class_name.constantize
|
|
22
|
+
@foreign_key = mongoid_field.key
|
|
23
|
+
@macro = case mongoid_field.macro
|
|
24
|
+
when :references_and_referenced_in_many
|
|
25
|
+
:has_and_belongs_to_many
|
|
26
|
+
when :references_many
|
|
27
|
+
:has_many
|
|
28
|
+
when :references_one
|
|
29
|
+
:has_one
|
|
30
|
+
when :referenced_in
|
|
31
|
+
:belongs_to
|
|
48
32
|
else
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
return "#{klass_name} ID: #{send(self.class.bhf_primary_key)}" if attributes[self.class.bhf_primary_key]
|
|
33
|
+
mongoid_field.macro
|
|
52
34
|
end
|
|
53
|
-
|
|
54
|
-
self.to_s.humanize
|
|
55
35
|
end
|
|
36
|
+
end
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def reflections
|
|
69
|
-
c = {}
|
|
70
|
-
relations.each do |key, meta|
|
|
71
|
-
next if meta.macro == :embedded_in
|
|
72
|
-
c[key.to_sym] = Reflection.new(meta)
|
|
73
|
-
end
|
|
74
|
-
c
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def bhf_attribute_method?(column_name)
|
|
78
|
-
attribute_method?(column_name)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def bhf_primary_key
|
|
82
|
-
'_id'
|
|
38
|
+
def to_bhf_s
|
|
39
|
+
return title if self.respond_to? :title
|
|
40
|
+
return name if self.respond_to? :name
|
|
41
|
+
|
|
42
|
+
if self.respond_to?(:attributes)
|
|
43
|
+
return title if attributes['title']
|
|
44
|
+
return name if attributes['name']
|
|
45
|
+
klass_name = if self.class.respond_to?(:model_name)
|
|
46
|
+
self.class.model_name.human
|
|
47
|
+
else
|
|
48
|
+
self.class.to_s.humanize
|
|
83
49
|
end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
50
|
+
return "#{klass_name} ID: #{send(self.class.bhf_primary_key)}" if attributes[self.class.bhf_primary_key]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
self.to_s.humanize
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
module ClassMethods
|
|
57
|
+
def columns_hash
|
|
58
|
+
c = {}
|
|
59
|
+
fields.each_pair do |key, meta|
|
|
60
|
+
next if meta.options[:metadata]
|
|
61
|
+
next if key == '_type'
|
|
62
|
+
c[key] = Field.new(meta)
|
|
87
63
|
end
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
c
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def reflections
|
|
68
|
+
c = {}
|
|
69
|
+
relations.each do |key, meta|
|
|
70
|
+
next if meta.macro == :embedded_in
|
|
71
|
+
c[key.to_sym] = Reflection.new(meta)
|
|
91
72
|
end
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
73
|
+
c
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def bhf_attribute_method?(column_name)
|
|
77
|
+
attribute_method?(column_name)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def bhf_primary_key
|
|
81
|
+
'_id'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def order(a)
|
|
85
|
+
order_by(a)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def reorder(a)
|
|
89
|
+
order_by(a)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def bhf_default_search(search_params)
|
|
93
|
+
return self if (search_term = search_params[:text]).blank?
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
95
|
+
arr = []
|
|
96
|
+
columns_hash.each_pair do |column, props|
|
|
97
|
+
is_number = search_term.to_i.to_s == search_term || search_term.to_f.to_s == search_term
|
|
113
98
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return parent
|
|
123
|
-
end
|
|
99
|
+
if props.type == :primary_key
|
|
100
|
+
arr << {props.name.to_sym => search_term}
|
|
101
|
+
elsif props.type == :string || props.type == :text
|
|
102
|
+
arr << {props.name.to_sym => /#{search_term}/i}
|
|
103
|
+
elsif props.type == :integer && is_number
|
|
104
|
+
arr << {props.name.to_sym => search_term.to_i}
|
|
105
|
+
elsif props.type == :float && is_number
|
|
106
|
+
arr << {props.name.to_sym => search_term.to_f}
|
|
124
107
|
end
|
|
108
|
+
|
|
125
109
|
end
|
|
110
|
+
self.or(arr)
|
|
111
|
+
end
|
|
126
112
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
else
|
|
137
|
-
parent.send(key_name).build(params)
|
|
138
|
-
end
|
|
113
|
+
def get_embedded_parent(parent_id, &block)
|
|
114
|
+
relations.each do |key, meta|
|
|
115
|
+
next unless meta.macro == :embedded_in
|
|
116
|
+
parent = meta.class_name.constantize
|
|
117
|
+
parent = parent.find(parent_id) rescue nil
|
|
118
|
+
|
|
119
|
+
if parent
|
|
120
|
+
return block.call(parent, meta) if block_given?
|
|
121
|
+
return parent
|
|
139
122
|
end
|
|
140
123
|
end
|
|
124
|
+
end
|
|
141
125
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
relation.find(ref_id)
|
|
154
|
-
end
|
|
126
|
+
def bhf_new_embed(parent_id, params = nil)
|
|
127
|
+
get_embedded_parent parent_id do |parent, meta|
|
|
128
|
+
key_name = if meta.inverse_of?
|
|
129
|
+
meta.inverse_of
|
|
130
|
+
else
|
|
131
|
+
meta.inverse_foreign_key.pluralize
|
|
132
|
+
end.to_s
|
|
133
|
+
if parent.relations[key_name] and parent.relations[key_name].macro == :embeds_one
|
|
134
|
+
parent.send("build_#{key_name}", params)
|
|
135
|
+
else
|
|
136
|
+
parent.send(key_name).build(params)
|
|
155
137
|
end
|
|
156
138
|
end
|
|
139
|
+
end
|
|
157
140
|
|
|
158
|
-
|
|
159
|
-
|
|
141
|
+
def bhf_find_embed(parent_id, ref_id)
|
|
142
|
+
get_embedded_parent parent_id do |parent, meta|
|
|
143
|
+
key_name = if meta.inverse_of?
|
|
144
|
+
meta.inverse_of
|
|
145
|
+
else
|
|
146
|
+
meta.inverse_foreign_key.pluralize
|
|
147
|
+
end.to_s
|
|
148
|
+
relation = parent.send(key_name)
|
|
149
|
+
if parent.relations[key_name].macro == :embeds_one
|
|
150
|
+
relation
|
|
151
|
+
else
|
|
152
|
+
relation.find(ref_id)
|
|
153
|
+
end
|
|
160
154
|
end
|
|
161
155
|
end
|
|
162
156
|
|
|
157
|
+
def bhf_embedded?
|
|
158
|
+
embedded?
|
|
159
|
+
end
|
|
163
160
|
end
|
|
161
|
+
|
|
164
162
|
end
|
|
165
163
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Bhf::Platform::Attribute
|
|
2
|
+
class Abstract
|
|
3
|
+
|
|
4
|
+
attr_reader :name, :title, :info
|
|
5
|
+
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@name = options[:name]
|
|
8
|
+
@title = options[:title]
|
|
9
|
+
@info = options[:info]
|
|
10
|
+
|
|
11
|
+
@options_form_type = options[:form_type].to_sym if options[:form_type]
|
|
12
|
+
@options_display_type = options[:display_type].to_sym if options[:display_type]
|
|
13
|
+
@options_show_type = options[:show_type].to_sym if options[:show_type]
|
|
14
|
+
|
|
15
|
+
@link_platform_settings = options[:link] unless options[:link].blank?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def macro
|
|
19
|
+
:column
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def form_type
|
|
23
|
+
@options_form_type || @name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def display_type
|
|
27
|
+
@options_display_type || @name
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def show_type
|
|
31
|
+
@options_show_type || display_type || @name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def link
|
|
35
|
+
return unless @link_platform_settings
|
|
36
|
+
@link ||= Bhf::Platform::Base.new(@link_platform_settings)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def reflection
|
|
40
|
+
false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def db_name
|
|
44
|
+
name
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def reorderble
|
|
48
|
+
false
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|