zen 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.gems +17 -15
  2. data/.gitignore +1 -1
  3. data/.travis.yml +1 -1
  4. data/MANIFEST +470 -0
  5. data/README.md +5 -3
  6. data/Rakefile +8 -6
  7. data/bin/zen +2 -7
  8. data/guide/asset_management.md +1 -0
  9. data/guide/autosaving_forms.md +1 -0
  10. data/guide/changelog.md +22 -0
  11. data/guide/faq.md +1 -0
  12. data/guide/getting_started.md +1 -0
  13. data/guide/hacking.md +1 -0
  14. data/guide/images/sections/revisions.png +0 -0
  15. data/guide/images/sections/revisions_diff.png +0 -0
  16. data/guide/images/sections/revisions_diff_multiple.png +0 -0
  17. data/guide/installation.md +4 -3
  18. data/guide/javascript.md +1 -0
  19. data/guide/javascript/zen_autosave.md +1 -0
  20. data/guide/javascript/zen_editor.md +1 -0
  21. data/guide/javascript/zen_form.md +1 -0
  22. data/guide/javascript/zen_hash.md +1 -0
  23. data/guide/javascript/zen_htmltable.md +1 -0
  24. data/guide/javascript/zen_tabs.md +1 -0
  25. data/guide/javascript/zen_window.md +1 -0
  26. data/guide/zen_compared.md +1 -0
  27. data/lib/zen.rb +10 -12
  28. data/lib/zen/event.rb +2 -2
  29. data/lib/zen/helper/controller.rb +13 -13
  30. data/lib/zen/helper/message.rb +3 -3
  31. data/lib/zen/helper/search.rb +4 -4
  32. data/lib/zen/helper/stacked_aspect.rb +9 -9
  33. data/lib/zen/html_diff.rb +151 -0
  34. data/lib/zen/language.rb +9 -7
  35. data/lib/zen/language/translation.rb +8 -8
  36. data/lib/zen/markup.rb +1 -1
  37. data/lib/zen/migrator.rb +2 -2
  38. data/lib/zen/model/helper.rb +4 -4
  39. data/lib/zen/model/plugin/events.rb +16 -16
  40. data/lib/zen/package.rb +2 -2
  41. data/lib/zen/package/all.rb +1 -1
  42. data/lib/zen/package/categories/lib/categories/controller/categories.rb +4 -4
  43. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +4 -4
  44. data/lib/zen/package/categories/lib/categories/helper/category.rb +3 -3
  45. data/lib/zen/package/categories/lib/categories/model/category.rb +9 -9
  46. data/lib/zen/package/categories/lib/categories/model/category_group.rb +9 -9
  47. data/lib/zen/package/comments/lib/comments/controller/comments.rb +4 -4
  48. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +2 -2
  49. data/lib/zen/package/comments/lib/comments/helper/comment.rb +1 -1
  50. data/lib/zen/package/comments/lib/comments/model/comment.rb +13 -13
  51. data/lib/zen/package/custom_fields/lib/custom_fields/blue_form_parameters.rb +1 -1
  52. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +4 -4
  53. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_types.rb +6 -6
  54. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +5 -5
  55. data/lib/zen/package/custom_fields/lib/custom_fields/helper/custom_field.rb +3 -3
  56. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +9 -9
  57. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +9 -9
  58. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_type.rb +9 -9
  59. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +8 -3
  60. data/lib/zen/package/custom_fields/migrations/1336171490_revisions.rb +41 -0
  61. data/lib/zen/package/dashboard/lib/dashboard/controller/dashboard.rb +6 -6
  62. data/lib/zen/package/dashboard/lib/dashboard/model/widget.rb +3 -3
  63. data/lib/zen/package/dashboard/lib/dashboard/widget.rb +12 -12
  64. data/lib/zen/package/extensions/lib/extensions/controller/extensions.rb +3 -3
  65. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +5 -5
  66. data/lib/zen/package/menus/lib/menus/controller/menus.rb +4 -4
  67. data/lib/zen/package/menus/lib/menus/helper/menu.rb +4 -4
  68. data/lib/zen/package/menus/lib/menus/model/menu.rb +11 -11
  69. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +10 -10
  70. data/lib/zen/package/menus/lib/menus/public/admin/menus/js/lib/nested_sortables.js +13 -13
  71. data/lib/zen/package/menus/lib/menus/public/admin/menus/js/menu_items.js +1 -1
  72. data/lib/zen/package/sections/lib/sections.rb +19 -0
  73. data/lib/zen/package/sections/lib/sections/controller/revisions.rb +184 -0
  74. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +5 -5
  75. data/lib/zen/package/sections/lib/sections/controller/sections.rb +9 -6
  76. data/lib/zen/package/sections/lib/sections/helper/revision.rb +124 -0
  77. data/lib/zen/package/sections/lib/sections/helper/section.rb +17 -15
  78. data/lib/zen/package/sections/lib/sections/helper/section_frontend.rb +104 -6
  79. data/lib/zen/package/sections/lib/sections/language/en/revisions.rb +34 -0
  80. data/lib/zen/package/sections/lib/sections/language/en/sections.rb +1 -0
  81. data/lib/zen/package/sections/lib/sections/language/nl/revisions.rb +35 -0
  82. data/lib/zen/package/sections/lib/sections/language/nl/sections.rb +1 -0
  83. data/lib/zen/package/sections/lib/sections/model/revision.rb +76 -0
  84. data/lib/zen/package/sections/lib/sections/model/section.rb +9 -9
  85. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +47 -12
  86. data/lib/zen/package/sections/lib/sections/view/admin/revisions/index.xhtml +89 -0
  87. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +1 -1
  88. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +14 -0
  89. data/lib/zen/package/sections/migrations/1335711557_revisions.rb +40 -0
  90. data/lib/zen/package/settings/lib/settings/controller/settings.rb +12 -4
  91. data/lib/zen/package/settings/lib/settings/setting.rb +6 -6
  92. data/lib/zen/package/users/lib/users/controller/user_groups.rb +4 -4
  93. data/lib/zen/package/users/lib/users/controller/users.rb +12 -12
  94. data/lib/zen/package/users/lib/users/helper/access.rb +1 -1
  95. data/lib/zen/package/users/lib/users/helper/acl.rb +4 -4
  96. data/lib/zen/package/users/lib/users/helper/users.rb +2 -2
  97. data/lib/zen/package/users/lib/users/model/permission.rb +1 -1
  98. data/lib/zen/package/users/lib/users/model/user.rb +11 -11
  99. data/lib/zen/package/users/lib/users/model/user_group.rb +9 -9
  100. data/lib/zen/package/users/lib/users/model/user_status.rb +2 -2
  101. data/lib/zen/public/admin/zen/css/general.css +54 -0
  102. data/lib/zen/public/admin/zen/css/messages.css +6 -3
  103. data/lib/zen/public/admin/zen/css/tables.css +10 -0
  104. data/lib/zen/public/admin/zen/images/icons/undo.png +0 -0
  105. data/lib/zen/public/admin/zen/js/lib/autosave.js +8 -8
  106. data/lib/zen/public/admin/zen/js/lib/base.js +2 -2
  107. data/lib/zen/public/admin/zen/js/lib/events.js +2 -2
  108. data/lib/zen/public/admin/zen/js/lib/form.js +7 -7
  109. data/lib/zen/public/admin/zen/js/lib/hash.js +7 -7
  110. data/lib/zen/public/admin/zen/js/lib/tabs.js +3 -3
  111. data/lib/zen/public/admin/zen/js/lib/window.js +1 -1
  112. data/lib/zen/security.rb +2 -2
  113. data/lib/zen/spec/helper.rb +3 -9
  114. data/lib/zen/spec/helper/capybara.rb +4 -4
  115. data/lib/zen/spec/helper/general.rb +1 -1
  116. data/lib/zen/spec/simplecov.rb +1 -5
  117. data/lib/zen/task/build.rake +22 -16
  118. data/lib/zen/task/db.rake +3 -2
  119. data/lib/zen/task/spelling.rake +10 -10
  120. data/lib/zen/task/test.rake +27 -19
  121. data/lib/zen/theme.rb +6 -6
  122. data/lib/zen/version.rb +1 -1
  123. data/spec/zen/all.rb +4 -0
  124. data/spec/zen/package/sections/controller/revisions.rb +235 -0
  125. data/spec/zen/package/sections/model/revision.rb +76 -0
  126. data/zen.gemspec +23 -21
  127. metadata +88 -29
  128. data/lib/zen/model/methods.rb +0 -27
  129. data/lib/zen/task/clean.rake +0 -20
  130. data/lib/zen/task/setup.rake +0 -4
  131. data/pkg/.gitkeep +0 -0
@@ -0,0 +1,124 @@
1
+ module Ramaze
2
+ module Helper
3
+ ##
4
+ # Helper for the controller {Sections::Controller::Revisions}.
5
+ #
6
+ # @since 2012-04-30
7
+ #
8
+ module Revision
9
+ ##
10
+ # Validates a revision ID. If the ID is invalid the user will be
11
+ # redirected back to the previous page and a message will be displayed.
12
+ #
13
+ # If the revision ID resulted in a valid Revision object then that object
14
+ # is returned.
15
+ #
16
+ # @since 2012-05-05
17
+ # @param [Fixnum|String] revision_id The ID of the revision.
18
+ # @return [Sections::Model::Revision]
19
+ #
20
+ def validate_revision(revision_id)
21
+ unless revision_id =~ /\d+/
22
+ message(:error, lang('revisions.errors.invalid'))
23
+ redirect_referer
24
+ end
25
+
26
+ revision = Sections::Model::Revision[revision_id]
27
+
28
+ if revision
29
+ return revision
30
+ else
31
+ message(:error, lang('revisions.errors.invalid'))
32
+ redirect_referer
33
+ end
34
+ end
35
+
36
+ ##
37
+ # Returns a hash containing the difference between the values of two
38
+ # section entries.
39
+ #
40
+ # @since 2012-04-30
41
+ # @param [Sections::Model::SectionEntry] entry The entry for which to
42
+ # generate the diff.
43
+ # @param [Fixnum|String] old_revision The old revision ID.
44
+ # @param [Fixnum|String] new_revision The new revision ID.
45
+ # @return [Hash]
46
+ #
47
+ def revision_diff(entry, old_revision, new_revision)
48
+ validate_revision(old_revision)
49
+ validate_revision(new_revision)
50
+
51
+ old_values = entry.custom_fields_and_values(old_revision)
52
+ new_values = entry.custom_fields_and_values(new_revision)
53
+ diff = {}
54
+
55
+ old_values.each do |field_id, hash|
56
+ new_hash = new_values[field_id]
57
+
58
+ if hash[:value] != new_hash[:value]
59
+ diff[hash[:name]] = Zen::HTMLDiff.diff(
60
+ hash[:value],
61
+ new_hash[:value]
62
+ )
63
+ end
64
+ end
65
+
66
+ return diff
67
+ end
68
+
69
+ ##
70
+ # Generates a radio button for an old revision ID.
71
+ #
72
+ # @since 2012-05-01
73
+ # @param [Fixnum|String] rev_id The revision ID.
74
+ # @param [Fixnum|String] current_rev_id The currently active old revision
75
+ # ID.
76
+ # @return [String]
77
+ #
78
+ def old_revision_radio(rev_id, current_rev_id)
79
+ g = Ramaze::Gestalt.new
80
+ attrs = {
81
+ :name => 'old_revision_id',
82
+ :id => "old_revision_id_#{rev_id}",
83
+ :type => 'radio',
84
+ :value => rev_id
85
+ }
86
+
87
+ if rev_id.to_i == current_rev_id.to_i
88
+ attrs[:checked] = 'checked'
89
+ end
90
+
91
+ g.input(attrs)
92
+
93
+ return g.to_s
94
+ end
95
+
96
+ ##
97
+ # Generates a radio button for a new revision ID.
98
+ #
99
+ # @since 2012-05-01
100
+ # @param [Fixnum|String] rev_id The revision ID.
101
+ # @param [Fixnum|String] current_rev_id The currently active new revision
102
+ # ID.
103
+ # @return [String]
104
+ #
105
+ def new_revision_radio(rev_id, current_rev_id)
106
+ g = Ramaze::Gestalt.new
107
+ attrs = {
108
+ :name => 'new_revision_id',
109
+ :id => "new_revision_id_#{rev_id}",
110
+ :type => 'radio',
111
+ :value => rev_id
112
+ }
113
+
114
+ if rev_id.to_i == current_rev_id.to_i
115
+ attrs[:checked] = 'checked'
116
+ end
117
+
118
+ g.input(attrs)
119
+
120
+ return g.to_s
121
+ end
122
+ end # Revision
123
+ end # Helper
124
+ end # Ramaze
@@ -52,7 +52,7 @@ module Ramaze
52
52
  ##
53
53
  # Creates or updates a set of custom fields for a given section entry.
54
54
  #
55
- # @since 17-02-2012
55
+ # @since 2012-02-17
56
56
  # @param [Sections::Model::SectionEntry] entry The entry for which to
57
57
  # create or update the fields.
58
58
  # @return [Hash] Hash containing any errors for the custom fields.
@@ -62,10 +62,9 @@ module Ramaze
62
62
 
63
63
  field_values = {}
64
64
  field_errors = {}
65
-
66
- entry.custom_field_values.each do |value|
67
- field_values[value.custom_field_id] = value
68
- end
65
+ revision = entry.add_revision(
66
+ :user_id => (user.id rescue entry.user_id)
67
+ )
69
68
 
70
69
  entry.custom_fields.each do |field|
71
70
  key = "custom_field_value_#{field.id}"
@@ -80,14 +79,17 @@ module Ramaze
80
79
 
81
80
  next unless request.POST.key?(key)
82
81
 
83
- if field_values.key?(field.id)
84
- field_values[field.id].update(:value => request.POST[key])
85
- else
86
- entry.add_custom_field_value(
87
- :custom_field_id => field.id,
88
- :value => request.POST[key]
89
- )
90
- end
82
+ entry.add_custom_field_value(
83
+ :custom_field_id => field.id,
84
+ :value => request.POST[key],
85
+ :revision_id => revision.id
86
+ )
87
+ end
88
+
89
+ if field_errors.empty?
90
+ entry.update(:revision_id => revision.id)
91
+ else
92
+ revision.destroy
91
93
  end
92
94
 
93
95
  return field_errors
@@ -97,7 +99,7 @@ module Ramaze
97
99
  # Redirects the user to the sections overview and shows a message
98
100
  # informing the user that the section he/she tried to access is invalid.
99
101
  #
100
- # @since 09-04-2012
102
+ # @since 2012-04-09
101
103
  #
102
104
  def redirect_invalid_section
103
105
  message(:error, lang('sections.errors.invalid_section'))
@@ -109,7 +111,7 @@ module Ramaze
109
111
  # section and shows a message informing the user that the section entry
110
112
  # he/she tried to access is invalid.
111
113
  #
112
- # @since 09-04-2012
114
+ # @since 2012-04-09
113
115
  # @param [Fixnum] section_id The ID of the section.
114
116
  #
115
117
  def redirect_invalid_section_entry(section_id)
@@ -1,13 +1,101 @@
1
1
  module Ramaze
2
2
  module Helper
3
3
  ##
4
- # Helper for retrieving section entries in your templates.
4
+ # Helper for retrieving section entries in your templates. See
5
+ # {Ramaze::Helper::SectionFrontend#get\_entries} and
6
+ # {Ramaze::Helper::SectionFrontend#get\_entry}.
5
7
  #
6
8
  # @since 0.3
7
9
  #
8
10
  module SectionFrontend
9
11
  ##
10
12
  # Retrieves a number of entries for a given section ID or section slug.
13
+ # The return value is a Sequel dataset or an empty array in case no rows
14
+ # were found.
15
+ #
16
+ # Each row returned by this method is an instance of
17
+ # {Sections::Model::SectionEntry}. The custom fields and their values of
18
+ # each row are stored as a hash (the keys are symbols) in the "fields"
19
+ # attribute. For example, if you want to access the value of the "body"
20
+ # custom field you can do so as following:
21
+ #
22
+ # get_entries('pages').each do |page|
23
+ # puts page.fields[:body]
24
+ # end
25
+ #
26
+ # Because the returned value is a Sequel dataset paginating content is
27
+ # very easy. This can be done by setting the option `:paginate` to true
28
+ # and calling `#navigation()` on the result set to generate a list of
29
+ # pagination links:
30
+ #
31
+ # pages = get_entries('pages', :paginate => true)
32
+ #
33
+ # pages.each do |page|
34
+ # # ...
35
+ # end
36
+ #
37
+ # pages.navigation
38
+ #
39
+ # ## Lazy Loading
40
+ #
41
+ # To increase performance this method does not automatically retrieve
42
+ # related data such as comments and categories until they are used.
43
+ # However, if you plan on using this data for each returned row it is
44
+ # recommended to eager load this data as you'll otherwise have to execute
45
+ # a number of extra queries for each row.
46
+ #
47
+ # For example, this code block would generate a query for every row in
48
+ # order to retrieve user data:
49
+ #
50
+ # get_entries('pages').each do |page|
51
+ # page.user.email
52
+ # end
53
+ #
54
+ # To work around this problem you can set the option `:user` (or another
55
+ # option depending on the related data you plan on using) to `true`. Doing
56
+ # so will make it possible to retrieve all related rows in a single query:
57
+ #
58
+ # get_entries('pages', :user => true).each do |page|
59
+ # page.user.email
60
+ # end
61
+ #
62
+ # The following options can be set to `true` to enable eager loading
63
+ # (these are set to `false` by default):
64
+ #
65
+ # * comments
66
+ # * categories
67
+ # * user
68
+ #
69
+ # ## Disabling Markup
70
+ #
71
+ # By default each row's markup will be converted to HTML. If you don't
72
+ # need the markup you can disable this to speed things up a bit. This can
73
+ # be done by setting `:markup` to `false`:
74
+ #
75
+ # get_entries('pages', :markup => false).each do |page|
76
+ # page.title
77
+ # end
78
+ #
79
+ # ## Etanni Example
80
+ #
81
+ # Below is an example on how to use this method inside an Etanni template.
82
+ #
83
+ # <?r entries = get_entries('blog', :user => true) ?>
84
+ #
85
+ # <?r entries.each do |entry| ?>
86
+ # <article>
87
+ # <header>
88
+ # <h1>#{entry.title}</h1>
89
+ # <p>Written by #{entry.user.name}</p>
90
+ # </header>
91
+ #
92
+ # <div class="body">
93
+ # #{entry.fields[:body]}
94
+ # </div>
95
+ # </article>
96
+ # <?r end ?>
97
+ #
98
+ # #{entries.navigation}
11
99
  #
12
100
  # @example Retrieving all entries by a section's ID
13
101
  # get_entries(2)
@@ -45,15 +133,15 @@ module Ramaze
45
133
  # results should be paginated.
46
134
  # @option options [String] :var The name of the query string item that
47
135
  # contains the current page number.
48
- # @option options [TrueClass|FalseClass] :field_values Whether or not
49
- # custom fields and their values should be eager loaded. When set to
136
+ # @option options [TrueClass|FalseClass] :custom_field_values Whether or
137
+ # not custom fields and their values should be eager loaded. When set to
50
138
  # false the hash ``fields`` on each entry will **not** be filled.
51
139
  # @option options [TrueClass|FalseClass] :user Whether or not the user
52
140
  # objects should be eager loaded for all entries. Set to ``false`` by
53
141
  # default.
54
142
  # @option options [TrueClass|FalseClass] :markup When set to true
55
143
  # (default) the values of custom fields are processed using
56
- # {Zen::Markup}}.
144
+ # {Zen::Markup}.
57
145
  # @return [Mixed]
58
146
  #
59
147
  def get_entries(section, options = {})
@@ -127,12 +215,22 @@ module Ramaze
127
215
  end
128
216
 
129
217
  ##
130
- # Retrieves the details of a single section entry.
218
+ # Retrieves the details of a single section entry. Due to the nature of
219
+ # this method all related data such as user details and categories are
220
+ # lazy loaded.
131
221
  #
132
- # @example Get a single entry
222
+ # @example Get a single entry by the entry slug.
133
223
  # entry = get_entry('home')
134
224
  #
225
+ # puts entry.title
226
+ #
227
+ # @example Get an entry by its ID.
228
+ # entry = get_entry(10)
229
+ #
230
+ # puts entry.title
231
+ #
135
232
  # @since 0.3
233
+ # @see Ramaze::Helper::SectionFrontend#get_entries()
136
234
  # @param [String|Fixnum] entry The ID or slug of an entry to retrieve.
137
235
  # @param [Hash] options A hash containing various options to customize
138
236
  # the return value.
@@ -0,0 +1,34 @@
1
+ Zen::Language::Translation.add do |trans|
2
+ trans.language = 'en'
3
+ trans.name = 'revisions'
4
+
5
+ trans.translate do |t|
6
+ t['titles.index'] = 'Revisions'
7
+ t['titles.differences'] = 'Differences'
8
+ t['titles.revisions_for'] = 'Revisions for %s'
9
+
10
+ t['labels.old'] = 'Old'
11
+ t['labels.new'] = 'New'
12
+ t['labels.id'] = '#'
13
+ t['labels.user'] = 'User'
14
+ t['labels.created_at'] = 'Created at'
15
+ t['labels.restore'] = 'Restore'
16
+ t['labels.maximum'] = 'Revision amount'
17
+
18
+ t['descriptions.maximum'] = 'The maximum amount of revisions to keep.'
19
+
20
+ t['buttons.compare'] = 'Compare'
21
+
22
+ t['messages.no_differences'] = 'There are no differences between the ' \
23
+ 'two specified revisions.'
24
+
25
+ t['messages.no_revisions'] = 'There are no revisions for this entry.'
26
+
27
+ t['success.restore'] = 'The revision has been restored'
28
+ t['errors.restore'] = 'The revision could not be restored'
29
+ t['errors.invalid'] = 'The specified revision is invalid'
30
+
31
+ t['permissions.show'] = 'Show revision'
32
+ t['permissions.restore'] = 'Restore revision'
33
+ end
34
+ end
@@ -27,6 +27,7 @@ Zen::Language::Translation.add do |trans|
27
27
  t['tabs.general'] = 'General'
28
28
  t['tabs.comment_settings'] = 'Comment Settings'
29
29
  t['tabs.group_assignments'] = 'Group Assignments'
30
+ t['tabs.content'] = 'Content'
30
31
 
31
32
  t['messages.no_sections'] = 'No sections have been created yet.'
32
33
 
@@ -0,0 +1,35 @@
1
+ Zen::Language::Translation.add do |trans|
2
+ trans.language = 'nl'
3
+ trans.name = 'revisions'
4
+
5
+ trans.translate do |t|
6
+ t['titles.index'] = 'Revisies'
7
+ t['titles.differences'] = 'Verschillen'
8
+ t['titles.revisions_for'] = 'Revisies voor %s'
9
+
10
+ t['labels.old'] = 'Oud'
11
+ t['labels.new'] = 'Nieuw'
12
+ t['labels.id'] = '#'
13
+ t['labels.user'] = 'Gebruiker'
14
+ t['labels.created_at'] = 'Aangemaak datum'
15
+ t['labels.restore'] = 'Herstel'
16
+ t['labels.maximum'] = 'Aantal revisies'
17
+
18
+ t['descriptions.maximum'] = 'Het maximale aantal revisies dat behouden ' \
19
+ 'moet blijven.'
20
+
21
+ t['buttons.compare'] = 'Vergelijk'
22
+
23
+ t['messages.no_differences'] = 'Er zijn geen verschillen tussen de twee ' \
24
+ 'geselecteerde revisies.'
25
+
26
+ t['messages.no_revisions'] = 'Er zijn geen revisies voor dit item.'
27
+
28
+ t['success.restore'] = 'De revisie is hersteld'
29
+ t['errors.restore'] = 'De revisie kon niet worden hersteld'
30
+ t['errors.invalid'] = 'De opgegeven revisie is ongeldig'
31
+
32
+ t['permissions.show'] = 'Revisie weergeven'
33
+ t['permissions.restore'] = 'Revisie herstellen'
34
+ end
35
+ end
@@ -27,6 +27,7 @@ Zen::Language::Translation.add do |trans|
27
27
  t['tabs.general'] = 'Algemeen'
28
28
  t['tabs.comment_settings'] = 'Reactie instellingen'
29
29
  t['tabs.group_assignments'] = 'Groepen'
30
+ t['tabs.content'] = 'Inhoud'
30
31
 
31
32
  t['messages.no_sections'] = 'Er konden geen secties worden gevonden.'
32
33
 
@@ -0,0 +1,76 @@
1
+ module Sections
2
+ module Model
3
+ ##
4
+ # Model for storing section entry revisions and linking these to custom
5
+ # field values.
6
+ #
7
+ # @since 2012-04-29
8
+ #
9
+ class Revision < Sequel::Model
10
+ many_to_one :section_entry,
11
+ :class => 'Sections::Model::SectionEntry'
12
+
13
+ many_to_one :user,
14
+ :class => 'Users::Model::User'
15
+
16
+ one_to_many :custom_field_values,
17
+ :class => 'CustomFields::Model::CustomFieldValue'
18
+
19
+ plugin :timestamps, :create => :created_at
20
+
21
+ plugin :association_dependencies,
22
+ :custom_field_values => :delete
23
+
24
+ ##
25
+ # Hook executed before inserting a new row. This hook is used to purge
26
+ # for a section entry if the amount of revisions for such an entry exceeds
27
+ # the maximum amount.
28
+ #
29
+ # @since 2012-05-01
30
+ #
31
+ def before_create
32
+ amount = Revision.filter(:section_entry_id => section_entry_id).count
33
+ max = get_setting(:maximum_revisions).value.to_i
34
+
35
+ if amount >= max
36
+ Revision.filter(:section_entry_id => section_entry_id) \
37
+ .order(:id.asc) \
38
+ .first \
39
+ .delete
40
+ end
41
+
42
+ super
43
+ end
44
+
45
+ ##
46
+ # Hook that is executed before deleting the revision. This hook is used to
47
+ # prevent the last revision of an entry from being deleted.
48
+ #
49
+ # @since 2012-04-29
50
+ #
51
+ def before_destroy
52
+ entry = section_entry
53
+ _id = id
54
+
55
+ # Set the revision ID of the entry to the previous revision.
56
+ if entry.revision_id == _id
57
+ prev_revision = Revision \
58
+ .filter(:section_entry_id => entry.id) { id < _id } \
59
+ .limit(1) \
60
+ .first
61
+
62
+ if prev_revision
63
+ entry.update(:revision_id => prev_revision.id)
64
+ else
65
+ raise(
66
+ Sequel::Error::InvalidOperation,
67
+ 'You can not delete the last revision'
68
+ )
69
+ end
70
+ end
71
+
72
+ super
73
+ end
74
+ end # Revision
75
+ end # Model
76
+ end # Sections