sortable_tree_rails 0.0.5 → 0.0.8

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: 1e2567700056448155ede5cd8f8e96629d4e1ba9
4
- data.tar.gz: 1bac6e8c9e67417ab1d4889f6ccbcc33824e3b64
3
+ metadata.gz: ee8d4e44aec0235ab2e31fc03bde95499d6830c4
4
+ data.tar.gz: 18c3ad4cb2516050843f3b89221bfcbb80205f90
5
5
  SHA512:
6
- metadata.gz: 62627120387f98b23f9b60255bab0ec1408dcfbf11e69e693f549c13b5cbd5749d0bd5703ec1d30b47c582bfc234b2a898a32d8eeb8b5c8e0fb0eb5a6d28708c
7
- data.tar.gz: 1ae8c924c9d0a7424c5a6861d38b25cce8cb23612d30497057c2f1c204276fe88822b621a3501a517abc5e32674d3223707db62624946564783126cd2b58317a
6
+ metadata.gz: c062364af1885e36f6d9d632a0bd0a98d2c311cdd665b022136318cc1ed82536add9c9d28a799f2ade4c8757182969a4f0ef8bb226332270ee3e3c4e10a03bdd
7
+ data.tar.gz: a774bce0c5707d547047f8fc8fbf4c0eb9f34141b67b5efddf43cfbba25eb9f04c5ce8333547afa5131cc788abd52bedcbb350e03e6864746e72db0d5c9eaab9
@@ -19,7 +19,7 @@ module SortableTreeController
19
19
  options[:sorting_attribute] ||= 'pos'
20
20
  options[:parent_method] ||= 'parent'
21
21
 
22
- records = params[:cat].inject({}) do |res, (resource, parent_resource)|
22
+ records = params[:cat].to_unsafe_h.inject({}) do |res, (resource, parent_resource)|
23
23
  res[resource_class.find(resource)] = resource_class.find(parent_resource) rescue nil
24
24
  res
25
25
  end
@@ -29,9 +29,10 @@ module SortableTreeHelper
29
29
 
30
30
  def sortable_tree_build_actions(item, opts={})
31
31
  partial = opts[:controls_partial] || nil
32
-
33
32
  if partial
34
- render :partial=>partial, locals: {item: item, options: opts}
33
+ return render :partial=>partial, locals: {item: item, options: opts}
34
+ else
35
+ return ""
35
36
  end
36
37
 
37
38
  end
@@ -1,5 +1,5 @@
1
1
  .sortable_tree_wrapper
2
- %ol.sortable_tree{data: {'sortable-url' => options[:sort_url]} }
2
+ %ol.sortable_tree{data: {'sortable-url' => options[:sort_url], 'max-levels'=> (options[:max_levels] || 5)} }
3
3
  - items.each do |root, children|
4
4
  %li{id: "cat_#{root.id}"}
5
5
  .item
@@ -15,61 +15,3 @@
15
15
 
16
16
 
17
17
 
18
- :javascript
19
- $(document).ready(function(){
20
- $('.sortable_tree').nestedSortable({
21
- forceHelperSizeType: true,
22
- errorClass: 'cantdoit',
23
- disableNesting: 'cantdoit',
24
- handle: '> .item',
25
- helper: 'clone',
26
- listType: 'ol',
27
- items: 'li',
28
- opacity: 0.6,
29
- placeholder: 'placeholder',
30
- revert: 250,
31
- maxLevels: #{options[:max_levels] || 5},
32
- //tabSize: 20,
33
- // protectRoot: $(this).data('protect-root'),
34
-
35
- // prevent drag flickers
36
- tolerance: 'pointer',
37
- toleranceElement: '> div',
38
- isTree: true,
39
- startCollapsed: false,
40
- //startCollapsed: $(this).data("start-collapsed"),
41
-
42
- relocate: function(){
43
- //$(this).nestedSortable("disable");
44
- var data = $(this).nestedSortable("serialize");
45
- var url = $(this).data("sortable-url");
46
-
47
- // update on server
48
- $.ajax({
49
- url: url,
50
- type: "post",
51
- data: data
52
- }).always(function(){
53
- //$(this).nestedSortable("enable");
54
-
55
- $(this).find('.item').each(function(index){
56
- if (index % 2){
57
- $(this).removeClass('odd').addClass('even');
58
- }else{
59
- $(this).removeClass('even').addClass('odd');
60
- }
61
- });
62
-
63
- }).done(function(data){
64
-
65
- }).fail(function(jqXHR, textStatus){
66
-
67
- });
68
-
69
-
70
- //$(this).nestedSortable("enable");
71
- }
72
- }); // nested tree
73
- }); // document.ready
74
-
75
-
@@ -0,0 +1,61 @@
1
+ $(document).ready(function(){
2
+
3
+ $('.sortable_tree').each(function() {
4
+ $(this).nestedSortable({
5
+ forceHelperSizeType: true,
6
+ errorClass: 'cantdoit',
7
+ disableNesting: 'cantdoit',
8
+ handle: '> .item',
9
+ helper: 'clone',
10
+ listType: 'ol',
11
+ items: 'li',
12
+ opacity: 0.6,
13
+ placeholder: 'placeholder',
14
+ revert: 250,
15
+ maxLevels: $(this).data('max-levels'),
16
+ //maxLevels: #{options[:max_levels] || 5},
17
+ //tabSize: 20,
18
+ // protectRoot: $(this).data('protect-root'),
19
+
20
+ // prevent drag flickers
21
+ tolerance: 'pointer',
22
+ toleranceElement: '> div',
23
+ isTree: true,
24
+ startCollapsed: false,
25
+ //startCollapsed: $(this).data("start-collapsed"),
26
+
27
+ relocate: function(){
28
+ //$(this).nestedSortable("disable");
29
+ var data = $(this).nestedSortable("serialize");
30
+ var url = $(this).data("sortable-url");
31
+
32
+ // update on server
33
+ $.ajax({
34
+ url: url,
35
+ type: "post",
36
+ data: data
37
+ }).always(function(){
38
+ //$(this).nestedSortable("enable");
39
+
40
+ $(this).find('.item').each(function(index){
41
+ if (index % 2){
42
+ $(this).removeClass('odd').addClass('even');
43
+ }else{
44
+ $(this).removeClass('even').addClass('odd');
45
+ }
46
+ });
47
+
48
+ }).done(function(data){
49
+
50
+ }).fail(function(jqXHR, textStatus){
51
+
52
+ });
53
+
54
+
55
+ //$(this).nestedSortable("enable");
56
+ }
57
+ }); // nested tree
58
+ });
59
+
60
+
61
+ }); // document.ready
@@ -1,3 +1,3 @@
1
1
  module SortableTreeRails
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.8"
3
3
  end
data/readme.md CHANGED
@@ -23,6 +23,9 @@ Run page with the tree: `http://localhost:3000/categories/manage`.
23
23
  ### Gemfile
24
24
 
25
25
  ```
26
+ gem 'jquery-rails'
27
+ gem "jquery-ui-rails"
28
+
26
29
  gem 'ancestry'
27
30
  gem 'sortable_tree_rails'
28
31
  ```
@@ -64,17 +67,24 @@ end
64
67
 
65
68
  ### Javascript
66
69
 
67
- Include js files in your assets file application.js:
70
+ Include js files in your assets file `application.js`:
68
71
 
69
72
  ```
70
73
  //= require jquery2
71
- //= require jquery_ujs
74
+ //= require jquery-ui
72
75
 
73
- //=require jquery-ui/sortable
74
76
  //=require jquery.mjs.nestedSortable.js
77
+ //=require sortable_tree.js
78
+
75
79
 
76
80
  ```
77
81
 
82
+ it depends on jquery and jquery-ui which come from gems 'jquery-rails', 'jquery-ui-rails'.
83
+ Change `application.js` to include jquery and jquery-ui (jquery-ui/sortable) if you are not using these gems.
84
+
85
+
86
+
87
+
78
88
  ### CSS
79
89
 
80
90
  Add CSS file to your styles.
@@ -154,9 +164,8 @@ in controller:
154
164
  sortable_tree 'ClassName', {parent_method: 'parent', sorting_attribute: 'pos'}
155
165
  ```
156
166
 
157
- * :controls_partial - specify what partial view to use to show control links for each item in a tree. Set to nil to not show controls.
158
167
 
159
- Use local variable `item` in the partial view.
168
+
160
169
 
161
170
 
162
171
  ## Options for view
@@ -165,9 +174,45 @@ Use local variable `item` in the partial view.
165
174
  = render_sortable_tree(@items, {__options_here})
166
175
  ```
167
176
 
168
- * name_method - defined which model method (usually, a column name) will be used to show name (default: :name)
169
- * sort_url - URL used to update data after item is moved to a new position
170
- * max_levels - max levels to show in tree (default: 5)
177
+ * :name_method - defined which model method (usually, a column name) will be used to show name (default: :name)
178
+ * :sort_url - URL used to update data after item is moved to a new position
179
+ * :max_levels - max levels to show in tree (default: 5)
180
+ * :controls_partial - specify what partial view to use to show control links for each item in a tree. Set to nil to not show controls.
181
+
182
+
183
+
184
+ * example.
185
+
186
+ ```
187
+ = render_sortable_tree(@items, {name_method: :name, sort_url: sort_categories_url, max_levels: 5})
188
+ ```
189
+
190
+
191
+ * example of partial view with controls.
192
+
193
+ * main view:
194
+ ```
195
+ = render_sortable_tree(@items, {name_method: :name, sort_url: sort_categories_url, max_levels: 5, controls_partial: 'controls'})
196
+ ```
197
+
198
+ * partial with controls. Use local variable `item` in the partial view.
199
+
200
+ `_controls.html.haml`:
201
+
202
+ ```
203
+ = link_to 'Edit', edit_category_url(item)
204
+ = link_to 'Delete', category_url(item), :method => :delete, :data => { :confirm => 'Are you sure?' }
205
+
206
+ ```
207
+
208
+
209
+ # Customize
210
+
211
+ ## customize view
212
+
213
+ * edit file 'views/sortable/_sortable.html.haml' to access the whole layout
214
+
215
+
171
216
 
172
217
 
173
218
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortable_tree_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-01 00:00:00.000000000 Z
11
+ date: 2018-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: 4.2.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: 4.2.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +61,7 @@ files:
61
61
  - app/views/sortable_tree/_sortable_tree.html.haml
62
62
  - config/routes.rb
63
63
  - lib/assets/javascripts/jquery.mjs.nestedSortable.js
64
+ - lib/assets/javascripts/sortable_tree.js
64
65
  - lib/assets/stylesheets/sortable_tree.scss
65
66
  - lib/sortable_tree_rails.rb
66
67
  - lib/sortable_tree_rails/engine.rb