lolita 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +36 -36
- data/Gemfile +29 -29
- data/README.md +147 -147
- data/Rakefile +6 -6
- data/app/assets/javascripts/lolita/application.js +6 -6
- data/app/assets/javascripts/lolita/tab.js +100 -100
- data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
- data/app/assets/stylesheets/lolita/PIE.htc +81 -81
- data/app/assets/stylesheets/lolita/application.css +6 -6
- data/app/assets/stylesheets/lolita/default.css.erb +169 -169
- data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
- data/app/assets/stylesheets/lolita/style.css.erb +553 -553
- data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
- data/app/helpers/components/lolita/configuration_component.rb +20 -20
- data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
- data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
- data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
- data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
- data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
- data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +7 -7
- data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
- data/app/views/components/lolita/configuration/tab/_display.html.haml +3 -3
- data/app/views/components/lolita/configuration/tabs/_form.html.haml +6 -6
- data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_gap.html.erb +8 -8
- data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_page.html.erb +12 -12
- data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
- data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
- data/app/views/lolita/info/index.html.erb +232 -232
- data/author +1 -1
- data/config/routes.rb +6 -6
- data/lib/generators/lolita/install_generator.rb +19 -19
- data/lib/generators/lolita/uninstall_generator.rb +70 -70
- data/lib/generators/templates/lolita.rb +13 -13
- data/lib/lolita.rb +140 -140
- data/lib/lolita/adapter/abstract_adapter.rb +15 -15
- data/lib/lolita/adapter/active_record.rb +227 -227
- data/lib/lolita/adapter/common_helper.rb +221 -221
- data/lib/lolita/adapter/field_helper.rb +18 -18
- data/lib/lolita/adapter/mongoid.rb +241 -241
- data/lib/lolita/components/base.rb +11 -11
- data/lib/lolita/configuration.rb +60 -60
- data/lib/lolita/configuration/column.rb +181 -181
- data/lib/lolita/configuration/field/big_decimal.rb +12 -12
- data/lib/lolita/configuration/field/boolean.rb +12 -12
- data/lib/lolita/configuration/field/date.rb +12 -12
- data/lib/lolita/configuration/field/hidden.rb +12 -12
- data/lib/lolita/configuration/field/integer.rb +11 -11
- data/lib/lolita/configuration/field/string.rb +16 -16
- data/lib/lolita/configuration/field/time.rb +13 -13
- data/lib/lolita/configuration/field_set.rb +25 -25
- data/lib/lolita/configuration/filter.rb +116 -116
- data/lib/lolita/configuration/list.rb +200 -200
- data/lib/lolita/configuration/search.rb +104 -104
- data/lib/lolita/controllers/component_helpers.rb +156 -156
- data/lib/lolita/controllers/internal_helpers.rb +71 -71
- data/lib/lolita/controllers/url_helpers.rb +7 -7
- data/lib/lolita/dbi/base.rb +56 -56
- data/lib/lolita/hooks/named_hook.rb +125 -125
- data/lib/lolita/lazy_loader.rb +54 -54
- data/lib/lolita/navigation/tree.rb +132 -132
- data/lib/lolita/rails/engine.rb +23 -23
- data/lib/lolita/rails/routes.rb +129 -129
- data/lib/lolita/ruby_ext/accessors.rb +26 -26
- data/lib/lolita/search/simple.rb +75 -75
- data/lib/lolita/support/formatter.rb +62 -62
- data/lib/lolita/support/formatter/rails.rb +56 -56
- data/lib/lolita/system_configuration/base.rb +178 -178
- data/lib/lolita/test/matchers.rb +77 -77
- data/lib/lolita/version.rb +30 -30
- data/lib/tasks/tinymce-assets.rake +6 -6
- data/lolita.gemspec +34 -34
- data/spec/adapter/common_helper_spec.rb +95 -95
- data/spec/adapter_helper.rb +42 -42
- data/spec/builder_spec.rb +120 -120
- data/spec/configuration/base_spec.rb +22 -22
- data/spec/configuration/field_spec.rb +118 -118
- data/spec/configuration/filter_spec.rb +131 -131
- data/spec/configuration/tab_spec.rb +187 -187
- data/spec/configuration/tabs_spec.rb +120 -120
- data/spec/generators/lolita/install_generator_spec.rb +54 -54
- data/spec/generators/lolita/uninstall_generator_spec.rb +48 -48
- data/spec/orm/mongoid.rb +12 -12
- data/spec/rails_app/app/controllers/application_controller.rb +3 -3
- data/spec/rails_app/app/helpers/application_helper.rb +3 -3
- data/spec/rails_app/app/mongoid/address.rb +7 -7
- data/spec/rails_app/app/mongoid/category.rb +18 -18
- data/spec/rails_app/app/mongoid/comment.rb +5 -5
- data/spec/rails_app/app/mongoid/post.rb +30 -30
- data/spec/rails_app/app/mongoid/preference.rb +5 -5
- data/spec/rails_app/app/mongoid/profile.rb +13 -13
- data/spec/rails_app/app/mongoid/tag.rb +3 -3
- data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
- data/spec/rails_app/config/application.rb +33 -33
- data/spec/rails_app/config/boot.rb +7 -7
- data/spec/rails_app/config/environment.rb +5 -5
- data/spec/rails_app/config/environments/development.rb +23 -23
- data/spec/rails_app/config/environments/production.rb +37 -37
- data/spec/rails_app/config/environments/test.rb +37 -37
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/rails_app/config/initializers/inflections.rb +2 -2
- data/spec/rails_app/config/initializers/secret_token.rb +1 -1
- data/spec/rails_app/config/routes.rb +2 -2
- data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
- data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
- data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
- data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
- data/spec/rails_app/public/javascripts/rails.js +137 -137
- data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
- data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
- data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
- data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
- data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
- data/spec/spec_helper.rb +51 -51
- data/vendor/assets/javascripts/application_vendor_lolita.js +4 -4
- data/vendor/assets/javascripts/jquery-numeric.js +279 -279
- data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
- data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
- metadata +4 -3
@@ -1,201 +1,201 @@
|
|
1
|
-
module Lolita
|
2
|
-
module Configuration
|
3
|
-
class List < Lolita::Configuration::Base
|
4
|
-
include Observable
|
5
|
-
include Lolita::Builder
|
6
|
-
|
7
|
-
attr_reader :initialized_attributes,:page_criteria
|
8
|
-
attr_writer :title
|
9
|
-
|
10
|
-
lolita_accessor :per_page, :pagination_method, :actions
|
11
|
-
|
12
|
-
def initialize(dbp,*args,&block)
|
13
|
-
set_and_validate_dbp(dbp)
|
14
|
-
set_list_attributes do
|
15
|
-
set_attributes(*args)
|
16
|
-
self.instance_eval(&block) if block_given?
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def title(new_title = nil)
|
21
|
-
if new_title
|
22
|
-
@title = new_title
|
23
|
-
end
|
24
|
-
Lolita::Utils.dynamic_string(@title, :default => dbp.klass.lolita_model_name.human(:count => 2))
|
25
|
-
end
|
26
|
-
|
27
|
-
def action name, options = {}, &block
|
28
|
-
@actions << decide_and_create_action(name, options, &block)
|
29
|
-
@actions.flatten!
|
30
|
-
end
|
31
|
-
|
32
|
-
# Allow to crate nested list for list
|
33
|
-
def list(*args, &block)
|
34
|
-
if args && args.any? || block_given?
|
35
|
-
association = dbi.associations[args[0].to_s.to_sym]
|
36
|
-
association_dbi = association && Lolita::DBI::Base.create(association.klass)
|
37
|
-
raise Lolita::UnknownDBPError.new("No DBI specified for list sublist") unless association_dbi
|
38
|
-
Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::NestedList,association_dbi, self, :association_name => association.name,&block)
|
39
|
-
else
|
40
|
-
@list
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# For details see Lolita::Configuration::Search
|
45
|
-
def search *args, &block
|
46
|
-
if (args && args.any?) || block_given?
|
47
|
-
@search = Lolita::Configuration::Search.new(self.dbi,*args,&block)
|
48
|
-
add_observer(@search)
|
49
|
-
end
|
50
|
-
@search
|
51
|
-
end
|
52
|
-
|
53
|
-
# Return page for list display. Method requires two arguments:
|
54
|
-
# * <tt>current_page</tt> - number of current page
|
55
|
-
# * <tt>request (optional) </tt> - request that is passed to adapter that passes this to model when #pagination_method is defined
|
56
|
-
def paginate(current_page, request = nil)
|
57
|
-
changed
|
58
|
-
@page_criteria = dbi.paginate(current_page,@per_page,:request => request, :pagination_method => @pagination_method)
|
59
|
-
notify_observers(:paginate,self,request)
|
60
|
-
@page_criteria
|
61
|
-
end
|
62
|
-
|
63
|
-
# Set columns. Allowed classes are Lolita::Configuration::Columns or
|
64
|
-
# Array.
|
65
|
-
def columns=(possible_columns)
|
66
|
-
if possible_columns.is_a?(Lolita::Configuration::Columns)
|
67
|
-
@columns = possible_columns
|
68
|
-
@columns.parent = self
|
69
|
-
elsif possible_columns.respond_to?(:each)
|
70
|
-
possible_columns.each{|possible_column|
|
71
|
-
column(possible_column)
|
72
|
-
}
|
73
|
-
else
|
74
|
-
raise ArgumentError.new("Accepts only Enumerable or Lolita::Configuration::Columns.")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Define columns for list. On first read if there is no columns they will be created.
|
79
|
-
def columns(*args,&block)
|
80
|
-
if (args && args.any?) || block_given? || !@columns
|
81
|
-
self.columns = Lolita::Configuration::Columns.new(dbi,*args,&block)
|
82
|
-
end
|
83
|
-
@columns
|
84
|
-
end
|
85
|
-
|
86
|
-
# Block setter for columns
|
87
|
-
def column(*args,&block)
|
88
|
-
columns.column(*args, &block)
|
89
|
-
end
|
90
|
-
|
91
|
-
# checks if filter defined
|
92
|
-
def filter?
|
93
|
-
@filter.is_a?(Lolita::Configuration::Filter)
|
94
|
-
end
|
95
|
-
|
96
|
-
# Create or return filter
|
97
|
-
def filter(*args,&block)
|
98
|
-
if args && args.any? || block_given?
|
99
|
-
@filter = Lolita::Configuration::Filter.new(dbi,*args,&block)
|
100
|
-
add_observer(@filter)
|
101
|
-
end
|
102
|
-
@filter
|
103
|
-
end
|
104
|
-
|
105
|
-
def by_path(path)
|
106
|
-
path = path.dup
|
107
|
-
object = self
|
108
|
-
while path.any?
|
109
|
-
part = path.pop.match(/(l|c)_(\w+)/)
|
110
|
-
object = if part[1] == "l"
|
111
|
-
object.list
|
112
|
-
else
|
113
|
-
object.columns.by_name(part[2]).list
|
114
|
-
end
|
115
|
-
end
|
116
|
-
object
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def set_list_attributes
|
122
|
-
init_default_attributes
|
123
|
-
yield if block_given?
|
124
|
-
create_default_actions
|
125
|
-
end
|
126
|
-
|
127
|
-
def init_default_attributes
|
128
|
-
initialize_actions
|
129
|
-
@per_page = Lolita.application.per_page || 10
|
130
|
-
end
|
131
|
-
|
132
|
-
def create_default_actions
|
133
|
-
if !skip_actions? && ( default_actions? || actions_empty?)
|
134
|
-
initialize_actions
|
135
|
-
@actions << add_edit_action
|
136
|
-
@actions << add_destroy_action
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def initialize_actions
|
141
|
-
@actions = [] unless @actions.respond_to?(:each)
|
142
|
-
end
|
143
|
-
|
144
|
-
def default_actions?
|
145
|
-
actions.to_s.to_sym == :default
|
146
|
-
end
|
147
|
-
|
148
|
-
def included_default_actions?
|
149
|
-
actions.include?(:default)
|
150
|
-
end
|
151
|
-
|
152
|
-
def actions_empty?
|
153
|
-
(@actions.respond_to?(:each) && @actions.empty?)
|
154
|
-
end
|
155
|
-
|
156
|
-
def skip_actions?
|
157
|
-
actions.to_s.to_sym == :none
|
158
|
-
end
|
159
|
-
|
160
|
-
def decide_and_create_action(name, options ={}, &block)
|
161
|
-
if name.to_s == 'default'
|
162
|
-
[add_edit_action,add_destroy_action]
|
163
|
-
else
|
164
|
-
create_action(name,options,&block)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def create_action name, options = {}, &block
|
169
|
-
Lolita::Configuration::Action.new(@dbi,name,options,&block)
|
170
|
-
end
|
171
|
-
|
172
|
-
def add_edit_action
|
173
|
-
unless actions.detect{|existing_action| existing_action.name == :edit}
|
174
|
-
create_action(:edit, &edit_action_block)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def add_destroy_action
|
179
|
-
unless actions.detect{|existing_action| existing_action.name == :destroy}
|
180
|
-
create_action(:destroy, &destroy_action_block)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def edit_action_block
|
185
|
-
Proc.new do
|
186
|
-
title Proc.new{::I18n.t("lolita.shared.edit")}
|
187
|
-
url Proc.new{|view,record| view.send(:edit_lolita_resource_path, :id => record.id)}
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def destroy_action_block
|
192
|
-
Proc.new do
|
193
|
-
title Proc.new{::I18n.t("lolita.shared.delete")}
|
194
|
-
url Proc.new{|view,record| view.send(:lolita_resource_path,:id => record.id)}
|
195
|
-
html :method => :delete, :confirm => Proc.new{::I18n.t("lolita.list.confirm")}
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
end
|
1
|
+
module Lolita
|
2
|
+
module Configuration
|
3
|
+
class List < Lolita::Configuration::Base
|
4
|
+
include Observable
|
5
|
+
include Lolita::Builder
|
6
|
+
|
7
|
+
attr_reader :initialized_attributes,:page_criteria
|
8
|
+
attr_writer :title
|
9
|
+
|
10
|
+
lolita_accessor :per_page, :pagination_method, :actions
|
11
|
+
|
12
|
+
def initialize(dbp,*args,&block)
|
13
|
+
set_and_validate_dbp(dbp)
|
14
|
+
set_list_attributes do
|
15
|
+
set_attributes(*args)
|
16
|
+
self.instance_eval(&block) if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def title(new_title = nil)
|
21
|
+
if new_title
|
22
|
+
@title = new_title
|
23
|
+
end
|
24
|
+
Lolita::Utils.dynamic_string(@title, :default => dbp.klass.lolita_model_name.human(:count => 2))
|
25
|
+
end
|
26
|
+
|
27
|
+
def action name, options = {}, &block
|
28
|
+
@actions << decide_and_create_action(name, options, &block)
|
29
|
+
@actions.flatten!
|
30
|
+
end
|
31
|
+
|
32
|
+
# Allow to crate nested list for list
|
33
|
+
def list(*args, &block)
|
34
|
+
if args && args.any? || block_given?
|
35
|
+
association = dbi.associations[args[0].to_s.to_sym]
|
36
|
+
association_dbi = association && Lolita::DBI::Base.create(association.klass)
|
37
|
+
raise Lolita::UnknownDBPError.new("No DBI specified for list sublist") unless association_dbi
|
38
|
+
Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::NestedList,association_dbi, self, :association_name => association.name,&block)
|
39
|
+
else
|
40
|
+
@list
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# For details see Lolita::Configuration::Search
|
45
|
+
def search *args, &block
|
46
|
+
if (args && args.any?) || block_given?
|
47
|
+
@search = Lolita::Configuration::Search.new(self.dbi,*args,&block)
|
48
|
+
add_observer(@search)
|
49
|
+
end
|
50
|
+
@search
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return page for list display. Method requires two arguments:
|
54
|
+
# * <tt>current_page</tt> - number of current page
|
55
|
+
# * <tt>request (optional) </tt> - request that is passed to adapter that passes this to model when #pagination_method is defined
|
56
|
+
def paginate(current_page, request = nil)
|
57
|
+
changed
|
58
|
+
@page_criteria = dbi.paginate(current_page,@per_page,:request => request, :pagination_method => @pagination_method)
|
59
|
+
notify_observers(:paginate,self,request)
|
60
|
+
@page_criteria
|
61
|
+
end
|
62
|
+
|
63
|
+
# Set columns. Allowed classes are Lolita::Configuration::Columns or
|
64
|
+
# Array.
|
65
|
+
def columns=(possible_columns)
|
66
|
+
if possible_columns.is_a?(Lolita::Configuration::Columns)
|
67
|
+
@columns = possible_columns
|
68
|
+
@columns.parent = self
|
69
|
+
elsif possible_columns.respond_to?(:each)
|
70
|
+
possible_columns.each{|possible_column|
|
71
|
+
column(possible_column)
|
72
|
+
}
|
73
|
+
else
|
74
|
+
raise ArgumentError.new("Accepts only Enumerable or Lolita::Configuration::Columns.")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Define columns for list. On first read if there is no columns they will be created.
|
79
|
+
def columns(*args,&block)
|
80
|
+
if (args && args.any?) || block_given? || !@columns
|
81
|
+
self.columns = Lolita::Configuration::Columns.new(dbi,*args,&block)
|
82
|
+
end
|
83
|
+
@columns
|
84
|
+
end
|
85
|
+
|
86
|
+
# Block setter for columns
|
87
|
+
def column(*args,&block)
|
88
|
+
columns.column(*args, &block)
|
89
|
+
end
|
90
|
+
|
91
|
+
# checks if filter defined
|
92
|
+
def filter?
|
93
|
+
@filter.is_a?(Lolita::Configuration::Filter)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Create or return filter
|
97
|
+
def filter(*args,&block)
|
98
|
+
if args && args.any? || block_given?
|
99
|
+
@filter = Lolita::Configuration::Filter.new(dbi,*args,&block)
|
100
|
+
add_observer(@filter)
|
101
|
+
end
|
102
|
+
@filter
|
103
|
+
end
|
104
|
+
|
105
|
+
def by_path(path)
|
106
|
+
path = path.dup
|
107
|
+
object = self
|
108
|
+
while path.any?
|
109
|
+
part = path.pop.match(/(l|c)_(\w+)/)
|
110
|
+
object = if part[1] == "l"
|
111
|
+
object.list
|
112
|
+
else
|
113
|
+
object.columns.by_name(part[2]).list
|
114
|
+
end
|
115
|
+
end
|
116
|
+
object
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def set_list_attributes
|
122
|
+
init_default_attributes
|
123
|
+
yield if block_given?
|
124
|
+
create_default_actions
|
125
|
+
end
|
126
|
+
|
127
|
+
def init_default_attributes
|
128
|
+
initialize_actions
|
129
|
+
@per_page = Lolita.application.per_page || 10
|
130
|
+
end
|
131
|
+
|
132
|
+
def create_default_actions
|
133
|
+
if !skip_actions? && ( default_actions? || actions_empty?)
|
134
|
+
initialize_actions
|
135
|
+
@actions << add_edit_action
|
136
|
+
@actions << add_destroy_action
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def initialize_actions
|
141
|
+
@actions = [] unless @actions.respond_to?(:each)
|
142
|
+
end
|
143
|
+
|
144
|
+
def default_actions?
|
145
|
+
actions.to_s.to_sym == :default
|
146
|
+
end
|
147
|
+
|
148
|
+
def included_default_actions?
|
149
|
+
actions.include?(:default)
|
150
|
+
end
|
151
|
+
|
152
|
+
def actions_empty?
|
153
|
+
(@actions.respond_to?(:each) && @actions.empty?)
|
154
|
+
end
|
155
|
+
|
156
|
+
def skip_actions?
|
157
|
+
actions.to_s.to_sym == :none
|
158
|
+
end
|
159
|
+
|
160
|
+
def decide_and_create_action(name, options ={}, &block)
|
161
|
+
if name.to_s == 'default'
|
162
|
+
[add_edit_action,add_destroy_action]
|
163
|
+
else
|
164
|
+
create_action(name,options,&block)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def create_action name, options = {}, &block
|
169
|
+
Lolita::Configuration::Action.new(@dbi,name,options,&block)
|
170
|
+
end
|
171
|
+
|
172
|
+
def add_edit_action
|
173
|
+
unless actions.detect{|existing_action| existing_action.name == :edit}
|
174
|
+
create_action(:edit, &edit_action_block)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def add_destroy_action
|
179
|
+
unless actions.detect{|existing_action| existing_action.name == :destroy}
|
180
|
+
create_action(:destroy, &destroy_action_block)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def edit_action_block
|
185
|
+
Proc.new do
|
186
|
+
title Proc.new{::I18n.t("lolita.shared.edit")}
|
187
|
+
url Proc.new{|view,record| view.send(:edit_lolita_resource_path, :id => record.id)}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def destroy_action_block
|
192
|
+
Proc.new do
|
193
|
+
title Proc.new{::I18n.t("lolita.shared.delete")}
|
194
|
+
url Proc.new{|view,record| view.send(:lolita_resource_path,:id => record.id)}
|
195
|
+
html :method => :delete, :confirm => Proc.new{::I18n.t("lolita.list.confirm")}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
201
201
|
end
|
@@ -1,105 +1,105 @@
|
|
1
|
-
module Lolita
|
2
|
-
module Configuration
|
3
|
-
# Proxy class for search. It supports two methods #with and #run.
|
4
|
-
# By default with method accepts method name or nothing and creates Lolita::Search::Simple instance
|
5
|
-
# that will be used to run search on current dbi.
|
6
|
-
# By default search run against all content fields, but when _:fields_ options is passed it search in
|
7
|
-
# those fields only.
|
8
|
-
# ==== Example
|
9
|
-
# class Post < ActiveRecord::Base
|
10
|
-
# include Lolita::Configuration
|
11
|
-
# lolita do
|
12
|
-
# list do
|
13
|
-
# search :fields => [:name]
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# #with method also accepts class or instance of some class, that will be used to run search.
|
18
|
-
# That class should have #run method that accepts query and request.
|
19
|
-
# ====Example
|
20
|
-
# class MyCustomSearch
|
21
|
-
# def initialize(dbi)
|
22
|
-
# @dbi = dbi
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# def run(query,request = nil)
|
26
|
-
# @dbi.klass.where(:my_field => query)
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
# Also you can put your search method in model. For more see Lolita::Search::Simple
|
30
|
-
# ====Example
|
31
|
-
# class Post < ActiveRecord::Base
|
32
|
-
# include Lolita::Configuration
|
33
|
-
# lolita do
|
34
|
-
# list do
|
35
|
-
# search :my_custom_search
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# def self.my_custom_search(query,request)
|
40
|
-
# self.where(:title => query, :user_id => request.params[:user_id])
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
class Search
|
44
|
-
include Lolita::Builder
|
45
|
-
attr_reader :dbi
|
46
|
-
attr_writer :with, :fields
|
47
|
-
|
48
|
-
def initialize dbi, *args, &block
|
49
|
-
@dbi = dbi
|
50
|
-
set_attributes(args ? args.extract_options! : {})
|
51
|
-
instance_eval(&block) if block_given?
|
52
|
-
@with ||= args[0]!=true && args[0] ? args[0] : nil
|
53
|
-
end
|
54
|
-
|
55
|
-
def with(value = nil)
|
56
|
-
@with = value if value
|
57
|
-
if !@with || [String,Symbol].include?(@with.class)
|
58
|
-
@with = Lolita::Search::Simple.new(dbi,@with, :fields => @fields)
|
59
|
-
elsif @with.class == Class
|
60
|
-
initialize_arity = @with.instance_method(:initialize).arity
|
61
|
-
@with = if initialize_arity < 0 || initialize_arity > 1
|
62
|
-
@with.new(dbi,:fields => @fields)
|
63
|
-
else
|
64
|
-
@with.new(dbi)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
@with
|
68
|
-
end
|
69
|
-
|
70
|
-
def run(query,request = nil)
|
71
|
-
if self.with.method(:run).arity < 0 || self.with.method(:run).arity > 1
|
72
|
-
self.with.run(query,request)
|
73
|
-
else
|
74
|
-
self.with.run(query)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def update method_name,list,request
|
79
|
-
if method_name == :paginate && list.search
|
80
|
-
search_criteria = list.search.run(request && request.params[:q] || "",request)
|
81
|
-
page_criteria = if search_criteria.respond_to?(:where)
|
82
|
-
list.page_criteria.merge(search_criteria)
|
83
|
-
elsif search_criteria.nil?
|
84
|
-
list.page_criteria
|
85
|
-
else
|
86
|
-
search_criteria
|
87
|
-
end
|
88
|
-
list.instance_variable_set(:@page_criteria,page_criteria)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def set_attributes options
|
95
|
-
if options.respond_to?(:each)
|
96
|
-
options.each do |method_name, value|
|
97
|
-
self.send(:"#{method_name}=",value)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
1
|
+
module Lolita
|
2
|
+
module Configuration
|
3
|
+
# Proxy class for search. It supports two methods #with and #run.
|
4
|
+
# By default with method accepts method name or nothing and creates Lolita::Search::Simple instance
|
5
|
+
# that will be used to run search on current dbi.
|
6
|
+
# By default search run against all content fields, but when _:fields_ options is passed it search in
|
7
|
+
# those fields only.
|
8
|
+
# ==== Example
|
9
|
+
# class Post < ActiveRecord::Base
|
10
|
+
# include Lolita::Configuration
|
11
|
+
# lolita do
|
12
|
+
# list do
|
13
|
+
# search :fields => [:name]
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# #with method also accepts class or instance of some class, that will be used to run search.
|
18
|
+
# That class should have #run method that accepts query and request.
|
19
|
+
# ====Example
|
20
|
+
# class MyCustomSearch
|
21
|
+
# def initialize(dbi)
|
22
|
+
# @dbi = dbi
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# def run(query,request = nil)
|
26
|
+
# @dbi.klass.where(:my_field => query)
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# Also you can put your search method in model. For more see Lolita::Search::Simple
|
30
|
+
# ====Example
|
31
|
+
# class Post < ActiveRecord::Base
|
32
|
+
# include Lolita::Configuration
|
33
|
+
# lolita do
|
34
|
+
# list do
|
35
|
+
# search :my_custom_search
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def self.my_custom_search(query,request)
|
40
|
+
# self.where(:title => query, :user_id => request.params[:user_id])
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
class Search
|
44
|
+
include Lolita::Builder
|
45
|
+
attr_reader :dbi
|
46
|
+
attr_writer :with, :fields
|
47
|
+
|
48
|
+
def initialize dbi, *args, &block
|
49
|
+
@dbi = dbi
|
50
|
+
set_attributes(args ? args.extract_options! : {})
|
51
|
+
instance_eval(&block) if block_given?
|
52
|
+
@with ||= args[0]!=true && args[0] ? args[0] : nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def with(value = nil)
|
56
|
+
@with = value if value
|
57
|
+
if !@with || [String,Symbol].include?(@with.class)
|
58
|
+
@with = Lolita::Search::Simple.new(dbi,@with, :fields => @fields)
|
59
|
+
elsif @with.class == Class
|
60
|
+
initialize_arity = @with.instance_method(:initialize).arity
|
61
|
+
@with = if initialize_arity < 0 || initialize_arity > 1
|
62
|
+
@with.new(dbi,:fields => @fields)
|
63
|
+
else
|
64
|
+
@with.new(dbi)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@with
|
68
|
+
end
|
69
|
+
|
70
|
+
def run(query,request = nil)
|
71
|
+
if self.with.method(:run).arity < 0 || self.with.method(:run).arity > 1
|
72
|
+
self.with.run(query,request)
|
73
|
+
else
|
74
|
+
self.with.run(query)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def update method_name,list,request
|
79
|
+
if method_name == :paginate && list.search
|
80
|
+
search_criteria = list.search.run(request && request.params[:q] || "",request)
|
81
|
+
page_criteria = if search_criteria.respond_to?(:where)
|
82
|
+
list.page_criteria.merge(search_criteria)
|
83
|
+
elsif search_criteria.nil?
|
84
|
+
list.page_criteria
|
85
|
+
else
|
86
|
+
search_criteria
|
87
|
+
end
|
88
|
+
list.instance_variable_set(:@page_criteria,page_criteria)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def set_attributes options
|
95
|
+
if options.respond_to?(:each)
|
96
|
+
options.each do |method_name, value|
|
97
|
+
self.send(:"#{method_name}=",value)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
105
|
end
|