lolita 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GUIDELINE +4 -0
- data/README.rdoc +50 -0
- data/VERSION +1 -1
- data/app/controllers/lolita/rest_controller.rb +27 -11
- data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
- data/app/helpers/lolita_helper.rb +1 -1
- data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
- data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
- data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
- data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
- data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
- data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
- data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
- data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
- data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
- data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
- data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
- data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
- data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
- data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
- data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
- data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
- data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
- data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
- data/author +1 -1
- data/lib/lolita.rb +31 -12
- data/lib/lolita/adapter/active_record.rb +16 -5
- data/lib/lolita/adapter/mongoid.rb +2 -2
- data/lib/lolita/base_configuration.rb +44 -2
- data/lib/lolita/builder.rb +31 -14
- data/lib/lolita/configuration/column.rb +92 -86
- data/lib/lolita/configuration/columns.rb +65 -65
- data/lib/lolita/configuration/factory.rb +8 -8
- data/lib/lolita/configuration/field.rb +156 -100
- data/lib/lolita/configuration/field/array.rb +74 -0
- data/lib/lolita/configuration/field/big_decimal.rb +12 -0
- data/lib/lolita/configuration/field/boolean.rb +7 -5
- data/lib/lolita/configuration/field/date.rb +13 -0
- data/lib/lolita/configuration/field/integer.rb +7 -5
- data/lib/lolita/configuration/field/string.rb +8 -6
- data/lib/lolita/configuration/field/time.rb +13 -0
- data/lib/lolita/configuration/fields.rb +36 -0
- data/lib/lolita/configuration/filter.rb +63 -0
- data/lib/lolita/configuration/list.rb +101 -91
- data/lib/lolita/configuration/page.rb +1 -0
- data/lib/lolita/configuration/tab.rb +137 -131
- data/lib/lolita/configuration/tab/content.rb +14 -12
- data/lib/lolita/configuration/tab/default.rb +15 -13
- data/lib/lolita/configuration/tabs.rb +2 -2
- data/lib/lolita/controllers/component_helpers.rb +26 -14
- data/lib/lolita/controllers/internal_helpers.rb +14 -0
- data/lib/lolita/controllers/url_helpers.rb +47 -10
- data/lib/lolita/dbi/base.rb +50 -50
- data/lib/lolita/errors.rb +2 -2
- data/lib/lolita/hooks.rb +298 -0
- data/lib/lolita/hooks/named_hook.rb +122 -0
- data/lib/lolita/lazy_loader.rb +46 -46
- data/lib/lolita/mapping.rb +3 -2
- data/lib/lolita/navigation.rb +48 -0
- data/lib/lolita/observed_array.rb +7 -0
- data/lib/lolita/rails/routes.rb +29 -3
- data/lolita.gemspec +65 -48
- data/public/javascripts/lolita/tab.js +5 -0
- data/public/javascripts/rails.js +137 -137
- data/public/stylesheets/lolita/style.css +3 -1
- data/spec/builder_spec.rb +42 -0
- data/spec/configuration/field_spec.rb +29 -18
- data/spec/configuration/filter_spec.rb +60 -0
- data/spec/configuration/tab_spec.rb +28 -20
- data/spec/configuration/tabs_spec.rb +8 -4
- data/spec/controllers/lolita_rest_spec.rb +15 -0
- data/spec/hooks_spec.rb +191 -0
- data/spec/lolita_spec.rb +6 -4
- data/spec/navigation/tree_spec.rb +59 -0
- data/spec/rails_app/app/mongoid/post.rb +2 -0
- data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/spec/rails_app/config/application.rb +1 -0
- data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
- data/spec/simple_spec_helper.rb +1 -0
- data/spec/spec_helper.rb +1 -2
- metadata +66 -49
- data/README.md +0 -5
- data/app/helpers/components/lolita/list_component.rb +0 -9
- data/app/views/components/lolita/field/_collection.html.erb +0 -5
- data/app/views/components/lolita/field/_date.html.erb +0 -1
- data/app/views/components/lolita/field/_datetime.html.erb +0 -1
- data/app/views/components/lolita/field/_display.html.erb +0 -6
- data/app/views/components/lolita/field/_integer.html.erb +0 -1
- data/app/views/components/lolita/field/_label.html.erb +0 -1
- data/app/views/components/lolita/field/_select.html.erb +0 -1
- data/app/views/components/lolita/field/_text.html.erb +0 -27
- data/app/views/components/lolita/list/_body.html.erb +0 -5
- data/app/views/components/lolita/list/_display.html.erb +0 -11
- data/app/views/components/lolita/list/_header.html.erb +0 -9
- data/app/views/components/lolita/list/_paginator.html.erb +0 -4
- data/app/views/components/lolita/list/_row.html.erb +0 -7
- data/app/views/components/lolita/tab/_content.html.erb +0 -1
- data/app/views/components/lolita/tab/_default.html.erb +0 -11
- data/app/views/components/lolita/tab/_display.html.erb +0 -7
- data/app/views/components/lolita/tab/_fields.html.erb +0 -7
- data/lib/lolita/configuration/field/collection.rb +0 -71
- data/lib/lolita/configuration/field/datetime.rb +0 -10
- data/lib/lolita/configuration/field/disabled.rb +0 -10
- data/lib/lolita/configuration/field/password.rb +0 -10
- data/lib/lolita/configuration/field/text.rb +0 -10
- data/lib/lolita/hooks/base.rb +0 -58
- data/lib/lolita/hooks/component.rb +0 -15
- data/lib/lolita/hooks/hooks.rb +0 -15
@@ -1,11 +1,13 @@
|
|
1
1
|
module Lolita
|
2
2
|
module Configuration
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Field
|
4
|
+
class String < Lolita::Configuration::Field::Base
|
5
|
+
lolita_accessor :simple, :rows
|
6
|
+
def initialize *args, &block
|
7
|
+
@type="string"
|
8
|
+
super
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Lolita
|
2
|
+
module Configuration
|
3
|
+
# Lolita::Configuration::Tabs is container class that holds all
|
4
|
+
# tabs for each lolita instance.
|
5
|
+
# Also it has some useful methods.
|
6
|
+
|
7
|
+
class Fields
|
8
|
+
include Enumerable
|
9
|
+
include Lolita::ObservedArray
|
10
|
+
|
11
|
+
def initialize *args,&block
|
12
|
+
@fields=[]
|
13
|
+
self.instance_eval(&block) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear
|
17
|
+
@fields=[]
|
18
|
+
end
|
19
|
+
|
20
|
+
def by_name(name)
|
21
|
+
@fields.detect{|field| (field.name==name.to_sym || field.name=="#{name}_id".to_sym) }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def collection_variable
|
27
|
+
@fields
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_element(element,&block)
|
31
|
+
element
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Lolita
|
2
|
+
module Configuration
|
3
|
+
class Filter
|
4
|
+
include Lolita::Builder
|
5
|
+
attr_reader :dbi
|
6
|
+
|
7
|
+
def initialize(dbi,*args,&block)
|
8
|
+
@dbi = dbi
|
9
|
+
@fields=Lolita::Configuration::Fields.new
|
10
|
+
set_attributes(*args)
|
11
|
+
self.instance_eval(&block) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def field *args, &block
|
15
|
+
field=Lolita::Configuration::Field.add(self.dbi,*args,&block)
|
16
|
+
@fields<<field
|
17
|
+
field
|
18
|
+
end
|
19
|
+
|
20
|
+
# Set all fields in tab. Accept <code>fields</code> as Array.
|
21
|
+
# Each array element can be Lolita::Configuration::Field object or
|
22
|
+
# Hash, that will be passed to #field method.
|
23
|
+
def fields=(fields)
|
24
|
+
if fields.is_a?(Array)
|
25
|
+
fields.each{|field_attr|
|
26
|
+
if field_attr.is_a?(Lolita::Configuration::Field)
|
27
|
+
@fields<<field_attr
|
28
|
+
else
|
29
|
+
self.field(field_attr)
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def fields(*args, &block)
|
36
|
+
unless args.empty?
|
37
|
+
args.each do |field_name|
|
38
|
+
f = field(field_name)
|
39
|
+
f.instance_eval(&block) if block_given?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if @fields.empty?
|
43
|
+
field :search
|
44
|
+
end
|
45
|
+
@fields
|
46
|
+
end
|
47
|
+
|
48
|
+
# Used to set attributes if block not given.
|
49
|
+
def set_attributes(*args)
|
50
|
+
if args && args[0]
|
51
|
+
if args[0].is_a?(Hash)
|
52
|
+
args[0].each{|m,value|
|
53
|
+
self.send("#{m}=".to_sym,value)
|
54
|
+
}
|
55
|
+
else
|
56
|
+
fields *args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,92 +1,102 @@
|
|
1
|
-
module Lolita
|
2
|
-
module Configuration
|
3
|
-
class List
|
4
|
-
include Lolita::Builder
|
5
|
-
|
6
|
-
attr_reader :dbi,:initialized_attributes
|
7
|
-
|
8
|
-
def initialize(*args,&block)
|
9
|
-
if args && args[0].is_a?(Lolita::DBI::Base)
|
10
|
-
@dbi=args.shift
|
11
|
-
end
|
12
|
-
@columns=Lolita::Configuration::Columns.new(self)
|
13
|
-
@set_attributes=[]
|
14
|
-
set_attributes(*args)
|
15
|
-
self.instance_eval(&block) if block_given?
|
16
|
-
self.generate!()
|
17
|
-
end
|
18
|
-
|
19
|
-
# Look for methods in Page class. Load @page on demand and call method on it.
|
20
|
-
def method_missing(method_name,*args,&block)
|
21
|
-
if Lolita::Configuration::Page.public_instance_methods.include?(method_name.to_sym)
|
22
|
-
@page||=Lolita::Configuration::Page.new(@dbi)
|
23
|
-
@page.send(method_name.to_sym,*args,&block)
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
# Set columns. Allowed classes are Lolita::Configuration::Columns or
|
29
|
-
# Array.
|
30
|
-
def columns=(value)
|
31
|
-
set_attribute(:columns)
|
32
|
-
if value.is_a?(Lolita::Configuration::Columns)
|
33
|
-
@columns=value
|
34
|
-
elsif value.is_a?(Array)
|
35
|
-
value.each{|el| @columns<<el}
|
36
|
-
else
|
37
|
-
raise ArgumentError.new("Columns must bet Array or Lolita::Configuration::Columns.")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Get list columns (also block setter)
|
42
|
-
def columns(*args)
|
43
|
-
if args && !args.empty?
|
44
|
-
self.columns=args
|
45
|
-
end
|
46
|
-
self.generate!
|
47
|
-
@columns
|
48
|
-
end
|
49
|
-
|
50
|
-
# Generate uninitialized attributes
|
51
|
-
def generate!()
|
52
|
-
@columns.generate! unless is_set?(:columns)
|
53
|
-
end
|
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
|
-
end
|
79
|
-
|
80
|
-
#
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
|
1
|
+
module Lolita
|
2
|
+
module Configuration
|
3
|
+
class List
|
4
|
+
include Lolita::Builder
|
5
|
+
|
6
|
+
attr_reader :dbi,:initialized_attributes
|
7
|
+
|
8
|
+
def initialize(*args,&block)
|
9
|
+
if args && args[0].is_a?(Lolita::DBI::Base)
|
10
|
+
@dbi=args.shift
|
11
|
+
end
|
12
|
+
@columns=Lolita::Configuration::Columns.new(self)
|
13
|
+
@set_attributes=[]
|
14
|
+
set_attributes(*args)
|
15
|
+
self.instance_eval(&block) if block_given?
|
16
|
+
self.generate!()
|
17
|
+
end
|
18
|
+
|
19
|
+
# Look for methods in Page class. Load @page on demand and call method on it.
|
20
|
+
def method_missing(method_name,*args,&block)
|
21
|
+
if Lolita::Configuration::Page.public_instance_methods.include?(method_name.to_sym)
|
22
|
+
@page||=Lolita::Configuration::Page.new(@dbi)
|
23
|
+
@page.send(method_name.to_sym,*args,&block)
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# Set columns. Allowed classes are Lolita::Configuration::Columns or
|
29
|
+
# Array.
|
30
|
+
def columns=(value)
|
31
|
+
set_attribute(:columns)
|
32
|
+
if value.is_a?(Lolita::Configuration::Columns)
|
33
|
+
@columns=value
|
34
|
+
elsif value.is_a?(Array)
|
35
|
+
value.each{|el| @columns<<el}
|
36
|
+
else
|
37
|
+
raise ArgumentError.new("Columns must bet Array or Lolita::Configuration::Columns.")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get list columns (also block setter)
|
42
|
+
def columns(*args)
|
43
|
+
if args && !args.empty?
|
44
|
+
self.columns=args
|
45
|
+
end
|
46
|
+
self.generate!
|
47
|
+
@columns
|
48
|
+
end
|
49
|
+
|
50
|
+
# Generate uninitialized attributes
|
51
|
+
def generate!()
|
52
|
+
@columns.generate! unless is_set?(:columns)
|
53
|
+
end
|
54
|
+
|
55
|
+
# checks if filter defined
|
56
|
+
def filter?
|
57
|
+
@filter.is_a?(Lolita::Configuration::Filter)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Adds filter
|
61
|
+
def filter(*args,&block)
|
62
|
+
@filter ||= Lolita::Configuration::Filter.new(self.dbi,*args,&block)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Used to set attributes if block not given.
|
68
|
+
def set_attributes(*args)
|
69
|
+
if args && args[0]
|
70
|
+
if args[0].is_a?(Hash)
|
71
|
+
args[0].each{|m,value|
|
72
|
+
self.send("#{m}=".to_sym,value)
|
73
|
+
}
|
74
|
+
else
|
75
|
+
raise ArgumentError.new("Lolita::Configuration::List arguments must be Hash instead of #{args[0].class}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Mark attribute as set.
|
81
|
+
def set_attribute(var)
|
82
|
+
@set_attributes<<var unless is_set?(var)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Determine if attribute is set and don't need to generate it.
|
86
|
+
def is_set?(var)
|
87
|
+
@set_attributes.include?(var)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Block setter for columns
|
91
|
+
def column(*args,&block)
|
92
|
+
set_attribute(:columns)
|
93
|
+
if block_given?
|
94
|
+
@columns<<block
|
95
|
+
else
|
96
|
+
@columns<<args[0]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
92
102
|
end
|
@@ -17,156 +17,162 @@ module Lolita
|
|
17
17
|
# lolita do
|
18
18
|
# tab(:files)
|
19
19
|
# end
|
20
|
-
|
21
|
-
|
20
|
+
module Tab
|
21
|
+
class Base
|
22
|
+
include Lolita::Builder
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# For different types there are different builders(cells)
|
25
|
+
@@default_tab_type=:default
|
26
|
+
@@available_types=[:content]
|
27
|
+
|
28
|
+
lolita_accessor :title,:name,:type
|
29
|
+
attr_accessor :dbi,:current_fieldset,:current_dbi
|
30
|
+
attr_reader :field_sets,:nested_form
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
# To create new tab the following parametrs need to be provided.
|
33
|
+
# * <tt>dbi</tt> Lolita::DBI::Base object, that represents database.
|
34
|
+
# * <tt>*args</tt> See #set_attributes, for how these args are processed.
|
35
|
+
# * <tt>&block</tt> Block can be passed, anything in block will be evaled for current instance.
|
36
|
+
def initialize dbi,*args,&block
|
37
|
+
@fields=Lolita::Configuration::Fields.new
|
38
|
+
@field_sets=[]
|
39
|
+
self.dbi=dbi
|
40
|
+
self.current_dbi=dbi
|
41
|
+
self.set_attributes(*args)
|
42
|
+
self.instance_eval(&block) if block_given?
|
43
|
+
validate
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
|
47
|
+
# Field setter method, accpet <i>*args</i> and <i>&block</i> to be passed.
|
48
|
+
# For details how to pass args and block see Lolita::Configuration::Field.
|
49
|
+
# Return field itself.
|
50
|
+
def field *args, &block
|
51
|
+
field=Lolita::Configuration::Field.add(self.current_dbi,*args,&block)
|
52
|
+
field.field_set=current_fieldset
|
53
|
+
if self.current_dbi!=self.dbi
|
54
|
+
field.nested_in=self.dbi
|
55
|
+
end
|
56
|
+
@fields<<field
|
57
|
+
field
|
54
58
|
end
|
55
|
-
@fields<<field
|
56
|
-
field
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
# Return all fields in tab.
|
61
|
+
def fields
|
62
|
+
@fields
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
# Set all fields in tab. Accept <code>fields</code> as Array.
|
66
|
+
# Each array element can be Lolita::Configuration::Field object or
|
67
|
+
# Hash, that will be passed to #field method.
|
68
|
+
def fields=(fields)
|
69
|
+
@fields=Lolita::Configuration::Fields.new
|
70
|
+
if fields.is_a?(Array)
|
71
|
+
fields.each{|field_attr|
|
72
|
+
if field_attr.is_a?(Lolita::Configuration::Field)
|
73
|
+
@fields<<field_attr
|
74
|
+
else
|
75
|
+
self.field(field_attr)
|
76
|
+
end
|
77
|
+
}
|
78
|
+
end
|
77
79
|
end
|
78
|
-
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
# Create fields for tab from database.
|
82
|
+
# See Lolita::Adapter classes for use of DB field method.
|
83
|
+
def default_fields
|
84
|
+
self.current_dbi.fields.each{|db_field|
|
85
|
+
self.field(db_field)
|
86
|
+
}
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
# Add tab nested fields for <em>class_or_name</em> and <em>&block</em>
|
90
|
+
# that will be evaluted in current tab instance.
|
91
|
+
def nested_fields_for class_or_name,&block
|
92
|
+
current_class=get_class(class_or_name)
|
93
|
+
self.current_dbi=Lolita::DBI::Base.new(current_class)
|
94
|
+
self.instance_eval(&block)
|
95
|
+
self.current_dbi=self.dbi
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
# Return nested field for given <em>class_or_name</em>
|
99
|
+
def nested_fields_of class_or_name
|
100
|
+
current_class=get_class(class_or_name)
|
101
|
+
self.fields.select{|field|
|
102
|
+
field.nested_in?(@dbi) && field.dbi.klass==current_class
|
103
|
+
}
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
106
|
+
# Create new field_set for current tab with given _name_ and <em>&block</em>
|
107
|
+
# that will be evaluted in current tab instance.
|
108
|
+
def field_set name,&block
|
109
|
+
field_set=Lolita::Configuration::FieldSet.new(self,name)
|
110
|
+
self.current_fieldset=field_set
|
111
|
+
@field_sets<<field_set
|
112
|
+
self.instance_eval(&block)
|
113
|
+
self.current_fieldset=nil
|
114
|
+
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
116
|
+
def fields_with_field_set
|
117
|
+
used_fieldsets=[]
|
118
|
+
self.fields.each{|field|
|
119
|
+
if !field.field_set || (!used_fieldsets.include?(field.field_set))
|
120
|
+
if field.field_set
|
121
|
+
yield field.field_set.fields,field.field_set
|
122
|
+
used_fieldsets<<field.field_set
|
123
|
+
else
|
124
|
+
yield field,nil
|
125
|
+
end
|
124
126
|
end
|
127
|
+
}
|
128
|
+
end
|
129
|
+
# tab.field do
|
130
|
+
# tab.fields_with_fieldset do |field,fieldset|
|
131
|
+
# =field
|
132
|
+
# end
|
133
|
+
|
134
|
+
|
135
|
+
# Set attributes from given <em>*args</em>.
|
136
|
+
# First element of args is used as <i>type</i> other interpreted as options.
|
137
|
+
# Every Hash key is used as setter method, and value as method value.
|
138
|
+
# ====Example
|
139
|
+
# set_attributes(:content,:field=>{:name=>"My Field"})
|
140
|
+
# set_attributes(:field=>{:name=>"My Field"})
|
141
|
+
def set_attributes *args
|
142
|
+
if args
|
143
|
+
options=args.extract_options!
|
144
|
+
self.type=args.first if args.first.is_a?(Symbol)
|
145
|
+
options.each{|method,options|
|
146
|
+
self.send(:"#{method}=",options)
|
147
|
+
}
|
125
148
|
end
|
126
|
-
|
127
|
-
|
128
|
-
# tab.field do
|
129
|
-
# tab.fields_with_fieldset do |field,fieldset|
|
130
|
-
# =field
|
131
|
-
# end
|
149
|
+
|
150
|
+
end
|
132
151
|
|
152
|
+
private
|
133
153
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
# set_attributes(:content,:field=>{:name=>"My Field"})
|
139
|
-
# set_attributes(:field=>{:name=>"My Field"})
|
140
|
-
def set_attributes *args
|
141
|
-
if args
|
142
|
-
options=args.extract_options!
|
143
|
-
self.type=args.first if args.first.is_a?(Symbol)
|
144
|
-
options.each{|method,options|
|
145
|
-
self.send(:"#{method}=",options)
|
146
|
-
}
|
154
|
+
def set_default_attributes
|
155
|
+
@type=@@default_tab_type unless @type
|
156
|
+
@name="tab_#{self.__id__}" unless @name
|
157
|
+
@title=@type.to_s.humanize unless @title
|
147
158
|
end
|
148
159
|
|
149
|
-
|
150
|
-
|
151
|
-
|
160
|
+
def get_class(str_or_sym_or_class)
|
161
|
+
str_or_sym_or_class.is_a?(Class) ? str_or_sym_or_class : str_or_sym_or_class.to_s.camelize.constantize
|
162
|
+
end
|
163
|
+
|
164
|
+
def validate
|
165
|
+
set_default_attributes
|
166
|
+
end
|
152
167
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
def validate
|
164
|
-
set_default_attributes
|
165
|
-
end
|
166
|
-
|
167
|
-
class << self
|
168
|
-
def default_types
|
169
|
-
@@available_types
|
168
|
+
def builder_local_variable_name
|
169
|
+
:tab
|
170
|
+
end
|
171
|
+
|
172
|
+
class << self
|
173
|
+
def default_types
|
174
|
+
@@available_types
|
175
|
+
end
|
170
176
|
end
|
171
177
|
end
|
172
178
|
end
|