smart_listing 1.0.0 → 1.1.0
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/README.md +31 -4
- data/Rakefile +1 -1
- data/app/assets/javascripts/smart_listing.coffee.erb +165 -123
- data/app/helpers/smart_listing/helper.rb +102 -45
- data/app/views/kaminari/smart_listing/_paginator.html.erb +2 -2
- data/app/views/smart_listing/_action_delete.html.erb +3 -2
- data/app/views/smart_listing/_action_edit.html.erb +4 -3
- data/app/views/smart_listing/_action_show.html.erb +4 -3
- data/app/views/smart_listing/_item_new.html.erb +2 -2
- data/app/views/smart_listing/_pagination_per_page_links.html.erb +1 -1
- data/app/views/smart_listing/_sortable.html.erb +2 -2
- data/app/views/smart_listing/create.js.erb +2 -0
- data/app/views/smart_listing/destroy.js.erb +1 -0
- data/app/views/smart_listing/edit.js.erb +1 -0
- data/app/views/smart_listing/index.js.erb +1 -0
- data/app/views/smart_listing/item/_destroy.js.erb +1 -1
- data/app/views/smart_listing/new.js.erb +1 -0
- data/app/views/smart_listing/update.js.erb +2 -0
- data/lib/generators/smart_listing/templates/initializer.rb +10 -1
- data/lib/smart_listing/config.rb +45 -22
- data/lib/smart_listing/version.rb +1 -1
- data/lib/smart_listing.rb +18 -15
- metadata +135 -44
@@ -1,8 +1,17 @@
|
|
1
1
|
module SmartListing
|
2
2
|
module Helper
|
3
3
|
module ControllerExtensions
|
4
|
-
|
5
|
-
|
4
|
+
# Creates new smart listing
|
5
|
+
#
|
6
|
+
# Possible calls:
|
7
|
+
# smart_listing_create name, collection, options = {}
|
8
|
+
# smart_listing_create options = {}
|
9
|
+
def smart_listing_create *args
|
10
|
+
options = args.extract_options!
|
11
|
+
name = (args[0] || options[:name] || controller_name).to_sym
|
12
|
+
collection = args[1] || options[:collection] || smart_listing_collection
|
13
|
+
|
14
|
+
options = {:config_profile => view_context.smart_listing_config_profile}.merge(options)
|
6
15
|
|
7
16
|
list = SmartListing::Base.new(name, collection, options)
|
8
17
|
list.setup(params, cookies)
|
@@ -16,6 +25,10 @@ module SmartListing
|
|
16
25
|
def smart_listing name
|
17
26
|
@smart_listings[name.to_sym]
|
18
27
|
end
|
28
|
+
|
29
|
+
def _prefixes
|
30
|
+
super << 'smart_listing'
|
31
|
+
end
|
19
32
|
end
|
20
33
|
|
21
34
|
class Builder
|
@@ -28,6 +41,10 @@ module SmartListing
|
|
28
41
|
@smart_listing_name, @smart_listing, @template, @options, @proc = smart_listing_name, smart_listing, template, options, proc
|
29
42
|
end
|
30
43
|
|
44
|
+
def name
|
45
|
+
@smart_listing_name
|
46
|
+
end
|
47
|
+
|
31
48
|
def paginate options = {}
|
32
49
|
if @smart_listing.collection.respond_to? :current_page
|
33
50
|
@template.paginate @smart_listing.collection, {:remote => @smart_listing.remote?, :param_name => @smart_listing.param_name(:page), :params => UNSAFE_PARAMS}.merge(@smart_listing.kaminari_options)
|
@@ -44,14 +61,14 @@ module SmartListing
|
|
44
61
|
end
|
45
62
|
|
46
63
|
def pagination_per_page_links options = {}
|
47
|
-
container_classes = [
|
48
|
-
container_classes <<
|
64
|
+
container_classes = [@template.smart_listing_config.classes(:pagination_per_page)]
|
65
|
+
container_classes << @template.smart_listing_config.classes(:hidden) if empty?
|
49
66
|
|
50
67
|
per_page_sizes = @smart_listing.page_sizes.clone
|
51
68
|
per_page_sizes.push(0) if @smart_listing.unlimited_per_page?
|
52
69
|
|
53
70
|
locals = {
|
54
|
-
:container_classes => container_classes,
|
71
|
+
:container_classes => container_classes,
|
55
72
|
:per_page_sizes => per_page_sizes,
|
56
73
|
}
|
57
74
|
|
@@ -64,7 +81,7 @@ module SmartListing
|
|
64
81
|
end
|
65
82
|
|
66
83
|
locals = {
|
67
|
-
:page => page,
|
84
|
+
:page => page,
|
68
85
|
:url => url,
|
69
86
|
}
|
70
87
|
|
@@ -72,8 +89,9 @@ module SmartListing
|
|
72
89
|
end
|
73
90
|
|
74
91
|
def sortable title, attribute, options = {}
|
75
|
-
dirs = [nil, "asc", "desc"]
|
76
|
-
|
92
|
+
dirs = options[:sort_dirs] || @smart_listing.sort_dirs || [nil, "asc", "desc"]
|
93
|
+
|
94
|
+
next_index = dirs.index(@smart_listing.sort_order(attribute)).nil? ? 0 : (dirs.index(@smart_listing.sort_order(attribute)) + 1) % dirs.length
|
77
95
|
|
78
96
|
sort_params = {
|
79
97
|
attribute => dirs[next_index]
|
@@ -82,7 +100,7 @@ module SmartListing
|
|
82
100
|
locals = {
|
83
101
|
:order => @smart_listing.sort_order(attribute),
|
84
102
|
:url => @template.url_for(sanitize_params(@template.params.merge(@smart_listing.all_params(:sort => sort_params)))),
|
85
|
-
:container_classes => [
|
103
|
+
:container_classes => [@template.smart_listing_config.classes(:sortable)],
|
86
104
|
:attribute => attribute,
|
87
105
|
:title => title
|
88
106
|
}
|
@@ -117,10 +135,10 @@ module SmartListing
|
|
117
135
|
|
118
136
|
# Add new item button & placeholder to list
|
119
137
|
def item_new options = {}, &block
|
120
|
-
no_records_classes = [
|
121
|
-
no_records_classes <<
|
138
|
+
no_records_classes = [@template.smart_listing_config.classes(:no_records)]
|
139
|
+
no_records_classes << @template.smart_listing_config.classes(:hidden) unless empty?
|
122
140
|
new_item_button_classes = []
|
123
|
-
new_item_button_classes <<
|
141
|
+
new_item_button_classes << @template.smart_listing_config.classes(:hidden) if max_count?
|
124
142
|
|
125
143
|
locals = {
|
126
144
|
:colspan => options.delete(:colspan),
|
@@ -134,15 +152,15 @@ module SmartListing
|
|
134
152
|
}
|
135
153
|
|
136
154
|
unless block_given?
|
137
|
-
locals[:placeholder_classes] = [
|
138
|
-
locals[:new_item_action_classes] = [
|
139
|
-
locals[:new_item_action_classes] <<
|
155
|
+
locals[:placeholder_classes] = [@template.smart_listing_config.classes(:new_item_placeholder), @template.smart_listing_config.classes(:hidden)]
|
156
|
+
locals[:new_item_action_classes] = [@template.smart_listing_config.classes(:new_item_action)]
|
157
|
+
locals[:new_item_action_classes] << @template.smart_listing_config.classes(:hidden) if !empty? && max_count?
|
140
158
|
|
141
159
|
@template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
|
142
160
|
else
|
143
|
-
locals[:placeholder_classes] = [
|
144
|
-
locals[:placeholder_classes] <<
|
145
|
-
locals[:new_item_action_classes] = [
|
161
|
+
locals[:placeholder_classes] = [@template.smart_listing_config.classes(:new_item_placeholder)]
|
162
|
+
locals[:placeholder_classes] << @template.smart_listing_config.classes(:hidden) if !empty? && max_count?
|
163
|
+
locals[:new_item_action_classes] = [@template.smart_listing_config.classes(:new_item_action), @template.smart_listing_config.classes(:hidden)]
|
146
164
|
|
147
165
|
locals[:new_item_content] = @template.capture(&block)
|
148
166
|
@template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
|
@@ -170,9 +188,16 @@ module SmartListing
|
|
170
188
|
end
|
171
189
|
end
|
172
190
|
|
191
|
+
def smart_listing_config_profile
|
192
|
+
defined?(super) ? super : :default
|
193
|
+
end
|
194
|
+
|
195
|
+
def smart_listing_config
|
196
|
+
SmartListing.config(smart_listing_config_profile)
|
197
|
+
end
|
198
|
+
|
173
199
|
# Outputs smart list container
|
174
200
|
def smart_listing_for name, *args, &block
|
175
|
-
puts args.to_yaml
|
176
201
|
raise ArgumentError, "Missing block" unless block_given?
|
177
202
|
name = name.to_sym
|
178
203
|
options = args.extract_options!
|
@@ -183,17 +208,18 @@ module SmartListing
|
|
183
208
|
output = ""
|
184
209
|
|
185
210
|
data = {}
|
186
|
-
data[
|
187
|
-
data[
|
188
|
-
data[
|
211
|
+
data[smart_listing_config.data_attributes(:max_count)] = @smart_listings[name].max_count if @smart_listings[name].max_count && @smart_listings[name].max_count > 0
|
212
|
+
data[smart_listing_config.data_attributes(:item_count)] = @smart_listings[name].count
|
213
|
+
data[smart_listing_config.data_attributes(:href)] = @smart_listings[name].href if @smart_listings[name].href
|
214
|
+
data[smart_listing_config.data_attributes(:callback_href)] = @smart_listings[name].callback_href if @smart_listings[name].callback_href
|
189
215
|
data.merge!(options[:data]) if options[:data]
|
190
216
|
|
191
217
|
if bare
|
192
218
|
output = capture(builder, &block)
|
193
219
|
else
|
194
|
-
output = content_tag(:div, :class =>
|
195
|
-
concat(content_tag(:div, "", :class =>
|
196
|
-
concat(content_tag(:div, :class =>
|
220
|
+
output = content_tag(:div, :class => smart_listing_config.classes(:main), :id => name, :data => data) do
|
221
|
+
concat(content_tag(:div, "", :class => smart_listing_config.classes(:loading)))
|
222
|
+
concat(content_tag(:div, :class => smart_listing_config.classes(:content)) do
|
197
223
|
concat(capture(builder, &block))
|
198
224
|
end)
|
199
225
|
end
|
@@ -202,7 +228,7 @@ module SmartListing
|
|
202
228
|
output
|
203
229
|
end
|
204
230
|
|
205
|
-
def smart_listing_render name, *args
|
231
|
+
def smart_listing_render name = controller_name, *args
|
206
232
|
smart_listing_for(name, *args) do |smart_listing|
|
207
233
|
concat(smart_listing.render_list)
|
208
234
|
end
|
@@ -211,9 +237,9 @@ module SmartListing
|
|
211
237
|
def smart_listing_controls_for name, *args, &block
|
212
238
|
smart_listing = @smart_listings.try(:[], name)
|
213
239
|
|
214
|
-
classes = [
|
240
|
+
classes = [smart_listing_config.classes(:controls), args.first.try(:[], :class)]
|
215
241
|
|
216
|
-
form_tag(smart_listing.try(:href) || {}, :remote => smart_listing.try(:remote?) || true, :method => :get, :class => classes, :data => {:
|
242
|
+
form_tag(smart_listing.try(:href) || {}, :remote => smart_listing.try(:remote?) || true, :method => :get, :class => classes, :data => {smart_listing_config.data_attributes(:main) => name}) do
|
217
243
|
concat(content_tag(:div, :style => "margin:0;padding:0;display:inline") do
|
218
244
|
concat(hidden_field_tag("#{smart_listing.try(:base_param)}[_]", 1, :id => nil)) # this forces smart_listing_update to refresh the list
|
219
245
|
end)
|
@@ -228,31 +254,41 @@ module SmartListing
|
|
228
254
|
next unless action.is_a?(Hash)
|
229
255
|
|
230
256
|
locals = {
|
231
|
-
:action_if => action.has_key?(:if) ? action[:if] : true,
|
257
|
+
:action_if => action.has_key?(:if) ? action[:if] : true,
|
232
258
|
:url => action.delete(:url),
|
233
259
|
:icon => action.delete(:icon),
|
234
260
|
:title => action.delete(:title),
|
235
261
|
}
|
236
|
-
locals[:icon] = [locals[:icon], SmartListing.config.classes(:muted)] if !locals[:action_if]
|
237
262
|
|
263
|
+
template = nil
|
238
264
|
action_name = action[:name].to_sym
|
265
|
+
|
239
266
|
case action_name
|
240
267
|
when :show
|
241
|
-
|
268
|
+
locals[:icon] ||= smart_listing_config.classes(:icon_show)
|
269
|
+
template = 'action_show'
|
242
270
|
when :edit
|
243
|
-
|
271
|
+
locals[:icon] ||= smart_listing_config.classes(:icon_edit)
|
272
|
+
template = 'action_edit'
|
244
273
|
when :destroy
|
274
|
+
locals[:icon] ||= smart_listing_config.classes(:icon_trash)
|
245
275
|
locals.merge!(
|
246
276
|
:confirmation => action.delete(:confirmation),
|
247
277
|
)
|
248
|
-
|
278
|
+
template = 'action_delete'
|
249
279
|
when :custom
|
250
280
|
locals.merge!(
|
251
281
|
:html_options => action,
|
252
282
|
)
|
253
|
-
|
283
|
+
template = 'action_custom'
|
284
|
+
end
|
285
|
+
|
286
|
+
locals[:icon] = [locals[:icon], smart_listing_config.classes(:muted)] if !locals[:action_if]
|
287
|
+
|
288
|
+
if template
|
289
|
+
concat(render(:partial => "smart_listing/#{template}", :locals => locals))
|
254
290
|
else
|
255
|
-
|
291
|
+
concat(render(:partial => "smart_listing/action_#{action_name}", :locals => {:action => action}))
|
256
292
|
end
|
257
293
|
end
|
258
294
|
end
|
@@ -268,9 +304,14 @@ module SmartListing
|
|
268
304
|
#################################################################################################
|
269
305
|
# JS helpers:
|
270
306
|
|
271
|
-
# Updates
|
272
|
-
|
273
|
-
|
307
|
+
# Updates smart listing
|
308
|
+
#
|
309
|
+
# Posible calls:
|
310
|
+
# smart_listing_update name, options = {}
|
311
|
+
# smart_listing_update options = {}
|
312
|
+
def smart_listing_update *args
|
313
|
+
options = args.extract_options!
|
314
|
+
name = (args[0] || options[:name] || controller_name).to_sym
|
274
315
|
smart_listing = @smart_listings[name]
|
275
316
|
|
276
317
|
# don't update list if params are missing (prevents interfering with other lists)
|
@@ -280,19 +321,35 @@ module SmartListing
|
|
280
321
|
|
281
322
|
builder = Builder.new(name, smart_listing, self, {}, nil)
|
282
323
|
render(:partial => 'smart_listing/update_list', :locals => {
|
283
|
-
:name => smart_listing.name,
|
284
|
-
:part => smart_listing.partial,
|
285
|
-
:smart_listing => builder,
|
324
|
+
:name => smart_listing.name,
|
325
|
+
:part => smart_listing.partial,
|
326
|
+
:smart_listing => builder,
|
286
327
|
:smart_listing_data => {
|
287
|
-
|
288
|
-
|
328
|
+
smart_listing_config.data_attributes(:params) => smart_listing.all_params,
|
329
|
+
smart_listing_config.data_attributes(:max_count) => smart_listing.max_count,
|
330
|
+
smart_listing_config.data_attributes(:item_count) => smart_listing.count,
|
289
331
|
}
|
290
332
|
})
|
291
333
|
end
|
292
334
|
|
293
335
|
# Renders single item (i.e for create, update actions)
|
294
|
-
|
295
|
-
|
336
|
+
#
|
337
|
+
# Possible calls:
|
338
|
+
# smart_listing_item name, item_action, object = nil, partial = nil, options = {}
|
339
|
+
# smart_listing_item item_action, object = nil, partial = nil, options = {}
|
340
|
+
def smart_listing_item *args
|
341
|
+
options = args.extract_options!
|
342
|
+
if [:create, :create_continue, :destroy, :edit, :new, :remove, :update].include?(args[1])
|
343
|
+
name = args[0]
|
344
|
+
item_action = args[1]
|
345
|
+
object = args[2]
|
346
|
+
partial = args[3]
|
347
|
+
else
|
348
|
+
name = (options[:name] || controller_name).to_sym
|
349
|
+
item_action = args[0]
|
350
|
+
object = args[1]
|
351
|
+
partial = args[2]
|
352
|
+
end
|
296
353
|
type = object.class.name.downcase.to_sym if object
|
297
354
|
id = options[:id] || object.try(:id)
|
298
355
|
valid = options[:valid] if options.has_key?(:valid)
|
@@ -7,8 +7,8 @@
|
|
7
7
|
paginator: the paginator that renders the pagination tags inside
|
8
8
|
-%>
|
9
9
|
<%= paginator.render do -%>
|
10
|
-
<div class="
|
11
|
-
<ul class="
|
10
|
+
<div class="<%= smart_listing_config.classes(:pagination_wrapper) %>">
|
11
|
+
<ul class="<%= smart_listing_config.classes(:pagination_container) %>">
|
12
12
|
<%= first_page_tag unless current_page.first? %>
|
13
13
|
<%= prev_page_tag unless current_page.first? %>
|
14
14
|
<% each_page do |page| -%>
|
@@ -2,10 +2,11 @@
|
|
2
2
|
Delete action.
|
3
3
|
|
4
4
|
Available local variables:
|
5
|
+
action_if: false if action is disabled
|
5
6
|
url: destroy url
|
6
|
-
icon
|
7
|
+
icon: icon css classes
|
7
8
|
confirmation: confrimation text
|
8
9
|
title
|
9
10
|
-%>
|
10
11
|
|
11
|
-
<%= link_to_if(action_if, content_tag(:i, "", :class => icon
|
12
|
+
<%= link_to_if(action_if, content_tag(:i, "", :class => icon), url, :remote => true, :class => "destroy", :method => :delete, :title => title || t("smart_listing.actions.destroy"), :data => {:confirmation => confirmation || t("smart_listing.msgs.destroy_confirmation")} ) %>
|
@@ -2,9 +2,10 @@
|
|
2
2
|
Edit action.
|
3
3
|
|
4
4
|
Available local variables:
|
5
|
-
|
6
|
-
|
5
|
+
action_if: false if action is disabled
|
6
|
+
url: edit url
|
7
|
+
icon: icon css classes
|
7
8
|
title
|
8
9
|
-%>
|
9
10
|
|
10
|
-
<%= link_to_if(action_if, content_tag(:i, '', :class => icon
|
11
|
+
<%= link_to_if(action_if, content_tag(:i, '', :class => icon), url, :remote => true, :class => "edit", :title => title || t("smart_listing.actions.edit") ) %>
|
@@ -2,9 +2,10 @@
|
|
2
2
|
Show action.
|
3
3
|
|
4
4
|
Available local variables:
|
5
|
-
|
6
|
-
|
5
|
+
action_if: false if action is disabled
|
6
|
+
url: show url
|
7
|
+
icon: icon clss classes
|
7
8
|
title
|
8
9
|
-%>
|
9
10
|
|
10
|
-
<%= link_to_if(action_if, content_tag(:i, '', :class => icon
|
11
|
+
<%= link_to_if(action_if, content_tag(:i, '', :class => icon), url, :class => "show", :title => title || t("smart_listing.actions.show") ) %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
new_item_content new item placeholder content (usually some form)
|
15
15
|
-%>
|
16
16
|
|
17
|
-
<%= content_tag(:tr, '', :class => placeholder_classes + %w{info}, :data => {
|
17
|
+
<%= content_tag(:tr, '', :class => placeholder_classes + %w{info}, :data => {smart_listing_config.data_attributes(:autoshow) => new_item_autoshow}) do %>
|
18
18
|
<%= new_item_content %>
|
19
19
|
<% end %>
|
20
20
|
<%= content_tag(:tr, :class => new_item_action_classes + %w{info}) do %>
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<%= no_items_text %>
|
24
24
|
<% end %>
|
25
25
|
<%= link_to(new_item_button_url, :remote => true, :class => new_item_button_classes + %w{btn pull-right}) do %>
|
26
|
-
<%= content_tag(:i, '', :class =>
|
26
|
+
<%= content_tag(:i, '', :class => smart_listing_config.classes(:icon_new)) %>
|
27
27
|
<%= new_item_button_text %>
|
28
28
|
<% end %>
|
29
29
|
<% end %>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
<%= content_tag(:div, :class => container_classes ) do %>
|
12
12
|
<% if smart_listing.options[:paginate] && (smart_listing.count > smart_listing.page_sizes.first) %>
|
13
13
|
<%= t('views.pagination.per_page') %>
|
14
|
-
<% per_page_sizes.each do |p| %><%= builder.pagination_per_page_link p %><% break if p
|
14
|
+
<% per_page_sizes.each do |p| %><%= builder.pagination_per_page_link p %><% break if p >= smart_listing.count %><% end %>
|
15
15
|
|
|
16
16
|
<% end %>
|
17
17
|
<%= t('views.pagination.total') %>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
<%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => true do %>
|
15
15
|
<%= title %>
|
16
16
|
<% if order %>
|
17
|
-
<span class="<%= order == "asc" ?
|
17
|
+
<span class="<%= order == "asc" ? smart_listing_config.classes(:icon_sort_up) : smart_listing_config.classes(:icon_sort_down) %>"></span>
|
18
18
|
<% else %>
|
19
|
-
<span class="<%=
|
19
|
+
<span class="<%= smart_listing_config.classes(:icon_sort_none) %>"></span>
|
20
20
|
<% end %>
|
21
21
|
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= smart_listing_item :destroy, smart_listing_resource %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= smart_listing_item :edit, smart_listing_resource, "form" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= smart_listing_update %>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var smart_listing = $('#<%= name %>').smart_listing();
|
1
|
+
var smart_listing = $('#<%= name.to_s %>').smart_listing();
|
2
2
|
smart_listing.destroy(<%= id %>, <%= object.destroyed? %>);
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= smart_listing_item :new, smart_listing_resource, "form" %>
|
@@ -12,6 +12,7 @@ SmartListing.configure do |config|
|
|
12
12
|
#:memorize_per_page => false, # save per page settings in the cookie
|
13
13
|
#:page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array
|
14
14
|
#:kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options
|
15
|
+
#:sort_dirs => [nil, "asc", "desc"], # Default sorting directions cycle of sortables
|
15
16
|
})
|
16
17
|
|
17
18
|
config.constants :classes, {
|
@@ -27,8 +28,9 @@ SmartListing.configure do |config|
|
|
27
28
|
#:hidden => "hidden",
|
28
29
|
#:autoselect => "autoselect",
|
29
30
|
#:callback => "callback",
|
31
|
+
#:pagination_wrapper => "text-center",
|
32
|
+
#:pagination_container => "pagination",
|
30
33
|
#:pagination_per_page => "pagination-per-page text-center",
|
31
|
-
#:pagination_count => "count",
|
32
34
|
#:inline_editing => "info",
|
33
35
|
#:no_records => "no-records",
|
34
36
|
#:limit => "smart-listing-limit",
|
@@ -48,15 +50,18 @@ SmartListing.configure do |config|
|
|
48
50
|
#:icon_sort_none => "glyphicon glyphicon-resize-vertical",
|
49
51
|
#:icon_sort_up => "glyphicon glyphicon-chevron-up",
|
50
52
|
#:icon_sort_down => "glyphicon glyphicon-chevron-down",
|
53
|
+
#:muted => "text-muted",
|
51
54
|
}
|
52
55
|
|
53
56
|
config.constants :data_attributes, {
|
54
57
|
#:main => "smart-listing",
|
58
|
+
#:controls_initialized => "smart-listing-controls-initialized",
|
55
59
|
#:confirmation => "confirmation",
|
56
60
|
#:id => "id",
|
57
61
|
#:href => "href",
|
58
62
|
#:callback_href => "callback-href",
|
59
63
|
#:max_count => "max-count",
|
64
|
+
#:item_count => "item-count",
|
60
65
|
#:inline_edit_backup => "smart-listing-edit-backup",
|
61
66
|
#:params => "params",
|
62
67
|
#:observed => "observed",
|
@@ -71,5 +76,9 @@ SmartListing.configure do |config|
|
|
71
76
|
#:row => "tr",
|
72
77
|
#:head => "thead",
|
73
78
|
#:filtering_icon => "i"
|
79
|
+
#:filtering_button => "button",
|
80
|
+
#:filtering_icon => "button span",
|
81
|
+
#:filtering_input => ".filter input",
|
82
|
+
#:pagination_count => ".pagination-per-page .count",
|
74
83
|
}
|
75
84
|
end
|
data/lib/smart_listing/config.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
module SmartListing
|
2
|
-
|
3
|
-
|
2
|
+
mattr_reader :configs
|
3
|
+
|
4
|
+
def self.configure profile = nil
|
5
|
+
profile ||= :default
|
6
|
+
@@configs ||= {}
|
7
|
+
yield @@configs[profile] ||= SmartListing::Configuration.new
|
4
8
|
end
|
5
9
|
|
6
|
-
def self.config
|
7
|
-
|
10
|
+
def self.config profile = nil
|
11
|
+
profile ||= :default
|
12
|
+
@@configs ||= {}
|
13
|
+
@@configs[profile] ||= SmartListing::Configuration.new
|
8
14
|
end
|
9
15
|
|
10
16
|
class Configuration
|
11
|
-
|
12
|
-
DEFAULT_PAGE_SIZES = [3, 10, 20, 50, 100]
|
13
|
-
else
|
14
|
-
DEFAULT_PAGE_SIZES = [10, 20, 50, 100]
|
15
|
-
end
|
17
|
+
DEFAULT_PAGE_SIZES = [10, 20, 50, 100].freeze
|
16
18
|
|
17
19
|
DEFAULTS = {
|
18
20
|
:global_options => {
|
@@ -26,8 +28,9 @@ module SmartListing
|
|
26
28
|
:unlimited_per_page => false, # allow infinite page size
|
27
29
|
:paginate => true, # allow pagination
|
28
30
|
:memorize_per_page => false,
|
29
|
-
:page_sizes => DEFAULT_PAGE_SIZES,
|
31
|
+
:page_sizes => DEFAULT_PAGE_SIZES.dup, # set available page sizes array
|
30
32
|
:kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options
|
33
|
+
:sort_dirs => [nil, "asc", "desc"], # Default sorting directions cycle of sortables
|
31
34
|
},
|
32
35
|
:constants => {
|
33
36
|
:classes => {
|
@@ -43,8 +46,9 @@ module SmartListing
|
|
43
46
|
:hidden => "hidden",
|
44
47
|
:autoselect => "autoselect",
|
45
48
|
:callback => "callback",
|
49
|
+
:pagination_wrapper => "text-center",
|
50
|
+
:pagination_container => "pagination",
|
46
51
|
:pagination_per_page => "pagination-per-page text-center",
|
47
|
-
:pagination_count => "count",
|
48
52
|
:inline_editing => "info",
|
49
53
|
:no_records => "no-records",
|
50
54
|
:limit => "smart-listing-limit",
|
@@ -68,15 +72,16 @@ module SmartListing
|
|
68
72
|
},
|
69
73
|
:data_attributes => {
|
70
74
|
:main => "smart-listing",
|
75
|
+
:controls_initialized => "smart-listing-controls-initialized",
|
71
76
|
:confirmation => "confirmation",
|
72
77
|
:id => "id",
|
73
78
|
:href => "href",
|
74
79
|
:callback_href => "callback-href",
|
75
80
|
:max_count => "max-count",
|
81
|
+
:item_count => "item-count",
|
76
82
|
:inline_edit_backup => "smart-listing-edit-backup",
|
77
83
|
:params => "params",
|
78
84
|
:observed => "observed",
|
79
|
-
:href => "href",
|
80
85
|
:autoshow => "autoshow",
|
81
86
|
:popover => "slpopover",
|
82
87
|
},
|
@@ -87,13 +92,16 @@ module SmartListing
|
|
87
92
|
:head => "thead",
|
88
93
|
:filtering_button => "button",
|
89
94
|
:filtering_icon => "button span",
|
90
|
-
:filtering_input => ".filter input"
|
95
|
+
:filtering_input => ".filter input",
|
96
|
+
:pagination_count => ".pagination-per-page .count",
|
91
97
|
}
|
92
98
|
}
|
93
|
-
}
|
99
|
+
}.freeze
|
100
|
+
|
101
|
+
attr_reader :options
|
94
102
|
|
95
103
|
def initialize
|
96
|
-
@options =
|
104
|
+
@options = {}
|
97
105
|
end
|
98
106
|
|
99
107
|
def method_missing(sym, *args, &block)
|
@@ -101,29 +109,44 @@ module SmartListing
|
|
101
109
|
end
|
102
110
|
|
103
111
|
def constants key, value = nil
|
104
|
-
if value
|
112
|
+
if value && !value.empty?
|
113
|
+
@options[:constants] ||= {}
|
114
|
+
@options[:constants][key] ||= {}
|
105
115
|
@options[:constants][key].merge!(value)
|
106
116
|
end
|
107
|
-
@options[:constants][key]
|
117
|
+
@options[:constants].try(:[], key) || DEFAULTS[:constants][key]
|
108
118
|
end
|
109
119
|
|
110
120
|
def classes key
|
111
|
-
@options[:constants][:classes][key]
|
121
|
+
@options[:constants].try(:[], :classes).try(:[], key) || DEFAULTS[:constants][:classes][key]
|
112
122
|
end
|
113
123
|
|
114
124
|
def data_attributes key
|
115
|
-
@options[:constants][:data_attributes][key]
|
125
|
+
@options[:constants].try(:[], :data_attributes).try(:[], key) || DEFAULTS[:constants][:data_attributes][key]
|
116
126
|
end
|
117
127
|
|
118
128
|
def selectors key
|
119
|
-
@options[:constants][:selectors][key]
|
129
|
+
@options[:constants].try(:[], :selectors).try(:[], key) || DEFAULTS[:constants][:selectors][key]
|
120
130
|
end
|
121
131
|
|
122
132
|
def global_options value = nil
|
123
|
-
if value
|
133
|
+
if value && !value.empty?
|
134
|
+
@options[:global_options] ||= {}
|
124
135
|
@options[:global_options].merge!(value)
|
125
136
|
end
|
126
|
-
@options[:global_options]
|
137
|
+
!@options[:global_options].try(:empty?) ? DEFAULTS[:global_options] : DEFAULTS[:global_options].deep_merge(@options[:global_options])
|
138
|
+
end
|
139
|
+
|
140
|
+
def to_json
|
141
|
+
@options.to_json
|
142
|
+
end
|
143
|
+
|
144
|
+
def dump
|
145
|
+
DEFAULTS.deep_merge(@options)
|
146
|
+
end
|
147
|
+
|
148
|
+
def dump_json
|
149
|
+
dump.to_json
|
127
150
|
end
|
128
151
|
end
|
129
152
|
end
|