drg_cms 0.4.39 → 0.4.53

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 (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
@@ -21,31 +21,47 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #++
24
+
25
+ ##########################################################################
26
+ # Controller holds methods which are of use for all application controllers.
27
+ ##########################################################################
24
28
  class DcApplicationController < ActionController::Base
25
29
  protect_from_forgery
26
30
 
27
31
  ########################################################################
28
- # Writes anything passed as parameter to log/dump file.
32
+ # Writes anything passed as parameter to logger file.
29
33
  #
30
34
  # Very usefull for debuging strange errors.
31
35
  ########################################################################
32
36
  def dc_dump(*args)
33
37
  args.each do |arg|
34
- File.open(Rails.root.join('log/dump.log'),'a') {|f| f.write(arg.to_s + "\n") }
38
+ logger.debug arg.to_s
35
39
  end
36
40
  end
37
41
 
38
42
  ####################################################################
39
- # return true if in edit mode
43
+ # Return true if CMS is in edit mode
40
44
  ####################################################################
41
45
  def dc_edit_mode?
42
46
  session[:edit_mode] > 1
43
47
  end
44
48
 
45
49
  ####################################################################
46
- # Return true if user has required role
50
+ # Checks if user has required role.
51
+ #
52
+ # [Parameters:]
53
+ # [role]
54
+ # Role can be passed as DcPolicyRole object or as string. If string
55
+ # is passed, dc_policy_roles files is searched for appropriate role.
56
+ #
57
+ # [Return:]
58
+ # Boolean. True if user has required role added to his profile.
59
+ #
60
+ # [Example:]
61
+ # if dc_user_has_role('admin') ...
62
+ # if dc_user_has_role('Site editors') ...
47
63
  ####################################################################
48
- def dc_user_has_role( role, user=session[:user_id] )
64
+ def dc_user_has_role(role)
49
65
  if role.class == String
50
66
  rol = role
51
67
  role = DcPolicyRole.find_by(name: rol)
@@ -57,7 +73,12 @@ def dc_user_has_role( role, user=session[:user_id] )
57
73
  end
58
74
 
59
75
  ####################################################################
60
- # Determine site from url and return site record (document)
76
+ # Determine site from url and return site document.
77
+ #
78
+ # [Return:]
79
+ # Site document. If site is not found and not in production environment 'test'
80
+ # site document is returned. If site has alias set then alias site document is
81
+ # returned.
61
82
  ####################################################################
62
83
  def dc_get_site()
63
84
  return @site if @site
@@ -80,24 +101,33 @@ end
80
101
  ####################################################################
81
102
  # Determine and return site record from url. It would be nice but it is not working.
82
103
  ####################################################################
83
- def self.dc_get_site_()
104
+ def self.dc_get_site_() #:nodoc:
84
105
  #self.dc_get_site()
85
106
  end
86
107
 
87
108
  ########################################################################
88
- # Searches forms file in forms path and returns it's name.
109
+ # Searches forms path for file_name and returns full file name or nil if not found.
110
+ #
111
+ # [Parameters:]
112
+ # [form_file] Additional data can be displayed with error.
113
+ #
114
+ # [Return:]
115
+ # String. Full form file name or nil if not found.
89
116
  ########################################################################
90
- def dc_find_form_file(form)
117
+ def dc_find_form_file(form_file)
91
118
  DrgCms.paths(:forms).reverse.each do |path|
92
- f = "#{path}/#{form}.yml"
119
+ f = "#{path}/#{form_file}.yml"
93
120
  return f if File.exist?(f)
94
121
  end
95
- p "Form file #{form} not found!"
122
+ p "Form file #{form_file} not found!"
96
123
  nil
97
124
  end
98
125
 
99
126
  #######################################################################
100
- # Render 404 error with some debug includded
127
+ # Will render public/404.html file with some debug code includded.
128
+ #
129
+ # [Parameters:]
130
+ # [Object where_the_error_is] Additional data can be displayed with error.
101
131
  ########################################################################
102
132
  def dc_render_404(where_the_error_is=nil)
103
133
  render(file: "#{Rails.root}/public/404", :status => 404, :layout => false, :formats => [:html],
@@ -105,7 +135,8 @@ def dc_render_404(where_the_error_is=nil)
105
135
  end
106
136
 
107
137
  ########################################################################
108
- # Log visit to dc_visit
138
+ # Will write document to dc_visits collection unless visit comes from robot.
139
+ # It also sets session[is_robot] variable to true if robot.
109
140
  ########################################################################
110
141
  def dc_log_visit()
111
142
  if request.env["HTTP_USER_AGENT"] and request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/)
@@ -126,31 +157,34 @@ protected
126
157
  #############################################################################
127
158
  # Add permissions. Subroutine of dc_user_can
128
159
  ############################################################################
129
- def add_permissions_l(table_name=nil) # NODOC
160
+ def add_permissions_for(table_name=nil) # :nodoc:
130
161
  perm = table_name.nil? ? DcPermission.find_by(is_default: true) : DcPermission.find_by(table_name: table_name, active: true)
131
162
  (perm.dc_policy_rules.each {|p1| @permissions[p1.dc_policy_role_id] = p1.permission }) if perm
132
163
  end
133
164
 
134
165
  ############################################################################
135
- # Returns true if user's role permits to perform operation on a table(collection)
136
- # with required permission.
166
+ # Checks if user can perform (read, create, edit, delete) document in specified
167
+ # table (collection).
168
+ #
169
+ # [Parameters:]
170
+ # [Integer permission] Required permission level
171
+ # [String table] Name of table(collection) for which permission is required. Defaults to params[table].
137
172
  #
138
- # @example
139
- # dc_user_can(DcPermission::CAN_VIEW, params[:table])
173
+ # [Returns:]
174
+ # Boolean true if user's role permits operation on a table(collection) with required permission.
140
175
  #
141
- # @param [ permission ] Required permission level
142
- # @param [ table ] Name of table(collection) for which permission is required
143
- # Defaults to params[:table]
176
+ # [Example:]
177
+ # dc_user_can(DcPermission::CAN_VIEW, params[:table])
144
178
  ############################################################################
145
179
  def dc_user_can(permission, table=params[:table])
146
180
  if @permissions.nil?
147
181
  @permissions = {}
148
- add_permissions_l # default permission
182
+ add_permissions_for # default permission
149
183
  table_name = ''
150
184
  # permission can be set for table or object embedded in table. Read all possible values
151
185
  table.strip.downcase.split(';').each do |t|
152
186
  table_name << (table_name.size > 0 ? ';' : '') + t # table;embedded;another;...
153
- add_permissions_l table_name
187
+ add_permissions_for table_name
154
188
  end
155
189
  end
156
190
  # Sometimes anonymous user is allowed to use cmsedit. Search for system default role.
@@ -165,8 +199,7 @@ def dc_user_can(permission, table=params[:table])
165
199
  end
166
200
 
167
201
  ####################################################################
168
- # Detects if called from mobile agent.
169
- # According to http://detectmobilebrowsers.com/
202
+ # Detects if called from mobile agent according to http://detectmobilebrowsers.com/
170
203
  ####################################################################
171
204
  def dc_set_is_mobile
172
205
  is_mobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.match(request.user_agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.match(request.user_agent[0..3])
@@ -175,7 +208,9 @@ end
175
208
 
176
209
 
177
210
  ##########################################################################
178
- # Merge values from params fields (from site, page ...) into internal @options hash.
211
+ # Merge values from parameters fields (from site, page ...) into internal @options hash.
212
+ # [Parameters:]
213
+ # [String parameters] String in yaml syntax.
179
214
  ##########################################################################
180
215
  def dc_set_options(parameters)
181
216
  @options ||= {}
@@ -195,9 +230,21 @@ def dc_set_options(parameters)
195
230
  end
196
231
 
197
232
  ##########################################################################
198
- # Default request processing.
233
+ # This is default page process action. It will search for site, page and
234
+ # design documents, collect parameters from different objects, add CMS edit code if allowed
235
+ # and at the end render design.body or design.rails_view or site.rails_view.
236
+ #
237
+ # [Example:] as defined in routes.rb
238
+ # get '*path' => 'dc_application_controller#dc_process_default_request'
239
+ # # or
240
+ # get '*path' => 'my_controller#page'
241
+ # # then in my_controller.rb
242
+ # def page
243
+ # dc_process_default_request
244
+ # end
245
+ #
199
246
  ##########################################################################
200
- def dc_process_default_request()
247
+ def dc_process_default_request()
201
248
  session[:edit_mode] ||= 0
202
249
  # Initialize parts
203
250
  @parts = nil
@@ -213,11 +260,11 @@ def dc_process_default_request()
213
260
  pageclass = @site.page_table.classify.constantize
214
261
  if params[:id]
215
262
  #Page.where(id: params[:id]).or(subject_link: params[:id]).first
216
- @page = pageclass.find_by(:dc_site_id.in => [@site._id, nil], subject_link: params[:id])
263
+ @page = pageclass.find_by(:dc_site_id.in => [@site._id, nil], subject_link: params[:id], active: true)
217
264
  @page = pageclass.find(params[:id]) if @page.nil? # I think that there will be more subject_link searchers than id
218
265
  elsif params[:path]
219
266
  # path may point direct to page's subject_link
220
- @page = pageclass.find_by(:dc_site_id.in => [@site._id, nil], subject_link: params[:path])
267
+ @page = pageclass.find_by(:dc_site_id.in => [@site._id, nil], subject_link: params[:path], active: true)
221
268
  if @page.nil?
222
269
  # no. Find if defined in links
223
270
  link = DcLink.find_by(:dc_site_id.in => [@site._id, nil], name: params[:path])
@@ -263,13 +310,17 @@ def dc_process_default_request()
263
310
  end
264
311
 
265
312
  ########################################################################
266
- # Decamelizes string. It probably doesn't work very good with non ascii chars.
267
- # Therefore it is very unwise to use non ascii chars for table (collection) names.
313
+ # Decamelizes string. Does oposite from camelize method. It probably doesn't work
314
+ # very good with non ascii chars. Since this method is used for converting from model
315
+ # to collection names it is very unwise to use non ascii chars for table (collection) names.
316
+ #
317
+ # [Parameters:]
318
+ # [String string] String to be converted # 'DcSimpleMenu' => 'dc_simple_menu'.
268
319
  ########################################################################
269
- def decamelize_type(st)
270
- return nil unless st
320
+ def decamelize_type(string)
321
+ return nil unless string
271
322
  r = ''
272
- st.to_s.each_char do |c|
323
+ string.to_s.each_char do |c|
273
324
  r << case
274
325
  when r.size == 0 then c.downcase
275
326
  when c.downcase != c then '_' + c.downcase
@@ -282,7 +333,11 @@ end
282
333
  ####################################################################
283
334
  # Return's error messages for the document formated for display on edit form.
284
335
  #
285
- # @param [ document ] Document var
336
+ # [Parameters:]
337
+ # [document] Document which will be examined for errors.
338
+ #
339
+ # [Return:]
340
+ # String. HTML code for displaying error on edit form.
286
341
  ####################################################################
287
342
  def dc_error_messages_for(document)
288
343
  return '' unless document.errors.any?
@@ -304,10 +359,23 @@ end
304
359
  ####################################################################
305
360
  # Checks if any errors exist on document and writes debug log. It can also
306
361
  # crash if requested. This is mostly usefull in development for debuging
307
- # model errors.
362
+ # model errors or when saving to multiple collections and where each save must be
363
+ # checked if succesfull.
308
364
  #
309
- # @param [ document ] Document var
310
- # @param [ crash ] Should crash when errors detected. Default = false.
365
+ # [Parameters:]
366
+ # [Object document] Document var
367
+ # [Boolean crash] Should crash when errors detected. Default = false.
368
+ #
369
+ # [Return:]
370
+ # String. Documents error message empty string if everything is OK.
371
+ #
372
+ # [Example:]
373
+ # model.save
374
+ # if (msg = dc_check_model(model) ).size > 0
375
+ # p msg
376
+ # error process ......
377
+ # end
378
+ #
311
379
  ####################################################################
312
380
  def dc_check_model(document, crash=false)
313
381
  return nil unless document.errors.any?
@@ -315,18 +383,20 @@ def dc_check_model(document, crash=false)
315
383
  document.errors.each do |attribute, errors_array|
316
384
  msg << "#{attribute}: #{errors_array}\n"
317
385
  end
318
- logger.debug(msg)
386
+ logger.debug(msg) if msg.size > 0
319
387
  crash_it if crash
320
388
  msg
321
389
  end
322
390
 
323
391
  ######################################################################
324
- # Can call rake task from controller.
325
- # @example
326
- # dc_call_rake('clear:all', some_parm: some_id)
392
+ # Call rake task from controller.
393
+ #
394
+ # [Parameters:]
395
+ # [String task] Rake task name
396
+ # [Hash options] Options that will be send to task as environment variables
327
397
  #
328
- # @param [ task ] Rake task name
329
- # @param [ options ] Options that will be send to task as environment variables
398
+ # [Example:]
399
+ # dc_call_rake('clear:all', some_parm: some_id)
330
400
  ######################################################################
331
401
  def dc_call_rake(task, options = {})
332
402
  options[:rails_env] ||= Rails.env
@@ -335,12 +405,22 @@ def dc_call_rake(task, options = {})
335
405
  end
336
406
 
337
407
  ######################################################################
338
- # Small helper for formating ajax return from controller. This is higly experimental.
339
- # @example
340
- # dc_render_ajax(operation: :div, prepand: html_code)
408
+ # Small helper for rendering ajax return code from controller. When ajax call is
409
+ # made from DRG CMS form return may be quite complicated. All ajax return combinations
410
+ # can be found in drg_cms.js file.
411
+ #
412
+ # [Parameters:]
413
+ # [Hash opts] Different options
414
+ #
415
+ # [Return:]
416
+ # String. Formatted to be used on ajax return.
417
+ #
418
+ # [Example:]
419
+ # html_code = '<span>Some text</span>'
420
+ # dc_render_ajax(div: 'mydiv', prepand: html_code) # Will prepand code to mydiv div
421
+ # dc_render_ajax(class: 'myclass', append: html_code) # Will append code to all objects with myclass class
422
+ # dc_render_ajax(operation: 'window', value: "/pdf_file.pdf") # will open pdf file in new window.
341
423
  #
342
- # @param [ task ] Rake task name
343
- # @param [ options ] Options that will be send to task as environment variables
344
424
  ######################################################################
345
425
  def dc_render_ajax(opts)
346
426
  result = {}
@@ -360,13 +440,19 @@ def dc_render_ajax(opts)
360
440
  end
361
441
 
362
442
  ########################################################################
363
- # Find document by parameters
364
- # @example
365
- # dc_find_document(params[:table], params[:id], params[:ids]
443
+ # Find document by parameters. This is how cmsedit finds document based
444
+ # on url parameters.
445
+ #
446
+ # [Parameters:]
447
+ # [String table] Table (collection) name. Could be dc_page;dc_part;... when searching for embedded document.
448
+ # [String id] Id of the document
449
+ # [String table] Ids of parent documents when document is embedded. Ids are separated by ; char.
450
+ #
451
+ # [Return:]
452
+ # Document. Required document or nil if not found.
366
453
  #
367
- # @param [ table ] table (collection) name. Could be dc_page;dc_part;... when embedded document
368
- # @param [ id ] Id of the document
369
- # @param [ ids ] Ids of parent documents when document is embedded. Ids are separated by ; char.
454
+ # [Example:]
455
+ # dc_find_document(params[:table], params[:id], params[:ids])
370
456
  ########################################################################
371
457
  def dc_find_document(table, id, ids)
372
458
  tables = table.split(';')
@@ -22,11 +22,27 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #++
24
24
 
25
+ ########################################################################
26
+ # This controller holds some common actions used by CMS.
27
+ ########################################################################
25
28
  class DcCommonController < DcApplicationController
26
29
  layout false
27
30
 
28
31
  ########################################################################
29
- # Autocomplete request, for search fiels
32
+ # This action is called on ajax autocomplete call. It checks if user has rights to
33
+ # wiev data.
34
+ #
35
+ # Url parameters:
36
+ # [table] Table (collection) model name in lower case indicating table which will be searched.
37
+ # [id] Name of id key field that will be returend. Default is '_id'
38
+ # [input] Search data entered in input field.
39
+ # [search] when passed without dot it defines field name on which search
40
+ # will be performed. When passed with dot class_method.method_name is assumed. Method name will
41
+ # be parsed and any class with class method name can be avalueted. Class method must accept
42
+ # input parameter and return array [ [_id, value],.. ] which will be used in autocomplete field.
43
+ #
44
+ # Return:
45
+ # JSON array [label, value, id] of first 20 documents that confirm to query.
30
46
  ########################################################################
31
47
  def autocomplete
32
48
  # return '' unless session[:edit_mode] > 0 #
@@ -34,7 +50,7 @@ def autocomplete
34
50
  # TODO Double check if previous line works as it should.
35
51
  table = params['table'].classify.constantize
36
52
  id = [params['id']] || '_id'
37
- # call method in class if search parameter has . This is for user defined sofisticated searches
53
+ # call method in class if search parameter has . This is for user defined searches
38
54
  # result must be returned as array of [id, search_field_value]
39
55
  a = if params['search'].match(/\./)
40
56
  name, method = params['search'].split('.')
@@ -51,13 +67,13 @@ def autocomplete
51
67
  end
52
68
 
53
69
  ########################################################################
54
- # Register and save click on ad link
70
+ # Register and record click when ad link is clicked.
55
71
  ########################################################################
56
72
  def ad_click
57
73
  if (ad = DcAd.find(params[:id]))
58
74
  ad.clicked += 1
59
75
  ad.save
60
- DcAdStat.create!(dc_ad_id: params[:id], ip: request.ip, type: 2 ) #.save
76
+ DcAdStat.create!(dc_ad_id: params[:id], ip: request.ip, type: 2 )
61
77
  else
62
78
  logger.error "ERROR ADS: Invalid ad id=#{params[:id]} ip=#{request.ip}."
63
79
  end
@@ -66,13 +82,14 @@ def ad_click
66
82
  end
67
83
 
68
84
  ##########################################################################
69
- # Toggle cmd edit mode
85
+ # Toggle CMS edit mode.This action is called when user clicks CMS option on
86
+ # top of the browser.
70
87
  ##########################################################################
71
88
  def toggle_edit_mode
72
89
  session[:edit_mode] ||= 0
73
90
  # called directly without authorization
74
91
  if session[:edit_mode] < 1
75
- dc_render_404 #(:file => "#{Rails.root}/public/404", :status => 404, :layout => false, :formats => [:html])
92
+ dc_render_404
76
93
  else
77
94
  session[:edit_mode] = (session[:edit_mode] == 1) ? 2 : 1
78
95
  redirect_to params[:return_to]
@@ -80,15 +97,17 @@ def toggle_edit_mode
80
97
  end
81
98
 
82
99
  ####################################################################
83
- # Process login action
100
+ # Default user login action.
84
101
  ####################################################################
85
102
  def process_login
86
103
  # Something is really wrong
87
104
  return dc_render_404 unless ( params[:record] and params[:record][:username] and params[:record][:password] )
88
-
89
- user = DcUser.find_by(username: params[:record][:username])
90
- if user and user.authenticate(params[:record][:password])
91
- fill_login_data(user, params[:record][:remember_me].to_i == 1)
105
+
106
+ if params[:record][:password].to_s.size > 0 #password must not be empty
107
+ user = DcUser.find_by(username: params[:record][:username])
108
+ if user and user.authenticate(params[:record][:password])
109
+ fill_login_data(user, params[:record][:remember_me].to_i == 1)
110
+ end
92
111
  else
93
112
  flash[:error] = t('drgcms.invalid_username')
94
113
  params[:return_to] = params[:return_to_error] # return_to error
@@ -97,7 +116,7 @@ def process_login
97
116
  end
98
117
 
99
118
  ####################################################################
100
- # Process logout action
119
+ # Default user logout action.
101
120
  ####################################################################
102
121
  def logout
103
122
  clear_login_data
@@ -105,7 +124,8 @@ def logout
105
124
  end
106
125
 
107
126
  ####################################################################
108
- # Alternative login. If remember_me cookie is found it tries to automatically logs
127
+ # Alternative login action with remember_me cookie. If found it will automatically
128
+ # login user otherwise user will be presented with regular login dialog.
109
129
  ####################################################################
110
130
  def login
111
131
  if cookies.signed[:remember_me]
@@ -126,7 +146,7 @@ def login
126
146
  end
127
147
 
128
148
  ####################################################################
129
- # Processes restore from journal action
149
+ # Action is called when restore document from journal is requested.
130
150
  ####################################################################
131
151
  def restore_from_journal
132
152
  # selected fields to hash
@@ -161,24 +181,6 @@ def restore_from_journal
161
181
  render inline: result.to_json, formats: 'js'
162
182
  end
163
183
 
164
- ########################################################################
165
- # Update some anomalies in json
166
- ########################################################################
167
- def update_json(json, is_update=false)
168
- result = {}
169
- json.each do |k,v|
170
- if v.class == Hash
171
- result[k] = v['$oid'] if is_update
172
- elsif v.class == Array
173
- result[k] = []
174
- v.each {|e| result[k] << update_json(e, is_update)}
175
- else
176
- result[k] = v
177
- end
178
- end
179
- result
180
- end
181
-
182
184
  ########################################################################
183
185
  # Copy current record to clipboard as json text. It will actually ouput an
184
186
  # window with data formatted as json.
@@ -202,6 +204,8 @@ end
202
204
 
203
205
  ########################################################################
204
206
  # Paste data from clipboard into text_area and update documents in destination database.
207
+ # This action is called twice. First time for displaying text_area field and second time
208
+ # ajax call for processing data.
205
209
  ########################################################################
206
210
  def paste_clipboard
207
211
  # Only administrators can perform this operation
@@ -236,6 +240,24 @@ end
236
240
 
237
241
  protected
238
242
 
243
+ ########################################################################
244
+ # Update some anomalies in json data on paste_clipboard action.
245
+ ########################################################################
246
+ def update_json(json, is_update=false) #:nodoc:
247
+ result = {}
248
+ json.each do |k,v|
249
+ if v.class == Hash
250
+ result[k] = v['$oid'] if is_update
251
+ elsif v.class == Array
252
+ result[k] = []
253
+ v.each {|e| result[k] << update_json(e, is_update)}
254
+ else
255
+ result[k] = v
256
+ end
257
+ end
258
+ result
259
+ end
260
+
239
261
  ########################################################################
240
262
  # Processes one document. Subroutine of paste_clipboard.
241
263
  ########################################################################
@@ -262,7 +284,7 @@ def process_document(line, table, id, ids)
262
284
  end
263
285
 
264
286
  ####################################################################
265
- # Clears all session data related to login
287
+ # Clears all session data related to login.
266
288
  ####################################################################
267
289
  def clear_login_data
268
290
  session[:edit_mode] = 0
@@ -273,7 +295,7 @@ def clear_login_data
273
295
  end
274
296
 
275
297
  ####################################################################
276
- # Fills session with data related to succesfull login.
298
+ # Fills session with data related to successful login.
277
299
  ####################################################################
278
300
  def fill_login_data(user, remember_me)
279
301
  session[:user_id] = user.id