smart_listing 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ec44fc0c5fafd591a4980ce79662010683d707d
4
- data.tar.gz: dbd5d450845dd1910e63f7e8e251070632d91edd
3
+ metadata.gz: aec78db2f43e9f78c7420c7a21efdd506da3dbe6
4
+ data.tar.gz: 8297a520f5c771c428aa2dddbb3219e1696a5e0b
5
5
  SHA512:
6
- metadata.gz: dc49ee300e56d870674b49ca922d24771f0bafefa87ef36497450019f31276bf9be99360f24c4e577e38b732361653c7d62a150ce9f78175be7178206bdf4d9e
7
- data.tar.gz: 8abbb0b78f672f177234356bd54f626a7c0afd679563cdd6fd463d70c24f2841b23abf73e157d491963c72413ebfce6041c1aa698b23fb882c74236fdce4f980
6
+ metadata.gz: 542635bdcc49d20e137793ee6e54dc46731c271fedd49d053b5e27c642b362e664b06ffc7f7d65774177f1efa63db6d85252481b9d7c9ad05275f775770393dc
7
+ data.tar.gz: fa82edc043dc01ac02e53b6d1a8a28388be34ca1e67a4b89061473cd60f5fef975c447679a02cbb479df0e95ced1093f28f41014f0e9666b5fb139fdd6550b6b
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013 Sology
3
+ Copyright (c) 2013 Sology (www.sology.eu)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -2,3 +2,7 @@ SmartListing
2
2
  ==========
3
3
 
4
4
  SmartListing helps creating sortable lists of ActiveRecord collections with pagination, filtering and inline editing.
5
+
6
+ Created by Sology http://www.sology.eu
7
+
8
+ Initial development sponsored by Smart Language Apps Limited http://smartlanguageapps.com/
@@ -1,6 +1,6 @@
1
1
  # Useful when smart list target url is different than current one
2
2
  $.rails.href = (element) ->
3
- element.attr('href') || element.data('href')
3
+ element.attr('href') || element.data('href')
4
4
 
5
5
  $.fn.observeField = (opts = {}) ->
6
6
  field = $(this)
@@ -35,280 +35,280 @@ $.fn.observeField = (opts = {}) ->
35
35
  , 400)
36
36
 
37
37
  class SmartListing
38
- constructor: (e) ->
39
- @container = e
40
- @name = @container.attr('id')
41
- @loading = @container.find('.loading')
42
- @content = @container.find('.content')
43
- @status = $(".smart_listing_status[data-smart-list='#{@name}']")
44
- @confirmed = null
45
-
46
- createPopover = (confirmation_elem, msg) =>
47
- deletion_popover = $('<div/>').addClass('confirmation_box')
48
- deletion_popover.append($('<p/>').html(msg))
49
- deletion_popover.append($('<p/>')
50
- .append($('<button/>').html('Yes').addClass('btn btn-danger ').click (event) =>
51
- # set @confirmed element and emulate click on icon
52
- editable = $(event.currentTarget).closest('.editable')
53
- @confirmed = confirmation_elem
54
- $(confirmation_elem).click()
55
- $(confirmation_elem).popover('destroy')
56
- )
57
- .append($('<button/>').html('No').addClass('btn btn-small').click (event) =>
58
- editable = $(event.currentTarget).closest('.editable')
59
- $(confirmation_elem).popover('destroy')
60
- )
61
- )
62
-
63
- @container.on 'ajax:before', (e) =>
64
- @fadeLoading()
65
-
66
- @container.on 'ajax:success', (e) =>
67
- if $(e.target).is('.actions a.destroy')
68
- # handle HEAD OK response for deletion request
69
- editable = $(e.target).closest('.editable')
70
- if @container.find(".editable").length == 1
71
- @reload()
72
- return false
73
- else
74
- editable.remove()
75
-
76
- @changeItemCount(-1)
77
- @refresh()
78
-
79
- @fadeLoaded()
80
- return false
81
-
82
- @container.on 'click', 'button.cancel', (event) =>
83
- editable = $(event.currentTarget).closest('.editable')
84
- if(editable.length > 0)
85
- # Cancel edit
86
- @cancelEdit(editable)
87
- else
88
- # Cancel new record
89
- @container.find('.new_item_placeholder').addClass('disabled')
90
- @container.find('.new_item_action').removeClass('disabled')
91
- false
92
-
93
- @container.on 'click', '.actions a[data-confirmation]', (event) =>
94
- # Check if we are confirming the right element
95
- if(@confirmed != event.currentTarget)
96
- # We need confirmation
97
- @container.find('.actions a').popover('destroy')
98
- $(event.currentTarget).popover(content: createPopover(event.currentTarget, $(event.currentTarget).data('confirmation')), html: true, trigger: 'manual')
99
- $(event.currentTarget).popover('show')
100
- false
101
- else
102
- # Confirmed, reset flag and go ahead with deletion
103
- @confirmed = null
104
- true
105
-
106
- @container.on 'click', 'input[type=text].autoselect', (event) ->
107
- $(this).select()
108
-
109
- fadeLoading: =>
110
- @content.stop(true).fadeTo(500, 0.2)
111
- @loading.show()
112
- @loading.stop(true).fadeTo(500, 1)
113
-
114
- fadeLoaded: =>
115
- @content.stop(true).fadeTo(500, 1)
116
- @loading.stop(true).fadeTo 500, 0, () =>
117
- @loading.hide()
118
-
119
- @content.find('.play').each () ->
120
- self.loadAudio($(this).data('key'), $(this).data('target'))
121
-
122
- itemCount: =>
123
- parseInt(@container.find('.pagination_per_page .count').html())
124
-
125
- maxCount: =>
126
- parseInt(@container.data('max-count'))
127
-
128
- changeItemCount: (value) =>
129
- @container.find('.pagination_per_page .count').html(@itemCount() + value)
130
-
131
- cancelEdit: (editable) =>
132
- if editable.data('smart_listing_edit_backup')
133
- editable.html(editable.data('smart_listing_edit_backup'))
134
- editable.removeClass('info')
135
- editable.removeData('smart_listing_edit_backup')
136
-
137
- # Callback called when record is added/deleted using ajax request
138
- refresh: () =>
139
- header = @content.find('thead')
140
- footer = @content.find('.pagination_per_page')
141
- no_records = @content.find('.no_records')
142
-
143
- if @itemCount() == 0
144
- header.hide()
145
- footer.hide()
146
- no_records.show()
147
- else
148
- header.show()
149
- footer.show()
150
- no_records.hide()
151
-
152
- if @maxCount()
153
- if @itemCount() >= @maxCount()
154
- if @itemCount()
155
- @container.find('.new_item_action').addClass('disabled')
156
- @container.find('.new_item_action .btn').addClass('disabled')
157
- else
158
- @container.find('.new_item_action').removeClass('disabled')
159
- @container.find('.new_item_action .btn').removeClass('disabled')
160
-
161
- @status.each (index, status) =>
162
- $(status).find('.smart_listing_limit').html(@maxCount() - @itemCount())
163
- if @maxCount() - @itemCount() == 0
164
- $(status).find('.smart_listing_limit_alert').show()
165
- else
166
- $(status).find('.smart_listing_limit_alert').hide()
167
-
168
- # Trigger AJAX request to reload the list
169
- reload: () =>
170
- $.rails.handleRemote(@container)
171
-
172
- params: () =>
173
- @container.data('params')
174
-
38
+ constructor: (e) ->
39
+ @container = e
40
+ @name = @container.attr('id')
41
+ @loading = @container.find('.loading')
42
+ @content = @container.find('.content')
43
+ @status = $(".smart_listing_status[data-smart-listing='#{@name}']")
44
+ @confirmed = null
45
+
46
+ createPopover = (confirmation_elem, msg) =>
47
+ deletion_popover = $('<div/>').addClass('confirmation_box')
48
+ deletion_popover.append($('<p/>').html(msg))
49
+ deletion_popover.append($('<p/>')
50
+ .append($('<button/>').html('Yes').addClass('btn btn-danger ').click (event) =>
51
+ # set @confirmed element and emulate click on icon
52
+ editable = $(event.currentTarget).closest('.editable')
53
+ @confirmed = confirmation_elem
54
+ $(confirmation_elem).click()
55
+ $(confirmation_elem).popover('destroy')
56
+ )
57
+ .append($('<button/>').html('No').addClass('btn btn-small').click (event) =>
58
+ editable = $(event.currentTarget).closest('.editable')
59
+ $(confirmation_elem).popover('destroy')
60
+ )
61
+ )
62
+
63
+ @container.on 'ajax:before', (e) =>
64
+ @fadeLoading()
65
+
66
+ @container.on 'ajax:success', (e) =>
67
+ if $(e.target).is('.actions a.destroy')
68
+ # handle HEAD OK response for deletion request
69
+ editable = $(e.target).closest('.editable')
70
+ if @container.find(".editable").length == 1
71
+ @reload()
72
+ return false
73
+ else
74
+ editable.remove()
75
+
76
+ @changeItemCount(-1)
77
+ @refresh()
78
+
79
+ @fadeLoaded()
80
+ return false
81
+
82
+ @container.on 'click', 'button.cancel', (event) =>
83
+ editable = $(event.currentTarget).closest('.editable')
84
+ if(editable.length > 0)
85
+ # Cancel edit
86
+ @cancelEdit(editable)
87
+ else
88
+ # Cancel new record
89
+ @container.find('.new_item_placeholder').addClass('disabled')
90
+ @container.find('.new_item_action').removeClass('disabled')
91
+ false
92
+
93
+ @container.on 'click', '.actions a[data-confirmation]', (event) =>
94
+ # Check if we are confirming the right element
95
+ if(@confirmed != event.currentTarget)
96
+ # We need confirmation
97
+ @container.find('.actions a').popover('destroy')
98
+ $(event.currentTarget).popover(content: createPopover(event.currentTarget, $(event.currentTarget).data('confirmation')), html: true, trigger: 'manual')
99
+ $(event.currentTarget).popover('show')
100
+ false
101
+ else
102
+ # Confirmed, reset flag and go ahead with deletion
103
+ @confirmed = null
104
+ true
105
+
106
+ @container.on 'click', 'input[type=text].autoselect', (event) ->
107
+ $(this).select()
108
+
109
+ fadeLoading: =>
110
+ @content.stop(true).fadeTo(500, 0.2)
111
+ @loading.show()
112
+ @loading.stop(true).fadeTo(500, 1)
113
+
114
+ fadeLoaded: =>
115
+ @content.stop(true).fadeTo(500, 1)
116
+ @loading.stop(true).fadeTo 500, 0, () =>
117
+ @loading.hide()
118
+
119
+ @content.find('.play').each () ->
120
+ self.loadAudio($(this).data('key'), $(this).data('target'))
121
+
122
+ itemCount: =>
123
+ parseInt(@container.find('.pagination_per_page .count').html())
124
+
125
+ maxCount: =>
126
+ parseInt(@container.data('max-count'))
127
+
128
+ changeItemCount: (value) =>
129
+ @container.find('.pagination_per_page .count').html(@itemCount() + value)
130
+
131
+ cancelEdit: (editable) =>
132
+ if editable.data('smart_listing_edit_backup')
133
+ editable.html(editable.data('smart_listing_edit_backup'))
134
+ editable.removeClass('info')
135
+ editable.removeData('smart_listing_edit_backup')
136
+
137
+ # Callback called when record is added/deleted using ajax request
138
+ refresh: () =>
139
+ header = @content.find('thead')
140
+ footer = @content.find('.pagination_per_page')
141
+ no_records = @content.find('.no_records')
142
+
143
+ if @itemCount() == 0
144
+ header.hide()
145
+ footer.hide()
146
+ no_records.show()
147
+ else
148
+ header.show()
149
+ footer.show()
150
+ no_records.hide()
151
+
152
+ if @maxCount()
153
+ if @itemCount() >= @maxCount()
154
+ if @itemCount()
155
+ @container.find('.new_item_action').addClass('disabled')
156
+ @container.find('.new_item_action .btn').addClass('disabled')
157
+ else
158
+ @container.find('.new_item_action').removeClass('disabled')
159
+ @container.find('.new_item_action .btn').removeClass('disabled')
160
+
161
+ @status.each (index, status) =>
162
+ $(status).find('.smart_listing_limit').html(@maxCount() - @itemCount())
163
+ if @maxCount() - @itemCount() == 0
164
+ $(status).find('.smart_listing_limit_alert').show()
165
+ else
166
+ $(status).find('.smart_listing_limit_alert').hide()
167
+
168
+ # Trigger AJAX request to reload the list
169
+ reload: () =>
170
+ $.rails.handleRemote(@container)
171
+
172
+ params: () =>
173
+ @container.data('params')
174
+
175
175
  #################################################################################################
176
- # Methods executed by rails UJS:
176
+ # Methods executed by rails UJS:
177
177
 
178
- new_item: (content) =>
179
- new_item_action = @container.find('.new_item_action')
180
- new_item_placeholder = @container.find('.new_item_placeholder').addClass('disabled')
178
+ new_item: (content) =>
179
+ new_item_action = @container.find('.new_item_action')
180
+ new_item_placeholder = @container.find('.new_item_placeholder').addClass('disabled')
181
181
 
182
- @container.find('.editable').each (i, v) =>
183
- @cancelEdit($(v))
182
+ @container.find('.editable').each (i, v) =>
183
+ @cancelEdit($(v))
184
184
 
185
- new_item_action.addClass('disabled')
186
- new_item_placeholder.removeClass('disabled')
187
- new_item_placeholder.html(content)
188
- new_item_placeholder.addClass('info')
185
+ new_item_action.addClass('disabled')
186
+ new_item_placeholder.removeClass('disabled')
187
+ new_item_placeholder.html(content)
188
+ new_item_placeholder.addClass('info')
189
189
 
190
- @fadeLoaded()
190
+ @fadeLoaded()
191
191
 
192
- create: (id, success, content) =>
193
- new_item_action = @container.find('.new_item_action')
194
- new_item_placeholder = @container.find('.new_item_placeholder')
192
+ create: (id, success, content) =>
193
+ new_item_action = @container.find('.new_item_action')
194
+ new_item_placeholder = @container.find('.new_item_placeholder')
195
195
 
196
- if success
197
- new_item_placeholder.addClass('disabled')
198
- new_item_action.removeClass('disabled')
196
+ if success
197
+ new_item_placeholder.addClass('disabled')
198
+ new_item_action.removeClass('disabled')
199
199
 
200
- new_item = $('<tr />').addClass('editable')
201
- new_item.attr('data-id', id)
202
- new_item.html(content)
203
- new_item_placeholder.before(new_item)
200
+ new_item = $('<tr />').addClass('editable')
201
+ new_item.attr('data-id', id)
202
+ new_item.html(content)
203
+ new_item_placeholder.before(new_item)
204
204
 
205
- @changeItemCount(1)
206
- @refresh()
207
- else
208
- new_item_placeholder.html(content)
205
+ @changeItemCount(1)
206
+ @refresh()
207
+ else
208
+ new_item_placeholder.html(content)
209
209
 
210
- @fadeLoaded()
210
+ @fadeLoaded()
211
211
 
212
- edit: (id, content) =>
213
- @container.find('.editable').each (i, v) =>
214
- @cancelEdit($(v))
215
- @container.find('.new_item_placeholder').addClass('disabled')
216
- @container.find('.new_item_action').removeClass('disabled')
212
+ edit: (id, content) =>
213
+ @container.find('.editable').each (i, v) =>
214
+ @cancelEdit($(v))
215
+ @container.find('.new_item_placeholder').addClass('disabled')
216
+ @container.find('.new_item_action').removeClass('disabled')
217
217
 
218
- editable = @container.find(".editable[data-id=#{id}]")
219
- editable.data('smart_listing_edit_backup', editable.html())
220
- editable.html(content)
221
- editable.addClass('info')
218
+ editable = @container.find(".editable[data-id=#{id}]")
219
+ editable.data('smart_listing_edit_backup', editable.html())
220
+ editable.html(content)
221
+ editable.addClass('info')
222
222
 
223
- @fadeLoaded()
223
+ @fadeLoaded()
224
224
 
225
- update: (id, success, content) =>
226
- editable = @container.find(".editable[data-id=#{id}]")
227
- if success
228
- editable.removeClass('info')
229
- editable.removeData('smart_listing_edit_backup')
230
- editable.html(content)
225
+ update: (id, success, content) =>
226
+ editable = @container.find(".editable[data-id=#{id}]")
227
+ if success
228
+ editable.removeClass('info')
229
+ editable.removeData('smart_listing_edit_backup')
230
+ editable.html(content)
231
231
 
232
- @refresh()
233
- else
234
- editable.html(content)
232
+ @refresh()
233
+ else
234
+ editable.html(content)
235
235
 
236
- @fadeLoaded()
237
-
238
- destroy: (id, destroyed) =>
239
- # No need to do anything here, already handled by ajax:success handler
240
-
241
- update_list: (content, data) =>
242
- $.each data, (key, value) =>
243
- @container.data(key, value)
236
+ @fadeLoaded()
237
+
238
+ destroy: (id, destroyed) =>
239
+ # No need to do anything here, already handled by ajax:success handler
240
+
241
+ update_list: (content, data) =>
242
+ $.each data, (key, value) =>
243
+ @container.data(key, value)
244
244
 
245
- @content.html(content)
245
+ @content.html(content)
246
246
 
247
- @refresh()
248
- @fadeLoaded()
247
+ @refresh()
248
+ @fadeLoaded()
249
249
 
250
250
  $.fn.smart_listing = () ->
251
- map = $(this).map () ->
252
- if !$(this).data('smart-list')
253
- $(this).data('smart-list', new SmartListing($(this)))
254
- $(this).data('smart-list')
255
- if map.length == 1
256
- map[0]
257
- else
258
- map
251
+ map = $(this).map () ->
252
+ if !$(this).data('smart-listing')
253
+ $(this).data('smart-listing', new SmartListing($(this)))
254
+ $(this).data('smart-listing')
255
+ if map.length == 1
256
+ map[0]
257
+ else
258
+ map
259
259
 
260
260
  $.fn.handleSmartListingControls = () ->
261
- $(this).each () ->
262
- controls = $(this)
263
- smart_listing = $("##{controls.data('smart-list')}")
261
+ $(this).each () ->
262
+ controls = $(this)
263
+ smart_listing = $("##{controls.data('smart-listing')}")
264
264
 
265
- controls.submit ->
266
- # Merges smart list params with the form action url before submitting.
267
- # This preserves smart list settings (page, sorting etc.).
265
+ controls.submit ->
266
+ # Merges smart list params with the form action url before submitting.
267
+ # This preserves smart list settings (page, sorting etc.).
268
268
 
269
- prms = $.extend({}, smart_listing.smart_listing().params())
270
- if $(this).data('reset')
271
- prms[$(this).data('reset')] = null
269
+ prms = $.extend({}, smart_listing.smart_listing().params())
270
+ if $(this).data('reset')
271
+ prms[$(this).data('reset')] = null
272
272
 
273
- if $.rails.href(smart_listing)
274
- # If smart list has different target url than current one
275
- controls.attr('action', $.rails.href(smart_listing) + "?" + jQuery.param(prms))
276
- else
277
- controls.attr('action', "?" + jQuery.param(prms))
273
+ if $.rails.href(smart_listing)
274
+ # If smart list has different target url than current one
275
+ controls.attr('action', $.rails.href(smart_listing) + "?" + jQuery.param(prms))
276
+ else
277
+ controls.attr('action', "?" + jQuery.param(prms))
278
278
 
279
- smart_listing.trigger('ajax:before')
280
- true
279
+ smart_listing.trigger('ajax:before')
280
+ true
281
281
 
282
- controls.find('input, select').change () ->
283
- unless $(this).data('observed') # do not submit controls form when changed field is observed (observing submits form by itself)
284
- controls.submit()
282
+ controls.find('input, select').change () ->
283
+ unless $(this).data('observed') # do not submit controls form when changed field is observed (observing submits form by itself)
284
+ controls.submit()
285
285
 
286
286
  $.fn.handleSmartListingFilter = () ->
287
- filter = $(this)
288
- form = filter.closest('form')
289
- button = filter.find('button')
290
- icon = filter.find('i')
291
- field = filter.find('input')
292
-
293
- field.observeField(
294
- onFilled: ->
295
- icon.removeClass('icon-search')
296
- icon.addClass('icon-remove')
297
- button.removeClass('disabled')
298
- onEmpty: ->
299
- icon.addClass('icon-search')
300
- icon.removeClass('icon-remove')
301
- button.addClass('disabled')
302
- onChange: ->
303
- form.submit()
304
- )
305
-
306
- button.click ->
307
- if field.val().length > 0
308
- field.val('')
309
- field.trigger('keydown')
287
+ filter = $(this)
288
+ form = filter.closest('form')
289
+ button = filter.find('button')
290
+ icon = filter.find('i')
291
+ field = filter.find('input')
292
+
293
+ field.observeField(
294
+ onFilled: ->
295
+ icon.removeClass('icon-search')
296
+ icon.addClass('icon-remove')
297
+ button.removeClass('disabled')
298
+ onEmpty: ->
299
+ icon.addClass('icon-search')
300
+ icon.removeClass('icon-remove')
301
+ button.addClass('disabled')
302
+ onChange: ->
303
+ form.submit()
304
+ )
305
+
306
+ button.click ->
307
+ if field.val().length > 0
308
+ field.val('')
309
+ field.trigger('keydown')
310
310
 
311
311
  $ ->
312
- $('.smart_listing').smart_listing()
313
- $('.smart_listing_controls').handleSmartListingControls()
314
- $('.smart_listing_controls .filter').handleSmartListingFilter()
312
+ $('.smart_listing').smart_listing()
313
+ $('.smart_listing_controls').handleSmartListingControls()
314
+ $('.smart_listing_controls .filter').handleSmartListingFilter()