31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/gtk3webtable.rb', line 31
def reload_table
html = Html_gen::Element.new(:html)
head = html.add(:head)
head.add(:link, {
:attr => {
"rel" => "stylesheet",
"type" => "text/css",
"href" => "file://#{File.realpath("#{File.dirname(__FILE__)}/../css")}/default.css"
}
})
head.add(:script, {
:attr => {
"type" => "text/javascript",
"src" => "file://#{File.realpath("#{File.dirname(__FILE__)}/../js")}/jquery-1.8.1.min.js"
}
})
script = head.add(:script, {
:attr => {"type" => "text/javascript"},
:str => "
function remove_row(row_ele){
$('div, span', row_ele).slideUp('fast', function(){
row_ele.remove()
})
}
"
})
body = html.add(:body)
table = body.add(:table, :css => {"width" => "100%"})
thead = table.add(:thead)
thead.add(:th, :str => "First name")
thead.add(:th, :str => "Last name")
thead.add(:th, :str => "Age")
thead.add(:th, :str => "Actions")
tbody = table.add(:tbody)
persons = [
["Kasper", "Johansen", "27"],
["Jacob", "Emcken", "29"],
["Christina", "Stöckel", "25"]
]
persons.each do |person|
tr = tbody.add(:tr)
person.each do |data|
td = tr.add(:td).add(:span, {
:str => data,
:css => {
"cursor" => "pointer"
},
:attr => {
"onclick" => "document.title = $(this).text()"
}
})
end
add = tr.add(:td).add(:span).add(:a, {
:str => "[remove]",
:css => {
"cursor" => "pointer"
},
:attr => {
"onclick" => "remove_row($(this).parent().parent().parent())"
}
})
end
html_str = html.html
print "Reload table HTML:\n"
print html_str
print "\n\n"
@wview.load_string(html_str, "text/html", "utf-8", "file://")
end
|