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.
- checksums.yaml +4 -4
- data/config/locales/tao_ui/components/tree/en.yml +6 -0
- data/config/locales/tao_ui/components/tree/zh-CN.yml +6 -0
- data/lib/assets/javascripts/tao/ui/dialog/index.coffee +11 -1
- data/lib/assets/javascripts/tao/ui/index.coffee +3 -0
- data/lib/assets/javascripts/tao/ui/mobile/slide_box/index.coffee +1 -3
- data/lib/assets/javascripts/tao/ui/popover/index.coffee +11 -1
- data/lib/assets/javascripts/tao/ui/shared/slide_box/export.coffee +11 -0
- data/lib/assets/javascripts/tao/ui/slide_box/index.coffee +1 -3
- data/lib/assets/javascripts/tao/ui/sortable.coffee +140 -0
- data/lib/assets/javascripts/tao/ui/table/element.coffee +13 -0
- data/lib/assets/javascripts/tao/ui/table/expandable.coffee +61 -0
- data/lib/assets/javascripts/tao/ui/table/index.coffee +6 -0
- data/lib/assets/javascripts/tao/ui/table/selectable.coffee +52 -0
- data/lib/assets/javascripts/tao/ui/tree/element.coffee +58 -0
- data/lib/assets/javascripts/tao/ui/tree/index.coffee +5 -0
- data/lib/assets/javascripts/tao/ui/tree/item.coffee +86 -0
- data/lib/assets/stylesheets/tao/ui/index.scss +2 -0
- data/lib/assets/stylesheets/tao/ui/mobile/buttons.scss +6 -0
- data/lib/assets/stylesheets/tao/ui/mobile/slide_box.scss +1 -1
- data/lib/assets/stylesheets/tao/ui/shared/_buttons.scss +1 -1
- data/lib/assets/stylesheets/tao/ui/shared/_tables.scss +3 -2
- data/lib/assets/stylesheets/tao/ui/shared/variables/_base.scss +1 -0
- data/lib/assets/stylesheets/tao/ui/shared/variables/_buttons.scss +1 -1
- data/lib/assets/stylesheets/tao/ui/shared/variables/_tables.scss +2 -0
- data/lib/assets/stylesheets/tao/ui/sortable.scss +16 -0
- data/lib/assets/stylesheets/tao/ui/tables.scss +77 -0
- data/lib/assets/stylesheets/tao/ui/tree.scss +126 -0
- data/lib/tao_ui/action_view/helpers.rb +23 -0
- data/lib/tao_ui/components.rb +3 -0
- data/lib/tao_ui/components/icon_component.rb +0 -2
- data/lib/tao_ui/components/slide_box_component.rb +0 -2
- data/lib/tao_ui/components/sortable_component.rb +17 -0
- data/lib/tao_ui/components/table/base_builder.rb +58 -0
- data/lib/tao_ui/components/table/body_builder.rb +30 -0
- data/lib/tao_ui/components/table/head_builder.rb +15 -0
- data/lib/tao_ui/components/table/row_builder.rb +53 -0
- data/lib/tao_ui/components/table/table_builder.rb +35 -0
- data/lib/tao_ui/components/table_component.rb +40 -0
- data/lib/tao_ui/components/tree/item_component.rb +121 -0
- data/lib/tao_ui/components/tree/list_component.rb +51 -0
- data/lib/tao_ui/components/tree_component.rb +43 -0
- data/lib/tao_ui/engine.rb +7 -0
- data/lib/tao_ui/version.rb +1 -1
- data/lib/views/components/tao_ui/components/_confirm_dialog.html.erb +2 -2
- data/lib/views/components/tao_ui/components/_confirm_popover.html.erb +2 -2
- data/lib/views/components/tao_ui/components/_message_dialog.html.erb +1 -1
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c1bccc0ee34c50adb3a33ea9518467baded118
|
4
|
+
data.tar.gz: c07e17ea24685306501e40b19f482494ce813e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1f8a06f43ded1c8cb3ae312dda29362a3d716b87863c96137be5475bb667f2a426104938b3935ea8f6ea386a7b3e4eee96f06d76d4b6a205d9a581163b729f
|
7
|
+
data.tar.gz: 2e13f7440facfaffd146a524fb45d8c2a53e055eccf482ad530c04f264e0821576a0fbffe8a6420732dcff7eb6e61595e09787d3ec1baa5826c2304d9994f130
|
@@ -3,4 +3,14 @@
|
|
3
3
|
#= require ./message
|
4
4
|
#= require ./confirm
|
5
5
|
|
6
|
-
window.TaoDialog = Tao.Dialog =
|
6
|
+
window.TaoDialog = Tao.Dialog =
|
7
|
+
|
8
|
+
closeAll: ->
|
9
|
+
$('.tao-dialog').each (i, dialog) ->
|
10
|
+
dialog.active = false
|
11
|
+
null
|
12
|
+
|
13
|
+
removeAll: ->
|
14
|
+
$('.tao-dialog').each (i, dialog) ->
|
15
|
+
dialog.remove()
|
16
|
+
null
|
@@ -3,4 +3,14 @@
|
|
3
3
|
#= require ./confirm
|
4
4
|
#= require ./create
|
5
5
|
|
6
|
-
window.TaoPopover = Tao.Popover =
|
6
|
+
window.TaoPopover = Tao.Popover =
|
7
|
+
|
8
|
+
closeAll: ->
|
9
|
+
$('.tao-popover').each (i, dialog) ->
|
10
|
+
dialog.active = false
|
11
|
+
null
|
12
|
+
|
13
|
+
removeAll: ->
|
14
|
+
$('.tao-popover').each (i, dialog) ->
|
15
|
+
dialog.remove()
|
16
|
+
null
|
@@ -0,0 +1,140 @@
|
|
1
|
+
class Tao.Sortable extends TaoComponent
|
2
|
+
|
3
|
+
@tag 'tao-sortable'
|
4
|
+
|
5
|
+
@attribute 'groupSelector'
|
6
|
+
|
7
|
+
@attribute 'itemSelector', default: '[draggable="true"]'
|
8
|
+
|
9
|
+
@attribute 'axis', default: 'y'
|
10
|
+
|
11
|
+
_connected: ->
|
12
|
+
@on 'dragstart', @itemSelector, (e) =>
|
13
|
+
e.stopPropagation()
|
14
|
+
$item = $ e.currentTarget
|
15
|
+
itemRect = $item.get(0).getBoundingClientRect()
|
16
|
+
@_startDragging $item
|
17
|
+
|
18
|
+
e.originalEvent.dataTransfer.effectAllowed = 'move'
|
19
|
+
e.originalEvent.dataTransfer.setData 'text/plain', 'tao-sortable'
|
20
|
+
e.originalEvent.dataTransfer.setDragImage(
|
21
|
+
@_sortingItem.get(0),
|
22
|
+
e.clientX - itemRect.left,
|
23
|
+
e.clientY - itemRect.top
|
24
|
+
)
|
25
|
+
null
|
26
|
+
|
27
|
+
_disconnected: ->
|
28
|
+
@off()
|
29
|
+
$(document).off ".tao-sortable-#{@taoId}"
|
30
|
+
|
31
|
+
_startDragging: ($item) ->
|
32
|
+
@trigger 'tao:beforeSortStart', [$item]
|
33
|
+
@_sortingItem = $item
|
34
|
+
setTimeout -> $item.addClass('tao-sortable-sorting')
|
35
|
+
@trigger 'tao:sortStart', [@_sortingItem]
|
36
|
+
|
37
|
+
$(window).on "scroll.tao-sortable-#{@taoId}", _.throttle (e) =>
|
38
|
+
@_expireDimensionCache()
|
39
|
+
null
|
40
|
+
, 100
|
41
|
+
|
42
|
+
$(document).on "dragover.tao-sortable-#{@taoId}", _.throttle (e) =>
|
43
|
+
e.preventDefault()
|
44
|
+
@_performDragging x: e.clientX, y: e.clientY
|
45
|
+
e.originalEvent.dataTransfer.dropEffect = 'move'
|
46
|
+
null
|
47
|
+
, 100
|
48
|
+
|
49
|
+
$(document).on "dragend.tao-sortable-#{@taoId}", (e) =>
|
50
|
+
e.preventDefault()
|
51
|
+
@_stopDragging()
|
52
|
+
$(document).off ".tao-sortable-#{@taoId}"
|
53
|
+
$(window).off ".tao-sortable-#{@taoId}"
|
54
|
+
null
|
55
|
+
|
56
|
+
_performDragging: (mousePosition) ->
|
57
|
+
return unless @_sortingItem
|
58
|
+
item = @_findNearestItem mousePosition
|
59
|
+
return unless item && item.el.get(0) != @_sortingItem.get(0)
|
60
|
+
|
61
|
+
@_moveItem item, mousePosition
|
62
|
+
@_expireDimensionCache()
|
63
|
+
|
64
|
+
_stopDragging: ->
|
65
|
+
@_sortingItem.removeClass('tao-sortable-sorting')
|
66
|
+
@trigger 'tao:sortEnd', [@_sortingItem]
|
67
|
+
@_sortingItem = null
|
68
|
+
|
69
|
+
_findNearestItem: (mousePosition, dimensions = @_itemDimensions()) ->
|
70
|
+
minDistance = null
|
71
|
+
nearestItem = null
|
72
|
+
|
73
|
+
dimensions.forEach (item) =>
|
74
|
+
distance = @_getDistanceFromItem item, mousePosition
|
75
|
+
if _.isNil(minDistance) || minDistance > distance
|
76
|
+
minDistance = distance
|
77
|
+
nearestItem = item
|
78
|
+
|
79
|
+
if nearestItem.type == 'group' && nearestItem.items &&
|
80
|
+
nearestItem.items.length > 0
|
81
|
+
nearestItem = @_findNearestItem mousePosition, nearestItem.items
|
82
|
+
|
83
|
+
nearestItem
|
84
|
+
|
85
|
+
_moveItem: (item, mousePosition) ->
|
86
|
+
if item.type == 'group'
|
87
|
+
item.el.append @_sortingItem
|
88
|
+
else
|
89
|
+
method = if (@axis == 'y' && mousePosition.y > item.center.y) ||
|
90
|
+
(@axis == 'x' && mousePosition.x > item.center.x)
|
91
|
+
'after'
|
92
|
+
else
|
93
|
+
'before'
|
94
|
+
item.el[method] @_sortingItem
|
95
|
+
|
96
|
+
_itemDimensions: ->
|
97
|
+
@_dimentions ||= do =>
|
98
|
+
if @groupSelector
|
99
|
+
@jq.find(@groupSelector).map (i, groupEl) =>
|
100
|
+
@_getGroupDimension groupEl
|
101
|
+
.get()
|
102
|
+
else
|
103
|
+
@jq.find(@itemSelector).map (i, itemEl) =>
|
104
|
+
@_getItemDimension itemEl
|
105
|
+
.get()
|
106
|
+
|
107
|
+
_getGroupDimension: (groupEl) ->
|
108
|
+
$group = $ groupEl
|
109
|
+
dimension = $group.get(0).getBoundingClientRect()
|
110
|
+
|
111
|
+
type: 'group'
|
112
|
+
el: $group
|
113
|
+
dimension: dimension
|
114
|
+
center: @_getCenterPointOfDimension(dimension)
|
115
|
+
items: $group.find(@itemSelector).map (i, itemEl) =>
|
116
|
+
@_getItemDimension itemEl
|
117
|
+
.get()
|
118
|
+
|
119
|
+
_getItemDimension: (itemEl) ->
|
120
|
+
$item = $ itemEl
|
121
|
+
dimension = $item.get(0).getBoundingClientRect()
|
122
|
+
|
123
|
+
type: 'item'
|
124
|
+
el: $item
|
125
|
+
dimension: dimension
|
126
|
+
center: @_getCenterPointOfDimension(dimension)
|
127
|
+
|
128
|
+
_getCenterPointOfDimension: (dimension) ->
|
129
|
+
x: dimension.left + (dimension.width / 2)
|
130
|
+
y: dimension.top + (dimension.height / 2)
|
131
|
+
|
132
|
+
_getDistanceFromItem: (item, position) ->
|
133
|
+
deltaX = Math.abs(position.x - item.center.x)
|
134
|
+
deltaY = Math.abs(position.y - item.center.y)
|
135
|
+
Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2))
|
136
|
+
|
137
|
+
_expireDimensionCache: ->
|
138
|
+
@_dimentions = null
|
139
|
+
|
140
|
+
TaoComponent.register Tao.Sortable
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Tao.Table.Expandable = ->
|
2
|
+
|
3
|
+
@attribute 'expandable', type: 'boolean'
|
4
|
+
|
5
|
+
_initExpandable: ->
|
6
|
+
@on 'click', 'tbody > tr.expandable', (e) =>
|
7
|
+
return if !@expandable || $(e.target).is('a, input')
|
8
|
+
$row = $ e.currentTarget
|
9
|
+
if $row.hasClass 'expanded'
|
10
|
+
@collapseRow $row
|
11
|
+
@trigger 'tao:expandRow', $row
|
12
|
+
else
|
13
|
+
@expandRow $row
|
14
|
+
@trigger 'tao:collapseRow', $row
|
15
|
+
null
|
16
|
+
|
17
|
+
expandRow: (row) ->
|
18
|
+
$row = $ row
|
19
|
+
return @ if $row.is('.disabled, .hidden, .expanded, .expanding')
|
20
|
+
|
21
|
+
$panel = $row.next('.expandable-panel')
|
22
|
+
return @ unless $panel.length > 0
|
23
|
+
$panelWrapper = $panel.find('> td > div:first')
|
24
|
+
|
25
|
+
$panel.show()
|
26
|
+
$panel[0].offsetHeight # force reflow
|
27
|
+
$panelWrapper.one 'transitionend', (e) ->
|
28
|
+
$row.removeClass 'expanding'
|
29
|
+
|
30
|
+
$row.addClass 'expanded expanding'
|
31
|
+
$panel.addClass 'expanded'
|
32
|
+
$panelWrapper.css 'height', $panelWrapper[0].scrollHeight
|
33
|
+
@_loadRemotePanel $panel
|
34
|
+
@
|
35
|
+
|
36
|
+
collapseRow: (row) ->
|
37
|
+
$row = $ row
|
38
|
+
return @ if $row.is('.disabled, .hidden, :not(.expanded), .collapsing')
|
39
|
+
|
40
|
+
$panel = $row.next('.expandable-panel')
|
41
|
+
return @ unless $panel.length > 0
|
42
|
+
$panelWrapper = $panel.find('> td > div:first')
|
43
|
+
|
44
|
+
$panelWrapper.one 'transitionend', (e) ->
|
45
|
+
$row.removeClass 'collapsing'
|
46
|
+
$panel.hide()
|
47
|
+
|
48
|
+
$row.removeClass 'expanded'
|
49
|
+
.addClass 'collapsing'
|
50
|
+
$panel.removeClass 'expanded'
|
51
|
+
$panelWrapper.css 'height', 0
|
52
|
+
@
|
53
|
+
|
54
|
+
_loadRemotePanel: ($panel) ->
|
55
|
+
return unless $panel.is('[data-url]')
|
56
|
+
$.ajax
|
57
|
+
url: $panel.data('url')
|
58
|
+
method: 'get'
|
59
|
+
dataType: 'script'
|
60
|
+
.done ->
|
61
|
+
$panel.removeAttr 'data-url'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
Tao.Table.Selectable = ->
|
2
|
+
|
3
|
+
@attribute 'selectable', type: 'boolean'
|
4
|
+
|
5
|
+
@get 'selectedRows', ->
|
6
|
+
@jq.find('tbody > tr.selected')
|
7
|
+
|
8
|
+
_initSelectable: ->
|
9
|
+
@on 'tao:change', '.td-checkbox tao-check-box', (e) =>
|
10
|
+
cb = e.currentTarget
|
11
|
+
$row = cb.jq.closest('tr')
|
12
|
+
@toggleSelectRow $row, cb.checked
|
13
|
+
@trigger 'tao:selectedChange', [@selectedRows]
|
14
|
+
|
15
|
+
@on 'tao:change', '.th-checkbox tao-check-box', (e) =>
|
16
|
+
cb = e.currentTarget
|
17
|
+
if cb.checked
|
18
|
+
@selectAllRows()
|
19
|
+
else
|
20
|
+
@unselectAllRows()
|
21
|
+
@trigger 'tao:selectedChange', [@selectedRows]
|
22
|
+
|
23
|
+
toggleSelectRow: (row, selected) ->
|
24
|
+
return @ unless @selectable
|
25
|
+
|
26
|
+
$row = $ row
|
27
|
+
currentSelected = $row.hasClass('selected')
|
28
|
+
selected = !currentSelected if _.isNil selected
|
29
|
+
if $row.is('.disabled, .hidden, .expandable-panel')\
|
30
|
+
|| selected == currentSelected
|
31
|
+
return @
|
32
|
+
|
33
|
+
$row.toggleClass 'selected', selected
|
34
|
+
cb = $row.find('.td-checkbox tao-check-box').get(0)
|
35
|
+
cb.checked = selected if cb.checked != selected
|
36
|
+
@
|
37
|
+
|
38
|
+
selectRow: (row) ->
|
39
|
+
@toggleSelectRow row, true
|
40
|
+
|
41
|
+
unselectRow: (row) ->
|
42
|
+
@toggleSelectRow row, false
|
43
|
+
|
44
|
+
selectAllRows: ->
|
45
|
+
return @ unless @selectable
|
46
|
+
@jq.find('tbody > tr').each (i, row) => @selectRow(row)
|
47
|
+
@
|
48
|
+
|
49
|
+
unselectAllRows: ->
|
50
|
+
return @ unless @selectable
|
51
|
+
@jq.find('tbody > tr').each (i, row) => @unselectRow(row)
|
52
|
+
@
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Tao.Tree.Element extends TaoComponent
|
2
|
+
|
3
|
+
@tag 'tao-tree'
|
4
|
+
|
5
|
+
@attribute 'selectable', 'associatedSelect', type: 'boolean'
|
6
|
+
|
7
|
+
@get 'selectedItems', ->
|
8
|
+
if @associatedSelect
|
9
|
+
@_getAssociatedSelectedItems()
|
10
|
+
else
|
11
|
+
@jq.find('.tao-tree-item[selected]').get()
|
12
|
+
|
13
|
+
_connected: ->
|
14
|
+
@_bind()
|
15
|
+
|
16
|
+
_disconnected: ->
|
17
|
+
@off()
|
18
|
+
|
19
|
+
_bind: ->
|
20
|
+
@on 'tao-tree-item:selectedChange', '.tao-tree-item', (e) =>
|
21
|
+
item = e.currentTarget
|
22
|
+
return unless item == e.target
|
23
|
+
@_refreshAssociatedItems(item) if @associatedSelect
|
24
|
+
@trigger 'tao-tree:selectedChange', [@selectedItems]
|
25
|
+
null
|
26
|
+
|
27
|
+
_refreshAssociatedItems: (item) ->
|
28
|
+
item.jq.find('.tao-tree-item').prop('selected', item.selected)
|
29
|
+
@_refreshAncestorItems(item)
|
30
|
+
|
31
|
+
_refreshAncestorItems: (item) ->
|
32
|
+
$parentItem = $(item).parent().closest('.tao-tree-item', @)
|
33
|
+
return unless $parentItem.length > 0
|
34
|
+
|
35
|
+
$items = $parentItem.find('> .tao-tree-list > .tao-tree-item')
|
36
|
+
if $items.filter('[selected], [indeterminate]').length == 0
|
37
|
+
$parentItem.prop 'selected', false
|
38
|
+
$parentItem.prop 'indeterminate', false
|
39
|
+
else if $items.filter(':not([selected])').length == 0
|
40
|
+
$parentItem.prop 'selected', true
|
41
|
+
$parentItem.prop 'indeterminate', false
|
42
|
+
else
|
43
|
+
$parentItem.prop 'selected', false
|
44
|
+
$parentItem.prop 'indeterminate', true
|
45
|
+
|
46
|
+
@_refreshAncestorItems $parentItem
|
47
|
+
|
48
|
+
_getAssociatedSelectedItems: ($list = @jq.find('> .tao-tree-list')) ->
|
49
|
+
selectedItems = []
|
50
|
+
$list.find('> .tao-tree-item').each (i, item) =>
|
51
|
+
if item.selected
|
52
|
+
selectedItems.push item
|
53
|
+
else if ($childList = item.jq.find('> .tao-tree-list')).length > 0
|
54
|
+
selectedItems = selectedItems.concat @_getAssociatedSelectedItems($childList)
|
55
|
+
selectedItems
|
56
|
+
|
57
|
+
|
58
|
+
TaoComponent.register Tao.Tree.Element
|