smart_listing 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -2
- data/app/assets/javascripts/smart_listing/smart_listing.coffee.erb +4 -4
- data/app/views/smart_listing/_action_delete.html.erb +1 -1
- data/app/views/smart_listing/_action_edit.html.erb +1 -1
- data/app/views/smart_listing/_action_inactive.html.erb +1 -1
- data/app/views/smart_listing/_action_show.html.erb +1 -1
- data/app/views/smart_listing/_item_new.html.erb +2 -2
- data/app/views/smart_listing/_sortable.html.erb +2 -2
- data/lib/generators/smart_listing/install_generator.rb +20 -0
- data/lib/generators/smart_listing/templates/initializer.rb +58 -0
- data/lib/smart_listing/config.rb +8 -0
- data/lib/smart_listing/version.rb +1 -1
- metadata +4 -3
- data/app/assets/javascripts/smart_listing/smart_listing.coffee +0 -333
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daba6372bdd51039d67e7a1b1925bbc241b4bda8
|
4
|
+
data.tar.gz: ff6eef29b68cf482c8baf5bc7198a4f27b831e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51d818330f8d5c6333de737bf4b141e4c2a0b49e90e91bba2cc554ae4dda94d9bc67d4f2aad8e8fe6822a5e0e13ab69450ee73c1c4b1c9deee8b2c2e0df3f4ee
|
7
|
+
data.tar.gz: 5bc2d838c9800a5eb040037afcc5b70a1674944997cafbbc024d88eed3a4bdd3b1f04913b99a7807dbae3a7e508fac43bf1c4ae023567096e1f5a4cb94e6525e
|
data/README.md
CHANGED
@@ -1,8 +1,43 @@
|
|
1
|
-
SmartListing
|
2
|
-
==========
|
1
|
+
# SmartListing
|
3
2
|
|
4
3
|
SmartListing helps creating sortable lists of ActiveRecord collections with pagination, filtering and inline editing.
|
5
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "smart_listing"
|
11
|
+
```
|
12
|
+
|
13
|
+
Then run:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Optionally you can also install some configuration initializer:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
$ rails generate smart_listing:install
|
23
|
+
```
|
24
|
+
|
25
|
+
and views in order to customize them:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
$ rails generate smart_listing:views
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Pending...
|
34
|
+
|
35
|
+
### View
|
36
|
+
|
37
|
+
## Credits
|
38
|
+
|
39
|
+
SmartListing uses great pagination gem Kaminari https://github.com/amatsuda/kaminari
|
40
|
+
|
6
41
|
Created by Sology http://www.sology.eu
|
7
42
|
|
8
43
|
Initial development sponsored by Smart Language Apps Limited http://smartlanguageapps.com/
|
@@ -273,13 +273,13 @@ $.fn.smart_listing.showPopover = (confirmation_elem, msg, confirm) ->
|
|
273
273
|
|
274
274
|
$.fn.smart_listing.onLoading = (content, loader) ->
|
275
275
|
content.stop(true).fadeTo(500, 0.2)
|
276
|
-
|
277
|
-
|
276
|
+
loader.show()
|
277
|
+
loader.stop(true).fadeTo(500, 1)
|
278
278
|
|
279
279
|
$.fn.smart_listing.onLoaded = (content, loader) ->
|
280
280
|
content.stop(true).fadeTo(500, 1)
|
281
|
-
|
282
|
-
|
281
|
+
loader.stop(true).fadeTo 500, 0, () =>
|
282
|
+
loader.hide()
|
283
283
|
|
284
284
|
$.fn.smart_listing_controls = () ->
|
285
285
|
$(this).each () ->
|
@@ -7,4 +7,4 @@
|
|
7
7
|
confirmation: confrimation text
|
8
8
|
-%>
|
9
9
|
|
10
|
-
<%= link_to(url, :remote => true, :class => "destroy", :method => :delete, :title => t("smart_listing.actions.destroy"), :data => {:confirmation => confirmation || t("smart_listing.msgs.destroy_confirmation")} ) do %><%= content_tag(:i, "", :class => icon ||
|
10
|
+
<%= link_to(url, :remote => true, :class => "destroy", :method => :delete, :title => t("smart_listing.actions.destroy"), :data => {:confirmation => confirmation || t("smart_listing.msgs.destroy_confirmation")} ) do %><%= content_tag(:i, "", :class => icon || SmartListing.config.classes(:icon_trash)) %><% end %>
|
@@ -6,4 +6,4 @@
|
|
6
6
|
icon
|
7
7
|
-%>
|
8
8
|
|
9
|
-
<%= link_to(url, :remote => true, :class => "edit", :title => t("smart_listing.actions.edit") ) do %><%= content_tag(:i, '', :class => icon ||
|
9
|
+
<%= link_to(url, :remote => true, :class => "edit", :title => t("smart_listing.actions.edit") ) do %><%= content_tag(:i, '', :class => icon || SmartListing.config.classes(:icon_edit)) %><% end %>
|
@@ -6,4 +6,4 @@
|
|
6
6
|
icon
|
7
7
|
-%>
|
8
8
|
|
9
|
-
<%= link_to(url, :class => "show", :title => t("smart_listing.actions.show") ) do %><%= content_tag(:i, '', :class => icon ||
|
9
|
+
<%= link_to(url, :class => "show", :title => t("smart_listing.actions.show") ) do %><%= content_tag(:i, '', :class => icon || SmartListing.config.classes(:icon_show)) %><% end %>
|
@@ -15,11 +15,11 @@
|
|
15
15
|
<%= content_tag(:tr, '', :class => placeholder_classes + %w{info}) %>
|
16
16
|
<%= content_tag(:tr, :class => new_item_action_classes + %w{info}) do %>
|
17
17
|
<%= content_tag(:td, :colspan => colspan) do %>
|
18
|
-
<%= content_tag(:
|
18
|
+
<%= content_tag(:p, :class => no_items_classes + %w{pull-left}) do %>
|
19
19
|
<%= no_items_text %>
|
20
20
|
<% end %>
|
21
21
|
<%= link_to(new_item_button_url, :remote => true, :class => new_item_button_classes + %w{btn pull-right}) do %>
|
22
|
-
<%= content_tag(:i, '', :class =>
|
22
|
+
<%= content_tag(:i, '', :class => SmartListing.config.classes(:icon_new)) %>
|
23
23
|
<%= new_item_button_text %>
|
24
24
|
<% end %>
|
25
25
|
<% end %>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
<%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => true do %>
|
15
15
|
<%= title %>
|
16
16
|
<% if ordered %>
|
17
|
-
<span class="<%= smart_listing.sort_order == "asc" ?
|
17
|
+
<span class="<%= smart_listing.sort_order == "asc" ? SmartListing.config.classes(:icon_sort_up) : SmartListing.config.classes(:icon_sort_down) %>"></span>
|
18
18
|
<% else %>
|
19
|
-
<span class="
|
19
|
+
<span class="<%= SmartListing.config.classes(:icon_sort_none) %>"></span>
|
20
20
|
<% end %>
|
21
21
|
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SmartListing
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def self.banner #:nodoc:
|
7
|
+
<<-BANNER.chomp
|
8
|
+
rails g smart_listing:install
|
9
|
+
|
10
|
+
Copies initializer file
|
11
|
+
BANNER
|
12
|
+
end
|
13
|
+
|
14
|
+
desc ''
|
15
|
+
def copy_views
|
16
|
+
template 'initializer.rb', 'config/initializers/smart_listing.rb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
SmartListing.configure do |config|
|
2
|
+
config.constants :classes, {
|
3
|
+
#:main => "smart-listing",
|
4
|
+
#:editable => "editable",
|
5
|
+
#:content => "content",
|
6
|
+
#:loading => "loading",
|
7
|
+
#:status => "smart-listing-status",
|
8
|
+
#:item_actions => "actions",
|
9
|
+
#:new_item_placeholder => "new-item-placeholder",
|
10
|
+
#:new_item_action => "new-item-action",
|
11
|
+
#:new_item_button => "btn",
|
12
|
+
#:hidden => "hidden",
|
13
|
+
#:autoselect => "autoselect",
|
14
|
+
#:callback => "callback",
|
15
|
+
#:pagination_per_page => "pagination-per-page",
|
16
|
+
#:pagination_count => "count",
|
17
|
+
#:inline_editing => "info",
|
18
|
+
#:no_records => "no-records",
|
19
|
+
#:limit => "limit",
|
20
|
+
#:limit_alert => "limit-alert",
|
21
|
+
#:controls => "smart-listing-controls",
|
22
|
+
#:controls_reset => "reset",
|
23
|
+
#:filtering => "filter",
|
24
|
+
#:filtering_search => "glyphicon-search",
|
25
|
+
#:filtering_cancel => "glyphicon-remove",
|
26
|
+
#:filtering_disabled => "disabled",
|
27
|
+
#:sortable => "sortable",
|
28
|
+
#:icon_new => "glyphicon glyphicon-plus",
|
29
|
+
#:icon_edit => "glyphicon glyphicon-pencil",
|
30
|
+
#:icon_trash => "glyphicon glyphicon-trash",
|
31
|
+
#:icon_inactive => "glyphicon glyphicon-circle",
|
32
|
+
#:icon_show => "glyphicon glyphicon-share-alt",
|
33
|
+
#:icon_sort_none => "glyphicon glyphicon-resize-vertical",
|
34
|
+
#:icon_sort_up => "glyphicon glyphicon-chevron-up",
|
35
|
+
#:icon_sort_down => "glyphicon glyphicon-chevron-down",
|
36
|
+
}
|
37
|
+
|
38
|
+
config.constants :data_attributes, {
|
39
|
+
#:main => "smart-listing",
|
40
|
+
#:confirmation => "confirmation",
|
41
|
+
#:id => "id",
|
42
|
+
#:href => "href",
|
43
|
+
#:callback_href => "callback-href",
|
44
|
+
#:max_count => "max-count",
|
45
|
+
#:inline_edit_backup => "smart-listing-edit-backup",
|
46
|
+
#:params => "params",
|
47
|
+
#:observed => "observed",
|
48
|
+
#:href => "href",
|
49
|
+
}
|
50
|
+
|
51
|
+
config.constants :selectors, {
|
52
|
+
#:item_action_destroy => "a.destroy",
|
53
|
+
#:edit_cancel => "button.cancel",
|
54
|
+
#:row => "tr",
|
55
|
+
#:head => "thead",
|
56
|
+
#:filtering_icon => "i"
|
57
|
+
}
|
58
|
+
end
|
data/lib/smart_listing/config.rb
CHANGED
@@ -36,6 +36,14 @@ module SmartListing
|
|
36
36
|
:filtering_cancel => "glyphicon-remove",
|
37
37
|
:filtering_disabled => "disabled",
|
38
38
|
:sortable => "sortable",
|
39
|
+
:icon_new => "glyphicon glyphicon-plus",
|
40
|
+
:icon_edit => "glyphicon glyphicon-pencil",
|
41
|
+
:icon_trash => "glyphicon glyphicon-trash",
|
42
|
+
:icon_inactive => "glyphicon glyphicon-circle",
|
43
|
+
:icon_show => "glyphicon glyphicon-share-alt",
|
44
|
+
:icon_sort_none => "glyphicon glyphicon-resize-vertical",
|
45
|
+
:icon_sort_up => "glyphicon glyphicon-chevron-up",
|
46
|
+
:icon_sort_down => "glyphicon glyphicon-chevron-down",
|
39
47
|
},
|
40
48
|
:data_attributes => {
|
41
49
|
:main => "smart-listing",
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- README.md
|
78
78
|
- Rakefile
|
79
79
|
- app/assets/javascripts/smart_listing/application.js
|
80
|
-
- app/assets/javascripts/smart_listing/smart_listing.coffee
|
81
80
|
- app/assets/javascripts/smart_listing/smart_listing.coffee.erb
|
82
81
|
- app/assets/stylesheets/smart_listing/application.css
|
83
82
|
- app/helpers/smart_listing/application_helper.rb
|
@@ -100,6 +99,8 @@ files:
|
|
100
99
|
- app/views/smart_listing/item/_update.js.erb
|
101
100
|
- config/locales/en.yml
|
102
101
|
- config/routes.rb
|
102
|
+
- lib/generators/smart_listing/install_generator.rb
|
103
|
+
- lib/generators/smart_listing/templates/initializer.rb
|
103
104
|
- lib/generators/smart_listing/views_generator.rb
|
104
105
|
- lib/smart_listing.rb
|
105
106
|
- lib/smart_listing/config.rb
|
@@ -1,333 +0,0 @@
|
|
1
|
-
# Useful when smart list target url is different than current one
|
2
|
-
$.rails.href = (element) ->
|
3
|
-
element.attr('href') || element.data('href')
|
4
|
-
|
5
|
-
$.fn.observeField = (opts = {}) ->
|
6
|
-
field = $(this)
|
7
|
-
key_timeout = null
|
8
|
-
last_value = null
|
9
|
-
options =
|
10
|
-
onFilled: () ->
|
11
|
-
onEmpty: () ->
|
12
|
-
onChange: () ->
|
13
|
-
options = $.extend(options, opts)
|
14
|
-
|
15
|
-
keyChange = () ->
|
16
|
-
if field.val().length > 0
|
17
|
-
options.onFilled()
|
18
|
-
else
|
19
|
-
options.onEmpty()
|
20
|
-
|
21
|
-
if field.val() == last_value && field.val().length != 0
|
22
|
-
return
|
23
|
-
lastValue = field.val()
|
24
|
-
|
25
|
-
options.onChange()
|
26
|
-
|
27
|
-
field.data('observed', true)
|
28
|
-
|
29
|
-
field.bind 'keydown', (e) ->
|
30
|
-
if(key_timeout)
|
31
|
-
clearTimeout(key_timeout)
|
32
|
-
|
33
|
-
key_timeout = setTimeout(->
|
34
|
-
keyChange()
|
35
|
-
, 400)
|
36
|
-
|
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-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(" ")
|
58
|
-
.append($('<button/>').html('No').addClass('btn btn-small').click (event) =>
|
59
|
-
editable = $(event.currentTarget).closest('.editable')
|
60
|
-
$(confirmation_elem).popover('destroy')
|
61
|
-
)
|
62
|
-
)
|
63
|
-
|
64
|
-
@container.on 'ajax:before', (e) =>
|
65
|
-
@fadeLoading()
|
66
|
-
|
67
|
-
@container.on 'ajax:success', (e) =>
|
68
|
-
if $(e.target).is('.actions a.destroy')
|
69
|
-
# handle HEAD OK response for deletion request
|
70
|
-
editable = $(e.target).closest('.editable')
|
71
|
-
if @container.find(".editable").length == 1
|
72
|
-
@reload()
|
73
|
-
return false
|
74
|
-
else
|
75
|
-
editable.remove()
|
76
|
-
|
77
|
-
@changeItemCount(-1)
|
78
|
-
@refresh()
|
79
|
-
|
80
|
-
@fadeLoaded()
|
81
|
-
return false
|
82
|
-
|
83
|
-
@container.on 'click', 'button.cancel', (event) =>
|
84
|
-
editable = $(event.currentTarget).closest('.editable')
|
85
|
-
if(editable.length > 0)
|
86
|
-
# Cancel edit
|
87
|
-
@cancelEdit(editable)
|
88
|
-
else
|
89
|
-
# Cancel new record
|
90
|
-
@container.find('.new_item_placeholder').addClass('hidden')
|
91
|
-
@container.find('.new_item_action').removeClass('hidden')
|
92
|
-
false
|
93
|
-
|
94
|
-
@container.on 'click', '.actions a[data-confirmation]', (event) =>
|
95
|
-
# Check if we are confirming the right element
|
96
|
-
if(@confirmed != event.currentTarget)
|
97
|
-
# We need confirmation
|
98
|
-
@container.find('.actions a').popover('destroy')
|
99
|
-
$(event.currentTarget).popover(content: createPopover(event.currentTarget, $(event.currentTarget).data('confirmation')), html: true, trigger: 'manual', title: null)
|
100
|
-
$(event.currentTarget).popover('show')
|
101
|
-
false
|
102
|
-
else
|
103
|
-
# Confirmed, reset flag and go ahead with deletion
|
104
|
-
@confirmed = null
|
105
|
-
true
|
106
|
-
|
107
|
-
@container.on 'click', 'input[type=text].autoselect', (event) ->
|
108
|
-
$(this).select()
|
109
|
-
|
110
|
-
@container.on 'change', '.callback', (event) =>
|
111
|
-
checkbox = $(event.currentTarget)
|
112
|
-
id = checkbox.closest("tr").data("id")
|
113
|
-
data = {}
|
114
|
-
data[checkbox.val()] = checkbox.is(":checked")
|
115
|
-
$.ajax({
|
116
|
-
beforeSend: (xhr, settings) ->
|
117
|
-
xhr.setRequestHeader "accept", "*/*;q=0.5, " + settings.accepts.script
|
118
|
-
url: @container.data("callback-href"),
|
119
|
-
type: "POST",
|
120
|
-
data: data,
|
121
|
-
})
|
122
|
-
|
123
|
-
fadeLoading: =>
|
124
|
-
@content.stop(true).fadeTo(500, 0.2)
|
125
|
-
@loading.show()
|
126
|
-
@loading.stop(true).fadeTo(500, 1)
|
127
|
-
|
128
|
-
fadeLoaded: =>
|
129
|
-
@content.stop(true).fadeTo(500, 1)
|
130
|
-
@loading.stop(true).fadeTo 500, 0, () =>
|
131
|
-
@loading.hide()
|
132
|
-
|
133
|
-
@content.find('.play').each () ->
|
134
|
-
self.loadAudio($(this).data('key'), $(this).data('target'))
|
135
|
-
|
136
|
-
itemCount: =>
|
137
|
-
parseInt(@container.find('.pagination_per_page .count').html())
|
138
|
-
|
139
|
-
maxCount: =>
|
140
|
-
parseInt(@container.data('max-count'))
|
141
|
-
|
142
|
-
changeItemCount: (value) =>
|
143
|
-
@container.find('.pagination_per_page .count').html(@itemCount() + value)
|
144
|
-
|
145
|
-
cancelEdit: (editable) =>
|
146
|
-
if editable.data('smart_listing_edit_backup')
|
147
|
-
editable.html(editable.data('smart_listing_edit_backup'))
|
148
|
-
editable.removeClass('info')
|
149
|
-
editable.removeData('smart_listing_edit_backup')
|
150
|
-
|
151
|
-
# Callback called when record is added/deleted using ajax request
|
152
|
-
refresh: () =>
|
153
|
-
header = @content.find('thead')
|
154
|
-
footer = @content.find('.pagination_per_page')
|
155
|
-
no_records = @content.find('.no_records')
|
156
|
-
|
157
|
-
if @itemCount() == 0
|
158
|
-
header.hide()
|
159
|
-
footer.hide()
|
160
|
-
no_records.show()
|
161
|
-
else
|
162
|
-
header.show()
|
163
|
-
footer.show()
|
164
|
-
no_records.hide()
|
165
|
-
|
166
|
-
if @maxCount()
|
167
|
-
if @itemCount() >= @maxCount()
|
168
|
-
if @itemCount()
|
169
|
-
@container.find('.new_item_action').addClass('hidden')
|
170
|
-
@container.find('.new_item_action .btn').addClass('hidden')
|
171
|
-
else
|
172
|
-
@container.find('.new_item_action').removeClass('hidden')
|
173
|
-
@container.find('.new_item_action .btn').removeClass('hidden')
|
174
|
-
|
175
|
-
@status.each (index, status) =>
|
176
|
-
$(status).find('.smart_listing_limit').html(@maxCount() - @itemCount())
|
177
|
-
if @maxCount() - @itemCount() == 0
|
178
|
-
$(status).find('.smart_listing_limit_alert').show()
|
179
|
-
else
|
180
|
-
$(status).find('.smart_listing_limit_alert').hide()
|
181
|
-
|
182
|
-
# Trigger AJAX request to reload the list
|
183
|
-
reload: () =>
|
184
|
-
$.rails.handleRemote(@container)
|
185
|
-
|
186
|
-
params: () =>
|
187
|
-
@container.data('params')
|
188
|
-
|
189
|
-
#################################################################################################
|
190
|
-
# Methods executed by rails UJS:
|
191
|
-
|
192
|
-
new_item: (content) =>
|
193
|
-
new_item_action = @container.find('.new_item_action')
|
194
|
-
new_item_placeholder = @container.find('.new_item_placeholder').addClass('hidden')
|
195
|
-
|
196
|
-
@container.find('.editable').each (i, v) =>
|
197
|
-
@cancelEdit($(v))
|
198
|
-
|
199
|
-
new_item_action.addClass('hidden')
|
200
|
-
new_item_placeholder.removeClass('hidden')
|
201
|
-
new_item_placeholder.html(content)
|
202
|
-
new_item_placeholder.addClass('info')
|
203
|
-
|
204
|
-
@fadeLoaded()
|
205
|
-
|
206
|
-
create: (id, success, content) =>
|
207
|
-
new_item_action = @container.find('.new_item_action')
|
208
|
-
new_item_placeholder = @container.find('.new_item_placeholder')
|
209
|
-
|
210
|
-
if success
|
211
|
-
new_item_placeholder.addClass('hidden')
|
212
|
-
new_item_action.removeClass('hidden')
|
213
|
-
|
214
|
-
new_item = $('<tr />').addClass('editable')
|
215
|
-
new_item.attr('data-id', id)
|
216
|
-
new_item.html(content)
|
217
|
-
new_item_placeholder.before(new_item)
|
218
|
-
|
219
|
-
@changeItemCount(1)
|
220
|
-
@refresh()
|
221
|
-
else
|
222
|
-
new_item_placeholder.html(content)
|
223
|
-
|
224
|
-
@fadeLoaded()
|
225
|
-
|
226
|
-
edit: (id, content) =>
|
227
|
-
@container.find('.editable').each (i, v) =>
|
228
|
-
@cancelEdit($(v))
|
229
|
-
@container.find('.new_item_placeholder').addClass('hidden')
|
230
|
-
@container.find('.new_item_action').removeClass('hidden')
|
231
|
-
|
232
|
-
editable = @container.find(".editable[data-id=#{id}]")
|
233
|
-
editable.data('smart_listing_edit_backup', editable.html())
|
234
|
-
editable.html(content)
|
235
|
-
editable.addClass('info')
|
236
|
-
|
237
|
-
@fadeLoaded()
|
238
|
-
|
239
|
-
update: (id, success, content) =>
|
240
|
-
editable = @container.find(".editable[data-id=#{id}]")
|
241
|
-
if success
|
242
|
-
editable.removeClass('info')
|
243
|
-
editable.removeData('smart_listing_edit_backup')
|
244
|
-
editable.html(content)
|
245
|
-
|
246
|
-
@refresh()
|
247
|
-
else
|
248
|
-
editable.html(content)
|
249
|
-
|
250
|
-
@fadeLoaded()
|
251
|
-
|
252
|
-
destroy: (id, destroyed) =>
|
253
|
-
# No need to do anything here, already handled by ajax:success handler
|
254
|
-
|
255
|
-
remove: (id) =>
|
256
|
-
editable = @container.find(".editable[data-id=#{id}]").first()
|
257
|
-
editable.remove()
|
258
|
-
|
259
|
-
update_list: (content, data) =>
|
260
|
-
$.each data, (key, value) =>
|
261
|
-
@container.data(key, value)
|
262
|
-
|
263
|
-
@content.html(content)
|
264
|
-
|
265
|
-
@refresh()
|
266
|
-
@fadeLoaded()
|
267
|
-
|
268
|
-
$.fn.smart_listing = () ->
|
269
|
-
map = $(this).map () ->
|
270
|
-
if !$(this).data('smart-listing')
|
271
|
-
$(this).data('smart-listing', new SmartListing($(this)))
|
272
|
-
$(this).data('smart-listing')
|
273
|
-
if map.length == 1
|
274
|
-
map[0]
|
275
|
-
else
|
276
|
-
map
|
277
|
-
|
278
|
-
$.fn.handleSmartListingControls = () ->
|
279
|
-
$(this).each () ->
|
280
|
-
controls = $(this)
|
281
|
-
smart_listing = $("##{controls.data('smart-listing')}")
|
282
|
-
reset = controls.find(".reset")
|
283
|
-
|
284
|
-
controls.submit ->
|
285
|
-
# Merges smart list params with the form action url before submitting.
|
286
|
-
# This preserves smart list settings (page, sorting etc.).
|
287
|
-
|
288
|
-
prms = $.extend({}, smart_listing.smart_listing().params())
|
289
|
-
if $(this).data('reset')
|
290
|
-
prms[$(this).data('reset')] = null
|
291
|
-
|
292
|
-
if $.rails.href(smart_listing)
|
293
|
-
# If smart list has different target url than current one
|
294
|
-
controls.attr('action', $.rails.href(smart_listing) + "?" + jQuery.param(prms))
|
295
|
-
else
|
296
|
-
controls.attr('action', "?" + jQuery.param(prms))
|
297
|
-
|
298
|
-
smart_listing.trigger('ajax:before')
|
299
|
-
true
|
300
|
-
|
301
|
-
controls.find('input, select').change () ->
|
302
|
-
unless $(this).data('observed') # do not submit controls form when changed field is observed (observing submits form by itself)
|
303
|
-
controls.submit()
|
304
|
-
|
305
|
-
$.fn.handleSmartListingFilter = () ->
|
306
|
-
filter = $(this)
|
307
|
-
form = filter.closest('form')
|
308
|
-
button = filter.find('button')
|
309
|
-
icon = filter.find('i')
|
310
|
-
field = filter.find('input')
|
311
|
-
|
312
|
-
field.observeField(
|
313
|
-
onFilled: ->
|
314
|
-
icon.removeClass('glyphicon-search')
|
315
|
-
icon.addClass('glyphicon-remove')
|
316
|
-
button.removeClass('disabled')
|
317
|
-
onEmpty: ->
|
318
|
-
icon.addClass('glyphicon-search')
|
319
|
-
icon.removeClass('glyphicon-remove')
|
320
|
-
button.addClass('disabled')
|
321
|
-
onChange: ->
|
322
|
-
form.submit()
|
323
|
-
)
|
324
|
-
|
325
|
-
icon.click ->
|
326
|
-
if field.val().length > 0
|
327
|
-
field.val('')
|
328
|
-
field.trigger('keydown')
|
329
|
-
|
330
|
-
$ ->
|
331
|
-
$('.smart_listing').smart_listing()
|
332
|
-
$('.smart_listing_controls').handleSmartListingControls()
|
333
|
-
$('.smart_listing_controls .filter').handleSmartListingFilter()
|