drg_cms 0.4.39 → 0.4.53

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -0
  3. data/app/assets/images/drg_cms/file_manager.png +0 -0
  4. data/app/assets/javascripts/drg_cms/drg_cms.js +8 -8
  5. data/app/assets/stylesheets/drg_cms/drg_cms.css +22 -20
  6. data/app/controllers/cmsedit_controller.rb +170 -114
  7. data/app/controllers/dc_application_controller.rb +142 -56
  8. data/app/controllers/dc_common_controller.rb +56 -34
  9. data/app/controllers/dc_main_controller.rb +1 -4
  10. data/app/controllers/drgcms_controls/dc_page_controls.rb +3 -0
  11. data/app/forms/all_options.yml +3 -0
  12. data/app/forms/cms_menu.yml +100 -117
  13. data/app/forms/dc_design.yml +1 -1
  14. data/app/forms/dc_ident.yml +37 -0
  15. data/app/forms/dc_menu_item.yml +1 -1
  16. data/app/forms/dc_permission.yml +1 -1
  17. data/app/forms/dc_site.yml +4 -0
  18. data/app/helpers/cmsedit_helper.rb +44 -80
  19. data/app/helpers/dc_ad_renderer.rb +27 -15
  20. data/app/helpers/dc_application_helper.rb +433 -196
  21. data/app/helpers/dc_big_menu_renderer.rb +40 -40
  22. data/app/helpers/dc_captcha_renderer.rb +38 -25
  23. data/app/helpers/dc_common_renderer.rb +15 -48
  24. data/app/helpers/dc_menu_renderer.rb +30 -20
  25. data/app/helpers/dc_page_renderer.rb +14 -18
  26. data/app/helpers/dc_part_renderer.rb +45 -16
  27. data/app/helpers/dc_piece_renderer.rb +23 -29
  28. data/app/helpers/dc_poll_renderer.rb +31 -20
  29. data/app/helpers/dc_renderer.rb +5 -4
  30. data/app/helpers/dc_simple_menu_renderer.rb +90 -68
  31. data/app/models/{__dc_global_data.rb → __dc_stat.rb} +20 -21
  32. data/app/models/dc_ad.rb +13 -1
  33. data/app/models/dc_ad_stat.rb +6 -0
  34. data/app/models/dc_big_menu.rb +15 -2
  35. data/app/models/dc_big_table.rb +27 -4
  36. data/app/models/dc_big_table_locale.rb +7 -0
  37. data/app/models/dc_big_table_value.rb +7 -0
  38. data/app/models/dc_category.rb +9 -3
  39. data/app/models/dc_design.rb +50 -0
  40. data/app/models/dc_dummy.rb +41 -1
  41. data/app/models/dc_folder_permission.rb +9 -2
  42. data/app/models/{dc_global_data.rb → dc_ident.rb} +20 -22
  43. data/app/models/dc_journal.rb +9 -1
  44. data/app/models/dc_key_value_store.rb +41 -4
  45. data/app/models/dc_link.rb +7 -0
  46. data/app/models/dc_menu.rb +20 -3
  47. data/app/models/dc_menu_item.rb +7 -0
  48. data/app/models/dc_page.rb +31 -12
  49. data/app/models/dc_part.rb +34 -4
  50. data/app/models/dc_permission.rb +32 -12
  51. data/app/models/dc_piece.rb +32 -4
  52. data/app/models/dc_policy.rb +17 -11
  53. data/app/models/dc_policy_role.rb +12 -7
  54. data/app/models/dc_policy_rule.rb +32 -4
  55. data/app/models/dc_poll.rb +8 -0
  56. data/app/models/dc_poll_item.rb +6 -0
  57. data/app/models/dc_simple_menu.rb +18 -3
  58. data/app/models/dc_simple_menu_item.rb +20 -2
  59. data/app/models/dc_site.rb +13 -3
  60. data/app/models/dc_stat.rb +8 -1
  61. data/app/models/dc_user.rb +18 -2
  62. data/app/models/dc_user_role.rb +7 -0
  63. data/app/models/dc_visit.rb +5 -0
  64. data/app/{helpers → models}/drgcms_form_field.rb +171 -73
  65. data/app/views/__dc_at_the_beginning/create.html.erb +9 -0
  66. data/app/views/__dc_at_the_beginning/index.html.erb +19 -0
  67. data/app/views/cmsedit/_edit_stuff.html.erb +2 -0
  68. data/app/views/cmsedit/_form.html.erb +0 -1
  69. data/app/views/dc_mail/subscribe.html.erb +0 -0
  70. data/config/initializers/kaminari_patch.rb +5 -4
  71. data/config/locales/drgcms_en.yml +4 -0
  72. data/config/locales/drgcms_sl.yml +1 -0
  73. data/config/locales/models_en.yml +14 -3
  74. data/config/locales/models_sl.yml +13 -4
  75. data/drg_cms.gemspec +4 -4
  76. data/lib/drg_cms.rb +37 -8
  77. data/lib/drg_cms/engine.rb +2 -2
  78. data/lib/drg_cms/version.rb +3 -2
  79. data/lib/tasks/at_the_beginning.yml +0 -0
  80. data/lib/tasks/dc_at_the_beginning.rake +118 -0
  81. data/lib/tasks/dc_cleanup.rake +19 -7
  82. data/lib/tasks/log_statistics.rb +66 -0
  83. data/lib/tasks/site_statistics.rake +29 -12
  84. data/test/dummy/app/controllers/application_controller.rb +1 -1
  85. data/test/dummy/app/helpers/application_helper.rb +1 -1
  86. metadata +15 -26
  87. data/README.rdoc +0 -3
  88. data/app/controllers/dc_at_the_beginning_controller.rb +0 -120
  89. data/app/controllers/dc_mail_controller.rb +0 -89
  90. data/app/forms/dc_forum_cat.yml +0 -54
  91. data/app/forms/dc_forum_forum.yml +0 -53
  92. data/app/forms/dc_forum_msg.yml +0 -124
  93. data/app/forms/dc_forum_privmsg.yml +0 -125
  94. data/app/forms/dc_forum_topic.yml +0 -131
  95. data/app/forms/dc_mail.yml +0 -88
  96. data/app/forms/dc_mail_address.yml +0 -56
  97. data/app/forms/dc_mail_list.yml +0 -44
  98. data/app/forms/dc_mail_list_member.yml +0 -42
  99. data/app/helpers/dc_mail_renderer.rb +0 -76
  100. data/app/models/dc_mail.rb +0 -64
  101. data/app/models/dc_mail_address.rb +0 -69
  102. data/app/models/dc_mail_list.rb +0 -48
  103. data/app/models/dc_mail_list_member.rb +0 -34
  104. data/app/models/dc_sendmail.rb +0 -48
@@ -22,7 +22,18 @@
22
22
  #++
23
23
 
24
24
  ########################################################################
25
- #
25
+ # Ads renderer. Typically ads renderer is defined in design like this.
26
+ # <div id="ads-on-top">
27
+ # <%= dc_render(:dc_ad, position: 'top') %>
28
+ # </div>
29
+ #
30
+ # There can be more than one ad shown on the same position. Therefore Ads can be grouped by position
31
+ # they are displayed at. Position name can be any string. I suggest using top, right ...
32
+ #
33
+ # Ads may be prioritized. Higher priority means higher probability that ad will be selected for display.
34
+ #
35
+ # Clicks on picture and flash can be intercepted and are saved into dc_ad_stat table.
36
+ # It is also possible to limit number of times ad will be displayed or clicked.
26
37
  ########################################################################
27
38
  class DcAdRenderer
28
39
 
@@ -31,7 +42,7 @@ include DcApplicationHelper
31
42
  ########################################################################
32
43
  #
33
44
  ########################################################################
34
- def initialize( parent, opts={} )
45
+ def initialize( parent, opts={} ) #:nodoc:
35
46
  @parent = parent
36
47
  @opts = opts
37
48
  @css = ''
@@ -39,9 +50,9 @@ def initialize( parent, opts={} )
39
50
  end
40
51
 
41
52
  ########################################################################
42
- #
53
+ # Finds ads that will be rendered. Subroutine of multi method.
43
54
  ########################################################################
44
- def find_ads_multi()
55
+ def find_ads_multi() #:nodoc:
45
56
  ads = DcAd.where( position: @opts[:position], active: true).to_a#, :valid_to.gt => Time.now, :valid_from.lt => Time.now).to_a
46
57
  #p @opts, ads.size, '*-*-*-*'
47
58
  ads.delete_if { |ad| (ad.valid_to and ad.valid_to < Time.now) or
@@ -53,7 +64,8 @@ def find_ads_multi()
53
64
  end
54
65
 
55
66
  ########################################################################
56
- # Default method for rendering ads
67
+ # This is an experiment of how to render multiple ads on same location simultaneously by
68
+ # fade in and out div on which ad resides.
57
69
  ########################################################################
58
70
  def multi
59
71
  return '' if @parent.session[:is_robot] # don't bother if robot
@@ -103,7 +115,7 @@ EOJS
103
115
  end
104
116
 
105
117
  ########################################################################
106
- #
118
+ # Determines which add will be displayed next. Subroutine of default method.
107
119
  ########################################################################
108
120
  def find_ad_to_display()
109
121
  ads = DcAd.where( dc_site_id: @parent.site._id, position: @opts[:position], active: true).to_a#, :valid_to.gt => Time.now, :valid_from.lt => Time.now).to_a
@@ -126,9 +138,9 @@ def find_ad_to_display()
126
138
  end
127
139
 
128
140
  ########################################################################
129
- # Create flash link for ad
141
+ # Code for flash ad.
130
142
  ########################################################################
131
- def flash_link(ad)
143
+ def flash_ad(ad)
132
144
  click_tag = ad.link.to_s.size > 5 ? "flashvars=\"clickTag=#{ad.link}\"" : ''
133
145
  <<EOT
134
146
  <div class="link_to_track" id="#{ad.id}">
@@ -149,14 +161,14 @@ EOT
149
161
  end
150
162
 
151
163
  ########################################################################
152
- # Create picture link for ad
164
+ # Code for picture ad.
153
165
  ########################################################################
154
- def picture_link(ad)
166
+ def picture_ad(ad)
155
167
  @parent.link_to @parent.image_tag(ad.file), ad.link, id: ad.id, class: 'link_to_track', target: ad.link_target
156
168
  end
157
169
 
158
170
  ########################################################################
159
- # Default method for rendering ads
171
+ # Default method for rendering ads.
160
172
  ########################################################################
161
173
  def default
162
174
  return '' if @parent.session[:is_robot] # don't bother if robot
@@ -171,9 +183,9 @@ def default
171
183
  end
172
184
  html << case ad.type
173
185
  when 1 then # picture
174
- picture_link ad
186
+ picture_ad ad
175
187
  when 2 then # flash
176
- flash_link ad
188
+ flash_ad ad
177
189
  when 3 then # script
178
190
  ad.script
179
191
  else
@@ -184,7 +196,7 @@ def default
184
196
  end
185
197
 
186
198
  ########################################################################
187
- # Render HTML
199
+ # Renderer dispatcher. Method returns HTML part of code.
188
200
  ########################################################################
189
201
  def render_html
190
202
  method = @opts[:method] || 'default'
@@ -197,7 +209,7 @@ def render_html
197
209
  end
198
210
 
199
211
  ########################################################################
200
- # Render CSS
212
+ # Render CSS. This method returns css part of code.
201
213
  ########################################################################
202
214
  def render_css
203
215
  @css
@@ -22,42 +22,75 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #++
24
24
 
25
+
26
+ ###########################################################################
27
+ #
28
+ # DcApplicationHelper defines common helper methods for using with DRG CMS.
29
+ #
30
+ ###########################################################################
25
31
  module DcApplicationHelper
26
- attr_reader :page, :design, :site, :tables, :ids, :form, :options
32
+ # page document
33
+ attr_reader :page
34
+ # design document
35
+ attr_reader :design
36
+ # site document
37
+ attr_reader :site
38
+ # tables url parameter
39
+ attr_reader :tables
40
+ # ids url parameter
41
+ attr_reader :ids
42
+ # form object
43
+ attr_reader :form
44
+ # options object
45
+ attr_reader :options
46
+
47
+ # all parts read from page, design, ...
27
48
  attr_accessor :parts
28
49
 
29
50
  ############################################################################
30
- # Calls part renderer to return part of design.
51
+ # This is main method used for render parts of design into final HTML document.
52
+ #
53
+ # Parameters:
54
+ # [renderer] String or Symbol. Class name (in lowercase) that will be used to render final HTML code.
55
+ # If class name is provided without '_renderer' suffix it will be added automatically.
56
+ # [opts] Hash. Additional options that are passed to method. Options are merged with
57
+ # options set on site, design, page and passed to renderer object.
58
+ #
59
+ # Example:
60
+ # <%= dc_render(:dc_page, method: 'view', category: 'news') %>
31
61
  ############################################################################
32
62
  def dc_render(renderer, opts={})
33
- type = renderer.to_s.downcase
34
63
  opts[:edit_mode] = session[:edit_mode]
35
- # TODO Check why did I always put return_to into link and will this break something
36
- # opts[:editparams] = { return_to: request.url }
37
64
  opts[:editparams] = {}
38
65
  opts = @options.merge(opts) # merge options with parameters passed on site, page, design ...
39
- opts.symbolize_keys! # this makes lots of things easier
66
+ opts.symbolize_keys! # this makes lots of things easier
40
67
  # Create renderer object
41
- klass = (type + '_renderer').classify
42
- obj = Kernel.const_get(klass, Class.new).new(self, opts)
68
+ klass = renderer.to_s.downcase
69
+ klass += '_renderer' unless klass.match('_renderer') #
70
+ obj = Kernel.const_get(klass.classify, Class.new).new(self, opts) rescue nil
43
71
  #
44
- html = obj.render_html
45
- @css << obj.render_css.to_s
46
- html.nil? ? '' : html.html_safe # nil can happened
72
+ if obj
73
+ html = obj.render_html
74
+ @css << obj.render_css.to_s
75
+ html.nil? ? '' : html.html_safe # nil can happened
76
+ else
77
+ "Class #{klass} not defined!"
78
+ end
47
79
  end
48
80
 
49
81
  ########################################################################
50
- # Used for designs with lots of common code and one part which is different.
82
+ # Used for designs with lots of common code and one (or more) part which differs.
83
+ # It will simply replace anchor code with value of variable.
51
84
  #
52
85
  # Example: As used in design. Backslashing < and % is important \<\%
53
- # <% part = "<div class='some-class'>\<\%= dc_render(:my_renderer, method: 'render_method') \%\></div>" %>
54
- # <%= dc_replace_in_design(piece: 'piece_name', replace: '[main]', with: part) %>
86
+ # <% part = "<div class='some-class'>\<\%= dc_render(:my_renderer, method: 'render_method') \%\></div>" %>
87
+ # <%= dc_replace_in_design(piece: 'piece_name', replace: '[main]', with: part) %>
55
88
  #
56
89
  # Want to replace more than one part. Use array.
57
- # <%= dc_replace_in_design(replace: ['[part1]','[part2]'], with: [part1, part2]) %>
90
+ # <%= dc_replace_in_design(replace: ['[part1]','[part2]'], with: [part1, part2]) %>
58
91
  #
59
- # This helper is replacement for 'script' method defined in dc_piece_renderer,
60
- # but it can also use design defined in site document if piece parameter is not set.
92
+ # This helper is replacement for old 'script' method defined in dc_piece_renderer,
93
+ # but it uses design defined in site document if piece parameter is not set.
61
94
  ########################################################################
62
95
  def dc_replace_in_design(opts={})
63
96
  design = opts[:piece] ? DcPiece.find(name: opts[:piece]).script : dc_get_site.design
@@ -73,26 +106,38 @@ def dc_replace_in_design(opts={})
73
106
  end
74
107
 
75
108
  ########################################################################
109
+ # Old method name.
76
110
  ########################################################################
77
- def dc_render_design(opts={}) #NODOC
111
+ def dc_render_design(opts={}) #:nodoc:
78
112
  p "dc_render_design will be deprecated. Use dc_replace_in_design instead."
79
113
  dc_replace_in_design(opts)
80
114
  end
81
115
 
82
116
  ############################################################################
83
- # Creates title for dialog. Title also has pagination link on its right side.
117
+ # Creates title div for DRG CMS dialogs. Title may also contain pagination section on right side if
118
+ # result_set is provided as parameter.
119
+ #
120
+ # Parameters:
121
+ # [text] String. Title caption.
122
+ # [result_set=nil] Document collection. If result_set is passed pagination links will be created.
123
+ #
124
+ # Returns:
125
+ # String. HTML code for title.
84
126
  ############################################################################
85
- def dc_table_title(text, result=nil)
127
+ def dc_table_title(text, result_set=nil)
86
128
  c = "<table width='100%' cellspacing='0' cellpadding='1' class='dc-title'><tr><td>#{text}</td>"
87
- if result and result.respond_to?(:current_page)
88
- c << "<td align='right' style='font-size: 0.8em;'> #{paginate(result, :params => {:action => 'index'})}</td>"
129
+ if result_set and result_set.respond_to?(:current_page)
130
+ c << "<td align='right' style='font-size: 0.8em;'> #{paginate(result_set, :params => {:action => 'index'})}</td>"
89
131
  end
90
132
  c << '<tr></table>'
91
133
  c.html_safe
92
134
  end
93
135
 
94
136
  ############################################################################
95
- # Creates title for cmsedit edit dialog.
137
+ # Creates title for cmsedit edit action dialog.
138
+ #
139
+ # Returns:
140
+ # String. HTML code for title.
96
141
  ############################################################################
97
142
  def dc_edit_title()
98
143
  c = "#{t('drgcms.edit')} : "
@@ -103,7 +148,10 @@ def dc_edit_title()
103
148
  end
104
149
 
105
150
  ############################################################################
106
- # Creates title for cmsedit new dialog.
151
+ # Creates title for cmsedit new action dialog.
152
+ #
153
+ # Returns:
154
+ # String. HTML code for title.
107
155
  ############################################################################
108
156
  def dc_new_title()
109
157
  if @form['table'] == 'dc_dummy'
@@ -114,7 +162,11 @@ def dc_new_title()
114
162
  end
115
163
 
116
164
  ####################################################################
117
- # Creates label for edit dialog.
165
+ # Formats label and html input code for display on edit form.
166
+ #
167
+ # Parameters:
168
+ # [input_html] String. HTML code for data input field.
169
+ # [label] String. Input field label.
118
170
  ####################################################################
119
171
  def dc_label_for(input_html, label)
120
172
  c =<<eot
@@ -127,7 +179,10 @@ eot
127
179
  end
128
180
 
129
181
  ####################################################################
130
- # Returns messages saved in flash formated for display.
182
+ # Returns flash messages formatted for display on message div.
183
+ #
184
+ # Returns:
185
+ # String. HTML code formatted for display.
131
186
  ####################################################################
132
187
  def dc_flash_messages()
133
188
  err = @parent ? @parent.flash[:error] : flash[:error]
@@ -158,11 +213,17 @@ end
158
213
  ########################################################################
159
214
  # Decamelizes string. This probably doesn't work very good with non ascii chars.
160
215
  # Therefore it is very unwise to use non ascii chars for table (collection) names.
216
+ #
217
+ # Parameters:
218
+ # [string] String. String to be converted into decamelized string.
219
+ #
220
+ # Returns:
221
+ # String. Decamelized string.
161
222
  ########################################################################
162
- def decamelize_type(st)
163
- return nil if st.nil?
223
+ def decamelize_type(string)
224
+ return nil if string.nil?
164
225
  r = ''
165
- st.to_s.each_char do |c|
226
+ string.to_s.each_char do |c|
166
227
  r << case
167
228
  when r.size == 0 then c.downcase
168
229
  when c.downcase != c then '_' + c.downcase
@@ -173,19 +234,26 @@ def decamelize_type(st)
173
234
  end
174
235
 
175
236
  ####################################################################
176
- # return error messages for the record
237
+ # Returns validation error messages for the document (record) formatted for
238
+ # display on message div.
239
+ #
240
+ # Parameters:
241
+ # [doc] Document. Document record which will be checked for errors.
242
+ #
243
+ # Returns:
244
+ # String. HTML code formatted for display.
177
245
  ####################################################################
178
- def dc_error_messages_for(r)
179
- return '' unless r.errors.any?
246
+ def dc_error_messages_for(doc)
247
+ return '' unless doc.errors.any?
180
248
  msgs = ''
181
- r.errors.each do |attribute, errors_array|
182
- label = t("helpers.label.#{decamelize_type(r.class)}.#{attribute}", attribute)
249
+ doc.errors.each do |attribute, errors_array|
250
+ label = t("helpers.label.#{decamelize_type(doc.class)}.#{attribute}", attribute)
183
251
  msgs << "<li>#{label} : #{errors_array}</li>"
184
252
  end
185
253
 
186
254
  c = <<eot
187
255
  <div class="dc-form-error">
188
- <h2>#{t('drgcms.errors_no')} #{r.errors.size}</h2>
256
+ <h2>#{t('drgcms.errors_no')} #{doc.errors.size}</h2>
189
257
  <ul>#{msgs}</ul>
190
258
  </div>
191
259
  eot
@@ -193,14 +261,30 @@ eot
193
261
  end
194
262
 
195
263
  ####################################################################
196
- # return true if in edit mode
264
+ # Checks if CMS is in edit mode (CMS menu bar is visible).
265
+ #
266
+ # Returns:
267
+ # Boolean. True if in edit mode
197
268
  ####################################################################
198
269
  def dc_edit_mode?
199
270
  (@parent ? @parent.session[:edit_mode] : session[:edit_mode]) > 1
200
271
  end
201
272
 
202
273
  ####################################################################
203
- # Return create link for drg_cms
274
+ # Will create HTML code required to create new document.
275
+ #
276
+ # Parameters:
277
+ # [opts] Hash. Optional parameters for url_for helper. These options must provide at least table and formname
278
+ # parameters.
279
+ #
280
+ # Example:
281
+ # if @opts[:edit_mode] > 1
282
+ # opts = {table: 'dc_page;dc_part', formname: 'dc_part', ids: @doc.id }
283
+ # html << dc_link_for_create( opts.merge!({title: 'Add new part', 'dc_part.name' => 'initial name', 'dc_part.order' => 10}) )
284
+ # end
285
+ #
286
+ # Returns:
287
+ # String. HTML code which includes add image and javascript to invoke new document create action.
204
288
  ####################################################################
205
289
  def dc_link_for_create(opts)
206
290
  title = opts.delete(:title) #
@@ -217,7 +301,17 @@ def dc_link_for_create(opts)
217
301
  end
218
302
 
219
303
  ####################################################################
304
+ # Will create HTML code required to edit document.
220
305
  #
306
+ # Parameters:
307
+ # [opts] Hash. Optional parameters for url_for helper. These options must provide at least table and formname
308
+ # and id parameters.
309
+ #
310
+ # Example:
311
+ # html << dc_link_for_edit( @options ) if @opts[:edit_mode] > 1
312
+ #
313
+ # Returns:
314
+ # String. HTML code which includes edit image and javascript to invoke edit document action.
221
315
  ####################################################################
222
316
  def dc_link_for_edit(opts)
223
317
  title = opts.delete(:title) #
@@ -235,9 +329,9 @@ def dc_link_for_edit(opts)
235
329
  end
236
330
 
237
331
  ####################################################################
238
- # Create edit link for drg_cms
332
+ # Create edit link with edit picture. Subroutine of dc_page_edit_menu.
239
333
  ####################################################################
240
- def dc_link_menu_tag(title)
334
+ def dc_link_menu_tag(title) #:nodoc:
241
335
  html =<<EOT
242
336
  <dl>
243
337
  <dt><div class='drgcms_popmenu' href="#"><span><img style="cursor:pointer;" src="/assets/drg_cms/edit.png" title="#{title}"></span></div></dt>
@@ -249,18 +343,33 @@ EOT
249
343
  end
250
344
 
251
345
  ####################################################################
252
- # Create one option in page edit link
346
+ # Create one option in page edit link. Subroutine of dc_page_edit_menu.
253
347
  ####################################################################
254
- def dc_link_for_edit1(opts, link_text) #NODOC
348
+ def dc_link_for_edit1(opts, link_text) #:nodoc:
255
349
  url = @parent.url_for(opts)
256
350
  "<li><div class='drgcms_popmenu_item' style='cursor: pointer;' data-url='#{url}'>#{link_text}</div></li>\n"
257
351
  end
258
352
 
259
353
  ########################################################################
260
- # Create edit menu for dc_page document.
354
+ # Create edit menu for editing existing or creating new dc_page documents. Edit menu
355
+ # consists of for options.
356
+ # * Edit content. Will edit only body part od document.
357
+ # * Edit advanced. Will create edit form for editing all document fields.
358
+ # * New page. Will create new document and pass some initial data to it. Initial data is saved to cookie.
359
+ # * New part. Will create new part of document.
360
+ #
361
+ # Parameters:
362
+ # [opts] Hash. Optional parameters for url_for helper. These options must provide at least table and formname
363
+ # and id parameters.
364
+ #
365
+ # Example:
366
+ # html << dc_page_edit_menu() if @opts[:edit_mode] > 1
367
+ #
368
+ # Returns:
369
+ # String. HTML code required for manipulation of currently processed document.
261
370
  ########################################################################
262
- def dc_page_edit_menu()
263
- return '' if @opts[:edit_mode] < 2
371
+ def dc_page_edit_menu(opts=@opts)
372
+ return '' if opts[:edit_mode] < 2
264
373
  # save some data to cookie. This can not go to session.
265
374
  t = @parent.site.page_table
266
375
  kukis = { "#{t}.dc_design_id" => @page.dc_design_id,
@@ -272,82 +381,110 @@ def dc_page_edit_menu()
272
381
  @parent.cookies[:record] = Marshal.dump(kukis)
273
382
  title = "#{t('drgcms.edit')}: #{@page.subject}"
274
383
  dc_link_menu_tag(title) do |html|
275
- @opts[:editparams].merge!( :controller => 'cmsedit', :action => 'edit' )
276
- @opts[:editparams].merge!( :id => @page.id, :table => @parent.site.page_table, formname: nil, edit_only: 'body' )
277
- html << dc_link_for_edit1( @opts[:editparams], t('drgcms.edit_content') )
384
+ opts[:editparams].merge!( :controller => 'cmsedit', :action => 'edit' )
385
+ opts[:editparams].merge!( :id => @page.id, :table => @parent.site.page_table, formname: nil, edit_only: 'body' )
386
+ html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_content') )
278
387
 
279
- @opts[:editparams][:edit_only] = nil
280
- html << dc_link_for_edit1( @opts[:editparams], t('drgcms.edit_advanced') )
388
+ opts[:editparams][:edit_only] = nil
389
+ html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_advanced') )
281
390
 
282
- @opts[:editparams][:action] = 'new'
283
- html << dc_link_for_edit1( @opts[:editparams], t('drgcms.edit_new_page') )
391
+ opts[:editparams][:action] = 'new'
392
+ html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_new_page') )
284
393
 
285
- @opts[:editparams].merge!(ids: @page.id, formname: 'dc_part', table: "#{@parent.site.page_table};dc_part" )
286
- html << dc_link_for_edit1( @opts[:editparams], t('drgcms.edit_new_part') )
394
+ opts[:editparams].merge!(ids: @page.id, formname: 'dc_part', table: "#{@parent.site.page_table};dc_part" )
395
+ html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_new_part') )
287
396
  end
288
397
  end
289
398
 
290
399
  ########################################################################
291
- # Return page class (from site record) which defines page_class table (collection)
292
- # used for saving page data.
400
+ # Return page class model defined in site document page_class field.
293
401
  #
294
- # Mostly used by forms, when some method must be called from page model.
402
+ # Used in forms, when method must be called from page model and model is overwritten by
403
+ # user's own model.
295
404
  #
296
- # @example usage from form description:
405
+ # Example as used on form:
297
406
  # 30:
298
407
  # name: link
299
408
  # type: text_with_select
300
- # eval: 'DcPageClass.all_pages_for_site(@parent.dc_get_site)'
409
+ # eval: 'dc_page_class.all_pages_for_site(@parent.dc_get_site)'
301
410
  ########################################################################
302
411
  def dc_page_class()
303
- dc_get_site.page_class.classify.constantize
412
+ dc_get_site.page_class.classify.constantize
304
413
  end
305
414
 
306
415
  ####################################################################
307
- # Wrapper for i18 t method, with some spice added
416
+ # Wrapper for i18 t method, with some spice added. If translation is not found English
417
+ # translation value will be returned. And if still not found default value will be returned if passed.
418
+ #
419
+ # Parameters:
420
+ # [key] String. String to be translated into locale.
421
+ # [default] String. Value returned if translation is not found.
422
+ #
423
+ # Example:
424
+ # t('translate.this','Enter text for ....')
425
+ #
426
+ # Returns:
427
+ # String. Translated text.
308
428
  ####################################################################
309
429
  def t(key, default='')
310
430
  c = I18n.t(key)
311
431
  if c.class == Hash or c.match( 'translation missing' )
312
432
  c = I18n.t(key, locale: 'en')
313
433
  # Still not found. Return default if set
314
- c = default unless default.blank?
434
+ c = default if c.match( 'translation missing' ) and !default.blank?
315
435
  end
316
436
  c
317
437
  end
318
438
 
319
439
  ####################################################################
320
- # Returns translated tablename.
440
+ # Returns table (collection) name translation for usage in dialog title. Tablename
441
+ # title is provided by helpers.label.table_name.tabletitle locale.
442
+ #
443
+ # Parameters:
444
+ # [tablename] String. Table (collection) name to be translated.
445
+ # [default] String. Value returned if translation is not found.
446
+ #
447
+ # Returns:
448
+ # String. Translated text.
321
449
  ####################################################################
322
450
  def t_tablename(tablename, default=nil)
323
451
  t('helpers.label.' + tablename + '.tabletitle', default || tablename)
324
452
  end
325
453
 
326
454
  ############################################################################
327
- # Translation for field name label.
455
+ # Returns label for field translated to current locale for usage on data entry form.
456
+ # Translation is provided by lang.helpers.label.table_name.field_name locale. If
457
+ # translation is not found method will capitalize field_name and replace '_' with ' '.
328
458
  ############################################################################
329
- def t_name(name, default='')
330
- c = t("helpers.label.#{@form['table']}.#{name}", default)
331
- c = name.capitalize.gsub('_',' ') if c.match( 'translation missing' )
459
+ def t_name(field_name, default='')
460
+ c = t("helpers.label.#{@form['table']}.#{field_name}", default)
461
+ c = field_name.capitalize.gsub('_',' ') if c.match( 'translation missing' )
332
462
  c
333
463
  end
334
464
 
335
465
  ############################################################################
336
- # Return name (description) for specified field in document
466
+ # When select field is used on form options for select can be provided by
467
+ # helpers.label.table_name.choices4_name locale. This is how select
468
+ # field options are translated. Method returns selected choice translated
469
+ # to current locale.
337
470
  #
338
- # @example usage from program
339
- # dc_name4_value('dc_user', 'name', text.id)
340
- #
341
- # @example usage from form description
342
- # columns:
343
- # 2:
344
- # name: site_id
345
- # eval: dc_name4_value('site','name',@record['site_id'])
346
- #
347
- # @param [ model ] table (collection) model name.
348
- # @param [ field ] field name to return
349
- # @param [ id ] id to search for
471
+ # Parameters:
472
+ # [model] String. Table (collection) model name (lowercase).
473
+ # [field] String. Field name used.
474
+ # [value] String. Value of field which translation will be returned.
350
475
  #
476
+ # Example:
477
+ # # usage in program. Choice values for state are 'Deactivated:0,Active:1,Waiting:2'
478
+ # dc_name4_value('dc_user', 'state', @record.active )
479
+ #
480
+ # # usage in form
481
+ # columns:
482
+ # 2:
483
+ # name: state
484
+ # eval: dc_name4_value dc_user, state
485
+ #
486
+ # Returns:
487
+ # String. Descriptive text (translated) for selected choice value.
351
488
  ############################################################################
352
489
  def dc_name4_value(model, field, value)
353
490
  return '' if value.nil?
@@ -358,21 +495,26 @@ def dc_name4_value(model, field, value)
358
495
  end
359
496
 
360
497
  ############################################################################
361
- # Return name (description) for specified table and id
498
+ # Will return descriptive text for id key when field in one table (collection) has belongs_to
499
+ # relation to other table.
362
500
  #
363
- # @example usage from program
364
- # dc_name4_id('dc_user', 'name', text.id)
365
- #
366
- # @example usage from form description
367
- # columns:
368
- # 2:
369
- # name: site_id
370
- # eval: name4_id('site','name',@record['site_id'])
501
+ # Parameters:
502
+ # [model] String. Table (collection) model name (lowercase).
503
+ # [field] String. Field name holding the value of descriptive text.
504
+ # [id] BSON Key. Key value.
505
+ #
506
+ # Example:
507
+ # # usage in program.
508
+ # dc_name4_id('dc_user', 'name', dc_page.created_by)
371
509
  #
372
- # @param [ model ] table (collection) model name.
373
- # @param [ field ] field name to return
374
- # @param [ id ] id to search for
510
+ # # usage in form
511
+ # columns:
512
+ # 2:
513
+ # name: site_id
514
+ # eval: dc_name4_id,site,name
375
515
  #
516
+ # Returns:
517
+ # String. Name (descriptive value) for specified key in table.
376
518
  ############################################################################
377
519
  def dc_name4_id(model, field, id)
378
520
  return '' if id.nil?
@@ -382,37 +524,55 @@ def dc_name4_id(model, field, id)
382
524
  end
383
525
 
384
526
  ############################################################################
385
- # Return icon representation for boolean value. Icon is a picture of checked or unchecked box.
527
+ # Return html code for icon presenting boolean value. Icon is a picture of checked or unchecked box.
386
528
  #
387
- # @example usage from program
388
- # dc_icon4_boolean(some_value)
389
- #
390
- # @example usage from form description
391
- # columns:
392
- # 10:
393
- # name: active
394
- # eval: dc_icon4_boolean
529
+ # Parameters:
530
+ # [value] Boolean.
531
+ #
532
+ # Example:
533
+ # # usage from program
534
+ # dc_icon4_boolean(some_value)
395
535
  #
396
- # @param [ value ] value
536
+ # # usage from form description
537
+ # columns:
538
+ # 10:
539
+ # name: active
540
+ # eval: dc_icon4_boolean
397
541
  ############################################################################
398
- def dc_icon4_boolean(val)
399
- dc_dont?(val) ? image_tag('drg_cms/checkbox-unchecked.png') : image_tag('drg_cms/checkbox-checked.png')
542
+ def dc_icon4_boolean(value)
543
+ dc_dont?(value) ? image_tag('drg_cms/checkbox-unchecked.png') : image_tag('drg_cms/checkbox-checked.png')
400
544
  end
401
545
 
402
546
  ############################################################################
403
- # Safely output date/time value in desired format. Will return '' if value is nil.
547
+ # Returns html code for displaying date/time formatted by strftime. Will return '' if value is nil.
404
548
  #
405
- # Mostly used for calling from views.
549
+ # Parameters:
550
+ # [value] Date/DateTime/Time.
551
+ # [format] String. strftime format mask. Defaults to locale's default format.
406
552
  ############################################################################
407
- def dc_date_time(val, default=nil)
408
- return '' if val.nil?
409
- default = ( val.class == Date ? t('date.formats.default') : t('time.formats.default') ) if default.nil?
410
- val.strftime(default)
553
+ def dc_format_date_time(value, format=nil)
554
+ return '' if value.nil?
555
+ format ||= value.class == Date ? t('date.formats.default') : t('time.formats.default')
556
+ value.strftime(format)
411
557
  end
412
558
 
413
559
  ####################################################################
414
- # Determine and return site record from url. Site record will be cached in
560
+ #
561
+ ####################################################################
562
+ def dc_date_time(value, format) #:nodoc:
563
+ p 'dc_date_time will be deprecated! Use dc_format_date_time instead.'
564
+ dc_format_date_time(value, format)
565
+ end
566
+
567
+ ####################################################################
568
+ # Parse site name from url and return dc_site document. Site document will be cached in
415
569
  # @site variable.
570
+ #
571
+ # If not in production environment and site document is not found
572
+ # method will search for 'test' document and return dc_site document found in alias_for field.
573
+ #
574
+ # Returns:
575
+ # DCSite. Site document.
416
576
  ####################################################################
417
577
  def dc_get_site()
418
578
  return @site if @site # already cached
@@ -425,7 +585,7 @@ def dc_get_site()
425
585
  @site = DcSite.find_by(name: @site.alias_for)
426
586
  end
427
587
  # Development environment. Check if site with name test exists and use
428
- # homepagelink field as pointer to real site name.
588
+ # alias_for field as pointer to real site name.
429
589
  if @site.nil? and ENV["RAILS_ENV"] != 'production'
430
590
  @site = DcSite.find_by(name: 'test')
431
591
  @site = DcSite.find_by(name: @site.alias_for) if @site
@@ -436,9 +596,10 @@ end
436
596
 
437
597
  ############################################################################
438
598
  # Return array of policies defined in a site document formated to be used
439
- # as choices select field, where policy_id field is defined in document.
599
+ # as choices for select field. Method is used for selecting site policy where
600
+ # policy for displaying data is required.
440
601
  #
441
- # @example (as used in forms)
602
+ # Example (as used in forms):
442
603
  # name: policy_id
443
604
  # type: select
444
605
  # eval: dc_choices4_site_policies
@@ -451,51 +612,77 @@ def dc_choices4_site_policies()
451
612
  end
452
613
 
453
614
  ############################################################################
454
- # Returns list of table names (collections) as array of choices for use in select field
455
- # on data permission form. Method gets list of available collections from
456
- # cms_menu.yml menu definition file.
615
+ # Returns list of all collections (tables) as array of choices for usage in select fields.
616
+ # List is collected from cms_menu.yml files and may not include all collections used in application.
617
+ # Currently list is only used for helping defining collection names on dc_permission form.
457
618
  #
458
- # @example (as used in forms)
459
- # eval: dc_choices4_tables_list
460
- ############################################################################
461
- def dc_choices4_tables_list
462
- menus = []
619
+ # Example (as used in forms):
620
+ # form:
621
+ # fields:
622
+ # 10:
623
+ # name: table_name
624
+ # type: text_with_select
625
+ # eval: dc_choices4_all_collections
626
+ ############################################################################
627
+ def dc_choices4_all_collections
628
+ choices = {}
463
629
  DrgCms.paths(:forms).reverse.each do |path|
464
- f = "#{path}/cms_menu.yml"
465
- menus << YAML.load_file(f)['menu'] if File.exist?(f)
630
+ filename = "#{path}/cms_menu.yml"
631
+ next unless File.exist?(filename)
632
+ #
633
+ menu = YAML.load_file(filename) rescue nil # load menu
634
+ next if menu.nil? or !menu['menu'] # not menu or error
635
+ menu['menu'].each do |section|
636
+ next unless section.last['items'] # next if no items
637
+ section.last['items'].each do |k, v| # look for caption and
638
+ key = v['params']['table']
639
+ choices[key] ||= "#{t(v['caption'], v['caption'])} - #{key}"
640
+ end
641
+ end
466
642
  end
467
- #
468
- choices = [] #['Default permission','Default permission']]
469
- menus.each do |section|
470
- section['items'].each do |e|
471
- c = t(e['caption'], e['caption'])
472
- choices << ["#{c} - #{e['params']['table']}", e['params']['table']]
643
+ choices.invert.to_a.sort # hash has to be inverted for values to be returned right
644
+ end
645
+
646
+ ########################################################################
647
+ # Merges two forms when current form extends other form. Subroutine of dc_choices4_cmsmenu.
648
+ # With a little help of https://www.ruby-forum.com/topic/142809
649
+ ########################################################################
650
+ def forms_merge(hash1, hash2) #:nodoc:
651
+ target = hash1.dup
652
+ hash2.keys.each do |key|
653
+ if hash2[key].is_a? Hash and hash1[key].is_a? Hash
654
+ target[key] = forms_merge(hash1[key], hash2[key])
655
+ next
473
656
  end
657
+ target[key] = hash2[key] == '/' ? nil : hash2[key]
474
658
  end
475
- choices
659
+ # delete keys with nil value
660
+ target.delete_if{ |k,v| v.nil? }
476
661
  end
477
662
 
478
663
  ##########################################################################
479
- # Returns available choices used by collection edit select field on CMS top menu.
480
- #
481
- # @example: dc_choices4_cmsmenu
482
- #
483
- # Returns 2d array ready for use in select field.
664
+ # Returns choices for creating collection edit select field on CMS top menu.
484
665
  ##########################################################################
485
666
  def dc_choices4_cmsmenu()
486
- menus = []
667
+ menus = {}
487
668
  DrgCms.paths(:forms).reverse.each do |path|
488
- f = "#{path}/cms_menu.yml"
489
- menus << YAML.load_file(f)['menu'] if File.exist?(f)
490
- end
669
+ filename = "#{path}/cms_menu.yml"
670
+ next unless File.exist?(filename)
671
+ menu = YAML.load_file(filename) rescue nil # load menu
672
+ next if menu.nil? or !menu['menu'] # not menu or error
673
+ menus = forms_merge(menu['menu'], menus) # ignore top level part
674
+ end
491
675
  #
492
676
  choices = []
493
- menus.each do |v|
494
- choices << ["--- #{ t(v['section'], v['section']) }",'#']
495
- v['items'].each do |i|
496
- opts = { controller: i['controller'], action: i['action'] }
497
- i['params'].each {|k,v| opts.merge!(k => v) }
498
- choices << [ t(i['caption'],i['caption']), url_for( opts ) ]
677
+ menus.to_a.sort.each do |one_menu| # sort menus, result is array of sorted hashes
678
+ menu = one_menu[1] # value is the second (1) element of array
679
+ next unless menu['caption']
680
+ choices << ["--- #{ t(menu['caption'], menu['caption']) }",'#']
681
+ menu['items'].to_a.sort.each do |item| # as above. sort items first
682
+ key, value = item[0], item[1]
683
+ opts = { controller: value['controller'], action: value['action'] }
684
+ value['params'].each {|k,v| opts.merge!(k => v) } # add parameters to options
685
+ choices << [ t(value['caption'], value['caption']), url_for( opts ) ]
499
686
  end
500
687
  end
501
688
  choices
@@ -503,10 +690,7 @@ end
503
690
 
504
691
  ############################################################################
505
692
  # Returns list of directories as array of choices for use in select field
506
- # on folder permission form.
507
- #
508
- # @example (as used in forms)
509
- # eval: dc_choices4_folders_list
693
+ # on folder permission form. Directory root is determined from dc_site.files_directory field.
510
694
  ############################################################################
511
695
  def dc_choices4_folders_list
512
696
  public = File.join(Rails.root,'public')
@@ -518,32 +702,56 @@ def dc_choices4_folders_list
518
702
  end
519
703
 
520
704
  ############################################################################
521
- # Returns choices for select input filed.
705
+ # Returns choices for select input field when choices can be generated from
706
+ # all documents in collection.
522
707
  #
523
- # @example
524
- # dc_choices4('dc_mail_list', 'name', '_id', :site_only => true)
525
- #
526
- # @param [ model ] table (collection) model name.
527
- # @param [ name ] field name with description
528
- # @param [ id ] field name with id field. Default value is '_id'
529
- #
708
+ # Parameters:
709
+ # [model] String. Collection (table) name in lowercase format.
710
+ # [name] String. Field name containing description text.
711
+ # [id] String. Field name containing id field. Default is '_id'
712
+ # [options] Hash. Various options. Currently site_only is used. Will return only
713
+ # documents belonging to current site.
714
+ #
715
+ # Example (as used in forms):
716
+ # 50:
717
+ # name: dc_poll_id
718
+ # type: select
719
+ # eval: dc_choices4('dc_poll','name','_id')
530
720
  ############################################################################
531
721
  def dc_choices4(model, name, id='_id', options = {})
532
722
  qry = model.classify.constantize.only(id, name).sort(name => 1)
533
723
  qry = qry.where(dc_site_id: dc_get_site()) if options[:site_only]
534
- r = []
535
- qry.each {|v| r << [ v[name], v[id] ] }
536
- r
724
+ choices = []
725
+ qry.each {|v| choices << [ v[name], v[id] ] }
726
+ choices
537
727
  end
538
728
 
539
729
  ############################################################################
540
- # Adds new key to record cookie, thus preparing some initial values for creating
541
- # new record on the next call.
730
+ # Returns list of choices for selection top level menu on dc_page form. Used for defining which
731
+ # top level menu will be highlited when page is displayed.
542
732
  #
543
- # @example
544
- # dc_add2_record_cookie(hash)
545
- #
546
- # @param [ hash ] hash of cookies to add
733
+ # Example (as used in forms):
734
+ # 20:
735
+ # name: menu_id
736
+ # type: select
737
+ # eval: dc_choices4_menu
738
+ ############################################################################
739
+ def dc_choices4_menu
740
+ m_clas = dc_get_site.menu_class
741
+ m_clas = 'DcSimpleMenu' if m_clas.blank?
742
+ klass = m_clas.classify.constantize
743
+ klass.choices4_menu(dc_get_site)
744
+ end
745
+
746
+ ############################################################################
747
+ # Will add data to record cookie. Record cookie is used to preload some
748
+ # data on next create action. Create action will look for cookies[:record] and
749
+ # if found initialize fields on form with matching name to value found in cookie data.
750
+ #
751
+ # Example:
752
+ # kukis = {'dc_page.dc_design_id' => @page.dc_design_id,
753
+ # 'dc_page.dc_menu_id' => @page.menu_id)
754
+ # dc_add2_record_cookie(kukis)
547
755
  ############################################################################
548
756
  def dc_add2_record_cookie(hash)
549
757
  kukis = if @parent.cookies[:record] and @parent.cookies[:record].size > 0
@@ -556,16 +764,23 @@ def dc_add2_record_cookie(hash)
556
764
  end
557
765
 
558
766
  ############################################################################
559
- # Returns true if access_policy allows user to view cms part
560
- # Returns false and message if access is not allowed
767
+ # Will check if user roles allow user to view data in document with defined access_policy.
561
768
  #
562
- # @example
563
- # dc_user_can_view(@parent, @page)
564
- # dc_user_can_view(@parent, @page.policy_id)
769
+ # Parameters:
770
+ # [ctrl] Controller object or object which holds methods to access session object. For example @parent
771
+ # variable when called from renderer.
772
+ # [policy_id] Document or documents policy_id field value required to view data. Method will automatically
773
+ # check if parameter send has policy_id field defined and use value of that field.
565
774
  #
566
- # @param [ ctrl ] Controller object or object which holds methods to access session.
567
- # @param [ policy_id ] Policy id to check. If record is send as parameter, method will
568
- # check for policy_id field and use that field.
775
+ # Example:
776
+ # can_view, message = dc_user_can_view(@parent, @page)
777
+ # # or
778
+ # can_view, message = dc_user_can_view(@parent, @page.policy_id)
779
+ # return message unless can_view
780
+ #
781
+ # Returns:
782
+ # True if access_policy allows user to view data.
783
+ # False and message from policy that is blocking view if access is not allowed.
569
784
  ############################################################################
570
785
  def dc_user_can_view(ctrl, policy_id)
571
786
  policy_id = policy_id.policy_id if policy_id and policy_id.respond_to?(:policy_id)
@@ -577,6 +792,7 @@ def dc_user_can_view(ctrl, policy_id)
577
792
  # permission defined by default policy
578
793
  default_policy = policies.find_by(is_default: true)
579
794
  return false, 'Default accsess policy not found for the site!' unless default_policy
795
+ #
580
796
  h = {}
581
797
  default_policy.dc_policy_rules.to_a.each { |v| h[v.dc_policy_role_id] = v.permission }
582
798
  # update permissions with defined policy
@@ -609,13 +825,21 @@ def dc_user_can_view(ctrl, policy_id)
609
825
  end
610
826
 
611
827
  ####################################################################
612
- # Return true if user has required role.
613
- # @example
614
- # dc_user_has_role('decision_maker', session[:user_id), session[:user_roles]) => true
828
+ # Check if user has required role assigned to its user profile. If role is passed as
829
+ # string method will check roles for name and system name.
615
830
  #
616
- # @param [ role ] Role. Can be passed as string or role object.
617
- # @param [ user ] User id. If not passed session[:user_id] will be used.
618
- # @param [ roles ] Array of roles that will be searched. If not passed session[:user_roles] will be used.
831
+ # Parameters:
832
+ # [role] DcPolicyRole/String. Required role. If passed as string role will be searched in dc_policy_roles collection.
833
+ # [user] User id. Defaults to session[:user_id].
834
+ # [roles] Array of roles that will be searched. Default session[:user_roles].
835
+ #
836
+ # Example:
837
+ # if dc_user_has_role('decision_maker', session[:user_id), session[:user_roles])
838
+ # do_something_important
839
+ # end
840
+ #
841
+ # Returns:
842
+ # Boolean. True if user has required role.
619
843
  ####################################################################
620
844
  def dc_user_has_role( role, user=nil, roles=nil )
621
845
  if roles.nil?
@@ -640,12 +864,13 @@ end
640
864
  # Returns true if parameter has value of 0, false, no or -. Returns default
641
865
  # if parameter has nil value.
642
866
  #
643
- # @example
644
- # dc_dont?('no') => true
645
- # dc_dont?(1) => false
867
+ # Parameters:
868
+ # [what] String/boolean.
869
+ # [default] Default value when what has value of nil. False by default.
646
870
  #
647
- # @param [ string ] String to be examined
648
- # @param [ default ] Default value when not set. false by default.
871
+ # Example:
872
+ # dc_dont?('no') # => true
873
+ # dc_dont?(1) # => false
649
874
  ####################################################################
650
875
  def dc_dont?(what, default=false)
651
876
  return default if what.nil?
@@ -653,13 +878,18 @@ def dc_dont?(what, default=false)
653
878
  end
654
879
 
655
880
  ############################################################################
656
- # Truncates string to the size and takes care, that words are not broken.
881
+ # Truncates string length maximal to the size required and takes care, that words are not broken in middle.
882
+ # Used for output text summary with texts that can be longer then allowed space.
657
883
  #
658
- # @example
659
- # dc_limit_string(description, 100)
884
+ # Parameters:
885
+ # [string] String of any size.
886
+ # [size] Maximal size of the string to be returned.
660
887
  #
661
- # @param [ string ] Input string
662
- # @param [ size ] Maximal size of the string
888
+ # Example:
889
+ # dc_limit_string(description, 100)
890
+ #
891
+ # Returns:
892
+ # String, truncated to required size. If string is truncated '...' will be added to the end.
663
893
  ############################################################################
664
894
  def dc_limit_string(string, size)
665
895
  return string if string.size < size
@@ -669,14 +899,21 @@ def dc_limit_string(string, size)
669
899
  end
670
900
 
671
901
  ############################################################################
672
- # Returns key defined in BigTable as array of choices for use in select fields.
673
- # It first checks if key is defined only for current site and then if site
674
- # is not defined.
902
+ # Returns key defined in DcBigTable as array of choices for use in select fields.
903
+ # DcBigTable can be used like a key/value store for all kind of predefined values
904
+ # which can be linked to site and or locale.
905
+ #
906
+ # Parameters:
907
+ # [key] String. Key name to be searched in dc_big_tables documents.
675
908
  #
676
- # @example
677
- # eval: dc_big_table 'some-key' # as used on form
909
+ # Example:
910
+ # 10:
911
+ # name: category
912
+ # type: select
913
+ # eval: dc_big_table 'categories_for_page' # as used on form
678
914
  #
679
- # @param [ string ] Key to be returned
915
+ # Returns:
916
+ # Array of choices ready for select field.
680
917
  ############################################################################
681
918
  def dc_big_table(key)
682
919
  ret = []