smart_listing 0.9.6 → 0.9.7

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: daba6372bdd51039d67e7a1b1925bbc241b4bda8
4
- data.tar.gz: ff6eef29b68cf482c8baf5bc7198a4f27b831e2d
3
+ metadata.gz: 3e5029b5f33d511b0683ca39c58f1d4956b6fd29
4
+ data.tar.gz: d924b0eb292135656a20c0b37e2ef1cf7e48a95f
5
5
  SHA512:
6
- metadata.gz: 51d818330f8d5c6333de737bf4b141e4c2a0b49e90e91bba2cc554ae4dda94d9bc67d4f2aad8e8fe6822a5e0e13ab69450ee73c1c4b1c9deee8b2c2e0df3f4ee
7
- data.tar.gz: 5bc2d838c9800a5eb040037afcc5b70a1674944997cafbbc024d88eed3a4bdd3b1f04913b99a7807dbae3a7e508fac43bf1c4ae023567096e1f5a4cb94e6525e
6
+ metadata.gz: 55401a3882f4b42e2797ea24c895d00e285c0f76b575b2809825b0f5ff4dd32ccf1953075290d4cdf25ad359e4c5446db5889b4e76797e529d9a58b93f603ac5
7
+ data.tar.gz: 6ab9ad98c2f7ec341d2d2d14c1a002f617cbb0317a1cb21b2ad82ac1003a77eec335beca1c68086342fc306aac15e8a4772d63b25b8025e9525423141b3c6516
@@ -39,6 +39,8 @@ class SmartListing
39
39
  # Cancel new record
40
40
  @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
41
41
  @container.find('.<%= SmartListing.config.classes(:new_item_action) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
42
+
43
+ @setAutoshow(false)
42
44
  false
43
45
 
44
46
  @container.on 'click', '.<%= SmartListing.config.classes(:item_actions) %> a[data-<%= SmartListing.config.data_attributes(:confirmation) %>]', (event) =>
@@ -81,6 +83,9 @@ class SmartListing
81
83
  maxCount: =>
82
84
  parseInt(@container.data('<%= SmartListing.config.data_attributes(:max_count) %>'))
83
85
 
86
+ setAutoshow: (v) =>
87
+ @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').data('<%= SmartListing.config.data_attributes(:autoshow) %>', v)
88
+
84
89
  changeItemCount: (value) =>
85
90
  @container.find('.<%= SmartListing.config.classes(:pagination_per_page) %> .<%= SmartListing.config.classes(:pagination_count) %>').html(@itemCount() + value)
86
91
 
@@ -107,12 +112,15 @@ class SmartListing
107
112
 
108
113
  if @maxCount()
109
114
  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) %>')
115
+ @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
116
+ @container.find('.<%= SmartListing.config.classes(:new_item_action) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
113
117
  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) %>')
118
+ if @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').data('<%= SmartListing.config.data_attributes(:autoshow) %>')
119
+ @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
120
+ @container.find('.<%= SmartListing.config.classes(:new_item_action) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
121
+ else
122
+ @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
123
+ @container.find('.<%= SmartListing.config.classes(:new_item_action) %>').removeClass('<%= SmartListing.config.classes(:hidden) %>')
116
124
 
117
125
  @status.each (index, status) =>
118
126
  $(status).find('.<%= SmartListing.config.classes(:limit) %>').html(@maxCount() - @itemCount())
@@ -132,18 +140,19 @@ class SmartListing
132
140
  # Methods executed by rails UJS:
133
141
 
134
142
  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) %>')
143
+ if !@maxCount() || (@itemCount() < @maxCount())
144
+ new_item_action = @container.find('.<%= SmartListing.config.classes(:new_item_action) %>')
145
+ new_item_placeholder = @container.find('.<%= SmartListing.config.classes(:new_item_placeholder) %>').addClass('<%= SmartListing.config.classes(:hidden) %>')
137
146
 
138
- @container.find('.<%= SmartListing.config.classes(:editable) %>').each (i, v) =>
139
- @cancelEdit($(v))
147
+ @container.find('.<%= SmartListing.config.classes(:editable) %>').each (i, v) =>
148
+ @cancelEdit($(v))
140
149
 
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) %>')
150
+ new_item_action.addClass('<%= SmartListing.config.classes(:hidden) %>')
151
+ new_item_placeholder.removeClass('<%= SmartListing.config.classes(:hidden) %>')
152
+ new_item_placeholder.html(content)
153
+ new_item_placeholder.addClass('<%= SmartListing.config.classes(:inline_editing) %>')
145
154
 
146
- @fadeLoaded()
155
+ @fadeLoaded()
147
156
 
148
157
  create: (id, success, content) =>
149
158
  new_item_action = @container.find('.<%= SmartListing.config.classes(:new_item_action) %>')
@@ -116,26 +116,37 @@ module SmartListing
116
116
  end
117
117
 
118
118
  # Add new item button & placeholder to list
119
- def item_new options = {}
120
- new_item_action_classes = [SmartListing.config.classes(:new_item_action)]
121
- new_item_action_classes << SmartListing.config.classes(:hidden) if !empty? && max_count?
119
+ def item_new options = {}, &block
122
120
  no_records_classes = [SmartListing.config.classes(:no_records)]
123
121
  no_records_classes << SmartListing.config.classes(:hidden) unless empty?
124
122
  new_item_button_classes = []
125
123
  new_item_button_classes << SmartListing.config.classes(:hidden) if max_count?
126
124
 
127
125
  locals = {
128
- :placeholder_classes => [SmartListing.config.classes(:new_item_placeholder), SmartListing.config.classes(:hidden)],
129
- :new_item_action_classes => new_item_action_classes,
130
126
  :colspan => options.delete(:colspan),
131
127
  :no_items_classes => no_records_classes,
132
128
  :no_items_text => options.delete(:no_items_text),
133
129
  :new_item_button_url => options.delete(:link),
134
130
  :new_item_button_classes => new_item_button_classes,
135
131
  :new_item_button_text => options.delete(:text),
132
+ :new_item_autoshow => block_given?,
133
+ :new_item_content => nil,
136
134
  }
137
135
 
138
- @template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
136
+ unless block_given?
137
+ locals[:placeholder_classes] = [SmartListing.config.classes(:new_item_placeholder), SmartListing.config.classes(:hidden)]
138
+ locals[:new_item_action_classes] = [SmartListing.config.classes(:new_item_action)]
139
+ locals[:new_item_action_classes] << SmartListing.config.classes(:hidden) if !empty? && max_count?
140
+
141
+ @template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
142
+ else
143
+ locals[:placeholder_classes] = [SmartListing.config.classes(:new_item_placeholder)]
144
+ locals[:placeholder_classes] << SmartListing.config.classes(:hidden) if !empty? && max_count?
145
+ locals[:new_item_action_classes] = [SmartListing.config.classes(:new_item_action), SmartListing.config.classes(:hidden)]
146
+
147
+ locals[:new_item_content] = @template.capture(&block)
148
+ @template.render(:partial => 'smart_listing/item_new', :locals => default_locals.merge(locals))
149
+ end
139
150
  end
140
151
 
141
152
  # Check if smart list is empty
@@ -272,8 +283,9 @@ module SmartListing
272
283
  id = options[:id] || object.try(:id)
273
284
  valid = options[:valid] if options.has_key?(:valid)
274
285
  object_key = options.delete(:object_key) || :object
286
+ new = options.delete(:new)
275
287
 
276
- render(:partial => "smart_listing/item/#{item_action.to_s}", :locals => {:name => name, :id => id, :valid => valid, :object_key => object_key, :object => object, :part => partial})
288
+ render(:partial => "smart_listing/item/#{item_action.to_s}", :locals => {:name => name, :id => id, :valid => valid, :object_key => object_key, :object => object, :part => partial, :new => new})
277
289
  end
278
290
  end
279
291
  end
@@ -10,9 +10,13 @@
10
10
  new_item_button_url: argument to link_to (new item button)
11
11
  new_item_button_classes
12
12
  new_item_button_text
13
+ new_item_autoshow automatically show new item placeholder
14
+ new_item_content new item placeholder content (usually some form)
13
15
  -%>
14
16
 
15
- <%= content_tag(:tr, '', :class => placeholder_classes + %w{info}) %>
17
+ <%= content_tag(:tr, '', :class => placeholder_classes + %w{info}, :data => {SmartListing.config.data_attributes(:autoshow) => new_item_autoshow}) do %>
18
+ <%= new_item_content %>
19
+ <% end %>
16
20
  <%= content_tag(:tr, :class => new_item_action_classes + %w{info}) do %>
17
21
  <%= content_tag(:td, :colspan => colspan) do %>
18
22
  <%= content_tag(:p, :class => no_items_classes + %w{pull-left}) do %>
@@ -0,0 +1,6 @@
1
+ var smart_listing = $('#<%= name %>').smart_listing();
2
+ smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
3
+ smart_listing.setAutoshow(true);
4
+ <% if object.persisted? %>
5
+ smart_listing.new_item("<%= escape_javascript(render(:partial => new.last, :locals => {object_key => new.first})) %>");
6
+ <% end %>
@@ -16,8 +16,8 @@ SmartListing.configure do |config|
16
16
  #:pagination_count => "count",
17
17
  #:inline_editing => "info",
18
18
  #:no_records => "no-records",
19
- #:limit => "limit",
20
- #:limit_alert => "limit-alert",
19
+ #:limit => "smart-listing-limit",
20
+ #:limit_alert => "smart-listing-limit-alert",
21
21
  #:controls => "smart-listing-controls",
22
22
  #:controls_reset => "reset",
23
23
  #:filtering => "filter",
@@ -46,6 +46,7 @@ SmartListing.configure do |config|
46
46
  #:params => "params",
47
47
  #:observed => "observed",
48
48
  #:href => "href",
49
+ #:autoshow => "autoshow",
49
50
  }
50
51
 
51
52
  config.constants :selectors, {
@@ -91,7 +91,7 @@ module SmartListing
91
91
  end
92
92
  end
93
93
  else
94
- @collection = @collection.order("#{@sort_attr} #{@sort_order}") if @options[:sort] && @sort_attr && !@sort_attr.empty? && @sort_order
94
+ @collection = @collection.order("#{@sort_attr} #{@sort_order}") if @options[:sort] && @sort_attr && !@sort_attr.empty? && @collection.column_names.include?(@sort_attr) && @sort_order
95
95
  if @options[:paginate] && @per_page > 0
96
96
  @collection = @collection.page(@page).per(@per_page)
97
97
  end
@@ -27,8 +27,8 @@ module SmartListing
27
27
  :pagination_count => "count",
28
28
  :inline_editing => "info",
29
29
  :no_records => "no-records",
30
- :limit => "limit",
31
- :limit_alert => "limit-alert",
30
+ :limit => "smart-listing-limit",
31
+ :limit_alert => "smart-listing-limit-alert",
32
32
  :controls => "smart-listing-controls",
33
33
  :controls_reset => "reset",
34
34
  :filtering => "filter",
@@ -56,6 +56,7 @@ module SmartListing
56
56
  :params => "params",
57
57
  :observed => "observed",
58
58
  :href => "href",
59
+ :autoshow => "autoshow",
59
60
  },
60
61
  :selectors => {
61
62
  :item_action_destroy => "a.destroy",
@@ -1,3 +1,3 @@
1
1
  module SmartListing
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
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.6
4
+ version: 0.9.7
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-28 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -92,6 +92,7 @@ files:
92
92
  - app/views/smart_listing/_sortable.html.erb
93
93
  - app/views/smart_listing/_update_list.js.erb
94
94
  - app/views/smart_listing/item/_create.js.erb
95
+ - app/views/smart_listing/item/_create_continue.js.erb
95
96
  - app/views/smart_listing/item/_destroy.js.erb
96
97
  - app/views/smart_listing/item/_edit.js.erb
97
98
  - app/views/smart_listing/item/_new.js.erb