the_sortable_tree 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -59,6 +59,43 @@ bundle
59
59
  2. gem 'haml'
60
60
  3. JQuery UI
61
61
 
62
+ ### Options
63
+
64
+ **id** - id field (:id => :friendly_id etc. **:id** by default)
65
+
66
+ **title** - title field of node (:title => :name etc. **:title** by default)
67
+
68
+ **path** - path to custom view partials (:path => 'pages/the_sortable_tree')
69
+
70
+ **title** - title field of node (:title => :name etc. **:title** by default)
71
+
72
+ **max_levels** - how many draggable levels can be? (**3** by default). **Can't be 0 (zero) and negative**
73
+
74
+ **namespace** - namespace for admin sections for example. (:namespace => :admin, **:namespace** => nil by default)
75
+
76
+ **opts[:level]** - view helper define level of recursion for each node. You can call **opts[:level]** into view partials
77
+
78
+ ### Partials
79
+
80
+ **_tree** - root container for nested set elements
81
+
82
+ **_node** - element of tree (link to current node and nested set of children)
83
+
84
+ **_link** - decoration of link to current element of tree
85
+
86
+ **_children** - decoration of children
87
+
88
+ **_new** - create new element link
89
+
90
+ **_controls** - control elements for current node
91
+
92
+
93
+ **_js_init_sortable_tree** - JS for sortable tree
94
+
95
+ **_js_on_update_tree**- JS for sortable tree
96
+
97
+ **_js_rebuild_ajax**- JS for sortable tree
98
+
62
99
  ### Example of using with Page Model
63
100
 
64
101
  ### Extend your Model
@@ -210,32 +247,12 @@ Customize and use it!
210
247
  = sortable_tree @pages, :new_url => new_page_path, :path => 'pages/the_sortable_tree', :max_levels => 2
211
248
  ```
212
249
 
213
- ### Partials
214
-
215
- **_tree** - root container for nested set elements
216
-
217
- **_node** - element of tree (link to current node and nested set of children)
218
-
219
- **_link** - decoration of link to current element of tree
220
-
221
- **_children** - decoration of children
222
-
223
- **_new** - create new element link
224
-
225
- **_controls** - control elements for current node
226
-
227
-
228
- **_js_init_sortable_tree** - JS for sortable tree
229
-
230
- **_js_on_update_tree**- JS for sortable tree
231
-
232
- **_js_rebuild_ajax**- JS for sortable tree
233
-
234
250
  ### Contributors
235
251
 
236
252
  * https://github.com/the-teacher
237
253
  * https://github.com/winescout
238
254
  * https://github.com/gbrain
255
+ * https://github.com/Mik-die
239
256
 
240
257
  ### Acknowledgments
241
258
 
@@ -5,12 +5,16 @@ module TheSortableTreeHelper
5
5
  # github.com/the-teacher
6
6
  #-------------------------------------------------------------------------------------------------------
7
7
 
8
- # = sortable_tree @pages, :new_url => new_page_url, :max_levels => 5
8
+ # = sortable_tree @pages, :new_url => new_page_url, :max_levels => 5
9
9
  # = sortable_tree @products, :new_url => new_product_url, :path => 'products/the_sortable_tree'
10
+ # = sortable_tree @catalogs, :namespace => :admin, :new_url => new_catalog_url, :max_levels => 5
10
11
 
11
12
  def define_class_of_elements_of tree
12
- return nil if tree.empty?
13
- tree.first.class.to_s.downcase
13
+ case
14
+ when tree.is_a?(ActiveRecord::Relation) then tree.name.to_s.downcase
15
+ when tree.empty? then nil
16
+ else tree.first.class.to_s.downcase
17
+ end
14
18
  end
15
19
 
16
20
  def sortable_tree(tree, opts= {})
@@ -18,7 +22,8 @@ module TheSortableTreeHelper
18
22
  :path => opts[:path] || :the_sortable_tree,
19
23
  :klass => define_class_of_elements_of(tree),
20
24
  :title => opts[:title] || :title,
21
- :max_levels => opts[:max_levels] || 3
25
+ :max_levels => opts[:max_levels] || 3,
26
+ :namespace => Array.wrap(opts[:namespace])
22
27
  })
23
28
  render :partial => "#{opts[:path]}/tree", :locals => { :tree => sortable_tree_builder(tree, opts), :opts => opts }
24
29
  end
@@ -36,7 +41,7 @@ module TheSortableTreeHelper
36
41
  node = opts[:node]
37
42
 
38
43
  unless node
39
- roots = tree.select{|elem| elem.parent_id.nil?}
44
+ roots = tree.select{|elem| elem.parent_id.nil?}
40
45
  roots.each do |root|
41
46
  _opts = opts.merge({:node => root, :root => true, :level => opts[:level].next})
42
47
  result << sortable_tree_builder(tree, _opts)
@@ -53,4 +58,4 @@ module TheSortableTreeHelper
53
58
  end
54
59
  raw result
55
60
  end# sortable_tree_builder
56
- end# module
61
+ end# module
@@ -1,8 +1,8 @@
1
1
  -# EDIT
2
- - edit = link_to '', polymorphic_url(node, :action => :edit), :title => t('.edit_this'), :class => 'button edit'
2
+ - edit = link_to '', polymorphic_url(opts[:namespace] + [node], :action => :edit), :title => t('.edit_this'), :class => 'button edit'
3
3
  -# DELETE
4
4
  - if opts[:has_children]
5
- - delete = link_to('', url_for(node),
5
+ - delete = link_to('', url_for(opts[:namespace] + [node]),
6
6
  :title => t('.delete'),
7
7
  :method => :delete,
8
8
  :confirm => t('.delete_confirm'),
@@ -1,7 +1,7 @@
1
1
  - title = node.send opts[:title]
2
2
  - handle = content_tag :i, '', :class => :handle
3
- - link = link_to(title, url_for(node), :title => title)
3
+ - link = link_to(title, url_for(opts[:namespace] + [node]), :title => title)
4
4
  - controls = render(:partial => "#{opts[:path]}/controls", :locals => { :node => node, :opts => opts })
5
5
  - controls = content_tag(:b, controls, :class => :controls)
6
6
  - element = handle + controls + link
7
- %div{ :class => "link#{' root' if root}" }= element
7
+ %div{ :class => "link#{' root' if root}" }= element
@@ -1 +1 @@
1
- = link_to node.send(opts[:title]), url_for(node), :title => node.send(opts[:title])
1
+ = link_to node.send(opts[:title]), url_for(opts[:namespace] + [node]), :title => node.send(opts[:title])
@@ -1,3 +1,3 @@
1
1
  module TheSortableTree
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_sortable_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Ilya N. Zykin, Matthew Clark
8
+ - Ilya N. Zykin, Matthew Clark, Mikhail Dieterle
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-28 00:00:00.000000000Z
12
+ date: 2012-02-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &85024190 !ruby/object:Gem::Requirement
16
+ requirement: &77493650 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.0
21
+ version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *85024190
24
+ version_requirements: *77493650
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &85023880 !ruby/object:Gem::Requirement
27
+ requirement: &77493170 !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: *85023880
35
+ version_requirements: *77493170
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &85023400 !ruby/object:Gem::Requirement
38
+ requirement: &77492740 !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: *85023400
46
+ version_requirements: *77492740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &85023110 !ruby/object:Gem::Requirement
49
+ requirement: &77492450 !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: *85023110
57
+ version_requirements: *77492450
58
58
  description: Drag&Drop GUI helper for awesome_nested_set gem. Sortable tree view helper
59
59
  email:
60
60
  - zykin-ilya@ya.ru