lolita 3.4.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +37 -36
  3. data/Gemfile +31 -29
  4. data/README.md +147 -147
  5. data/Rakefile +17 -7
  6. data/app/assets/javascripts/lolita/application.js +5 -6
  7. data/app/assets/javascripts/lolita/tab.js +98 -100
  8. data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
  9. data/app/assets/stylesheets/lolita/PIE.htc +81 -81
  10. data/app/assets/stylesheets/lolita/application.css +7 -6
  11. data/app/assets/stylesheets/lolita/default.css.erb +169 -169
  12. data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
  13. data/app/assets/stylesheets/lolita/style.css.erb +554 -553
  14. data/app/assets/stylesheets/tinymce/skins/lolita/content.inline.min.css +1 -0
  15. data/app/assets/stylesheets/tinymce/skins/lolita/content.min.css +1 -0
  16. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/readme.md +1 -0
  17. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.eot +0 -0
  18. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.svg +175 -0
  19. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.ttf +0 -0
  20. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.woff +0 -0
  21. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.eot +0 -0
  22. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.svg +153 -0
  23. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.ttf +0 -0
  24. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.woff +0 -0
  25. data/app/assets/stylesheets/tinymce/skins/lolita/img/anchor.gif +0 -0
  26. data/app/assets/stylesheets/tinymce/skins/lolita/img/loader.gif +0 -0
  27. data/app/assets/stylesheets/tinymce/skins/lolita/img/object.gif +0 -0
  28. data/app/assets/stylesheets/tinymce/skins/lolita/img/trans.gif +0 -0
  29. data/app/assets/stylesheets/tinymce/skins/lolita/img/wline.gif +0 -0
  30. data/app/assets/stylesheets/tinymce/skins/lolita/skin.ie7.min.css +1 -0
  31. data/app/assets/stylesheets/tinymce/skins/lolita/skin.min.css +2 -0
  32. data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
  33. data/app/helpers/components/lolita/configuration_component.rb +21 -21
  34. data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
  35. data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
  36. data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
  37. data/app/views/components/lolita/configuration/columns/body/_display.html.haml +1 -1
  38. data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
  39. data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
  40. data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +4 -7
  41. data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
  42. data/app/views/components/lolita/configuration/tab/_display.html.haml +4 -4
  43. data/app/views/components/lolita/configuration/tabs/_form.html.haml +7 -6
  44. data/app/views/components/lolita/configuration/tabs/yo.html +1 -0
  45. data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
  46. data/app/views/kaminari/lolita/_gap.html.erb +8 -8
  47. data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
  48. data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
  49. data/app/views/kaminari/lolita/_page.html.erb +12 -12
  50. data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
  51. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
  52. data/app/views/lolita/info/index.html.erb +232 -232
  53. data/author +1 -1
  54. data/config/locales/sv_SE.yml +37 -0
  55. data/config/routes.rb +6 -6
  56. data/lib/generators/lolita/install_generator.rb +22 -19
  57. data/lib/generators/lolita/uninstall_generator.rb +76 -71
  58. data/lib/generators/templates/lolita.rb +17 -14
  59. data/lib/generators/templates/tinymce.yml +22 -0
  60. data/lib/lolita.rb +142 -141
  61. data/lib/lolita/adapter/abstract_adapter.rb +17 -16
  62. data/lib/lolita/adapter/active_record.rb +229 -227
  63. data/lib/lolita/adapter/common_helper.rb +220 -221
  64. data/lib/lolita/adapter/field_helper.rb +18 -18
  65. data/lib/lolita/adapter/mongoid.rb +244 -241
  66. data/lib/lolita/components/base.rb +10 -12
  67. data/lib/lolita/configuration.rb +61 -61
  68. data/lib/lolita/configuration/column.rb +170 -181
  69. data/lib/lolita/configuration/field/big_decimal.rb +12 -12
  70. data/lib/lolita/configuration/field/boolean.rb +12 -12
  71. data/lib/lolita/configuration/field/date.rb +12 -12
  72. data/lib/lolita/configuration/field/hidden.rb +12 -12
  73. data/lib/lolita/configuration/field/integer.rb +11 -11
  74. data/lib/lolita/configuration/field/string.rb +16 -16
  75. data/lib/lolita/configuration/field/time.rb +13 -13
  76. data/lib/lolita/configuration/field_set.rb +25 -25
  77. data/lib/lolita/configuration/filter.rb +130 -116
  78. data/lib/lolita/configuration/list.rb +201 -201
  79. data/lib/lolita/configuration/search.rb +105 -105
  80. data/lib/lolita/controllers/component_helpers.rb +156 -156
  81. data/lib/lolita/controllers/internal_helpers.rb +74 -71
  82. data/lib/lolita/dbi/base.rb +56 -56
  83. data/lib/lolita/hooks/named_hook.rb +125 -125
  84. data/lib/lolita/lazy_loader.rb +54 -54
  85. data/lib/lolita/navigation/tree.rb +132 -132
  86. data/lib/lolita/rails/engine.rb +29 -24
  87. data/lib/lolita/rails/routes.rb +133 -129
  88. data/lib/lolita/ruby_ext/accessors.rb +26 -26
  89. data/lib/lolita/search/simple.rb +75 -75
  90. data/lib/lolita/support/formatter.rb +62 -62
  91. data/lib/lolita/support/formatter/rails.rb +56 -56
  92. data/lib/lolita/system_configuration/base.rb +182 -178
  93. data/lib/lolita/test/matchers.rb +77 -77
  94. data/lib/lolita/version.rb +30 -30
  95. data/lolita.gemspec +35 -34
  96. data/spec/adapter/common_helper_spec.rb +96 -96
  97. data/spec/builder_spec.rb +120 -120
  98. data/spec/configuration/base_spec.rb +23 -23
  99. data/spec/configuration/field_spec.rb +117 -118
  100. data/spec/configuration/filter_spec.rb +145 -131
  101. data/spec/configuration/tab_spec.rb +184 -187
  102. data/spec/configuration/tabs_spec.rb +116 -120
  103. data/spec/generators/lolita/install_generator_spec.rb +70 -55
  104. data/spec/generators/lolita/uninstall_generator_spec.rb +65 -49
  105. data/spec/helpers/url_for_spec.rb +8 -0
  106. data/spec/orm/active_record.rb +53 -0
  107. data/spec/orm/mongoid.rb +2 -13
  108. data/spec/orm/mongoid.yml +6 -0
  109. data/spec/rails_app/app/controllers/application_controller.rb +3 -3
  110. data/spec/rails_app/app/helpers/application_helper.rb +3 -3
  111. data/spec/rails_app/app/orm/active_record/address.rb +3 -0
  112. data/spec/rails_app/app/orm/active_record/category.rb +16 -0
  113. data/spec/rails_app/app/orm/active_record/comment.rb +4 -0
  114. data/spec/rails_app/app/orm/active_record/post.rb +24 -0
  115. data/spec/rails_app/app/orm/active_record/preference.rb +4 -0
  116. data/spec/rails_app/app/orm/active_record/profile.rb +9 -0
  117. data/spec/rails_app/app/orm/active_record/tag.rb +2 -0
  118. data/spec/rails_app/app/{mongoid → orm/mongoid}/address.rb +7 -7
  119. data/spec/rails_app/app/{mongoid → orm/mongoid}/category.rb +18 -19
  120. data/spec/rails_app/app/{mongoid → orm/mongoid}/comment.rb +5 -5
  121. data/spec/rails_app/app/{mongoid → orm/mongoid}/post.rb +30 -30
  122. data/spec/rails_app/app/{mongoid → orm/mongoid}/preference.rb +5 -5
  123. data/spec/rails_app/app/{mongoid → orm/mongoid}/profile.rb +13 -14
  124. data/spec/rails_app/app/{mongoid → orm/mongoid}/tag.rb +3 -3
  125. data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
  126. data/spec/rails_app/config/application.rb +34 -33
  127. data/spec/rails_app/config/boot.rb +7 -8
  128. data/spec/rails_app/config/environment.rb +5 -5
  129. data/spec/rails_app/config/environments/development.rb +22 -23
  130. data/spec/rails_app/config/environments/production.rb +37 -37
  131. data/spec/rails_app/config/environments/test.rb +36 -37
  132. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
  133. data/spec/rails_app/config/initializers/inflections.rb +2 -2
  134. data/spec/rails_app/config/initializers/secret_token.rb +1 -1
  135. data/spec/rails_app/config/routes.rb +4 -3
  136. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
  137. data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
  138. data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
  139. data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
  140. data/spec/rails_app/public/javascripts/rails.js +137 -137
  141. data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
  142. data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
  143. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
  144. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
  145. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
  146. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
  147. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
  148. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
  149. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
  150. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
  151. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
  152. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
  153. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
  154. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
  155. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
  156. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
  157. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
  158. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
  159. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
  160. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  161. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  162. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  163. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
  164. data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
  165. data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
  166. data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
  167. data/spec/spec_helper.rb +44 -51
  168. data/spec/support/cleaner.rb +12 -0
  169. data/vendor/assets/javascripts/application_vendor_lolita.js +5 -4
  170. data/vendor/assets/javascripts/jquery-numeric.js +279 -279
  171. data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
  172. data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
  173. metadata +105 -72
  174. data/lib/tasks/tinymce-assets.rake +0 -7
  175. data/spec/adapter_helper.rb +0 -43
  176. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +0 -66
  177. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +0 -117
  178. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/butt2.png +0 -0
  179. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/button-bg.png +0 -0
  180. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/buttons.png +0 -0
  181. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/down_arrow.gif +0 -0
  182. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/fade-butt.png +0 -0
  183. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/icons.png +0 -0
  184. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/items.gif +0 -0
  185. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-arrow.png +0 -0
  186. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-check.png +0 -0
  187. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/progress.gif +0 -0
  188. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/tabs.gif +0 -0
  189. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/toolbarbg.png +0 -0
  190. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +0 -988
@@ -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
201
- 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, data: { confirm: Proc.new{::I18n.t("lolita.list.confirm")} }
196
+ end
197
+ end
198
+
199
+ end
200
+ end
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
105
- 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
+ end