smart_listing 0.9.2 → 0.9.3

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: aec78db2f43e9f78c7420c7a21efdd506da3dbe6
4
- data.tar.gz: 8297a520f5c771c428aa2dddbb3219e1696a5e0b
3
+ metadata.gz: ed162afb1635a06affeb6c2bb0f3bc0d539b7cad
4
+ data.tar.gz: 9cae821c8260b22a3782daf452008b1da9822e54
5
5
  SHA512:
6
- metadata.gz: 542635bdcc49d20e137793ee6e54dc46731c271fedd49d053b5e27c642b362e664b06ffc7f7d65774177f1efa63db6d85252481b9d7c9ad05275f775770393dc
7
- data.tar.gz: fa82edc043dc01ac02e53b6d1a8a28388be34ca1e67a4b89061473cd60f5fef975c447679a02cbb479df0e95ced1093f28f41014f0e9666b5fb139fdd6550b6b
6
+ metadata.gz: 1ee4da5ad5023f269936c615dd547c2710c13925ab6e892fc28dad1bb86c2d2e54aacabe4ce8b241b7c9c2847fe1353539f06a2def7c381cdd5355684d4c556d
7
+ data.tar.gz: 56fb50e405e8afdee3f471f1e565dd3e764197a183c8113b02321c7edf5756ed40c3bdcca01e5978209a49d1b42d75760812c730f76c183f167de5d99669db25
@@ -237,6 +237,10 @@ class SmartListing
237
237
 
238
238
  destroy: (id, destroyed) =>
239
239
  # No need to do anything here, already handled by ajax:success handler
240
+
241
+ remove: (id) =>
242
+ editable = @container.find(".editable[data-id=#{id}]").first()
243
+ editable.remove()
240
244
 
241
245
  update_list: (content, data) =>
242
246
  $.each data, (key, value) =>
@@ -30,7 +30,7 @@ module SmartListing
30
30
 
31
31
  def paginate options = {}
32
32
  if @smart_listing.collection.respond_to? :current_page
33
- @template.paginate @smart_listing.collection, :remote => true, :param_name => @smart_listing.param_names[:page], :params => UNSAFE_PARAMS
33
+ @template.paginate @smart_listing.collection, {:remote => true, :param_name => @smart_listing.param_names[:page], :params => UNSAFE_PARAMS}.merge(@smart_listing.kaminari_options)
34
34
  end
35
35
  end
36
36
 
@@ -39,25 +39,31 @@ module SmartListing
39
39
  end
40
40
 
41
41
  def pagination_per_page_links options = {}
42
- @template.content_tag(:div, :class => "pagination_per_page #{'disabled' if empty?}") do
43
- if @smart_listing.count > @smart_listing.page_sizes.first
44
- @template.concat(@template.t('views.pagination.per_page'))
45
- per_page_sizes = @smart_listing.page_sizes.clone
46
- per_page_sizes.push(0) if @smart_listing.unlimited_per_page?
47
- per_page_sizes.each do |p|
48
- name = p == 0 ? @template.t('views.pagination.unlimited') : p
49
- if @smart_listing.per_page.to_i != p
50
- @template.concat(@template.link_to(name, @template.url_for(sanitize_params(@template.params.merge(@smart_listing.param_names[:per_page] => p, @smart_listing.param_names[:page] => 1))), :remote => true))
51
- else
52
- @template.concat(@template.content_tag(:span, name))
53
- end
54
- break if p > @smart_listing.count
55
- end
56
- @template.concat ' | '
57
- end if @smart_listing.options[:paginate]
58
- @template.concat(@template.t('views.pagination.total'))
59
- @template.concat(@template.content_tag(:span, @smart_listing.count, :class => "count"))
42
+ container_classes = ["pagination_per_page"]
43
+ container_classes << "disabled" if empty?
44
+
45
+ per_page_sizes = @smart_listing.page_sizes.clone
46
+ per_page_sizes.push(0) if @smart_listing.unlimited_per_page?
47
+
48
+ locals = {
49
+ :container_classes => container_classes,
50
+ :per_page_sizes => per_page_sizes,
51
+ }
52
+
53
+ @template.render(:partial => 'smart_listing/pagination_per_page_links', :locals => default_locals.merge(locals))
54
+ end
55
+
56
+ def pagination_per_page_link page
57
+ if @smart_listing.per_page.to_i != page
58
+ url = @template.url_for(sanitize_params(@template.params.merge(@smart_listing.param_names[:per_page] => page, @smart_listing.param_names[:page] => 1)))
60
59
  end
60
+
61
+ locals = {
62
+ :page => page,
63
+ :url => url,
64
+ }
65
+
66
+ @template.render(:partial => 'smart_listing/pagination_per_page_link', :locals => default_locals.merge(locals))
61
67
  end
62
68
 
63
69
  def sortable title, attribute, options = {}
@@ -69,14 +75,15 @@ module SmartListing
69
75
  @smart_listing.param_names[:sort_extra] => extra
70
76
  }
71
77
 
72
- @template.link_to(@template.url_for(sanitize_params(@template.params.merge(sort_params))), :class => "sortable", :data => {:attr => attribute}, :remote => true) do
73
- @template.concat(title)
74
- if @smart_listing.sort_attr == attribute && (!@smart_listing.sort_extra || @smart_listing.sort_extra == extra.to_s)
75
- @template.concat(@template.content_tag(:span, "", :class => (@smart_listing.sort_order == "asc" ? "glyphicon glyphicon-chevron-up" : "glyphicon glyphicon-chevron-down")))
76
- else
77
- @template.concat(@template.content_tag(:span, "", :class => "glyphicon glyphicon-resize-vertical"))
78
- end
79
- end
78
+ locals = {
79
+ :ordered => @smart_listing.sort_attr == attribute && (!@smart_listing.sort_extra || @smart_listing.sort_extra == extra.to_s),
80
+ :url => @template.url_for(sanitize_params(@template.params.merge(sort_params))),
81
+ :container_classes => ["sortable"],
82
+ :attribute => attribute,
83
+ :title => title
84
+ }
85
+
86
+ @template.render(:partial => 'smart_listing/sortable', :locals => default_locals.merge(locals))
80
87
  end
81
88
 
82
89
  def update options = {}
@@ -100,24 +107,31 @@ module SmartListing
100
107
  else
101
108
  locals.merge!({:smart_listing => self})
102
109
  end
110
+
103
111
  @template.render options, locals, &block
104
112
  end
105
113
 
106
114
  # Add new item button & placeholder to list
107
115
  def item_new options = {}
108
- @template.concat(@template.content_tag(:tr, '', :class => "info new_item_placeholder disabled"))
109
- @template.concat(@template.content_tag(:tr, :class => "info new_item_action #{'disabled' if !empty? && max_count?}") do
110
- @template.concat(@template.content_tag(:td, :colspan => options.delete(:colspan)) do
111
- @template.concat(@template.content_tag(:p, :class => "no_records pull-left #{'disabled' unless empty?}") do
112
- @template.concat(options.delete(:no_items_text))
113
- end)
114
- @template.concat(@template.link_to(options.delete(:link), :remote => true, :class => "btn pull-right #{'disabled' if max_count?}") do
115
- @template.concat(@template.content_tag(:i, '', :class => "glyphicon glyphicon-plus"))
116
- @template.concat(" ")
117
- @template.concat(options.delete(:text))
118
- end)
119
- end)
120
- end)
116
+ new_item_action_classes = %{new_item_action}
117
+ new_item_action_classes << "disabled" if !empty? && max_count?
118
+ no_records_classes = %{no_records}
119
+ no_records_classes << "disabled" unless empty?
120
+ new_item_button_classes = []
121
+ new_item_button_classes << "disabled" if max_count?
122
+
123
+ locals = {
124
+ :placeholder_classes => %w{new_item_placeholder disabled},
125
+ :new_item_action_classes => new_item_action_classes,
126
+ :colspan => options.delete(:colspan),
127
+ :no_items_classes => no_records_classes,
128
+ :no_items_text => options.delete(:no_items_text),
129
+ :new_item_button_url => options.delete(:link),
130
+ :new_item_button_classes => new_item_button_classes,
131
+ :new_item_button_text => options.delete(:text),
132
+ }
133
+
134
+ @template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
121
135
  nil
122
136
  end
123
137
 
@@ -137,6 +151,10 @@ module SmartListing
137
151
  def sanitize_params params
138
152
  params.merge(UNSAFE_PARAMS)
139
153
  end
154
+
155
+ def default_locals
156
+ {:smart_listing => @smart_listing, :builder => self}
157
+ end
140
158
  end
141
159
 
142
160
  # Outputs smart list container
@@ -148,11 +166,12 @@ module SmartListing
148
166
 
149
167
  builder = Builder.new(name, @smart_listings[name], self, options, block)
150
168
 
151
- output =""
169
+ output = ""
152
170
 
153
171
  data = {}
154
172
  data['max-count'] = @smart_listings[name].max_count if @smart_listings[name].max_count && @smart_listings[name].max_count > 0
155
173
  data['href'] = @smart_listings[name].href if @smart_listings[name].href
174
+ data.merge!(options[:data]) if options[:data]
156
175
 
157
176
  if bare
158
177
  output = capture(builder, &block)
@@ -176,45 +195,35 @@ module SmartListing
176
195
 
177
196
  if action.has_key?(:if)
178
197
  unless action[:if]
179
- concat(content_tag(:i, '', :class => "glyphicon glyphicon-remove-circle"))
198
+ concat(render(:partial => 'smart_listing/action_inactive'))
180
199
  next
181
200
  end
182
201
  end
183
202
 
184
- case action.delete(:name).to_sym
203
+ action_name = action[:name].to_sym
204
+ case action_name
185
205
  when :edit
186
- url = action.delete(:url)
187
- html_options = {
188
- :remote => true,
189
- :class => "edit",
190
- :title => t("smart_listing.actions.edit")
191
- }.merge(action)
192
-
193
- concat(link_to(url, html_options) do
194
- concat(content_tag(:i, '', :class => "glyphicon glyphicon-pencil"))
195
- end)
206
+ locals = {
207
+ :url => action.delete(:url),
208
+ :icon => action.delete(:icon),
209
+ }
210
+ concat(render(:partial => 'smart_listing/action_edit', :locals => locals))
196
211
  when :destroy
197
- url = action.delete(:url)
198
- icon = action.delete(:icon) || "glyphicon glyphicon-trash"
199
- html_options = {
200
- :remote => true,
201
- :class => "destroy",
202
- :method => :delete,
203
- :title => t("smart_listing.actions.destroy"),
204
- :data => {:confirmation => action.delete(:confirmation) || t("smart_listing.msgs.destroy_confirmation")},
205
- }.merge(action)
206
-
207
- concat(link_to(url, html_options) do
208
- concat(content_tag(:i, '', :class => icon))
209
- end)
212
+ locals = {
213
+ :url => action.delete(:url),
214
+ :icon => action.delete(:icon),
215
+ :confirmation => action.delete(:confirmation),
216
+ }
217
+ concat(render(:partial => 'smart_listing/action_delete', :locals => locals))
210
218
  when :custom
211
- url = action.delete(:url)
212
- icon = action.delete(:icon)
213
- html_options = action
214
-
215
- concat(link_to(url, html_options) do
216
- concat(content_tag(:i, '', :class => icon))
217
- end)
219
+ locals = {
220
+ :url => action.delete(:url),
221
+ :icon => action.delete(:icon),
222
+ :html_options => action,
223
+ }
224
+ concat(render(:partial => 'smart_listing/action_custom', :locals => locals))
225
+ else
226
+ concat(render(:partial => "smart_listing/action_#{action_name}", :locals => {:action => action}))
218
227
  end
219
228
  end
220
229
  end
@@ -250,10 +259,11 @@ module SmartListing
250
259
  def smart_listing_item name, item_action, object = nil, partial = nil, options = {}
251
260
  name = name.to_sym
252
261
  type = object.class.name.downcase.to_sym if object
253
- id = object.id if object
262
+ id = options[:id] || object.try(:id)
263
+ valid = options[:valid] if options.has_key?(:valid)
254
264
  object_key = options.delete(:object_key) || :object
255
265
 
256
- render(:partial => "smart_listing/item/#{item_action.to_s}", :locals => {:name => name, :id => id, :object_key => object_key, :object => object, :part => partial})
266
+ render(:partial => "smart_listing/item/#{item_action.to_s}", :locals => {:name => name, :id => id, :valid => valid, :object_key => object_key, :object => object, :part => partial})
257
267
  end
258
268
  end
259
269
  end
@@ -0,0 +1,10 @@
1
+ <%#
2
+ Custom action.
3
+
4
+ Available local variables:
5
+ url
6
+ icon
7
+ html_options: custom html options
8
+ -%>
9
+
10
+ <%= link_to(url, html_options) do %><%= content_tag(:i, '', :class => icon) %><% end %>
@@ -0,0 +1,10 @@
1
+ <%#
2
+ Delete action.
3
+
4
+ Available local variables:
5
+ url: destroy url
6
+ icon
7
+ confirmation: confrimation text
8
+ -%>
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 || "glyphicon glyphicon-trash") %><% end %>
@@ -0,0 +1,9 @@
1
+ <%#
2
+ Edit action.
3
+
4
+ Available local variables:
5
+ url
6
+ icon
7
+ -%>
8
+
9
+ <%= link_to(url, :remote => true, :class => "edit", :title => t("smart_listing.actions.edit") ) do %><%= content_tag(:i, '', :class => icon || "glyphicon glyphicon-pencil") %><% end %>
@@ -0,0 +1,5 @@
1
+ <%#
2
+ Inactive action.
3
+ -%>
4
+
5
+ <%= content_tag(:i, '', :class => "glyphicon glyphicon-remove-circle") %>
@@ -0,0 +1,26 @@
1
+ <%#
2
+ New list item element (contains new item placeholder and add button).
3
+
4
+ Available local variables:
5
+ placeholder_classes: classes for the main container
6
+ new_item_action_classes: new item action classes
7
+ colspan
8
+ no_items_classes: no items container classes
9
+ no_items_text: no items text displayed inside container
10
+ new_item_button_url: argument to link_to (new item button)
11
+ new_item_button_classes
12
+ new_item_button_text
13
+ -%>
14
+
15
+ <%= content_tag(:tr, '', :class => placeholder_classes.merge(%{info})) %>
16
+ <%= content_tag(:tr, :class => new_item_action_classes.merge(%{info})) do %>
17
+ <%= content_tag(:td, :colspan => colspan) do %>
18
+ <%= content_tag(:p, :class => no_items_classes.merge(%{pull-left})) do %>
19
+ <%= no_items_text %>
20
+ <% end %>
21
+ <%= link_to(new_item_button_url, :remote => true, :class => new_item_button_classes.merge(%{btn pull-right})) do %>
22
+ <%= content_tag(:i, '', :class => "glyphicon glyphicon-plus") %>
23
+ <%= new_item_text %>
24
+ <% end %>
25
+ <% end %>
26
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <%#
2
+ Pagination single per-page link.
3
+
4
+ Available local variables:
5
+ page: page number
6
+ url: page url (if page is not selected)
7
+ smart_listing: current SmartListing instance
8
+ builder: current builder instance
9
+ -%>
10
+
11
+ <% name = page == 0 ? t('views.pagination.unlimited') : page %>
12
+ <%= url ? link_to(name, url) : content_tag(:span, name) %>
@@ -0,0 +1,19 @@
1
+ <%#
2
+ Pagination per-page links.
3
+
4
+ Available local variables:
5
+ container_classes: classes for the main container
6
+ per_page_sizes: array of available per-page sizes
7
+ smart_listing: current SmartListing instance
8
+ builder: current builder instance
9
+ -%>
10
+
11
+ <%= content_tag(:div, :class => container_classes ) do %>
12
+ <% if smart_listing.options[:paginate] && (smart_listing.count > smart_listing.page_sizes.first) %>
13
+ <%= t('views.pagination.per_page') %>
14
+ <% per_page_sizes.each do |p| %><%= builder.pagination_per_page_link p %><% break if p > smart_listing.count %><% end %>
15
+ |
16
+ <% end %>
17
+ <%= t('views.pagination.total') %>
18
+ <%= content_tag(:span, smart_listing.count, :class => "count") %>
19
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ Sortable attribute listing header.
3
+
4
+ Available local variables:
5
+ container_classes: classes for the main container
6
+ url: sortable link url
7
+ attribute: current attribute name
8
+ title: current attribute title
9
+ ordered: defines whether column is sorted or not
10
+ smart_listing: current SmartListing instance
11
+ builder: current builder instance
12
+ -%>
13
+
14
+ <%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => true do %>
15
+ <%= title %>
16
+ <% if ordered %>
17
+ <span class="<%= smart_listing.sort_order == "asc" ? "glyphicon glyphicon-chevron-up" : "glyphicon glyphicon-chevron-down" %>"></span>
18
+ <% else %>
19
+ <span class="glyphicon glyphicon-resize-vertical"></span>
20
+ <% end %>
21
+ <% end %>
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.destroy(<%= id %>, <%= object.destroyed? %>);
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.edit(<%= id %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.new_item("<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.remove(<%= id %>);
@@ -0,0 +1,2 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.update(<%= id %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -0,0 +1,12 @@
1
+ en:
2
+ smart_listing:
3
+ msgs:
4
+ destroy_confirmation: Destroy?
5
+ actions:
6
+ destroy: Destroy
7
+ edit: Edit
8
+ views:
9
+ pagination:
10
+ per_page: Per page
11
+ unlimited: Unlimited
12
+ total: Total
@@ -0,0 +1,23 @@
1
+ module SmartListing
2
+ module Generators
3
+ class ViewsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../../app/views/smart_listing', __FILE__)
5
+
6
+ def self.banner #:nodoc:
7
+ <<-BANNER.chomp
8
+ rails g smart_listing:views
9
+
10
+ Copies all smart listing partials templates to your application.
11
+ BANNER
12
+ end
13
+
14
+ desc ''
15
+ def copy_views
16
+ filename_pattern = File.join self.class.source_root, "*.html.erb"
17
+ Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
18
+ copy_file f, "app/views/smart_listing/#{f}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/smart_listing.rb CHANGED
@@ -31,6 +31,7 @@ module SmartListing
31
31
  :default_sort_attr => nil, # default sort by
32
32
  :memorize_per_page => false,
33
33
  :page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array
34
+ :kaminari_options => {}, # Kaminari's paginate helper options
34
35
  }.merge!(options)
35
36
 
36
37
  if @options[:array]
@@ -110,6 +111,10 @@ module SmartListing
110
111
  @options[:page_sizes]
111
112
  end
112
113
 
114
+ def kaminari_options
115
+ @options[:kaminari_options]
116
+ end
117
+
113
118
  def all_params
114
119
  ap = {}
115
120
  @options[:param_names].each do |k, v|
@@ -1,3 +1,3 @@
1
1
  module SmartListing
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  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.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -73,16 +73,32 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - app/views/smart_listing/item/_new.js.erb
77
+ - app/views/smart_listing/item/_edit.js.erb
78
+ - app/views/smart_listing/item/_create.js.erb
79
+ - app/views/smart_listing/item/_remove.js.erb
80
+ - app/views/smart_listing/item/_update.js.erb
81
+ - app/views/smart_listing/item/_destroy.js.erb
82
+ - app/views/smart_listing/_pagination_per_page_links.html.erb
83
+ - app/views/smart_listing/_action_custom.html.erb
84
+ - app/views/smart_listing/_action_inactive.html.erb
76
85
  - app/views/smart_listing/_update_list.js.erb
86
+ - app/views/smart_listing/_pagination_per_page_link.html.erb
87
+ - app/views/smart_listing/_action_delete.html.erb
88
+ - app/views/smart_listing/_item_new.html.erb
89
+ - app/views/smart_listing/_sortable.html.erb
90
+ - app/views/smart_listing/_action_edit.html.erb
77
91
  - app/assets/stylesheets/smart_listing/application.css
78
92
  - app/assets/javascripts/smart_listing/smart_listing.coffee
79
93
  - app/assets/javascripts/smart_listing/application.js
80
94
  - app/helpers/smart_listing/application_helper.rb
81
95
  - app/helpers/smart_listing/helper.rb
82
96
  - config/routes.rb
97
+ - config/locales/en.yml
83
98
  - lib/tasks/smart_list_tasks.rake
84
99
  - lib/smart_listing/engine.rb
85
100
  - lib/smart_listing/version.rb
101
+ - lib/generators/smart_listing/views_generator.rb
86
102
  - lib/smart_listing.rb
87
103
  - LICENSE
88
104
  - Rakefile
@@ -107,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
123
  version: '0'
108
124
  requirements: []
109
125
  rubyforge_project:
110
- rubygems_version: 2.0.0
126
+ rubygems_version: 2.0.14
111
127
  signing_key:
112
128
  specification_version: 4
113
129
  summary: SmartListing helps creating sortable lists of ActiveRecord collections with