the_sortable_tree 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,7 +24,7 @@ Awesome nested set, Nested set, Ruby, Rails, Nested set view helper, Sortable ne
24
24
 
25
25
  ```ruby
26
26
  gem 'awesome_nested_set' # or any similar gem (gem 'nested_set')
27
- gem "the_sortable_tree", "~> 2.2.1"
27
+ gem "the_sortable_tree", "~> 2.3.0"
28
28
  ```
29
29
 
30
30
  Console
@@ -0,0 +1,50 @@
1
+ @append_children_to_node = (node, html) ->
2
+ html = html.trim()
3
+ item = node.children('.item')
4
+
5
+ button = node.children('.item').children('.expand')
6
+
7
+ if html.length is 0
8
+ button.addClass 'empty'
9
+
10
+ if html.length > 0
11
+ button.removeClass('plus').addClass('minus').html('–')
12
+ item.after html
13
+
14
+
15
+ @upload_nodes_children = (node, expand_node_url, tree_type = 'expandable') ->
16
+ node_id = node.attr 'id'
17
+
18
+ $.ajax
19
+ type: 'POST'
20
+ dataType: 'html'
21
+ url: expand_node_url
22
+ data:
23
+ id: node_id
24
+ tree_type: tree_type
25
+
26
+ beforeSend: (xhr) ->
27
+ $('.sortable_tree i.handle').hide()
28
+ $('.sortable_tree b.expand').hide()
29
+
30
+ success: (data, status, xhr) ->
31
+ $('.sortable_tree i.handle').show()
32
+ $('.sortable_tree b.expand').show()
33
+ append_children_to_node(node, data)
34
+
35
+ error: (xhr, status, error) ->
36
+ console.log error
37
+
38
+ $ ->
39
+ for sortable_tree in $('ol.sortable_tree')
40
+ sortable_tree = $ sortable_tree
41
+ expand_node_url = sortable_tree.data('expand_node_url')
42
+ tree_type = sortable_tree.data('tree_type')
43
+
44
+ pluses = $ '.expand.plus', sortable_tree
45
+
46
+ pluses.live 'click', (e) ->
47
+ node = $(@).parent().parent()
48
+ upload_nodes_children(node, expand_node_url, tree_type)
49
+
50
+ false
@@ -21,8 +21,8 @@
21
21
  $ ->
22
22
  for sortable_tree in $('ol.sortable_tree')
23
23
  sortable_tree = $ sortable_tree
24
- rebuild_url = sortable_tree.data('rebuild_url')
25
- max_levels = sortable_tree.data('max_levels')
24
+ rebuild_url = sortable_tree.data('rebuild_url') || sortable_tree.data('rebuild-url')
25
+ max_levels = sortable_tree.data('max_levels') || sortable_tree.data('rebuild-url')
26
26
 
27
27
  ############################################
28
28
  # Initialize Sortable Tree
@@ -0,0 +1,20 @@
1
+ .sortable_tree{
2
+ .expand{
3
+ float: left;
4
+ cursor: pointer;
5
+
6
+ border: 1px solid gray;
7
+ color: gray;
8
+
9
+ font-size: 13px;
10
+ font-weight: normal;
11
+ line-height: 13px;
12
+ text-align: center;
13
+
14
+ width: 13px;
15
+ height: 13px;
16
+ margin: 3px 10px 0 0;
17
+
18
+ &.empty{ display:none !important; }
19
+ }
20
+ }
@@ -1,6 +1,7 @@
1
1
  module TheSortableTreeController
2
2
  # include TheSortableTreeController::ReversedRebuild
3
3
  # include TheSortableTreeController::Rebuild
4
+ # include TheSortableTreeController::ExpandNode
4
5
 
5
6
  module DefineVariablesMethod
6
7
  public
@@ -13,6 +14,22 @@ module TheSortableTreeController
13
14
  end
14
15
  end
15
16
 
17
+
18
+ module ExpandNode
19
+ include DefineVariablesMethod
20
+ def expand_node
21
+ id = params[:id].to_i
22
+ render :text => "Do nothing" and return unless id
23
+
24
+ variable, collection, klass = self.the_define_common_variables
25
+ variable = self.instance_variable_set(variable, klass.find(id))
26
+ @children = variable.children
27
+
28
+ render :text => nil and return if @children.count.zero?
29
+ render :layout => false, :template => "#{collection}/expand_children"
30
+ end
31
+ end
32
+
16
33
  module Rebuild
17
34
  include DefineVariablesMethod
18
35
  public
@@ -0,0 +1,64 @@
1
+ # DOC:
2
+ # We use Helper Methods for tree building,
3
+ # because it's faster than View Templates and Partials
4
+
5
+ # SECURITY note
6
+ # Prepare your data on server side for rendering
7
+ # or use h.html_escape(node.content)
8
+ # for escape potentially dangerous content
9
+ module RenderExpandableTreeHelper
10
+ module Render
11
+ class << self
12
+ attr_accessor :h, :options
13
+
14
+ def render_node(h, options)
15
+ @h, @options = h, options
16
+
17
+ node = options[:node]
18
+ # &ndash;
19
+
20
+ "
21
+ <li id='#{ node.id }_#{ options[:klass] }'>
22
+ <div class='item'>
23
+ <i class='handle'></i>
24
+ <b class='expand plus'>+</b>
25
+ #{ show_link }
26
+ #{ controls }
27
+ </div>
28
+ #{ children }
29
+ </li>
30
+ "
31
+ end
32
+
33
+ def show_link
34
+ node = options[:node]
35
+ ns = options[:namespace]
36
+ url = h.url_for(ns + [node])
37
+ title_field = options[:title]
38
+
39
+ "<h4>#{ h.link_to(node.send(title_field), url) }</h4>"
40
+ end
41
+
42
+ def controls
43
+ node = options[:node]
44
+
45
+ edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
46
+ show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)
47
+
48
+ "
49
+ <div class='controls'>
50
+ #{ h.link_to '', edit_path, :class => :edit }
51
+ #{ h.link_to '', show_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
52
+ </div>
53
+ "
54
+ end
55
+
56
+ def children
57
+ unless options[:children].blank?
58
+ "<ol class='nested_set'>#{ options[:children] }</ol>"
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -9,6 +9,7 @@ module TheSortableTreeHelper
9
9
  TREE_RENDERERS = {
10
10
  :tree => RenderTreeHelper,
11
11
  :sortable => RenderSortableTreeHelper,
12
+ :expandable => RenderExpandableTreeHelper,
12
13
  :nested_options => RenderNestedOptionsHelper
13
14
  }
14
15
 
@@ -44,6 +45,10 @@ module TheSortableTreeHelper
44
45
  build_server_tree(tree, { :type => :nested_options }.merge!(options))
45
46
  end
46
47
 
48
+ def expandable_tree tree, options = {}
49
+ build_server_tree(tree, { :type => :expandable }.merge!(options))
50
+ end
51
+
47
52
  ###############################################
48
53
  # Server Side Render Tree Helper
49
54
  ###############################################
@@ -1,3 +1,3 @@
1
1
  module TheSortableTree
2
- VERSION = "2.3.0"
2
+ VERSION = "2.3.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: 2.3.0
4
+ version: 2.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &85053720 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *85053720
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: sqlite3
27
- requirement: &85053300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *85053300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &85052940 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *85052940
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec-rails
49
- requirement: &85052650 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *85052650
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  description: Drag&Drop GUI for awesom_nested_set. Render Tree Helper. Very fast! Ready
59
79
  for Rails 4
60
80
  email:
@@ -65,66 +85,69 @@ extra_rdoc_files:
65
85
  - README.md
66
86
  files:
67
87
  - app/controllers/the_sortable_tree_controller.rb
68
- - app/assets/images/iconza/icons/edit.png
69
- - app/assets/images/iconza/icons/red_edit.png
88
+ - app/helpers/render_sortable_tree_helper.rb
89
+ - app/helpers/render_tree_helper.rb
90
+ - app/helpers/render_expandable_tree_helper.rb
91
+ - app/helpers/the_sortable_tree_helper.rb
92
+ - app/helpers/render_nested_options_helper.rb
93
+ - app/views/sortable/client/_tree.html.erb
94
+ - app/views/tree/client/_tree.html.erb
70
95
  - app/assets/images/iconza/icons/red_delete.png
71
- - app/assets/images/iconza/icons/red_move.png
96
+ - app/assets/images/iconza/icons/red_edit.png
72
97
  - app/assets/images/iconza/icons/red_add.png
98
+ - app/assets/images/iconza/icons/red_move.png
73
99
  - app/assets/images/iconza/icons/move.png
74
- - app/assets/images/iconza/icons/delete.png
75
100
  - app/assets/images/iconza/icons/add.png
101
+ - app/assets/images/iconza/icons/delete.png
102
+ - app/assets/images/iconza/icons/edit.png
76
103
  - app/assets/stylesheets/nested_options.css.scss
77
- - app/assets/stylesheets/tree.css.scss
78
104
  - app/assets/stylesheets/sortable_tree.css.scss
105
+ - app/assets/stylesheets/tree.css.scss
106
+ - app/assets/stylesheets/expandable_tree.css.scss
79
107
  - app/assets/javascripts/jquery.ui.nestedSortable.js
80
108
  - app/assets/javascripts/render_tree_helper.js.coffee
109
+ - app/assets/javascripts/expandable_tree/initializer.js.coffee
81
110
  - app/assets/javascripts/sortable_tree/initializer.js.coffee
82
- - app/views/sortable/client/_tree.html.erb
83
- - app/views/tree/client/_tree.html.erb
84
- - app/helpers/render_tree_helper.rb
85
- - app/helpers/the_sortable_tree_helper.rb
86
- - app/helpers/render_sortable_tree_helper.rb
87
- - app/helpers/render_nested_options_helper.rb
111
+ - lib/fake.example
112
+ - lib/generators/the_sortable_tree/views_generator.rb
88
113
  - lib/the_sortable_tree/version.rb
89
114
  - lib/the_sortable_tree/engine.rb
90
- - lib/generators/the_sortable_tree/views_generator.rb
91
- - lib/fake.example
92
115
  - lib/the_sortable_tree.rb
93
116
  - MIT-LICENSE
94
117
  - Rakefile
95
118
  - README.md
96
119
  - spec/controlllers/controller_mixin_spec.rb
97
- - spec/spec_helper.rb
98
- - spec/dummy/README.rdoc
99
120
  - spec/dummy/Rakefile
121
+ - spec/dummy/db/test.sqlite3
100
122
  - spec/dummy/config.ru
123
+ - spec/dummy/log/test.log
101
124
  - spec/dummy/config/boot.rb
102
125
  - spec/dummy/config/application.rb
103
- - spec/dummy/config/environment.rb
104
126
  - spec/dummy/config/locales/en.yml
105
- - spec/dummy/config/initializers/session_store.rb
106
- - spec/dummy/config/initializers/backtrace_silencers.rb
107
- - spec/dummy/config/initializers/mime_types.rb
108
- - spec/dummy/config/initializers/wrap_parameters.rb
109
- - spec/dummy/config/initializers/secret_token.rb
110
- - spec/dummy/config/initializers/inflections.rb
111
- - spec/dummy/config/routes.rb
112
127
  - spec/dummy/config/environments/development.rb
113
128
  - spec/dummy/config/environments/test.rb
114
129
  - spec/dummy/config/environments/production.rb
130
+ - spec/dummy/config/routes.rb
131
+ - spec/dummy/config/initializers/backtrace_silencers.rb
132
+ - spec/dummy/config/initializers/inflections.rb
133
+ - spec/dummy/config/initializers/session_store.rb
134
+ - spec/dummy/config/initializers/wrap_parameters.rb
135
+ - spec/dummy/config/initializers/secret_token.rb
136
+ - spec/dummy/config/initializers/mime_types.rb
137
+ - spec/dummy/config/environment.rb
115
138
  - spec/dummy/config/database.yml
116
- - spec/dummy/public/500.html
117
- - spec/dummy/public/404.html
118
- - spec/dummy/public/422.html
119
- - spec/dummy/public/favicon.ico
120
- - spec/dummy/db/test.sqlite3
121
- - spec/dummy/log/test.log
122
- - spec/dummy/app/controllers/application_controller.rb
139
+ - spec/dummy/script/rails
123
140
  - spec/dummy/app/controllers/tests_controller.rb
141
+ - spec/dummy/app/controllers/application_controller.rb
142
+ - spec/dummy/app/views/layouts/application.html.erb
124
143
  - spec/dummy/app/assets/stylesheets/application.css
125
144
  - spec/dummy/app/assets/javascripts/application.js
126
- - spec/dummy/app/views/layouts/application.html.erb
127
- - spec/dummy/script/rails
145
+ - spec/dummy/public/500.html
146
+ - spec/dummy/public/favicon.ico
147
+ - spec/dummy/public/422.html
148
+ - spec/dummy/public/404.html
149
+ - spec/dummy/README.rdoc
150
+ - spec/spec_helper.rb
128
151
  homepage: https://github.com/the-teacher/the_sortable_tree
129
152
  licenses: []
130
153
  post_install_message:
@@ -145,41 +168,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
168
  version: '0'
146
169
  requirements: []
147
170
  rubyforge_project: the_sortable_tree
148
- rubygems_version: 1.8.15
171
+ rubygems_version: 1.8.25
149
172
  signing_key:
150
173
  specification_version: 3
151
174
  summary: Drag&Drop GUI for awesom_nested_set. Render Tree Helper. Very fast! Ready
152
175
  for Rails 4
153
176
  test_files:
154
177
  - spec/controlllers/controller_mixin_spec.rb
155
- - spec/spec_helper.rb
156
- - spec/dummy/README.rdoc
157
178
  - spec/dummy/Rakefile
179
+ - spec/dummy/db/test.sqlite3
158
180
  - spec/dummy/config.ru
181
+ - spec/dummy/log/test.log
159
182
  - spec/dummy/config/boot.rb
160
183
  - spec/dummy/config/application.rb
161
- - spec/dummy/config/environment.rb
162
184
  - spec/dummy/config/locales/en.yml
163
- - spec/dummy/config/initializers/session_store.rb
164
- - spec/dummy/config/initializers/backtrace_silencers.rb
165
- - spec/dummy/config/initializers/mime_types.rb
166
- - spec/dummy/config/initializers/wrap_parameters.rb
167
- - spec/dummy/config/initializers/secret_token.rb
168
- - spec/dummy/config/initializers/inflections.rb
169
- - spec/dummy/config/routes.rb
170
185
  - spec/dummy/config/environments/development.rb
171
186
  - spec/dummy/config/environments/test.rb
172
187
  - spec/dummy/config/environments/production.rb
188
+ - spec/dummy/config/routes.rb
189
+ - spec/dummy/config/initializers/backtrace_silencers.rb
190
+ - spec/dummy/config/initializers/inflections.rb
191
+ - spec/dummy/config/initializers/session_store.rb
192
+ - spec/dummy/config/initializers/wrap_parameters.rb
193
+ - spec/dummy/config/initializers/secret_token.rb
194
+ - spec/dummy/config/initializers/mime_types.rb
195
+ - spec/dummy/config/environment.rb
173
196
  - spec/dummy/config/database.yml
174
- - spec/dummy/public/500.html
175
- - spec/dummy/public/404.html
176
- - spec/dummy/public/422.html
177
- - spec/dummy/public/favicon.ico
178
- - spec/dummy/db/test.sqlite3
179
- - spec/dummy/log/test.log
180
- - spec/dummy/app/controllers/application_controller.rb
197
+ - spec/dummy/script/rails
181
198
  - spec/dummy/app/controllers/tests_controller.rb
199
+ - spec/dummy/app/controllers/application_controller.rb
200
+ - spec/dummy/app/views/layouts/application.html.erb
182
201
  - spec/dummy/app/assets/stylesheets/application.css
183
202
  - spec/dummy/app/assets/javascripts/application.js
184
- - spec/dummy/app/views/layouts/application.html.erb
185
- - spec/dummy/script/rails
203
+ - spec/dummy/public/500.html
204
+ - spec/dummy/public/favicon.ico
205
+ - spec/dummy/public/422.html
206
+ - spec/dummy/public/404.html
207
+ - spec/dummy/README.rdoc
208
+ - spec/spec_helper.rb