the_sortable_tree 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,6 +42,8 @@ https://github.com/the-teacher/the_sortable_tree_test_app
42
42
 
43
43
  ### Changelog
44
44
 
45
+ 1.9.1 - Rewrite with coffee => **assets/javascripts/sortable/base.js.coffee**
46
+
45
47
  1.9.0 - 1) **Helper API changed!** 2) Comments tree with sand form and reply fu! 3) Way to manual set sortable Model klass into controller.
46
48
 
47
49
  1.8.6 - fixed CamelCase names definition (by andisthejackass)
@@ -173,7 +175,7 @@ end
173
175
  <%= csrf_meta_tags %>
174
176
 
175
177
  <%= javascript_include_tag 'jquery.ui.nestedSortable' %>
176
- <%= javascript_include_tag 'comments_tree' %>
178
+ <%= javascript_include_tag 'sortable/base' %>
177
179
 
178
180
  <%= stylesheet_link_tag 'tree', :media => :all %>
179
181
  <%= stylesheet_link_tag 'sortable', :media => :all %>
@@ -221,19 +223,39 @@ rails g the_sortable_tree:views Model [option]
221
223
  rails g the_sortable_tree:views Page
222
224
  ```
223
225
 
226
+ And render with partials from **pages/tree/base**
227
+
228
+ ``` ruby
229
+ = sortable_tree @pages, :path => 'pages/tree/base'
230
+ ```
231
+
224
232
  ### Customize your sortable tree
225
233
 
226
234
  ``` ruby
227
235
  rails g the_sortable_tree:views Page sortable
228
236
  ```
229
237
 
238
+ And render with partials from **pages/sortable/base**
239
+
240
+ ``` ruby
241
+ = sortable_tree @pages, :path => 'pages/sortable/base', :new_url => new_page_path
242
+ ```
243
+
230
244
  ### Customize your comments tree
231
245
 
232
246
  ``` ruby
233
247
  rails g the_sortable_tree:views Comment comments
234
248
  ```
235
249
 
236
- ### Rendering a part of tree
250
+ And render with partials from **comments/comments/base**
251
+
252
+ ``` ruby
253
+ = sortable_tree @comments, :path => 'comments/comments/base', :title => :name
254
+ ```
255
+
256
+ ### Troubleshooting
257
+
258
+ If you need to render a part of tree:
237
259
 
238
260
  ``` ruby
239
261
  @root = Page.root
@@ -245,8 +267,6 @@ rails g the_sortable_tree:views Comment comments
245
267
  = sortable_tree @pages, :new_url => new_page_path
246
268
  ```
247
269
 
248
- ### Troubleshooting
249
-
250
270
  If **TheSortableTree** can't correctly define a Name of your Model, just add **sortable_model** into your Controller:
251
271
 
252
272
  ``` ruby
@@ -267,21 +287,31 @@ class Inventory::CategoriesController < ApplicationController
267
287
  end
268
288
  ```
269
289
 
270
- ### Options
290
+ ### Comments Options
291
+
292
+ **node_id** - comment's id which should be set as value of hidden field **parend_id** when Reply link pressed (**:id** by default)
293
+
294
+ **contacts_field** - **:email** field by default. If you want to hide contacts field - you should use customization by view generators
271
295
 
272
- **id** - id field (:id => :friendly_id etc. **:id** by default)
296
+ **content_field** - field with prepared comment's content (**:content** by default)
273
297
 
274
- **title** - title field of node (:title => :name etc. **:title** by default)
298
+ **raw_content_field** - field with raw comment's content (**:raw_content** by default, you can set it to **:content**)
275
299
 
276
- **path** - path to custom view partials (:path => 'pages/the_sortable_tree')
300
+ ### Common Options
277
301
 
278
- **max_levels** - how many draggable levels can be? (**3** by default). **Can't be 0 (zero) and negative**
302
+ **id** - id field (**:id** by default)
279
303
 
280
- **namespace** - namespace for admin sections for example. (:namespace => :admin, **:namespace** => nil by default)
304
+ **title** - title field of node (**:title** by default)
305
+
306
+ **path** - path to custom view partials (:path => 'pages/sortable/tree')
307
+
308
+ **max_levels** - count of draggable levels or **max reply level** in comments tree. (**3** by default). **Can't be 0 (zero) and negative**
309
+
310
+ **namespace** - namespace for admin sections for example. (**nil** by default)
281
311
 
282
312
  **opts[:level]** - view helper define level of recursion for each node. You can call **opts[:level]** into view partials
283
313
 
284
- ### Partials
314
+ ### Base partial's descriptions
285
315
 
286
316
  **_tree** - root container for nested set elements
287
317
 
@@ -296,12 +326,6 @@ end
296
326
  **_controls** - control elements for current node
297
327
 
298
328
 
299
- **_js_init_sortable_tree** - JS for sortable tree
300
-
301
- **_js_on_update_tree**- JS for sortable tree
302
-
303
- **_js_rebuild_ajax**- JS for sortable tree
304
-
305
329
  ### Contributors
306
330
 
307
331
  * https://github.com/the-teacher
@@ -0,0 +1,48 @@
1
+ $ ->
2
+ class @TheSortableTree
3
+ max_levels = 3
4
+ rebuild_url = '/'
5
+
6
+ init: ->
7
+ $('ol.sortable').nestedSortable
8
+ disableNesting: 'no-nest'
9
+ forcePlaceholderSize: true
10
+ handle: 'i.handle'
11
+ helper: 'clone'
12
+ items: 'li'
13
+ maxLevels: @max_levels
14
+ opacity: .6
15
+ placeholder: 'placeholder'
16
+ revert: 250
17
+ tabSize: 25
18
+ tolerance: 'pointer'
19
+ toleranceElement: '> div'
20
+
21
+ $('ol.sortable').sortable
22
+ update: (event, ui) ->
23
+ parent_id = ui.item.parent().parent().attr('id')
24
+ item_id = ui.item.attr('id')
25
+ prev_id = ui.item.prev().attr('id')
26
+ next_id = ui.item.next().attr('id')
27
+
28
+ @rebuild item_id, parent_id, prev_id, next_id
29
+
30
+ rebuild: (item_id, parent_id, prev_id, next_id) ->
31
+ $.ajax
32
+ type: 'POST'
33
+ dataType: 'script'
34
+ url: @rebuild_url
35
+ data:
36
+ id: item_id
37
+ parent_id: parent_id
38
+ prev_id: prev_id
39
+ next_id: next_id
40
+
41
+ beforeSend: (xhr) ->
42
+ $('.nested_set i.handle').hide()
43
+
44
+ success: (data, status, xhr) ->
45
+ $('.nested_set i.handle').show()
46
+
47
+ error: (xhr, status, error) ->
48
+ alert error
@@ -2,6 +2,7 @@
2
2
  = hidden_field :comment, :id, :value => node.send(opts[:node_id]), :id => nil
3
3
  .title
4
4
  %span.main= node.send opts[:title]
5
- %span.reply= link_to t('.reply'), '#'
5
+ - if opts[:level] <= opts[:max_levels]
6
+ %span.reply= link_to t('.reply'), '#'
6
7
  .contacts= node.send opts[:contacts_field]
7
8
  .content= raw node.send opts[:content_field]
@@ -1,7 +1,12 @@
1
1
  .sortable
2
2
  = render :partial => "#{opts[:path]}/new", :locals => { :opts => opts }
3
3
  - unless tree.empty?
4
- = render :partial => "#{opts[:path]}/js_init_sortable_tree", :locals => { :opts => opts }
5
- = render :partial => "#{opts[:path]}/js_on_update_tree"
6
- = render :partial => "#{opts[:path]}/js_rebuild_ajax", :locals => { :opts => opts }
4
+ :javascript
5
+ $(function() {
6
+ sortable = new document.TheSortableTree;
7
+ sortable.max_levels = #{opts[:max_levels]};
8
+ sortable.rebuild_url = "#{url_for(:controller => opts[:klass].pluralize, :action => :rebuild)}";
9
+ sortable.init()
10
+ })
11
+
7
12
  %ol.ui-sortable.sortable.nested_set{ :id => "#{opts[:klass]}_nested_set" }= raw tree
@@ -1,3 +1,3 @@
1
1
  module TheSortableTree
2
- VERSION = "1.9.0"
2
+ VERSION = "1.9.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_sortable_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &76895850 !ruby/object:Gem::Requirement
16
+ requirement: &71085670 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76895850
24
+ version_requirements: *71085670
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &76895640 !ruby/object:Gem::Requirement
27
+ requirement: &71085460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *76895640
35
+ version_requirements: *71085460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &76895410 !ruby/object:Gem::Requirement
38
+ requirement: &71085230 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *76895410
46
+ version_requirements: *71085230
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &76895200 !ruby/object:Gem::Requirement
49
+ requirement: &71085020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *76895200
57
+ version_requirements: *71085020
58
58
  description: Sortable awesom_nested_set, Drag&Drop GUI for awesom_nested_set, View
59
59
  Helper for nested set, Nested Comments
60
60
  email:
@@ -91,8 +91,9 @@ files:
91
91
  - app/assets/stylesheets/tree.css.scss
92
92
  - app/assets/stylesheets/comments_tree.css.scss
93
93
  - app/assets/stylesheets/sortable.css.scss
94
+ - app/assets/javascripts/comments/comments.js.coffee
95
+ - app/assets/javascripts/sortable/base.js.coffee
94
96
  - app/assets/javascripts/jquery.ui.nestedSortable.js
95
- - app/assets/javascripts/comments_tree.js.coffee
96
97
  - app/views/comments/base/_children.html.haml
97
98
  - app/views/comments/base/_node.html.haml
98
99
  - app/views/comments/base/_tree.html.haml
@@ -104,9 +105,6 @@ files:
104
105
  - app/views/sortable/base/_tree.html.haml
105
106
  - app/views/sortable/base/_new.html.haml
106
107
  - app/views/sortable/base/_controls.html.haml
107
- - app/views/sortable/base/_js_rebuild_ajax.html.haml
108
- - app/views/sortable/base/_js_init_sortable_tree.html.haml
109
- - app/views/sortable/base/_js_on_update_tree.html.haml
110
108
  - app/views/tree/base/_children.html.haml
111
109
  - app/views/tree/base/_node.html.haml
112
110
  - app/views/tree/base/_link.html.haml
@@ -1,17 +0,0 @@
1
- :javascript
2
- $(function(){
3
- $('ol.sortable').nestedSortable({
4
- disableNesting: 'no-nest',
5
- forcePlaceholderSize: true,
6
- handle: 'i.handle',
7
- helper: 'clone',
8
- items: 'li',
9
- maxLevels: #{opts[:max_levels]},
10
- opacity: .6,
11
- placeholder: 'placeholder',
12
- revert: 250,
13
- tabSize: 25,
14
- tolerance: 'pointer',
15
- toleranceElement: '> div'
16
- })
17
- });
@@ -1,12 +0,0 @@
1
- :javascript
2
- $(function(){
3
- $('ol.sortable').sortable({
4
- update: function(event, ui){
5
- parent_id = ui.item.parent().parent().attr('id');
6
- item_id = ui.item.attr('id');
7
- prev_id = ui.item.prev().attr('id');
8
- next_id = ui.item.next().attr('id');
9
- sortable_tree(item_id, parent_id, prev_id, next_id);
10
- }
11
- });
12
- });
@@ -1,13 +0,0 @@
1
- :javascript
2
- function sortable_tree(item_id, parent_id, prev_id, next_id){
3
- jQuery.ajax({
4
- type: 'POST',
5
- dataType: 'script',
6
- url: '#{url_for(:controller => opts[:klass].pluralize, :action => :rebuild)}',
7
- data: { id: item_id, parent_id: parent_id, prev_id: prev_id, next_id: next_id },
8
-
9
- beforeSend: function(xhr){ $('.nested_set i.handle').hide() },
10
- success: function(data, status, xhr){ $('.nested_set i.handle').show() },
11
- error: function(xhr, status, error){ alert(error) }
12
- });
13
- }