zena 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,4 @@
1
- == 1.2.0
1
+ == 1.2.0 2012-05-01
2
2
 
3
3
  * Major changes
4
4
  * Added 'remove_from_db' method to remove a site from the database.
@@ -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
- if node.can_write?
66
- msg = opts[:msg] || _('type to edit')
67
- res << "<table data-a='node[#{attribute}]' data-msg='#{msg}' class='grid'>\n<tr>"
68
- else
69
- res << "<table><tr>"
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
- attr = @params[:attr]
98
- return parser_error("Missing 'attr' parameter") unless attr
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, attr)
104
+ code = RubyLess.translate(node(Node).klass, attribute)
101
105
  msg = RubyLess.translate(self, "t('type to edit')")
102
- out "<%= make_table(:attribute => #{attr.inspect}, :node => #{node(Node)}, :msg => #{msg}) %>"
103
- if @params[:edit] == 'true'
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
@@ -1,4 +1,4 @@
1
1
  module Zena
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
4
4
  end
@@ -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 row = cell.up().nextSiblings().first();
155
+ var crow = cell.up();
156
+ var row = crow.nextSiblings().first();
156
157
  // find elem
157
- var next = row.childElements()[pos];
158
- if (next) Grid.open_cell(next);
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
- if (Grid.pos(row) == 1) {
164
- // stop
165
- } else {
166
- var pos = Grid.pos(cell);
167
- // move up
168
- row = row.previousSiblings().first();
169
- var next = row.childElements()[pos];
170
- Grid.open_cell(next);
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zena}
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaspard Bucher"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zena
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gaspard Bucher