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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d94fdf5dd3c4202a47c8308f9ce276c0dec7566
4
- data.tar.gz: 9f9e2fb6bbb2b3dc3302535a3ab9299ecc03e8a2
3
+ metadata.gz: 2c6d463a57873f36206d79f579228023ed356039
4
+ data.tar.gz: d71aa866d90e89c10f28c626b28ea8dfa4856ab2
5
5
  SHA512:
6
- metadata.gz: 17a312d3032859f56a2062174d5f103e3e7c4e59e8c09d2244a1f38dc7bc73cc7b623d8da584325b3dd78f4d8d793756967b6e5c39e163b2df92e56bccba367b
7
- data.tar.gz: c9e3bcf5e5cd0415c6fcf0a58c3db7d710e375d22a373c90b30c34aa4347e06b073fd49dd5c51eea5f4fb135a000d41b69e61983db10b161c8ff0afcb865bed0
6
+ metadata.gz: 48d0b72c23fa6a41faf4343c9d53aeeeb1b8dfc4f0cb4d16fce610ea482e2763b5cac02be4a2214118c43e7c81af954049c36f6e1b7218193f295e1a539d770f
7
+ data.tar.gz: d7dc6ea5bb8ecdbab1702963983369d4eeb632b396d87e23458fc096e21dc76a8f12b6830d02d77c89a0c05b538ec9e604c9eac44161bba0ee6589cbc794a590
@@ -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
+
@@ -28,6 +28,8 @@ class Array
28
28
  end
29
29
 
30
30
  def to_sorted_nodes
31
- self.group_by(&:parent_id).each {|k,v| v.sort_by! {|a| a.send(a.class.order_column) }}.to_a.flatten.select{|c| !c.is_a?Integer}.compact
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
@@ -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).to_json.html_safe.delete("\"").gsub("=>",": ")
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
@@ -0,0 +1,5 @@
1
+ module Ztree
2
+ def self.version
3
+ "0.0.8"
4
+ end
5
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ztree'
5
- s.version = '0.0.7'
5
+ s.version = '0.0.8'
6
6
  s.authors = ['Zhimeng Sun']
7
7
  s.email = ['zhimengSun@gmail.com']
8
8
  s.homepage = 'https://github.com/zhimengSun/ztree'
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.7
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-07-26 00:00:00.000000000 Z
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