smart_listing 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/smart_listing/smart_listing.coffee +2 -0
- data/app/assets/javascripts/smart_listing/smart_listing.coffee.erb +339 -0
- data/app/helpers/smart_listing/helper.rb +27 -17
- data/app/views/smart_listing/_action_show.html.erb +9 -0
- data/config/locales/en.yml +1 -0
- data/lib/smart_listing.rb +4 -0
- data/lib/smart_listing/config.rb +90 -0
- data/lib/smart_listing/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b40428000bfc11c02baa6cc4bc4ffa833895374
|
4
|
+
data.tar.gz: 8216002025b1b94989383185e3a0e74ef6f3edd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb27518994b2809cca48dc8c1b51fe6a5345eba4083d7f376f724924aa7f37ecfc86ef96f67f5245a9dd9a2880ad12ca0a24ebea54b8f4e5174844908fbcf0f6
|
7
|
+
data.tar.gz: c54bbcf9716bfc35e186ddaa0fcae0e4dcaa86c59e5facd0adb383adc36c016badcd210a1dda6139ba5124645f93c9b3365d7ead9d2f71bd82a66c133b32a113
|
@@ -113,6 +113,8 @@ class SmartListing
|
|
113
113
|
data = {}
|
114
114
|
data[checkbox.val()] = checkbox.is(":checked")
|
115
115
|
$.ajax({
|
116
|
+
beforeSend: (xhr, settings) ->
|
117
|
+
xhr.setRequestHeader "accept", "*/*;q=0.5, " + settings.accepts.script
|
116
118
|
url: @container.data("callback-href"),
|
117
119
|
type: "POST",
|
118
120
|
data: data,
|
@@ -0,0 +1,339 @@
|
|
1
|
+
# Useful when SmartListing target url is different than current one
|
2
|
+
$.rails.href = (element) ->
|
3
|
+
element.attr('href') || element.data('<% SmartListing.config.data_attributes(:href) %>')
|
4
|
+
|
5
|
+
class SmartListing
|
6
|
+
constructor: (e) ->
|
7
|
+
@container = e
|
8
|
+
@name = @container.attr('id')
|
9
|
+
@loading = @container.find(".<%= SmartListing.config.classes(:loading) %>")
|
10
|
+
@content = @container.find(".<%= SmartListing.config.classes(:content) %>")
|
11
|
+
@status = $(".<%= SmartListing.config.classes(:status) %>[data-<%= SmartListing.config.data_attributes(:main) %>='#{@name}']")
|
12
|
+
@confirmed = null
|
13
|
+
|
14
|
+
@container.on 'ajax:before', (e) =>
|
15
|
+
@fadeLoading()
|
16
|
+
|
17
|
+
@container.on 'ajax:success', (e) =>
|
18
|
+
if $(e.target).is('.<%= SmartListing.config.classes(:item_actions) %> <%= SmartListing.config.selectors(:item_action_destroy) %>')
|
19
|
+
# handle HEAD OK response for deletion request
|
20
|
+
editable = $(e.target).closest('.<%= SmartListing.config.classes(:editable) %>')
|
21
|
+
if @container.find(".<%= SmartListing.config.classes(:editable) %>").length == 1
|
22
|
+
@reload()
|
23
|
+
return false
|
24
|
+
else
|
25
|
+
editable.remove()
|
26
|
+
|
27
|
+
@changeItemCount(-1)
|
28
|
+
@refresh()
|
29
|
+
|
30
|
+
@fadeLoaded()
|
31
|
+
return false
|
32
|
+
|
33
|
+
@container.on 'click', '<%= SmartListing.config.selectors(:edit_cancel) %>', (event) =>
|
34
|
+
editable = $(event.currentTarget).closest('.<%= SmartListing.config.classes(:editable) %>')
|
35
|
+
if(editable.length > 0)
|
36
|
+
# Cancel edit
|
37
|
+
@cancelEdit(editable)
|
38
|
+
else
|
39
|
+
# Cancel new record
|
40
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
|
41
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
42
|
+
false
|
43
|
+
|
44
|
+
@container.on 'click', '.<%= SmartListing.config.classes(:item_actions) %> a[data-<%= SmartListing.config.data_attributes(:confirmation) %>]', (event) =>
|
45
|
+
# Check if we are confirming the right element
|
46
|
+
if(@confirmed != event.currentTarget)
|
47
|
+
# We need confirmation
|
48
|
+
$.fn.smart_listing.showPopover $(event.currentTarget), $(event.currentTarget).data('<%= SmartListing.config.data_attributes(:confirmation) %>'), (confirm_elem) =>
|
49
|
+
@confirmed = confirm_elem[0]
|
50
|
+
false
|
51
|
+
else
|
52
|
+
# Confirmed, reset flag and go ahead with deletion
|
53
|
+
@confirmed = null
|
54
|
+
true
|
55
|
+
|
56
|
+
@container.on 'click', 'input[type=text].<%= SmartListing.config.classes(:autoselect) %>', (event) ->
|
57
|
+
$(this).select()
|
58
|
+
|
59
|
+
@container.on 'change', '.<%= SmartListing.config.classes(:callback) %>', (event) =>
|
60
|
+
checkbox = $(event.currentTarget)
|
61
|
+
id = checkbox.closest("<%= SmartListing.config.selectors(:row) %>").data("<%= SmartListing.config.data_attributes(:id) %>")
|
62
|
+
data = {}
|
63
|
+
data[checkbox.val()] = checkbox.is(":checked")
|
64
|
+
$.ajax({
|
65
|
+
beforeSend: (xhr, settings) ->
|
66
|
+
xhr.setRequestHeader "accept", "*/*;q=0.5, " + settings.accepts.script
|
67
|
+
url: @container.data("<%= SmartListing.config.data_attributes(:callback_href) %>"),
|
68
|
+
type: "POST",
|
69
|
+
data: data,
|
70
|
+
})
|
71
|
+
|
72
|
+
fadeLoading: =>
|
73
|
+
$.fn.smart_listing.onLoading(@content, @loading)
|
74
|
+
|
75
|
+
fadeLoaded: =>
|
76
|
+
$.fn.smart_listing.onLoaded(@content, @loading)
|
77
|
+
|
78
|
+
itemCount: =>
|
79
|
+
parseInt(@container.find('.<%= SmartListing.config.classes(:pagination_per_page) %> .<%= SmartListing.config.classes(:pagination_count) %>').html())
|
80
|
+
|
81
|
+
maxCount: =>
|
82
|
+
parseInt(@container.data('<%= SmartListing.config.data_attributes(:max_count) %>'))
|
83
|
+
|
84
|
+
changeItemCount: (value) =>
|
85
|
+
@container.find('.<%= SmartListing.config.classes(:pagination_per_page) %> .<%= SmartListing.config.classes(:pagination_count) %>').html(@itemCount() + value)
|
86
|
+
|
87
|
+
cancelEdit: (editable) =>
|
88
|
+
if editable.data('<%= SmartListing.config.data_attributes(:inline_edit_backup) %>')
|
89
|
+
editable.html(editable.data('<%= SmartListing.config.data_attributes(:inline_edit_backup) %>'))
|
90
|
+
editable.removeClass('<%= SmartListing.config.classes(:inline_editing) %>')
|
91
|
+
editable.removeData('<%= SmartListing.config.data_attributes(:inline_edit_backup) %>')
|
92
|
+
|
93
|
+
# Callback called when record is added/deleted using ajax request
|
94
|
+
refresh: () =>
|
95
|
+
header = @content.find('<%= SmartListing.config.selectors(:head) %>')
|
96
|
+
footer = @content.find('.<%= SmartListing.config.classes(:pagination_per_page) %>')
|
97
|
+
no_records = @content.find('.<%= SmartListing.config.classes(:no_records) %>')
|
98
|
+
|
99
|
+
if @itemCount() == 0
|
100
|
+
header.hide()
|
101
|
+
footer.hide()
|
102
|
+
no_records.show()
|
103
|
+
else
|
104
|
+
header.show()
|
105
|
+
footer.show()
|
106
|
+
no_records.hide()
|
107
|
+
|
108
|
+
if @maxCount()
|
109
|
+
if @itemCount() >= @maxCount()
|
110
|
+
if @itemCount()
|
111
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
|
112
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %> .<%= SmartListing.config.classes(:new_item_button) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
|
113
|
+
else
|
114
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
115
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %> .<%= SmartListing.config.classes(:new_item_button) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
116
|
+
|
117
|
+
@status.each (index, status) =>
|
118
|
+
$(status).find('.<%= SmartListing.config.classes(:limit) %>').html(@maxCount() - @itemCount())
|
119
|
+
if @maxCount() - @itemCount() == 0
|
120
|
+
$(status).find('.<%= SmartListing.config.classes(:limit_alert) %>').show()
|
121
|
+
else
|
122
|
+
$(status).find('.<%= SmartListing.config.classes(:limit_alert) %>').hide()
|
123
|
+
|
124
|
+
# Trigger AJAX request to reload the list
|
125
|
+
reload: () =>
|
126
|
+
$.rails.handleRemote(@container)
|
127
|
+
|
128
|
+
params: () =>
|
129
|
+
@container.data('<%= SmartListing.config.data_attributes(:params) %>')
|
130
|
+
|
131
|
+
#################################################################################################
|
132
|
+
# Methods executed by rails UJS:
|
133
|
+
|
134
|
+
new_item: (content) =>
|
135
|
+
new_item_action = @container.find('.<%= SmartListing.config.classes(:new_item_action) %>')
|
136
|
+
new_item_placeholder = @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
|
137
|
+
|
138
|
+
@container.find('.<%= SmartListing.config.classes(:editable) %>').each (i, v) =>
|
139
|
+
@cancelEdit($(v))
|
140
|
+
|
141
|
+
new_item_action.addClass('<%= SmartListing.config.classes(:hidden) %>')
|
142
|
+
new_item_placeholder.removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
143
|
+
new_item_placeholder.html(content)
|
144
|
+
new_item_placeholder.addClass('<%= SmartListing.config.classes(:inline_editing) %>')
|
145
|
+
|
146
|
+
@fadeLoaded()
|
147
|
+
|
148
|
+
create: (id, success, content) =>
|
149
|
+
new_item_action = @container.find('.<%= SmartListing.config.classes(:new_item_action) %>')
|
150
|
+
new_item_placeholder = @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>')
|
151
|
+
|
152
|
+
if success
|
153
|
+
new_item_placeholder.addClass('<%= SmartListing.config.classes(:hidden) %>')
|
154
|
+
new_item_action.removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
155
|
+
|
156
|
+
new_item = $('<tr />').addClass('<%= SmartListing.config.classes(:editable) %>')
|
157
|
+
new_item.attr('data-<%= SmartListing.config.data_attributes(:id) %>', id)
|
158
|
+
new_item.html(content)
|
159
|
+
new_item_placeholder.before(new_item)
|
160
|
+
|
161
|
+
@changeItemCount(1)
|
162
|
+
@refresh()
|
163
|
+
else
|
164
|
+
new_item_placeholder.html(content)
|
165
|
+
|
166
|
+
@fadeLoaded()
|
167
|
+
|
168
|
+
edit: (id, content) =>
|
169
|
+
@container.find('.<%= SmartListing.config.classes(:editable) %>').each (i, v) =>
|
170
|
+
@cancelEdit($(v))
|
171
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
|
172
|
+
@container.find('.<%= SmartListing.config.classes(:new_item_action) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
|
173
|
+
|
174
|
+
editable = @container.find(".<%= SmartListing.config.classes(:editable) %>[data-<%= SmartListing.config.data_attributes(:id) %>=#{id}]")
|
175
|
+
editable.data('<%= SmartListing.config.data_attributes(:inline_edit_backup) %>', editable.html())
|
176
|
+
editable.html(content)
|
177
|
+
editable.addClass('<%= SmartListing.config.classes(:inline_editing) %>')
|
178
|
+
|
179
|
+
@fadeLoaded()
|
180
|
+
|
181
|
+
update: (id, success, content) =>
|
182
|
+
editable = @container.find(".<%= SmartListing.config.classes(:editable) %>[data-<%= SmartListing.config.data_attributes(:id) %>=#{id}]")
|
183
|
+
if success
|
184
|
+
editable.removeClass('<%= SmartListing.config.classes(:inline_editing) %>')
|
185
|
+
editable.removeData('<%= SmartListing.config.data_attributes(:inline_edit_backup) %>')
|
186
|
+
editable.html(content)
|
187
|
+
|
188
|
+
@refresh()
|
189
|
+
else
|
190
|
+
editable.html(content)
|
191
|
+
|
192
|
+
@fadeLoaded()
|
193
|
+
|
194
|
+
destroy: (id, destroyed) =>
|
195
|
+
# No need to do anything here, already handled by ajax:success handler
|
196
|
+
|
197
|
+
remove: (id) =>
|
198
|
+
editable = @container.find(".<%= SmartListing.config.classes(:editable) %>[data-<%= SmartListing.config.data_attributes(:id) %>=#{id}]").first()
|
199
|
+
editable.remove()
|
200
|
+
|
201
|
+
update_list: (content, data) =>
|
202
|
+
$.each data, (key, value) =>
|
203
|
+
@container.data(key, value)
|
204
|
+
|
205
|
+
@content.html(content)
|
206
|
+
|
207
|
+
@refresh()
|
208
|
+
@fadeLoaded()
|
209
|
+
|
210
|
+
$.fn.smart_listing = () ->
|
211
|
+
map = $(this).map () ->
|
212
|
+
if !$(this).data('<%= SmartListing.config.data_attributes(:main) %>')
|
213
|
+
$(this).data('<%= SmartListing.config.data_attributes(:main) %>', new SmartListing($(this)))
|
214
|
+
$(this).data('<%= SmartListing.config.data_attributes(:main) %>')
|
215
|
+
if map.length == 1
|
216
|
+
map[0]
|
217
|
+
else
|
218
|
+
map
|
219
|
+
|
220
|
+
$.fn.smart_listing.observeField = (field, opts = {}) ->
|
221
|
+
key_timeout = null
|
222
|
+
last_value = null
|
223
|
+
options =
|
224
|
+
onFilled: () ->
|
225
|
+
onEmpty: () ->
|
226
|
+
onChange: () ->
|
227
|
+
options = $.extend(options, opts)
|
228
|
+
|
229
|
+
keyChange = () ->
|
230
|
+
if field.val().length > 0
|
231
|
+
options.onFilled()
|
232
|
+
else
|
233
|
+
options.onEmpty()
|
234
|
+
|
235
|
+
if field.val() == last_value && field.val().length != 0
|
236
|
+
return
|
237
|
+
lastValue = field.val()
|
238
|
+
|
239
|
+
options.onChange()
|
240
|
+
|
241
|
+
field.data('<%= SmartListing.config.data_attributes(:observed) %>', true)
|
242
|
+
|
243
|
+
field.bind 'keydown', (e) ->
|
244
|
+
if(key_timeout)
|
245
|
+
clearTimeout(key_timeout)
|
246
|
+
|
247
|
+
key_timeout = setTimeout(->
|
248
|
+
keyChange()
|
249
|
+
, 400)
|
250
|
+
|
251
|
+
$.fn.smart_listing.showPopover = (confirmation_elem, msg, confirm) ->
|
252
|
+
buildPopover = (confirmation_elem, msg) ->
|
253
|
+
deletion_popover = $('<div/>').addClass('confirmation_box')
|
254
|
+
deletion_popover.append($('<p/>').html(msg))
|
255
|
+
deletion_popover.append($('<p/>')
|
256
|
+
.append($('<button/>').html('Yes').addClass('btn btn-danger ').click (event) =>
|
257
|
+
# set @confirmed element and emulate click on icon
|
258
|
+
editable = $(event.currentTarget).closest('.<%= SmartListing.config.classes(:editable) %>')
|
259
|
+
confirm(confirmation_elem)
|
260
|
+
$(confirmation_elem).click()
|
261
|
+
$(confirmation_elem).popover('destroy')
|
262
|
+
)
|
263
|
+
.append(" ")
|
264
|
+
.append($('<button/>').html('No').addClass('btn btn-small').click (event) =>
|
265
|
+
editable = $(event.currentTarget).closest('.<%= SmartListing.config.classes(:editable) %>')
|
266
|
+
$(confirmation_elem).popover('destroy')
|
267
|
+
)
|
268
|
+
)
|
269
|
+
|
270
|
+
confirmation_elem.popover('destroy')
|
271
|
+
confirmation_elem.popover(content: buildPopover(confirmation_elem, msg), html: true, trigger: 'manual', title: null)
|
272
|
+
confirmation_elem.popover('show')
|
273
|
+
|
274
|
+
$.fn.smart_listing.onLoading = (content, loader) ->
|
275
|
+
content.stop(true).fadeTo(500, 0.2)
|
276
|
+
loading.show()
|
277
|
+
loading.stop(true).fadeTo(500, 1)
|
278
|
+
|
279
|
+
$.fn.smart_listing.onLoaded = (content, loader) ->
|
280
|
+
content.stop(true).fadeTo(500, 1)
|
281
|
+
loading.stop(true).fadeTo 500, 0, () =>
|
282
|
+
loading.hide()
|
283
|
+
|
284
|
+
$.fn.smart_listing_controls = () ->
|
285
|
+
$(this).each () ->
|
286
|
+
controls = $(this)
|
287
|
+
smart_listing = $("##{controls.data('<%= SmartListing.config.data_attributes(:main) %>')}")
|
288
|
+
reset = controls.find(".<%= SmartListing.config.classes(:controls_reset) %>")
|
289
|
+
|
290
|
+
controls.submit ->
|
291
|
+
# Merges smart list params with the form action url before submitting.
|
292
|
+
# This preserves smart list settings (page, sorting etc.).
|
293
|
+
|
294
|
+
prms = $.extend({}, smart_listing.smart_listing().params())
|
295
|
+
if $(this).data('<%= SmartListing.config.classes(:controls_reset) %>')
|
296
|
+
prms[$(this).data('<%= SmartListing.config.classes(:controls_reset) %>')] = null
|
297
|
+
|
298
|
+
if $.rails.href(smart_listing)
|
299
|
+
# If smart list has different target url than current one
|
300
|
+
controls.attr('action', $.rails.href(smart_listing) + "?" + jQuery.param(prms))
|
301
|
+
else
|
302
|
+
controls.attr('action', "?" + jQuery.param(prms))
|
303
|
+
|
304
|
+
smart_listing.trigger('ajax:before')
|
305
|
+
true
|
306
|
+
|
307
|
+
controls.find('input, select').change () ->
|
308
|
+
unless $(this).data('<%= SmartListing.config.data_attributes(:observed) %>') # do not submit controls form when changed field is observed (observing submits form by itself)
|
309
|
+
controls.submit()
|
310
|
+
|
311
|
+
$.fn.smart_listing_controls.filter(controls.find('.<%= SmartListing.config.classes(:filtering) %>'))
|
312
|
+
|
313
|
+
$.fn.smart_listing_controls.filter = (filter) ->
|
314
|
+
form = filter.closest('form')
|
315
|
+
button = filter.find('button')
|
316
|
+
icon = filter.find('<%= SmartListing.config.selectors(:filtering_icon) %>')
|
317
|
+
field = filter.find('input')
|
318
|
+
|
319
|
+
$.fn.smart_listing.observeField(field,
|
320
|
+
onFilled: ->
|
321
|
+
icon.removeClass('<%= SmartListing.config.classes(:filtering_search) %>')
|
322
|
+
icon.addClass('<%= SmartListing.config.classes(:filtering_cancel) %>')
|
323
|
+
button.removeClass('<%= SmartListing.config.classes(:filtering_disabled) %>')
|
324
|
+
onEmpty: ->
|
325
|
+
icon.addClass('<%= SmartListing.config.classes(:filtering_search) %>')
|
326
|
+
icon.removeClass('<%= SmartListing.config.classes(:filtering_cancel) %>')
|
327
|
+
button.addClass('<%= SmartListing.config.classes(:filtering_disabled) %>')
|
328
|
+
onChange: ->
|
329
|
+
form.submit()
|
330
|
+
)
|
331
|
+
|
332
|
+
icon.click ->
|
333
|
+
if field.val().length > 0
|
334
|
+
field.val('')
|
335
|
+
field.trigger('keydown')
|
336
|
+
|
337
|
+
$ ->
|
338
|
+
$('.<%= SmartListing.config.classes(:main) %>').smart_listing()
|
339
|
+
$('.<%= SmartListing.config.classes(:controls) %>').smart_listing_controls()
|
@@ -38,9 +38,13 @@ module SmartListing
|
|
38
38
|
@smart_listing.collection
|
39
39
|
end
|
40
40
|
|
41
|
+
def empty?
|
42
|
+
@smart_listing.count == 0
|
43
|
+
end
|
44
|
+
|
41
45
|
def pagination_per_page_links options = {}
|
42
|
-
container_classes = [
|
43
|
-
container_classes <<
|
46
|
+
container_classes = [SmartListing.config.classes(:pagination_per_page)]
|
47
|
+
container_classes << SmartListing.config.classes(:hidden) if empty?
|
44
48
|
|
45
49
|
per_page_sizes = @smart_listing.page_sizes.clone
|
46
50
|
per_page_sizes.push(0) if @smart_listing.unlimited_per_page?
|
@@ -78,7 +82,7 @@ module SmartListing
|
|
78
82
|
locals = {
|
79
83
|
:ordered => @smart_listing.sort_attr == attribute && (!@smart_listing.sort_extra || @smart_listing.sort_extra == extra.to_s),
|
80
84
|
:url => @template.url_for(sanitize_params(@template.params.merge(sort_params))),
|
81
|
-
:container_classes => [
|
85
|
+
:container_classes => [SmartListing.config.classes(:sortable)],
|
82
86
|
:attribute => attribute,
|
83
87
|
:title => title
|
84
88
|
}
|
@@ -113,15 +117,15 @@ module SmartListing
|
|
113
117
|
|
114
118
|
# Add new item button & placeholder to list
|
115
119
|
def item_new options = {}
|
116
|
-
new_item_action_classes =
|
117
|
-
new_item_action_classes <<
|
118
|
-
no_records_classes =
|
119
|
-
no_records_classes <<
|
120
|
+
new_item_action_classes = [SmartListing.config.classes(:new_item_action)]
|
121
|
+
new_item_action_classes << SmartListing.config.classes(:hidden) if !empty? && max_count?
|
122
|
+
no_records_classes = [SmartListing.config.classes(:no_records)]
|
123
|
+
no_records_classes << SmartListing.config.classes(:hidden) unless empty?
|
120
124
|
new_item_button_classes = []
|
121
|
-
new_item_button_classes <<
|
125
|
+
new_item_button_classes << SmartListing.config.classes(:hidden) if max_count?
|
122
126
|
|
123
127
|
locals = {
|
124
|
-
:placeholder_classes =>
|
128
|
+
:placeholder_classes => [SmartListing.config.classes(:new_item_placeholder), SmartListing.config.classes(:hidden)],
|
125
129
|
:new_item_action_classes => new_item_action_classes,
|
126
130
|
:colspan => options.delete(:colspan),
|
127
131
|
:no_items_classes => no_records_classes,
|
@@ -168,17 +172,17 @@ module SmartListing
|
|
168
172
|
output = ""
|
169
173
|
|
170
174
|
data = {}
|
171
|
-
data[
|
172
|
-
data[
|
173
|
-
data[
|
175
|
+
data[SmartListing.config.data_attributes(:max_count)] = @smart_listings[name].max_count if @smart_listings[name].max_count && @smart_listings[name].max_count > 0
|
176
|
+
data[SmartListing.config.data_attributes(:href)] = @smart_listings[name].href if @smart_listings[name].href
|
177
|
+
data[SmartListing.config.data_attributes(:callback_href)] = @smart_listings[name].callback_href if @smart_listings[name].callback_href
|
174
178
|
data.merge!(options[:data]) if options[:data]
|
175
179
|
|
176
180
|
if bare
|
177
181
|
output = capture(builder, &block)
|
178
182
|
else
|
179
|
-
output = content_tag(:div, :class =>
|
180
|
-
concat(content_tag(:div, "", :class =>
|
181
|
-
concat(content_tag(:div, :class =>
|
183
|
+
output = content_tag(:div, :class => SmartListing.config.classes(:main), :id => name, :data => data) do
|
184
|
+
concat(content_tag(:div, "", :class => SmartListing.config.classes(:loading)))
|
185
|
+
concat(content_tag(:div, :class => SmartListing.config.classes(:content)) do
|
182
186
|
concat(capture(builder, &block))
|
183
187
|
end)
|
184
188
|
end
|
@@ -202,6 +206,12 @@ module SmartListing
|
|
202
206
|
|
203
207
|
action_name = action[:name].to_sym
|
204
208
|
case action_name
|
209
|
+
when :show
|
210
|
+
locals = {
|
211
|
+
:url => action.delete(:url),
|
212
|
+
:icon => action.delete(:icon),
|
213
|
+
}
|
214
|
+
concat(render(:partial => 'smart_listing/action_show', :locals => locals))
|
205
215
|
when :edit
|
206
216
|
locals = {
|
207
217
|
:url => action.delete(:url),
|
@@ -249,8 +259,8 @@ module SmartListing
|
|
249
259
|
:part => smart_listing.partial,
|
250
260
|
:smart_listing => builder,
|
251
261
|
:smart_listing_data => {
|
252
|
-
:params => smart_listing.all_params,
|
253
|
-
|
262
|
+
SmartListing.config.data_attributes(:params) => smart_listing.all_params,
|
263
|
+
SmartListing.config.data_attributes(:max_count) => smart_listing.max_count,
|
254
264
|
}
|
255
265
|
})
|
256
266
|
end
|
data/config/locales/en.yml
CHANGED
data/lib/smart_listing.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'smart_listing/config'
|
1
2
|
require "smart_listing/engine"
|
2
3
|
require "kaminari"
|
4
|
+
|
3
5
|
module SmartListing
|
4
6
|
class Base
|
5
7
|
if Rails.env.development?
|
@@ -45,6 +47,7 @@ module SmartListing
|
|
45
47
|
def setup params, cookies
|
46
48
|
@page = params[param_names[:page]]
|
47
49
|
@per_page = !params[param_names[:per_page]] || params[param_names[:per_page]].empty? ? (@options[:memorize_per_page] && cookies[param_names[:per_page]].to_i > 0 ? cookies[param_names[:per_page]].to_i : page_sizes.first) : params[param_names[:per_page]].to_i
|
50
|
+
@per_page = DEFAULT_PAGE_SIZES.first unless DEFAULT_PAGE_SIZES.include?(@per_page)
|
48
51
|
@sort_attr = params[param_names[:sort_attr]] || @options[:default_sort_attr]
|
49
52
|
@sort_order = ["asc", "desc"].include?(params[param_names[:sort_order]]) ? params[param_names[:sort_order]] : "desc"
|
50
53
|
@sort_extra = params[param_names[:sort_extra]]
|
@@ -52,6 +55,7 @@ module SmartListing
|
|
52
55
|
cookies[param_names[:per_page]] = @per_page if @options[:memorize_per_page]
|
53
56
|
|
54
57
|
@count = @collection.size
|
58
|
+
@count = @count.length if @count.is_a?(Hash)
|
55
59
|
|
56
60
|
# Reset @page if greater than total number of pages
|
57
61
|
no_pages = (@count.to_f / @per_page.to_f).ceil.to_i
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module SmartListing
|
2
|
+
def self.configure(&block)
|
3
|
+
yield @config ||= SmartListing::Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@config ||= SmartListing::Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
DEFAULTS = {
|
12
|
+
:constants => {
|
13
|
+
:classes => {
|
14
|
+
:main => "smart-listing",
|
15
|
+
:editable => "editable",
|
16
|
+
:content => "content",
|
17
|
+
:loading => "loading",
|
18
|
+
:status => "smart-listing-status",
|
19
|
+
:item_actions => "actions",
|
20
|
+
:new_item_placeholder => "new-item-placeholder",
|
21
|
+
:new_item_action => "new-item-action",
|
22
|
+
:new_item_button => "btn",
|
23
|
+
:hidden => "hidden",
|
24
|
+
:autoselect => "autoselect",
|
25
|
+
:callback => "callback",
|
26
|
+
:pagination_per_page => "pagination-per-page",
|
27
|
+
:pagination_count => "count",
|
28
|
+
:inline_editing => "info",
|
29
|
+
:no_records => "no-records",
|
30
|
+
:limit => "limit",
|
31
|
+
:limit_alert => "limit-alert",
|
32
|
+
:controls => "smart-listing-controls",
|
33
|
+
:controls_reset => "reset",
|
34
|
+
:filtering => "filter",
|
35
|
+
:filtering_search => "glyphicon-search",
|
36
|
+
:filtering_cancel => "glyphicon-remove",
|
37
|
+
:filtering_disabled => "disabled",
|
38
|
+
:sortable => "sortable",
|
39
|
+
},
|
40
|
+
:data_attributes => {
|
41
|
+
:main => "smart-listing",
|
42
|
+
:confirmation => "confirmation",
|
43
|
+
:id => "id",
|
44
|
+
:href => "href",
|
45
|
+
:callback_href => "callback-href",
|
46
|
+
:max_count => "max-count",
|
47
|
+
:inline_edit_backup => "smart-listing-edit-backup",
|
48
|
+
:params => "params",
|
49
|
+
:observed => "observed",
|
50
|
+
:href => "href",
|
51
|
+
},
|
52
|
+
:selectors => {
|
53
|
+
:item_action_destroy => "a.destroy",
|
54
|
+
:edit_cancel => "button.cancel",
|
55
|
+
:row => "tr",
|
56
|
+
:head => "thead",
|
57
|
+
:filtering_icon => "i"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
@options = DEFAULTS
|
64
|
+
end
|
65
|
+
|
66
|
+
def method_missing(sym, *args, &block)
|
67
|
+
@options[sym] = *args
|
68
|
+
end
|
69
|
+
|
70
|
+
def constants key, value = nil
|
71
|
+
if value == nil
|
72
|
+
@options[:constants][key]
|
73
|
+
else
|
74
|
+
@options[:constants][key].merge!(value)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def classes key
|
79
|
+
@options[:constants][:classes][key]
|
80
|
+
end
|
81
|
+
|
82
|
+
def data_attributes key
|
83
|
+
@options[:constants][:data_attributes][key]
|
84
|
+
end
|
85
|
+
|
86
|
+
def selectors key
|
87
|
+
@options[:constants][:selectors][key]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_listing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- Rakefile
|
79
79
|
- app/assets/javascripts/smart_listing/application.js
|
80
80
|
- app/assets/javascripts/smart_listing/smart_listing.coffee
|
81
|
+
- app/assets/javascripts/smart_listing/smart_listing.coffee.erb
|
81
82
|
- app/assets/stylesheets/smart_listing/application.css
|
82
83
|
- app/helpers/smart_listing/application_helper.rb
|
83
84
|
- app/helpers/smart_listing/helper.rb
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- app/views/smart_listing/_action_delete.html.erb
|
86
87
|
- app/views/smart_listing/_action_edit.html.erb
|
87
88
|
- app/views/smart_listing/_action_inactive.html.erb
|
89
|
+
- app/views/smart_listing/_action_show.html.erb
|
88
90
|
- app/views/smart_listing/_item_new.html.erb
|
89
91
|
- app/views/smart_listing/_pagination_per_page_link.html.erb
|
90
92
|
- app/views/smart_listing/_pagination_per_page_links.html.erb
|
@@ -100,6 +102,7 @@ files:
|
|
100
102
|
- config/routes.rb
|
101
103
|
- lib/generators/smart_listing/views_generator.rb
|
102
104
|
- lib/smart_listing.rb
|
105
|
+
- lib/smart_listing/config.rb
|
103
106
|
- lib/smart_listing/engine.rb
|
104
107
|
- lib/smart_listing/version.rb
|
105
108
|
- lib/tasks/smart_list_tasks.rake
|