ztree 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/exts/array.rb +3 -1
- data/lib/ztree/helpers.rb +26 -4
- data/lib/ztree/version.rb +5 -0
- data/ztree.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c6d463a57873f36206d79f579228023ed356039
|
4
|
+
data.tar.gz: d71aa866d90e89c10f28c626b28ea8dfa4856ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d0b72c23fa6a41faf4343c9d53aeeeb1b8dfc4f0cb4d16fce610ea482e2763b5cac02be4a2214118c43e7c81af954049c36f6e1b7218193f295e1a539d770f
|
7
|
+
data.tar.gz: d7dc6ea5bb8ecdbab1702963983369d4eeb632b396d87e23458fc096e21dc76a8f12b6830d02d77c89a0c05b538ec9e604c9eac44161bba0ee6589cbc794a590
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
ztree
|
2
|
+
=====
|
3
|
+
|
4
|
+
|
5
|
+
install
|
6
|
+
----------
|
7
|
+
gem install ztree
|
8
|
+
|
9
|
+
|
10
|
+
usage
|
11
|
+
----------
|
12
|
+
|
13
|
+
|
14
|
+
Default order column is :order_num, and you can set it in the model as below
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class A < ActiveRecord::Base
|
18
|
+
|
19
|
+
ztrees order_column: :my_ordered_column_name
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
data/lib/exts/array.rb
CHANGED
@@ -28,6 +28,8 @@ class Array
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_sorted_nodes
|
31
|
-
|
31
|
+
return [] if self.empty?
|
32
|
+
col = self.first.class.order_column || :order_num
|
33
|
+
self.group_by(&:parent_id).each {|k,v| v.sort_by!{|a| a.send(col) }}.to_a.flatten.select{|c| !c.is_a?Integer}.compact
|
32
34
|
end
|
33
35
|
end
|
data/lib/ztree/helpers.rb
CHANGED
@@ -1,11 +1,29 @@
|
|
1
1
|
module ActionView
|
2
2
|
module Helpers
|
3
|
-
|
4
3
|
|
5
|
-
def tree_list(link_title = '', opts = {})
|
4
|
+
def tree_list(link_title = '', opts = {}, ztree_opts = {})
|
6
5
|
id, cls_name = opts[:id] || 'tree-list', opts[:class] || 'menus_ztree ztree small'
|
7
6
|
ul = content_tag :ul, '', {id: id, class: cls_name, style: "width:260px; overflow:auto;"}.merge(opts)
|
8
|
-
init_tree_js(link_title) + content_tag(:div, ul, class: 'ground fl')
|
7
|
+
return init_tree_js(link_title) + content_tag(:div, ul, class: 'ground fl') if defined? init_tree_js
|
8
|
+
init_tree(link_title, opts, ztree_opts) + content_tag(:div, ul, class: 'ground fl')
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_tree(link_title = "", opts = {}, ztree_opts = {})
|
12
|
+
js = "$(document).ready(function(){
|
13
|
+
if (typeof(treeOpts) == 'undefined'){
|
14
|
+
treeOpts = #{{
|
15
|
+
zNodes: ztree_opts[:zNodes] || [],
|
16
|
+
current_tree: "#{opts[:id] || "tree-list"}",
|
17
|
+
url: "#{ztree_opts[:url] || "/"}"
|
18
|
+
}.to_json}
|
19
|
+
}
|
20
|
+
if (typeof(ztreeSetting) == 'undefined'){
|
21
|
+
ztreeSetting = #{ztree_settings(ztree_opts[:settings] || {})}
|
22
|
+
}
|
23
|
+
$.fn.zTree.init($('#' + treeOpts.current_tree), ztreeSetting, treeOpts.zNodes);
|
24
|
+
"
|
25
|
+
js << '});'
|
26
|
+
javascript_tag(js)
|
9
27
|
end
|
10
28
|
|
11
29
|
def ztree_settings(opts = {})
|
@@ -48,7 +66,11 @@ module ActionView
|
|
48
66
|
onClick: "onClick",
|
49
67
|
}
|
50
68
|
}
|
51
|
-
default_settings.merge(opts)
|
69
|
+
h_to_j default_settings.merge(opts)
|
70
|
+
end
|
71
|
+
|
72
|
+
def h_to_j(h)
|
73
|
+
h.to_json.html_safe.delete("\"").gsub("=>",": ")
|
52
74
|
end
|
53
75
|
end
|
54
76
|
end
|
data/ztree.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhimeng Sun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- .gitignore
|
35
|
+
- README.md
|
35
36
|
- lib/assets/rails/engine.rb
|
36
37
|
- lib/exts/array.rb
|
37
38
|
- lib/exts/hash.rb
|
@@ -41,6 +42,7 @@ files:
|
|
41
42
|
- lib/ztree/order_column.rb
|
42
43
|
- lib/ztree/railtie.rb
|
43
44
|
- lib/ztree/sort_tree.rb
|
45
|
+
- lib/ztree/version.rb
|
44
46
|
- vendor/assets/images/diy/1_close.png
|
45
47
|
- vendor/assets/images/diy/1_open.png
|
46
48
|
- vendor/assets/images/diy/2.png
|