dynatree-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -2
- data/lib/dynatree-rails/renderer.rb +53 -0
- data/lib/dynatree-rails/version.rb +1 -1
- data/lib/dynatree-rails.rb +1 -0
- data/vendor/assets/stylesheets/dynatree/skin.sass +7 -7
- metadata +2 -1
data/README.md
CHANGED
@@ -24,14 +24,47 @@ css:
|
|
24
24
|
|
25
25
|
or
|
26
26
|
|
27
|
-
//= require dynatree/skin
|
27
|
+
//= require dynatree/skin
|
28
28
|
|
29
29
|
js:
|
30
30
|
|
31
31
|
//= require dynatree/jquery.dynatree
|
32
32
|
|
33
33
|
For dynatree usage and examples see: http://code.google.com/p/dynatree/
|
34
|
-
|
34
|
+
|
35
|
+
## An optional model-to-javascript tree renderer for mongoid_nested_set
|
36
|
+
|
37
|
+
Can be used to turn association select to a tree select, like this:
|
38
|
+
|
39
|
+
#checkboxes
|
40
|
+
= f.association :categories, as: :check_boxes, collection: Category.all
|
41
|
+
#tree.controls.input{style: 'width: 220px;'}
|
42
|
+
|
43
|
+
:javascript
|
44
|
+
var categories = #{Dynatree::Renderer.new(Category.nested_set.all, f.object.categories).render()};
|
45
|
+
$(function(){
|
46
|
+
$('#checkboxes').hide();
|
47
|
+
|
48
|
+
$("#tree").dynatree({
|
49
|
+
checkbox: true,
|
50
|
+
selectMode: 3,
|
51
|
+
classNames: {
|
52
|
+
active: "dynatree-active-no"
|
53
|
+
},
|
54
|
+
children: categories
|
55
|
+
});
|
56
|
+
|
57
|
+
$("form").submit(function() {
|
58
|
+
var tree = $("#tree").dynatree("getTree"),
|
59
|
+
arr = tree.serializeArray(),
|
60
|
+
sel = $('#restaurant_category_ids');
|
61
|
+
sel.find('option:selected').removeAttr('selected');
|
62
|
+
$.each(arr, function(k, v) {
|
63
|
+
sel.find('[value=' + v.value + ']').prop('selected', 'selected');
|
64
|
+
});
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
35
68
|
## Contributing
|
36
69
|
|
37
70
|
1. Fork it
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Configure for Rails 3.1
|
2
|
+
module Dynatree
|
3
|
+
class Renderer
|
4
|
+
def initialize(tree, association)
|
5
|
+
@tree = tree
|
6
|
+
@association = association
|
7
|
+
end
|
8
|
+
|
9
|
+
def render()
|
10
|
+
self.recurse(nil).to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_selected_children(id)
|
14
|
+
items = @tree.select{ |elem| elem.parent_id == id }
|
15
|
+
if items.empty?
|
16
|
+
false
|
17
|
+
else
|
18
|
+
items.each do |item|
|
19
|
+
if @association.include? item
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
if has_selected_children(item.id)
|
23
|
+
return true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def recurse(parent_id)
|
31
|
+
ret = []
|
32
|
+
items = @tree.select{ |elem| elem.parent_id == parent_id }
|
33
|
+
unless items.empty?
|
34
|
+
items.each do |item|
|
35
|
+
ch = {}
|
36
|
+
if @association.include? item
|
37
|
+
ch['select'] = true
|
38
|
+
ch['expand'] = true
|
39
|
+
else
|
40
|
+
if has_selected_children(item.id)
|
41
|
+
ch['expand'] = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
ch['title'] = item.name
|
45
|
+
ch['key'] = item.id
|
46
|
+
ch['children'] = self.recurse(item.id)
|
47
|
+
ret << ch
|
48
|
+
end
|
49
|
+
end
|
50
|
+
ret
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/dynatree-rails.rb
CHANGED
@@ -28,10 +28,10 @@ ul
|
|
28
28
|
background-attachment: scroll
|
29
29
|
background-color: transparent
|
30
30
|
background-repeat: repeat-y
|
31
|
-
background-image: url("vline.gif")
|
31
|
+
background-image: image-url("dynatree/skin/vline.gif")
|
32
32
|
background-position: 0 0
|
33
33
|
/*
|
34
|
-
*background-image: url("icons_96x256.gif");
|
34
|
+
*background-image: image-url("dynatree/skin/icons_96x256.gif");
|
35
35
|
*background-position: -80px -64px;
|
36
36
|
margin: 0
|
37
37
|
padding: 1px 0 0 0
|
@@ -65,7 +65,7 @@ span
|
|
65
65
|
vertical-align: top
|
66
66
|
background-repeat: no-repeat
|
67
67
|
background-position: left
|
68
|
-
background-image: url("icons.gif")
|
68
|
+
background-image: image-url("dynatree/skin/icons.gif")
|
69
69
|
background-position: 0 0
|
70
70
|
|
71
71
|
#dynatree-drop-marker
|
@@ -78,7 +78,7 @@ span
|
|
78
78
|
vertical-align: top
|
79
79
|
background-repeat: no-repeat
|
80
80
|
background-position: left
|
81
|
-
background-image: url("icons.gif")
|
81
|
+
background-image: image-url("dynatree/skin/icons.gif")
|
82
82
|
background-position: 0 0
|
83
83
|
|
84
84
|
/** Used by 'icon' node option:
|
@@ -127,7 +127,7 @@ span
|
|
127
127
|
|
128
128
|
.dynatree-loading span.dynatree-expander
|
129
129
|
background-position: 0 0
|
130
|
-
background-image: url("loading.gif")
|
130
|
+
background-image: image-url("dynatree/skin/loading.gif")
|
131
131
|
|
132
132
|
/*******************************************************************************
|
133
133
|
* Checkbox icon
|
@@ -191,11 +191,11 @@ span.dynatree-icon
|
|
191
191
|
/* Status node icons
|
192
192
|
|
193
193
|
.dynatree-statusnode-wait span.dynatree-icon
|
194
|
-
background-image: url("loading.gif")
|
194
|
+
background-image: image-url("dynatree/skin/loading.gif")
|
195
195
|
|
196
196
|
.dynatree-statusnode-error span.dynatree-icon
|
197
197
|
background-position: 0px -112px
|
198
|
-
/* background-image: url("ltError.gif");
|
198
|
+
/* background-image: image-url("dynatree/skin/ltError.gif");
|
199
199
|
|
200
200
|
/*******************************************************************************
|
201
201
|
* Node titles
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynatree-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- dynatree-rails.gemspec
|
28
28
|
- lib/dynatree-rails.rb
|
29
29
|
- lib/dynatree-rails/engine.rb
|
30
|
+
- lib/dynatree-rails/renderer.rb
|
30
31
|
- lib/dynatree-rails/version.rb
|
31
32
|
- vendor/assets/images/dynatree/jquery.dynatree.js
|
32
33
|
- vendor/assets/images/dynatree/skin-vista/icons.gif
|