zena 1.2.1 → 1.2.2

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.
Files changed (202) hide show
  1. data/History.txt +38 -1
  2. data/app/controllers/documents_controller.rb +7 -5
  3. data/app/controllers/nodes_controller.rb +47 -6
  4. data/app/controllers/user_sessions_controller.rb +12 -3
  5. data/app/controllers/virtual_classes_controller.rb +8 -2
  6. data/app/models/acl.rb +5 -2
  7. data/app/models/cached_page.rb +5 -5
  8. data/app/models/column.rb +27 -4
  9. data/app/models/group.rb +1 -1
  10. data/app/models/node.rb +106 -24
  11. data/app/models/note.rb +2 -1
  12. data/app/models/relation.rb +9 -4
  13. data/app/models/relation_proxy.rb +2 -2
  14. data/app/models/role.rb +12 -5
  15. data/app/models/site.rb +10 -9
  16. data/app/models/skin.rb +8 -0
  17. data/app/models/string_hash.rb +65 -0
  18. data/app/models/text_document.rb +1 -1
  19. data/app/models/user.rb +2 -0
  20. data/app/models/virtual_class.rb +43 -10
  21. data/app/views/comments/create.rjs +1 -32
  22. data/app/views/comments/edit.rjs +1 -1
  23. data/app/views/comments/update.rjs +1 -1
  24. data/app/views/documents/show.rhtml +1 -1
  25. data/app/views/groups/_form.rhtml +7 -0
  26. data/app/views/groups/_li.rhtml +1 -1
  27. data/app/views/nodes/500.html +2 -1
  28. data/app/views/nodes/destroy.rjs +2 -0
  29. data/app/views/sites/jobs.erb +2 -3
  30. data/app/views/templates/document_create_tabs/_file.rhtml +1 -1
  31. data/app/views/templates/document_create_tabs/_import.rhtml +4 -1
  32. data/app/views/templates/document_create_tabs/_template.rhtml +3 -0
  33. data/app/views/templates/document_create_tabs/_text_document.rhtml +3 -0
  34. data/app/views/versions/custom_tab.rhtml +1 -1
  35. data/app/views/versions/edit.rhtml +1 -1
  36. data/bricks/acls/lib/bricks/acls.rb +3 -3
  37. data/bricks/acls/zena/test/unit/acl_test.rb +15 -0
  38. data/bricks/fs_skin/lib/bricks/fs_skin.rb +190 -0
  39. data/bricks/fs_skin/zena/init.rb +1 -0
  40. data/bricks/fs_skin/zena/migrate/20110702010330_add_fs_skin_to_idx_templates.rb +12 -0
  41. data/bricks/{static → fs_skin}/zena/skins/blog/Image-edit.zafu +0 -0
  42. data/bricks/{static → fs_skin}/zena/skins/blog/Image.zafu +0 -0
  43. data/bricks/{static → fs_skin}/zena/skins/blog/Node-+index.zafu +0 -0
  44. data/bricks/{static → fs_skin}/zena/skins/blog/Node-+notFound.zafu +0 -0
  45. data/bricks/{static → fs_skin}/zena/skins/blog/Node-+search.zafu +0 -0
  46. data/bricks/{static → fs_skin}/zena/skins/blog/Node.zafu +1 -1
  47. data/bricks/{static → fs_skin}/zena/skins/blog/Post.zafu +0 -0
  48. data/bricks/{static → fs_skin}/zena/skins/blog/Project--kml.zafu +0 -0
  49. data/bricks/{static → fs_skin}/zena/skins/blog/Project.zafu +0 -0
  50. data/bricks/{static → fs_skin}/zena/skins/blog/comments.zafu +0 -0
  51. data/bricks/{static → fs_skin}/zena/skins/blog/dict.yml +0 -0
  52. data/bricks/{static → fs_skin}/zena/skins/blog/img/dateBg.jpg +0 -0
  53. data/bricks/{static → fs_skin}/zena/skins/blog/img/header.png +0 -0
  54. data/bricks/{static → fs_skin}/zena/skins/blog/img/mapPin.png +0 -0
  55. data/bricks/{static → fs_skin}/zena/skins/blog/img/menu.gif +0 -0
  56. data/bricks/{static → fs_skin}/zena/skins/blog/img/menuover.gif +0 -0
  57. data/bricks/{static → fs_skin}/zena/skins/blog/img/style.css +0 -0
  58. data/bricks/fs_skin/zena/tasks.rb +26 -0
  59. data/bricks/{static/zena/test/integration/static_integration_test.rb → fs_skin/zena/test/integration/fs_skin_integration_test.rb} +6 -6
  60. data/bricks/fs_skin/zena/test/unit/fs_skin_test.rb +33 -0
  61. data/bricks/grid/lib/bricks/grid.rb +4 -3
  62. data/bricks/tags/lib/bricks/tags.rb +1 -7
  63. data/bricks/zena/zena/migrate/20120605091558_add_ssl_login_to_site.rb +7 -0
  64. data/bricks/zena/zena/migrate/20120630123551_add_auto_publish_to_group.rb +9 -0
  65. data/config/bricks.yml +3 -3
  66. data/config/gems.yml +2 -3
  67. data/lib/tasks/zena.rake +7 -3
  68. data/lib/zafu.rb +7 -0
  69. data/lib/zafu/all.rb +21 -0
  70. data/lib/zafu/compiler.rb +7 -0
  71. data/lib/zafu/controller_methods.rb +58 -0
  72. data/lib/zafu/handler.rb +57 -0
  73. data/lib/zafu/info.rb +4 -0
  74. data/lib/zafu/markup.rb +309 -0
  75. data/lib/zafu/mock_helper.rb +42 -0
  76. data/lib/zafu/node_context.rb +203 -0
  77. data/lib/zafu/ordered_hash.rb +53 -0
  78. data/lib/zafu/parser.rb +676 -0
  79. data/lib/zafu/parsing_rules.rb +382 -0
  80. data/lib/zafu/process/ajax.rb +530 -0
  81. data/lib/zafu/process/conditional.rb +92 -0
  82. data/lib/zafu/process/context.rb +186 -0
  83. data/lib/zafu/process/forms.rb +143 -0
  84. data/lib/zafu/process/html.rb +186 -0
  85. data/lib/zafu/process/ruby_less_processing.rb +321 -0
  86. data/lib/zafu/security.rb +15 -0
  87. data/lib/zafu/template.rb +25 -0
  88. data/lib/zafu/test_helper.rb +19 -0
  89. data/lib/zafu/view_methods.rb +6 -0
  90. data/lib/zena.rb +1 -1
  91. data/lib/zena/acts/enrollable.rb +1 -1
  92. data/lib/zena/app.rb +4 -17
  93. data/lib/zena/console.rb +18 -1
  94. data/lib/zena/core_ext/file_utils.rb +13 -1
  95. data/lib/zena/core_ext/fixnum.rb +4 -0
  96. data/lib/zena/core_ext/float.rb +7 -0
  97. data/lib/zena/deploy.rb +4 -2
  98. data/lib/zena/deploy/app_init.rhtml +2 -1
  99. data/lib/zena/deploy/database.rhtml +1 -1
  100. data/lib/zena/info.rb +1 -1
  101. data/lib/zena/parser/zazen_rules.rb +4 -4
  102. data/lib/zena/routes.rb +1 -1
  103. data/lib/zena/test_controller.rb +1 -1
  104. data/lib/zena/use.rb +14 -1
  105. data/lib/zena/use/action.rb +4 -2
  106. data/lib/zena/use/ajax.rb +86 -38
  107. data/lib/zena/use/authlogic.rb +16 -1
  108. data/lib/zena/use/calendar.rb +37 -17
  109. data/lib/zena/use/conditional.rb +2 -2
  110. data/lib/zena/use/context.rb +30 -9
  111. data/lib/zena/use/dates.rb +39 -3
  112. data/lib/zena/use/display.rb +6 -19
  113. data/lib/zena/use/forms.rb +100 -79
  114. data/lib/zena/use/i18n.rb +40 -16
  115. data/lib/zena/use/query_builder.rb +0 -6
  116. data/lib/zena/use/query_node.rb +17 -4
  117. data/lib/zena/use/relations.rb +1 -3
  118. data/lib/zena/use/rendering.rb +10 -8
  119. data/lib/zena/use/scope_index.rb +5 -1
  120. data/lib/zena/use/search.rb +2 -1
  121. data/lib/zena/use/urls.rb +82 -77
  122. data/lib/zena/use/workflow.rb +12 -4
  123. data/lib/zena/use/zafu_safe_definitions.rb +37 -9
  124. data/lib/zena/use/zafu_templates.rb +49 -20
  125. data/lib/zena/use/zazen.rb +6 -2
  126. data/locale/it/LC_MESSAGES/zena.mo +0 -0
  127. data/locale/it/zena.mo +0 -0
  128. data/locale/it/zena.po +1982 -0
  129. data/public/images/arrow_back.png +0 -0
  130. data/public/images/remove_tag.png +0 -0
  131. data/public/javascripts/grid.js +800 -199
  132. data/public/javascripts/window.js +1 -1
  133. data/public/javascripts/zena.js +130 -21
  134. data/public/stylesheets/grid.css +11 -2
  135. data/public/stylesheets/zena.css +2 -1
  136. data/test/custom_queries/complex.host.yml +5 -0
  137. data/test/fixtures/files/TestNode.zafu +36 -0
  138. data/test/functional/nodes_controller_test.rb +18 -1
  139. data/test/integration/zafu_compiler/action.yml +2 -2
  140. data/test/integration/zafu_compiler/ajax.yml +44 -26
  141. data/test/integration/zafu_compiler/asset.yml +12 -2
  142. data/test/integration/zafu_compiler/basic.yml +0 -16
  143. data/test/integration/zafu_compiler/calendar.yml +6 -6
  144. data/test/integration/zafu_compiler/complex_ok.yml +23 -1
  145. data/test/integration/zafu_compiler/conditional.yml +5 -5
  146. data/test/integration/zafu_compiler/context.yml +6 -5
  147. data/test/integration/zafu_compiler/dates.yml +23 -2
  148. data/test/integration/zafu_compiler/display.yml +46 -2
  149. data/test/integration/zafu_compiler/errors.yml +2 -2
  150. data/test/integration/zafu_compiler/eval.yml +35 -7
  151. data/test/integration/zafu_compiler/forms.yml +47 -13
  152. data/test/integration/zafu_compiler/i18n.yml +2 -2
  153. data/test/integration/zafu_compiler/meta.yml +35 -1
  154. data/test/integration/zafu_compiler/query.yml +23 -4
  155. data/test/integration/zafu_compiler/relations.yml +10 -6
  156. data/test/integration/zafu_compiler/roles.yml +4 -4
  157. data/test/integration/zafu_compiler/rubyless.yml +11 -1
  158. data/test/integration/zafu_compiler/safe_definitions.yml +23 -5
  159. data/test/integration/zafu_compiler/security.yml +10 -6
  160. data/test/integration/zafu_compiler/urls.yml +23 -6
  161. data/test/integration/zafu_compiler/zafu_attributes.yml +1 -1
  162. data/test/integration/zafu_compiler/zazen.yml +14 -0
  163. data/test/selenium/Add/add3.rsel +8 -8
  164. data/test/selenium/Destroy/0setup.rsel +12 -0
  165. data/test/selenium/Destroy/destroy1.rsel +16 -0
  166. data/test/selenium/Edit/edit2.rsel +9 -9
  167. data/test/selenium/Edit/edit5.rsel +9 -9
  168. data/test/selenium/Edit/edit6.rsel +9 -9
  169. data/test/selenium/Form/form4.rsel +17 -0
  170. data/test/selenium/Toggle/toggle1.rsel +2 -0
  171. data/test/selenium/Toggle/toggle2.rsel +18 -0
  172. data/test/sites/zena/columns.yml +3 -0
  173. data/test/sites/zena/versions.yml +7 -0
  174. data/test/unit/cached_page_test.rb +13 -13
  175. data/test/unit/column_test.rb +26 -0
  176. data/test/unit/node_test.rb +16 -1
  177. data/test/unit/project_test.rb +6 -1
  178. data/test/unit/relation_test.rb +1 -1
  179. data/test/unit/role_test.rb +1 -1
  180. data/test/unit/string_hash_test.rb +30 -0
  181. data/test/unit/virtual_class_test.rb +31 -17
  182. data/test/unit/zafu_markup_test.rb +414 -0
  183. data/test/unit/zafu_node_context_test.rb +375 -0
  184. data/test/unit/zafu_ordered_hash_test.rb +69 -0
  185. data/test/unit/zena/acts/enrollable_test.rb +1 -1
  186. data/test/unit/zena/parser/zafu_asset.yml +0 -10
  187. data/test/unit/zena/parser/zazen.yml +1 -1
  188. data/test/unit/zena/parser_test.rb +1 -72
  189. data/test/unit/zena/use/dates_test.rb +1 -1
  190. data/test/unit/zena/use/rendering_test.rb +24 -7
  191. data/test/unit/zena/use/scope_index_test.rb +17 -0
  192. data/test/unit/zena/use/zazen_test.rb +2 -1
  193. data/zena.gemspec +71 -37
  194. metadata +104 -83
  195. data/app/views/nodes/destroy.erb +0 -0
  196. data/bricks/static/lib/bricks/static.rb +0 -151
  197. data/bricks/static/zena/init.rb +0 -1
  198. data/bricks/static/zena/migrate/20110702010330_add_static_to_idx_templates.rb +0 -12
  199. data/bricks/static/zena/test/unit/static_test.rb +0 -33
  200. data/lib/zena/parser/zafu_rules.rb +0 -244
  201. data/lib/zena/parser/zafu_tags.rb +0 -198
  202. data/lib/zena/parser/zena_rules.rb +0 -23
@@ -42,7 +42,8 @@ class Note < Node
42
42
 
43
43
  def export_keys
44
44
  h = super
45
- h[:dates].merge!('log_at' => log_at, 'event_at' => event_at)
45
+ h[:dates].merge!('log_at' => log_at) unless log_at.blank?
46
+ h[:dates].merge!('event_at' => event_at) unless event_at.blank?
46
47
  h
47
48
  end
48
49
 
@@ -1,5 +1,5 @@
1
1
  class Relation < ActiveRecord::Base
2
- EXPORT_FIELDS = %w{target_kpath target_icon target_unique source_role source_icon source_unique rel_group}
2
+ EXPORT_FIELDS = %w{target_name target_icon target_unique source_role source_icon source_unique rel_group}
3
3
 
4
4
  before_validation :singularize_roles
5
5
  validate :valid_relation
@@ -21,11 +21,16 @@ class Relation < ActiveRecord::Base
21
21
  def export
22
22
  res = Zafu::OrderedHash.new
23
23
  EXPORT_FIELDS.each do |key|
24
- value = self[key]
25
- if !value.blank?
26
- res[key] = value
24
+ if key == 'target_name'
25
+ res[key] = VirtualClass.find_by_kpath(self['target_kpath']).name
26
+ else
27
+ value = self[key]
28
+ if !value.blank?
29
+ res[key] = value
30
+ end
27
31
  end
28
32
  end
33
+
29
34
  res
30
35
  end
31
36
 
@@ -1,3 +1,4 @@
1
+ # This is a mess and would need a rewrite...
1
2
  class RelationProxy < Relation
2
3
  include RubyLess
3
4
 
@@ -35,8 +36,7 @@ class RelationProxy < Relation
35
36
  # Find a relation proxy for a role through a given node.
36
37
  # The finder makes sure the class path is compatible with the node's class/virtual_class given as parameter.
37
38
  def get_proxy(node, role)
38
- # TODO: use find_by_role(role, node.kpath) when all tests are clear
39
- rel = find_by_role(role)
39
+ rel = find_by_role(role, node.new_record? ? nil : node.kpath)
40
40
  if rel && (node.new_record? || node.kpath =~ /\A#{rel.this_kpath}/)
41
41
  rel.start = node
42
42
  rel
@@ -51,7 +51,7 @@ class Role < ActiveRecord::Base
51
51
  raise Exception.new("Importation needs to start with a real class: '#{name}' is not a real class.")
52
52
  else
53
53
  # start importing
54
- res += import_all(klass, definition, post_import)
54
+ res += import_vclass(nil, name, definition, post_import)
55
55
  end
56
56
  end
57
57
 
@@ -119,7 +119,7 @@ class Role < ActiveRecord::Base
119
119
 
120
120
  def import_vclass(superclass, name, definition, post_import)
121
121
  res = []
122
- vclass = ::Role.find_by_name_and_site_id(name, current_site.id)
122
+ vclass = VirtualClass[name]
123
123
  if vclass && vclass.class != VirtualClass
124
124
  # Change from role to vclass ?
125
125
  # Reject
@@ -129,7 +129,7 @@ class Role < ActiveRecord::Base
129
129
  vclass = VirtualClass.new(:name => name, :superclass => superclass)
130
130
  vclass.save!
131
131
  end
132
-
132
+
133
133
  res << vclass
134
134
 
135
135
  # 2. create or update columns (never delete)
@@ -153,7 +153,8 @@ class Role < ActiveRecord::Base
153
153
  # We do not clear attributes (import is ADD/UPDATE only).
154
154
  end
155
155
  end
156
- vclass.save!
156
+
157
+ vclass.save! unless vclass.real_class?
157
158
 
158
159
  # 5. create or update sub-classes
159
160
  res += import_all(vclass, definition, post_import)
@@ -248,7 +249,13 @@ class Role < ActiveRecord::Base
248
249
  end
249
250
  Relation::EXPORT_FIELDS.each do |key|
250
251
  value = definition[key]
251
- if !value.blank?
252
+ if key == 'target_name' && !value.blank?
253
+ if target = VirtualClass[value]
254
+ relation['target_kpath'] = target.kpath
255
+ else
256
+ raise Exception.new("Could not find a target named '#{value}' to create relation '#{name}'.")
257
+ end
258
+ elsif !value.blank?
252
259
  relation[key] = value
253
260
  end
254
261
  end
@@ -56,7 +56,7 @@ class Site < ActiveRecord::Base
56
56
 
57
57
  validate :valid_site
58
58
  validates_uniqueness_of :host
59
- attr_accessible :name, :languages, :default_lang, :authentication, :http_auth, :auto_publish, :redit_time, :api_group_id
59
+ attr_accessible :name, :languages, :default_lang, :authentication, :http_auth, :ssl_on_auth, :auto_publish, :redit_time, :api_group_id
60
60
  has_many :groups, :order => "name"
61
61
  has_many :nodes
62
62
  has_many :users
@@ -70,7 +70,7 @@ class Site < ActiveRecord::Base
70
70
  include Zena::Use::MLIndex::SiteMethods
71
71
 
72
72
  @@attributes_for_form = {
73
- :bool => %w{authentication http_auth auto_publish},
73
+ :bool => %w{authentication http_auth auto_publish ssl_on_auth},
74
74
  :text => %w{name languages default_lang},
75
75
  }
76
76
 
@@ -118,8 +118,8 @@ class Site < ActiveRecord::Base
118
118
 
119
119
  unless admin_user.save
120
120
  # rollback
121
- Site.connection.execute "DELETE FROM #{Site.table_name} WHERE id = #{site.id}"
122
- Site.connection.execute "DELETE FROM zips WHERE site_id = #{site.id}"
121
+ Zena::Db.execute "DELETE FROM #{Site.table_name} WHERE id = #{site.id}"
122
+ Zena::Db.execute "DELETE FROM zips WHERE site_id = #{site.id}"
123
123
  raise Exception.new("Could not create admin user for site [#{host}] (site#{site[:id]})\n#{admin_user.errors.map{|k,v| "[#{k}] #{v}"}.join("\n")}")
124
124
  end
125
125
 
@@ -221,6 +221,7 @@ class Site < ActiveRecord::Base
221
221
 
222
222
  property.string 'usr_prototype_attributes'
223
223
  property.boolean 'expire_in_dev'
224
+ property.boolean 'ssl_on_auth'
224
225
 
225
226
  Site.attributes_for_form[:text] << 'usr_prototype_attributes'
226
227
  Site.attributes_for_form[:bool] << 'expire_in_dev'
@@ -348,7 +349,7 @@ class Site < ActiveRecord::Base
348
349
  end
349
350
 
350
351
  def iformats_updated!
351
- Site.connection.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
352
+ Zena::Db.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
352
353
  if $iformats
353
354
  $iformats[self[:id]] = @iformats = nil
354
355
  end
@@ -366,7 +367,7 @@ class Site < ActiveRecord::Base
366
367
  end
367
368
 
368
369
  def iformats_updated!
369
- Site.connection.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
370
+ Zena::Db.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
370
371
  if $iformats
371
372
  $iformats[self[:id]] = @iformats = nil
372
373
  end
@@ -382,9 +383,9 @@ class Site < ActiveRecord::Base
382
383
  FileUtils.rmtree(File.join(path, elem))
383
384
  end
384
385
 
385
- Site.connection.execute "DELETE FROM caches WHERE site_id = #{self[:id]}"
386
- Site.connection.execute "DELETE FROM cached_pages_nodes WHERE cached_pages_nodes.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.site_id = #{self[:id]})"
387
- Site.connection.execute "DELETE FROM cached_pages WHERE site_id = #{self[:id]}"
386
+ Zena::Db.execute "DELETE FROM caches WHERE site_id = #{self[:id]}"
387
+ Zena::Db.execute "DELETE FROM cached_pages_nodes WHERE cached_pages_nodes.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.site_id = #{self[:id]})"
388
+ Zena::Db.execute "DELETE FROM cached_pages WHERE site_id = #{self[:id]}"
388
389
  end
389
390
 
390
391
  if clear_zafu
@@ -1,4 +1,12 @@
1
1
  # A skin is a container for templates and css to render a full site or sectioon
2
2
  # of a site.
3
3
  class Skin < Section
4
+ def skin_name
5
+ title.to_filename
6
+ end
7
+
8
+ def self.text_from_fs_skin(brick_name, skin_name, path, opts)
9
+ # dummy implementation
10
+ nil
11
+ end
4
12
  end
@@ -0,0 +1,65 @@
1
+ class StringHash < Hash
2
+ include RubyLess
3
+
4
+ def self.from_string(str)
5
+ from_hash(JSON.parse(str))
6
+ end
7
+
8
+ def self.from_hash(hash)
9
+ obj = new
10
+ hash.each do |k,v|
11
+ obj[k.to_s] = v.to_s
12
+ end
13
+ obj
14
+ end
15
+
16
+ def self.[](value)
17
+ from_hash(value)
18
+ end
19
+
20
+ # Deserialization used by Property
21
+ def self.json_create(serialized)
22
+ if data = serialized['data']
23
+ StringHash[data]
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ def []=(k, v)
30
+ if v.blank?
31
+ delete(k.to_s)
32
+ else
33
+ super(k.to_s, v.to_s)
34
+ end
35
+ end
36
+
37
+ def merge!(value)
38
+ value.each do |k,v|
39
+ self[k] = v
40
+ end
41
+ self
42
+ end
43
+
44
+ def merge(value)
45
+ obj = dup
46
+ value.each do |k,v|
47
+ obj[k] = v
48
+ end
49
+ obj
50
+ end
51
+
52
+ # Serialization used by Property
53
+ def to_json(*args)
54
+ { 'json_class' => 'StringHash', 'data' => Hash[self] }.to_json
55
+ end
56
+
57
+ # This is used in case we show a form with the StringHash so that the value
58
+ # is not serialized to junk. This is the other side of "from_string".
59
+ def to_s
60
+ Hash[self].to_json
61
+ end
62
+
63
+ safe_context [:[], String] => String
64
+ safe_method :keys => [String]
65
+ end
@@ -15,7 +15,7 @@ class TextDocument < Document
15
15
  class << self
16
16
  # Return true if a new text document can be created with the content_type. Used by the superclass Document to choose the corret subclass when creating a new object.
17
17
  def accept_content_type?(content_type)
18
- (content_type =~ /^(text|image\/svg\+xml|x-javascript)/) &&
18
+ (content_type =~ /(^text|^image\/svg\+xml|x-javascript)/) &&
19
19
  (Zena::TYPE_TO_EXT[content_type.chomp] != ['rtf'])
20
20
  end
21
21
 
@@ -24,6 +24,8 @@ things they can/cannot do :
24
24
  TODO: when a user is 'destroyed', pass everything he owns to another user or just mark the user as 'deleted'...
25
25
  =end
26
26
  class User < ActiveRecord::Base
27
+ attr_accessor :zafu_cache
28
+
27
29
  include Property
28
30
  RESCUE_SKIN_ID = -1
29
31
  ANY_SKIN_ID = 0
@@ -58,8 +58,16 @@ class VirtualClass < Role
58
58
  safe_method [:relations, String] => {:class => ['RelationProxy'], :method => 'filtered_relations'}
59
59
  # All columns defined for a VirtualClass (kpath based).
60
60
  safe_method :all_columns => {:class => ['Column'], :method => 'safe_columns'}
61
-
62
-
61
+
62
+ # Methods on VirtualClass['Post'] instances, not nodes.
63
+ def self.safe_method_type(signature, receiver)
64
+ if signature.first == 'new'
65
+ {:method => 'zafu_new', :class => receiver.literal}
66
+ else
67
+ super
68
+ end
69
+ end
70
+
63
71
  class Cache
64
72
  def initialize
65
73
  clear_cache!
@@ -343,7 +351,16 @@ class VirtualClass < Role
343
351
 
344
352
  # In order to use types other then String, we use the overwritten property's
345
353
  # type.
346
- if type = safe_column_types[method]
354
+ if type_name = query.types[method]
355
+ klass = Node.cast_to_class(type_name)
356
+ if klass == String
357
+ return {:method => "attributes[#{method.inspect}]", :nil => true, :class => klass}
358
+ elsif klass
359
+ return {:method => "rcast(#{method.inspect}, #{type_name.inspect})", :nil => true, :class => klass}
360
+ else
361
+ return nil
362
+ end
363
+ elsif type = safe_column_types[method]
347
364
  return type.merge(:method => "attributes[#{method.inspect}]", :nil => true)
348
365
  elsif type = real_class.safe_method_type(signature)
349
366
  return type.merge(:nil => true)
@@ -474,6 +491,11 @@ class VirtualClass < Role
474
491
  def new_instance(hash={})
475
492
  real_class.new(hash, self)
476
493
  end
494
+
495
+ # Build new nodes instances of this VirtualClass from zafu.
496
+ def zafu_new(hash={})
497
+ real_class.new(Node.transform_attributes(hash.stringify_keys), self)
498
+ end
477
499
 
478
500
  # Create new nodes instances of this VirtualClass
479
501
  def create_instance(*args)
@@ -509,8 +531,9 @@ class VirtualClass < Role
509
531
  def rebuild_kpath(superclass)
510
532
  index = 0
511
533
  kpath = nil
512
- while index < self[:name].length
513
- try_kpath = superclass.kpath + self[:name][index..index].upcase
534
+ try_keys = "#{name}ABCDEFGHIJKLMNOPQRSTUCWXYZ1234567890"
535
+ while index < try_keys.length
536
+ try_kpath = superclass.kpath + try_keys[index..index].upcase
514
537
  if found = VirtualClass.find_by_kpath(try_kpath)
515
538
  if found.id && found.id == self[:id]
516
539
  kpath = try_kpath
@@ -568,10 +591,11 @@ class VirtualClass < Role
568
591
 
569
592
  def propagate_kpath_change
570
593
  if kpath_changed?
594
+ new_kpath = self.kpath
571
595
  old_kpath = kpath_was
572
- Zena::Db.execute "UPDATE nodes SET kpath = '#{kpath}' WHERE vclass_id = #{self.id} AND site_id = #{current_site.id}"
573
- Zena::Db.execute "UPDATE roles SET kpath = '#{kpath}' WHERE kpath = '#{old_kpath}' AND site_id = #{current_site.id} AND (type = 'Role' or type IS NULL)"
574
- # Find templates
596
+ Zena::Db.execute "UPDATE nodes SET kpath = '#{new_kpath}' WHERE vclass_id = #{self.id} AND site_id = #{current_site.id}"
597
+ Zena::Db.execute "UPDATE roles SET kpath = '#{new_kpath}' WHERE kpath = '#{old_kpath}' AND site_id = #{current_site.id} AND (type = 'Role' or type IS NULL)"
598
+ # ========================================= Update templates
575
599
  idx_templates = IdxTemplate.all(
576
600
  :conditions => ['tkpath = ? AND site_id = ?', old_kpath, site_id]
577
601
  )
@@ -591,8 +615,17 @@ class VirtualClass < Role
591
615
  end
592
616
  end
593
617
  end
594
-
595
- # Sub-classes
618
+
619
+ # ========================================= Update relations
620
+ Relation.all(
621
+ :conditions => ['source_kpath = ? or target_kpath = ?', old_kpath, old_kpath]
622
+ ).each do |rel|
623
+ rel.source_kpath = new_kpath if rel.source_kpath == old_kpath
624
+ rel.target_kpath = new_kpath if rel.target_kpath == old_kpath
625
+ rel.save!
626
+ end
627
+
628
+ # ========================================= Update sub-classes
596
629
  if sub_classes = secure(VirtualClass) { VirtualClass.all(
597
630
  :conditions => ['kpath LIKE ?', "#{old_kpath}_"]
598
631
  )}
@@ -1,32 +1 @@
1
- #if @errors
2
- # page.replace_html 'comment_errors', :inline => render_errors
3
- #elsif @comment.new_record?
4
- # page.replace_html "add_comment_form#{@comment.reply_to || ''}", :partial=>'comments/form'
5
- # page.replace_html "comment_errors#{@comment.reply_to || ''}", :inline=>error_messages_for(:comment, :object => @comment)
6
- #else
7
- # if @comment.reply_to
8
- # page.remove "add_comment_form#{@comment.reply_to}"
9
- # page.insert_html :bottom, "replies_to#{@comment.reply_to}", :partial=>'comments/li', :collection=>[@comment]
10
- # else
11
- # page.insert_html :before, "add_comment#{@node.zip}", :partial=>'comments/li', :collection=>[@comment]
12
- # page.toggle "add_comment#{@node.zip}", "add_comment_form#{@node.zip}"
13
- # end
14
- # page.visual_effect :highlight, "comment#{@comment[:id]}", :duration => 0.3
15
- #end
16
- update_page_content(page, @comment)
17
- =begin
18
- if @comment.new_record?
19
- page.replace "#{params[:dom_id]}_form", :file => template_path_from_template_url + "_form.erb"
20
- else
21
- pos = params[:position] || :before
22
- ref = params[:reference] || "#{params[:dom_id]}_add"
23
- page.insert_html pos.to_sym, ref, :file => template_path_from_template_url + ".erb"
24
- @comment = Comment.new
25
- page.replace "#{params[:dom_id]}_form", :file => template_path_from_template_url + "_form.erb"
26
- if params[:done]
27
- page << params[:done]
28
- else
29
- page.toggle "#{params[:dom_id]}_form", "#{params[:dom_id]}_add"
30
- end
31
- end
32
- =end
1
+ update_page_content(page, @comment)
@@ -1,2 +1,2 @@
1
- page.replace "#{params[:dom_id]}_#{@comment.zip}", :file => template_path_from_template_url + "_form.erb"
1
+ page.replace "#{params[:dom_id]}_#{@comment.zip}", :file => template_path_from_template_url('_form')
2
2
  page << "$('#{params[:dom_id]}_form_t').focusFirstElement();"
@@ -1 +1 @@
1
- page.replace "#{params[:dom_id]}.#{@comment.zip}", :file => template_path_from_template_url + ".erb"
1
+ page.replace "#{params[:dom_id]}.#{@comment.zip}", :file => template_path_from_template_url
@@ -12,6 +12,6 @@
12
12
  <td class='preview'><p><%= img_tag(@node, :mode=>'pv') %></p><p class='size'><%= fsize(@node.size) %></p></td>
13
13
  <td class='description'><h3 class='title s<%= @node.version.status %>'><span class='doc_id'><%= @node[:zip] %></span> <%= @node.title %> <%= node_actions(@node, :actions => :all) %></h3><p class='summary'><%= zazen(@node.summary) %></p></td></tr>
14
14
  </table>
15
- <p class='btn_validate'><%= link_to _("upload more"), new_document_path(:parent_id => @node.parent_zip) %> // <%= link_to_function _('close'), "Zena.reload_and_close();" %></p>
15
+ <p class='btn_validate'><%= link_to _("upload more"), new_document_path(:parent_id => @node.parent_zip, :js => params[:js], :reload => params[:reload]) %> // <%= link_to_function _('close'), "Zena.t().Windows.close(#{win_id(@node.parent_zip, 'add_doc').inspect});" %></p>
16
16
  </div>
17
17
  </div>
@@ -32,6 +32,13 @@
32
32
  <% if !@group.new_record? -%>
33
33
  <tr><td class='label'><%= _('replace by') %></td><td><%= select('group', 'replace_by', @groups.map{|g| [g[:name], g[:id]]} , {:include_blank => true}) %></td></tr>
34
34
  <% end -%>
35
+ <tr>
36
+ <td class='label'><%= _('auto_publish') %></td>
37
+ <td>
38
+ <input type='hidden' name='group[auto_publish]' value=''/>
39
+ <input type='checkbox' name='group[auto_publish]' value='1'<%= @group.auto_publish? ? " checked='checked'" : '' %>/> <%= _('auto_publish') %>
40
+ </td>
41
+ </tr>
35
42
  <tr><td colspan='2'><input type='submit' class='btn_validate' value='<%= _('validate') %>'/></td></tr>
36
43
  </table>
37
44
  </form>
@@ -8,6 +8,6 @@ else
8
8
  end %>
9
9
  <tr id='group<%= li[:id] %>'>
10
10
  <td class="adm_icon"><%= link_to_remote( _("img_#{icon}"), :update=>"group#{li[:id]}", :url=>edit_group_path(li), :method=>:get) %></td>
11
- <td class="name"><%= li.name %></td>
11
+ <td class="name"><%= li.name %><%= li.auto_publish? ? '*' : '' %></td>
12
12
  <td class="users"><%= li.active_users.map {|u| (u.login || 'anon') }.join(', ') %></td>
13
13
  </tr>
@@ -7,7 +7,8 @@
7
7
  </head>
8
8
 
9
9
  <body style='font-family:Helvetica, Arial, sans-serif;'>
10
- <div style='display:table; margin:50px auto; background:#aaa; height:200px; width:600px; border:1px solid black;'>
10
+ <!-- The zena_error500 is used we running automated tests. Do not change -->
11
+ <div id='zena_error500' style='display:table; margin:50px auto; background:#aaa; height:200px; width:600px; border:1px solid black;'>
11
12
  <h2 style='font-size:18px; text-align:center; margin-top:20px; border:1px solid red; border-width:1px 0; background:#faa; padding:10px;'>Sorry... An error prevented the requested page from rendering</h2>
12
13
  <p style='text-align:center; text-style:italic;'>This problem has been logged and will be acted upon.</p>
13
14
  </div>