zena 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +1 -1
- data/bricks/grid/lib/bricks/grid.rb +28 -26
- data/lib/zena/info.rb +1 -1
- data/public/javascripts/grid.js +25 -13
- data/zena.gemspec +1 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'json'
|
3
|
+
require 'uuidtools'
|
3
4
|
|
4
5
|
module Bricks
|
5
6
|
module Grid
|
@@ -27,20 +28,7 @@ module Bricks
|
|
27
28
|
|
28
29
|
return table, error
|
29
30
|
end
|
30
|
-
|
31
|
-
end # Common
|
32
|
-
|
33
|
-
module ControllerMethods
|
34
|
-
include Common
|
35
|
-
end
|
36
|
-
|
37
|
-
# Routes = {
|
38
|
-
# :cell_update => :post, :table_update => :post, :cell_edit => :get
|
39
|
-
# }
|
40
|
-
|
41
|
-
module ViewMethods
|
42
|
-
include Common
|
43
|
-
|
31
|
+
|
44
32
|
# Create a table from an attribute
|
45
33
|
def make_table(opts)
|
46
34
|
style, node, attribute = opts[:style], opts[:node], opts[:attribute]
|
@@ -62,11 +50,11 @@ module Bricks
|
|
62
50
|
table, error = get_table_from_json(node.prop[attribute])
|
63
51
|
|
64
52
|
res = prefix + error.to_s
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
53
|
+
uuid = UUIDTools::UUID.random_create.to_s.gsub('-','')
|
54
|
+
msg = opts[:msg] || _('type to edit')
|
55
|
+
res << "<table id='grid#{uuid}' data-a='node[#{attribute}]' data-msg='#{msg}' class='grid'>\n<tr>"
|
56
|
+
if node.can_write? && !opts[:no_edit]
|
57
|
+
js_data << "Grid.make($('grid#{uuid}'));"
|
70
58
|
end
|
71
59
|
|
72
60
|
|
@@ -89,20 +77,34 @@ module Bricks
|
|
89
77
|
rescue JSON::ParserError
|
90
78
|
"<span class='unknownLink'>could not build table from text</span>"
|
91
79
|
end
|
80
|
+
end # Common
|
81
|
+
|
82
|
+
module ControllerMethods
|
83
|
+
include Common
|
84
|
+
end
|
85
|
+
|
86
|
+
# Routes = {
|
87
|
+
# :cell_update => :post, :table_update => :post, :cell_edit => :get
|
88
|
+
# }
|
89
|
+
|
90
|
+
module ViewMethods
|
91
|
+
include Common
|
92
|
+
|
93
|
+
def grid_asset(opts)
|
94
|
+
make_table(:node => opts[:node], :attribute => opts[:content])
|
95
|
+
end
|
92
96
|
end
|
93
97
|
|
94
98
|
# New better grid using JS.
|
95
99
|
module ZafuMethods
|
96
100
|
def r_grid
|
97
|
-
|
98
|
-
return parser_error("Missing 'attr' parameter") unless
|
101
|
+
attribute = @params[:attr]
|
102
|
+
return parser_error("Missing 'attr' parameter") unless attribute
|
99
103
|
# Make sure it compiles
|
100
|
-
code = RubyLess.translate(node(Node).klass,
|
104
|
+
code = RubyLess.translate(node(Node).klass, attribute)
|
101
105
|
msg = RubyLess.translate(self, "t('type to edit')")
|
102
|
-
|
103
|
-
|
104
|
-
out "<% js_data << %Q{$$('.grid').each(function(e) {Grid.make(e)})} %>"
|
105
|
-
end
|
106
|
+
editable = @params[:edit] == 'true' ? '' : ', :no_edit => true'
|
107
|
+
out "<%= make_table(:attribute => #{attribute.inspect}, :node => #{node(Node)}, :msg => #{msg}#{editable}) %>"
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end # Grid
|
data/lib/zena/info.rb
CHANGED
data/public/javascripts/grid.js
CHANGED
@@ -148,27 +148,38 @@ Grid.keydown = function(event) {
|
|
148
148
|
}
|
149
149
|
Grid.open_cell(prev);
|
150
150
|
event.stop();
|
151
|
-
} else if (key == 40) {
|
151
|
+
} else if (key == 40 || key == 13) {
|
152
152
|
// find position
|
153
153
|
var pos = Grid.pos(cell);
|
154
154
|
// go to next row
|
155
|
-
var
|
155
|
+
var crow = cell.up();
|
156
|
+
var row = crow.nextSiblings().first();
|
156
157
|
// find elem
|
157
|
-
|
158
|
-
|
158
|
+
if (!row) {
|
159
|
+
// open new row
|
160
|
+
Grid.add_row(crow.up(), cell.up());
|
161
|
+
row = crow.nextSiblings().first();
|
162
|
+
var next = row.childElements()[0];
|
163
|
+
setTimeout(function() {
|
164
|
+
Grid.open_cell(next);
|
165
|
+
}, 100);
|
166
|
+
} else {
|
167
|
+
next = row.childElements()[pos];
|
168
|
+
Grid.open_cell(next);
|
169
|
+
}
|
159
170
|
event.stop();
|
160
171
|
} else if (key == 38) {
|
161
172
|
// go to prev row
|
162
173
|
var row = cell.up();
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
174
|
+
if (Grid.pos(row) == 1) {
|
175
|
+
// stop
|
176
|
+
} else {
|
177
|
+
var pos = Grid.pos(cell);
|
178
|
+
// move up
|
179
|
+
row = row.previousSiblings().first();
|
180
|
+
var next = row.childElements()[pos];
|
181
|
+
Grid.open_cell(next);
|
182
|
+
}
|
172
183
|
event.stop();
|
173
184
|
}
|
174
185
|
return false;
|
@@ -391,6 +402,7 @@ Grid.addButtons = function(table) {
|
|
391
402
|
}
|
392
403
|
|
393
404
|
Grid.make = function(table) {
|
405
|
+
if (table.grid) return;
|
394
406
|
Grid.grid_c++;
|
395
407
|
Grid.grids[Grid.grid_c] = table;
|
396
408
|
table.grid = {
|
data/zena.gemspec
CHANGED
metadata
CHANGED