tao_ui 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/tao_ui/components/tree/en.yml +6 -0
  3. data/config/locales/tao_ui/components/tree/zh-CN.yml +6 -0
  4. data/lib/assets/javascripts/tao/ui/dialog/index.coffee +11 -1
  5. data/lib/assets/javascripts/tao/ui/index.coffee +3 -0
  6. data/lib/assets/javascripts/tao/ui/mobile/slide_box/index.coffee +1 -3
  7. data/lib/assets/javascripts/tao/ui/popover/index.coffee +11 -1
  8. data/lib/assets/javascripts/tao/ui/shared/slide_box/export.coffee +11 -0
  9. data/lib/assets/javascripts/tao/ui/slide_box/index.coffee +1 -3
  10. data/lib/assets/javascripts/tao/ui/sortable.coffee +140 -0
  11. data/lib/assets/javascripts/tao/ui/table/element.coffee +13 -0
  12. data/lib/assets/javascripts/tao/ui/table/expandable.coffee +61 -0
  13. data/lib/assets/javascripts/tao/ui/table/index.coffee +6 -0
  14. data/lib/assets/javascripts/tao/ui/table/selectable.coffee +52 -0
  15. data/lib/assets/javascripts/tao/ui/tree/element.coffee +58 -0
  16. data/lib/assets/javascripts/tao/ui/tree/index.coffee +5 -0
  17. data/lib/assets/javascripts/tao/ui/tree/item.coffee +86 -0
  18. data/lib/assets/stylesheets/tao/ui/index.scss +2 -0
  19. data/lib/assets/stylesheets/tao/ui/mobile/buttons.scss +6 -0
  20. data/lib/assets/stylesheets/tao/ui/mobile/slide_box.scss +1 -1
  21. data/lib/assets/stylesheets/tao/ui/shared/_buttons.scss +1 -1
  22. data/lib/assets/stylesheets/tao/ui/shared/_tables.scss +3 -2
  23. data/lib/assets/stylesheets/tao/ui/shared/variables/_base.scss +1 -0
  24. data/lib/assets/stylesheets/tao/ui/shared/variables/_buttons.scss +1 -1
  25. data/lib/assets/stylesheets/tao/ui/shared/variables/_tables.scss +2 -0
  26. data/lib/assets/stylesheets/tao/ui/sortable.scss +16 -0
  27. data/lib/assets/stylesheets/tao/ui/tables.scss +77 -0
  28. data/lib/assets/stylesheets/tao/ui/tree.scss +126 -0
  29. data/lib/tao_ui/action_view/helpers.rb +23 -0
  30. data/lib/tao_ui/components.rb +3 -0
  31. data/lib/tao_ui/components/icon_component.rb +0 -2
  32. data/lib/tao_ui/components/slide_box_component.rb +0 -2
  33. data/lib/tao_ui/components/sortable_component.rb +17 -0
  34. data/lib/tao_ui/components/table/base_builder.rb +58 -0
  35. data/lib/tao_ui/components/table/body_builder.rb +30 -0
  36. data/lib/tao_ui/components/table/head_builder.rb +15 -0
  37. data/lib/tao_ui/components/table/row_builder.rb +53 -0
  38. data/lib/tao_ui/components/table/table_builder.rb +35 -0
  39. data/lib/tao_ui/components/table_component.rb +40 -0
  40. data/lib/tao_ui/components/tree/item_component.rb +121 -0
  41. data/lib/tao_ui/components/tree/list_component.rb +51 -0
  42. data/lib/tao_ui/components/tree_component.rb +43 -0
  43. data/lib/tao_ui/engine.rb +7 -0
  44. data/lib/tao_ui/version.rb +1 -1
  45. data/lib/views/components/tao_ui/components/_confirm_dialog.html.erb +2 -2
  46. data/lib/views/components/tao_ui/components/_confirm_popover.html.erb +2 -2
  47. data/lib/views/components/tao_ui/components/_message_dialog.html.erb +1 -1
  48. metadata +26 -2
@@ -0,0 +1,17 @@
1
+ module TaoUi
2
+ module Components
3
+ class SortableComponent < TaoOnRails::Components::Base
4
+
5
+ def self.component_name
6
+ :sortable
7
+ end
8
+
9
+ private
10
+
11
+ def default_options
12
+ {class: 'tao-sortable'}
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ module TaoUi
2
+ module Components
3
+ module Table
4
+
5
+ class BaseBuilder
6
+
7
+ attr_reader :view, :options, :expandable, :selectable
8
+
9
+ def initialize view, options = {}
10
+ @view = view
11
+ @options = options
12
+ @expandable = options[:expandable].presence || false
13
+ @selectable = options[:selectable].presence || false
14
+ end
15
+
16
+ def merge_options options, other_options
17
+ options.merge(other_options) { |key, old_val, new_val|
18
+ if key.to_s == 'class'
19
+ old_val = old_val.split(' ') if old_val.is_a? String
20
+ new_val = new_val.split(' ') if new_val.is_a? String
21
+ Array(old_val) + Array(new_val)
22
+ elsif old_val.is_a?(Hash) && old_val.is_a?(Hash)
23
+ old_val.merge! new_val
24
+ else
25
+ new_val
26
+ end
27
+ }
28
+ end
29
+
30
+ protected
31
+
32
+ def expandable_th
33
+ @expandable_th ||= view.content_tag 'th', nil, class: 'th-expand-icon'
34
+ end
35
+
36
+ def selectable_th
37
+ @selectable_th ||= view.content_tag 'th', class: 'th-checkbox' do
38
+ view.tao_check_box
39
+ end
40
+ end
41
+
42
+ def expandable_td
43
+ @expandable_td ||= view.content_tag 'td', class: 'td-expand-icon' do
44
+ view.tao_icon :arrow_right
45
+ end
46
+ end
47
+
48
+ def selectable_td
49
+ @selectable_td ||= view.content_tag 'td', class: 'td-checkbox' do
50
+ view.tao_check_box
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,30 @@
1
+ module TaoUi
2
+ module Components
3
+ module Table
4
+
5
+ class BodyBuilder < BaseBuilder
6
+
7
+ def row row_options = {}, &block
8
+ row_content = view.capture(row_builder, &block)
9
+ row_builder.reset_cell_count
10
+
11
+ if expandable
12
+ row_content
13
+ else
14
+ row_content = selectable_td + row_content if selectable
15
+ row_content = expandable_td + row_content if expandable
16
+ view.content_tag 'tr', row_content, row_options
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def row_builder
23
+ @row_builder ||= RowBuilder.new(view, options)
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ module TaoUi
2
+ module Components
3
+ module Table
4
+
5
+ class HeadBuilder < BaseBuilder
6
+
7
+ def cell content_or_options = nil, cell_options = nil, &block
8
+ view.content_tag 'th', content_or_options, cell_options, &block
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module TaoUi
2
+ module Components
3
+ module Table
4
+
5
+ class RowBuilder < BaseBuilder
6
+
7
+ def initialize view, options = {}
8
+ super
9
+ reset_cell_count
10
+ end
11
+
12
+ def cell content_or_options = nil, cell_options = nil, &block
13
+ @cell_count += 1
14
+ view.content_tag 'td', content_or_options, cell_options, &block
15
+ end
16
+
17
+ def content content_options = {}, &block
18
+ raise 'content method requires expandable option set to true' unless expandable
19
+ content_options = merge_options({
20
+ class: 'expandable'
21
+ }, content_options)
22
+ row_content = view.capture(self, &block)
23
+ row_content = selectable_td + row_content if selectable
24
+ row_content = expandable_td + row_content if expandable
25
+ view.content_tag 'tr', row_content, content_options
26
+ end
27
+
28
+ def panel panel_options = {}, &block
29
+ raise 'panel method requires expandable option set to true' unless expandable
30
+ view.content_tag 'tr', class: 'expandable-panel' do
31
+ view.content_tag 'td', colspan: @cell_count do
32
+ view.content_tag 'div', panel_options, &block
33
+ end
34
+ end
35
+ end
36
+
37
+ def reset_cell_count
38
+ @cell_count = 0
39
+ @cell_count += 1 if selectable
40
+ @cell_count += 1 if expandable
41
+ end
42
+
43
+ private
44
+
45
+ def row_builder
46
+ @row_builder ||= RowBuilder.new(view)
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ module TaoUi
2
+ module Components
3
+ module Table
4
+
5
+ class TableBuilder < BaseBuilder
6
+
7
+ def head head_options = {}, &block
8
+ head_content = view.capture(head_builder, &block)
9
+ head_content = selectable_th + head_content if selectable
10
+ head_content = expandable_th + head_content if expandable
11
+ view.content_tag 'thead', head_options do
12
+ view.content_tag 'tr', head_content
13
+ end
14
+ end
15
+
16
+ def body body_options = {}, &block
17
+ body_content = view.capture(body_builder, &block)
18
+ view.content_tag 'tbody', body_content, body_options
19
+ end
20
+
21
+ private
22
+
23
+ def head_builder
24
+ @head_builder ||= HeadBuilder.new(view, options)
25
+ end
26
+
27
+ def body_builder
28
+ @body_builder ||= BodyBuilder.new(view, options)
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'tao_ui/components/table/base_builder'
2
+ require 'tao_ui/components/table/table_builder'
3
+ require 'tao_ui/components/table/head_builder'
4
+ require 'tao_ui/components/table/body_builder'
5
+ require 'tao_ui/components/table/row_builder'
6
+
7
+ module TaoUi
8
+ module Components
9
+ class TableComponent < TaoOnRails::Components::Base
10
+
11
+ def render &block
12
+ if block_given?
13
+ table_content = view.capture(builder, &block)
14
+ table = view.content_tag('table', table_content, class: 'table')
15
+ view.content_tag tag_name, table, html_options
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def self.component_name
22
+ :table
23
+ end
24
+
25
+ private
26
+
27
+ def builder
28
+ @builder ||= Table::TableBuilder.new(view, {
29
+ expandable: options[:expandable],
30
+ selectable: options[:selectable]
31
+ })
32
+ end
33
+
34
+ def default_options
35
+ {class: 'tao-table'}
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,121 @@
1
+ module TaoUi
2
+ module Components
3
+ module Tree
4
+ class ItemComponent < TaoOnRails::Components::Base
5
+
6
+ attr_reader :item, :selectable, :depth, :remote,
7
+ :expandable, :expanded, :children, :children_key
8
+
9
+ def initialize view, item, options = {}
10
+ super view, options
11
+ @item = item
12
+ @children_key = @options.delete(:children_key)
13
+ @selectable = @options[:selectable] || false
14
+ @depth = @options[:depth]
15
+
16
+ init_remote
17
+ init_children
18
+ init_expanded
19
+ end
20
+
21
+ def render &block
22
+ view.content_tag tag_name, html_options do
23
+ content = view.content_tag 'div', class: 'tao-tree-item-content' do
24
+ render_padding + render_icon +
25
+ render_checkbox + view.capture(item, self, &block)
26
+ end
27
+
28
+ children = render_children &block
29
+ content + children
30
+ end
31
+ end
32
+
33
+ def self.component_name
34
+ :tree_item
35
+ end
36
+
37
+ private
38
+
39
+ def default_options
40
+ {class: 'tao-tree-item', children_key: :children, depth: 0}
41
+ end
42
+
43
+ def init_children
44
+ @children = if item.is_a?(Hash)
45
+ item[children_key]
46
+ elsif item.respond_to?(children_key)
47
+ item.send(children_key)
48
+ else
49
+ nil
50
+ end
51
+ end
52
+
53
+ def init_remote
54
+ @remote = html_options.delete(:remote) || false
55
+ @remote = @remote.call(item, depth) if @remote.respond_to?(:call)
56
+ if @remote && @remote.is_a?(Hash)
57
+ html_options[:remote] = @remote.to_json
58
+ end
59
+ end
60
+
61
+ def init_expanded
62
+ @expandable = !!remote || (children.is_a?(Array) && children.size > 0)
63
+ html_options[:expandable] = @expandable ? '' : nil
64
+
65
+ @expanded = (html_options.delete(:expanded) || false) && expandable && !remote
66
+ @expanded = @expanded.call(item, depth) if @expanded.respond_to?(:call)
67
+ html_options[:expanded] = @expanded ? '' : nil
68
+ end
69
+
70
+ def render_padding(size = depth)
71
+ if size > 0
72
+ view.content_tag 'div', class: 'tao-tree-item-padding' do
73
+ (view.content_tag('div', nil, class: 'padding-item') * size).html_safe
74
+ end
75
+ else
76
+ ''.html_safe
77
+ end
78
+ end
79
+
80
+ def render_icon
81
+ view.link_to 'javascript:;', class: 'link-toggle-item' do
82
+ view.tao_icon :arrow_right
83
+ end
84
+ end
85
+
86
+ def render_checkbox
87
+ if @selectable
88
+ view.tao_check_box
89
+ else
90
+ ''.html_safe
91
+ end
92
+ end
93
+
94
+ def render_children &block
95
+ if expandable
96
+ if remote
97
+ render_children_placeholder
98
+ else
99
+ view.tao_tree_list children, {
100
+ selectable: selectable,
101
+ depth: depth + 1,
102
+ remote: options[:remote],
103
+ expanded: options[:expanded],
104
+ children_key: @children_key
105
+ }, &block
106
+ end
107
+ end
108
+ end
109
+
110
+ def render_children_placeholder
111
+ view.content_tag 'div', class: 'tao-tree-list' do
112
+ view.content_tag 'div', class: 'tao-tree-loading' do
113
+ render_padding(depth + 1) + view.tao_icon(:loading, class: 'spin') + t(:loading)
114
+ end
115
+ end
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,51 @@
1
+ module TaoUi
2
+ module Components
3
+ module Tree
4
+ class ListComponent < TaoOnRails::Components::Base
5
+
6
+ attr_reader :items, :selectable, :depth, :remote,
7
+ :expanded, :children_key, :selected
8
+
9
+ def initialize view, items, options = {}
10
+ super view, options
11
+ @items = items
12
+ @children_key = @options.delete(:children_key)
13
+ @selectable = @options.delete(:selectable)
14
+ @selected = @options.delete(:selected)
15
+ @remote = @options.delete(:remote)
16
+ @expanded = @options.delete(:expanded)
17
+ @depth = @options.delete(:depth)
18
+ end
19
+
20
+ def render &block
21
+ view.content_tag 'div', html_options do
22
+ content = ''.html_safe
23
+ items.each do |item|
24
+ content += view.tao_tree_item item, {
25
+ children_key: children_key,
26
+ selectable: selectable,
27
+ selected: selected,
28
+ depth: depth,
29
+ remote: remote,
30
+ expanded: expanded
31
+ }, &block
32
+ end
33
+
34
+ content
35
+ end
36
+ end
37
+
38
+ def self.component_name
39
+ :tree_list
40
+ end
41
+
42
+ private
43
+
44
+ def default_options
45
+ {class: 'tao-tree-list', children_key: :children, depth: 0}
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ require 'tao_ui/components/tree/item_component'
2
+ require 'tao_ui/components/tree/list_component'
3
+
4
+ module TaoUi
5
+ module Components
6
+ class TreeComponent < TaoOnRails::Components::Base
7
+
8
+ attr_reader :items, :selectable, :children_key, :remote, :expanded
9
+
10
+ def initialize view, items, options = {}
11
+ super view,options
12
+ @items = items
13
+ @children_key = @options.delete(:children_key)
14
+ @selectable = @options[:selectable] || false
15
+ @remote = @options.delete(:remote)
16
+ @expanded = @options.delete(:expanded)
17
+ end
18
+
19
+ def render &block
20
+ view.content_tag tag_name, html_options do
21
+ view.tao_tree_list items, {
22
+ depth: 0,
23
+ selectable: selectable,
24
+ remote: remote,
25
+ expanded: expanded,
26
+ children_key: children_key
27
+ }, &block
28
+ end
29
+ end
30
+
31
+ def self.component_name
32
+ :tree
33
+ end
34
+
35
+ private
36
+
37
+ def default_options
38
+ {class: 'tao-tree', children_key: :children}
39
+ end
40
+
41
+ end
42
+ end
43
+ end