drg_cms 0.5.50.2 → 0.5.51.1

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/History.log +47 -0
  3. data/README.md +2 -1
  4. data/app/assets/images/32px.png +0 -0
  5. data/app/assets/images/drg_cms/32px.png +0 -0
  6. data/app/assets/images/drg_cms/40px.png +0 -0
  7. data/app/assets/images/drg_cms/throbber.gif +0 -0
  8. data/app/assets/images/throbber.gif +0 -0
  9. data/app/assets/javascripts/drg_cms/drg_cms.js +3 -3
  10. data/app/assets/javascripts/drg_cms/jstree.min.js +6 -0
  11. data/app/assets/javascripts/drg_cms_cms.js +2 -1
  12. data/app/assets/stylesheets/drg_cms/drg_cms.css +9 -0
  13. data/app/assets/stylesheets/drg_cms/jstree.css +1108 -0
  14. data/app/assets/stylesheets/drg_cms_cms.css +1 -0
  15. data/app/controllers/cmsedit_controller.rb +14 -12
  16. data/app/controllers/dc_application_controller.rb +2 -2
  17. data/app/controllers/dc_common_controller.rb +15 -20
  18. data/app/controllers/dc_page_control.rb +8 -0
  19. data/app/controllers/design_element_settings_control.rb +135 -0
  20. data/app/forms/all_options.yml +7 -1
  21. data/app/forms/cms_menu.yml +1 -1
  22. data/app/forms/dc_browse_fields.yml +1 -1
  23. data/app/forms/dc_browse_models.yml +2 -2
  24. data/app/forms/dc_category.yml +4 -4
  25. data/app/forms/dc_menu.yml +6 -0
  26. data/app/forms/dc_page.yml +22 -12
  27. data/app/forms/dc_simple_menu.yml +6 -0
  28. data/app/forms/dc_site.yml +6 -0
  29. data/app/helpers/cmsedit_helper.rb +12 -8
  30. data/app/helpers/dc_application_helper.rb +79 -18
  31. data/app/helpers/dc_menu_renderer.rb +6 -1
  32. data/app/helpers/dc_part_renderer.rb +1 -1
  33. data/app/models/concerns/dc_page_concern.rb +133 -0
  34. data/app/models/concerns/dc_piece_concern.rb +57 -0
  35. data/app/models/concerns/dc_policy_rule_concern.rb +78 -0
  36. data/app/models/concerns/dc_site_concern.rb +94 -0
  37. data/app/models/concerns/dc_user_concern.rb +130 -0
  38. data/app/models/dc_ad.rb +1 -1
  39. data/app/models/dc_big_menu.rb +1 -1
  40. data/app/models/dc_category.rb +19 -4
  41. data/app/models/dc_dummy.rb +3 -2
  42. data/app/models/dc_link.rb +1 -1
  43. data/app/models/dc_memory.rb +127 -0
  44. data/app/models/dc_menu.rb +69 -3
  45. data/app/models/dc_menu_item.rb +17 -0
  46. data/app/models/dc_page.rb +0 -106
  47. data/app/models/dc_part.rb +0 -1
  48. data/app/models/dc_piece.rb +0 -35
  49. data/app/models/dc_policy_rule.rb +0 -56
  50. data/app/models/dc_simple_menu.rb +36 -0
  51. data/app/models/dc_simple_menu_item.rb +0 -0
  52. data/app/models/dc_site.rb +1 -71
  53. data/app/models/dc_user.rb +0 -108
  54. data/app/models/drgcms_form_fields.rb +187 -26
  55. data/app/views/cmsedit/_result.html.erb +3 -4
  56. data/config/locales/models_en.yml +11 -3
  57. data/config/locales/models_sl.yml +7 -0
  58. data/lib/drg_cms.rb +1 -0
  59. data/lib/drg_cms/version.rb +1 -1
  60. data/lib/tasks/log_statistics.rb +14 -8
  61. metadata +16 -2
@@ -52,6 +52,12 @@ form:
52
52
  type: text_field
53
53
  html:
54
54
  size: 20
55
+ 50:
56
+ name: dc_site_id
57
+ type: select
58
+ eval: DcSite.choices4_site
59
+ html:
60
+ include_blank: true
55
61
 
56
62
  tab2:
57
63
  10:
@@ -133,6 +133,12 @@ form:
133
133
  5permissions:
134
134
 
135
135
  10:
136
+ name: inherit_policy
137
+ type: select
138
+ eval: DcSite.choices4_site
139
+ html:
140
+ include_blank: true
141
+ 20:
136
142
  name: dc_policies
137
143
  type: embedded
138
144
  formname: dc_policy
@@ -411,7 +411,7 @@ def dc_columns_for_result(document)
411
411
  # as field
412
412
  elsif document.respond_to?(v['name'])
413
413
  dc_format_value(document.send( v['name'] ), v['format'])
414
- # as hash (dc_dummy)
414
+ # as hash (dc_memory)
415
415
  elsif document.class == Hash
416
416
  document[ v['name'] ]
417
417
  # error
@@ -589,13 +589,17 @@ end
589
589
  ############################################################################
590
590
  # Create background div and table definitions for result set.
591
591
  ############################################################################
592
- def dc_background_for_result
593
- html = '<div class="dc-result-div" '
594
- html << (@form['result_set']['table_style'] ? "style=\"overflow-x: scroll;\" >" : '>')
595
- html << "\n"
596
- #
597
- html << "<table class=\"dc-result #{@form['result_set']['table_class']}\" "
598
- html << (@form['result_set']['table_style'] ? "style=\"#{@form['result_set']['table_style']}\" >" : '>')
592
+ def dc_background_for_result(start)
593
+ if start == :start
594
+ html = '<div class="dc-result-div" '
595
+ html << (@form['result_set']['table_style'] ? "style=\"overflow-x: scroll;\" >" : '>')
596
+ html << "\n"
597
+ #
598
+ html << "<table class=\"dc-result #{@form['result_set']['table_class']}\" "
599
+ html << (@form['result_set']['table_style'] ? "style=\"#{@form['result_set']['table_style']}\" >" : '>')
600
+ else
601
+ html = '</table></div>'
602
+ end
599
603
  html.html_safe
600
604
  end
601
605
 
@@ -65,7 +65,7 @@ end
65
65
  # find where the message is comming from.
66
66
  ############################################################################
67
67
  def dc_deprecate(msg)
68
- p "#{dc_get_site.name}: #{msg}"
68
+ logger.info "#{dc_get_site.name}: #{msg}"
69
69
  end
70
70
 
71
71
  ############################################################################
@@ -154,8 +154,6 @@ def dc_render_from_site(opts={})
154
154
  render(inline: design, layout: opts[:layout], with: opts[:with])
155
155
  end
156
156
 
157
-
158
-
159
157
  ########################################################################
160
158
  # Used for designs with lots of common code and one (or more) part which differs.
161
159
  # Point is to define design once and replace some parts of design dinamically.
@@ -172,13 +170,24 @@ end
172
170
  # This helper is replacement dc_render_from_site method which will soon be deprecated.
173
171
  ########################################################################
174
172
  def dc_render_design_part(part)
175
- if part.nil?
176
- ''
177
- elsif part.class == Proc
173
+ case
174
+ when part.nil? then ''
175
+ # Send as array. Part may be defined with options on page. First element has
176
+ # name of element which defines what to do. If not defined default behaviour is
177
+ # called. That is what is defined in second part of array.
178
+ when part.class == Array then
179
+ if @options.dig(:settings, part.first)
180
+ #TODO to be defined
181
+ else
182
+ result = part.last.call
183
+ result.class == Array ? result.first : result
184
+ end
185
+ when part.class == Proc then
178
186
  result = part.call
179
187
  result.class == Array ? result.first : result
180
- elsif part.class == String
181
- eval part
188
+ # Send as string. Evaluate content of string
189
+ when part.class == String then eval part
190
+ # For future maybe. Just call objects to_s method.
182
191
  else
183
192
  part.to_s
184
193
  end.html_safe
@@ -188,6 +197,26 @@ def dc_render_design(part)
188
197
  dc_render_design_part(part)
189
198
  end
190
199
 
200
+ ############################################################################
201
+ # This is main method used for render parts of design into final HTML document.
202
+ #
203
+ # Parameters:
204
+ # [renderer] String or Symbol. Class name (in lowercase) that will be used to render final HTML code.
205
+ # If class name is provided without '_renderer' suffix it will be added automatically.
206
+ #
207
+ # When renderer has value :part, it is a shortcut for dc_render_design_part method which
208
+ # is used to draw parts of layout on design.
209
+ #
210
+ # [opts] Hash. Additional options that are passed to method. Options are merged with
211
+ # options set on site, design, page and passed to renderer object.
212
+ #
213
+ # Example:
214
+ # <%= dc_render(:dc_page, method: 'view', category: 'news') %>
215
+ ############################################################################
216
+ def dc_render_partial(opts={})
217
+ _origin.render(partial: opts[:partial], formats: [:html], locals: opts[:locals])
218
+ end
219
+
191
220
  ########################################################################
192
221
  # Helper for rendering top CMS menu when in editing mode
193
222
  ########################################################################
@@ -206,6 +235,7 @@ end
206
235
  def dc_page_bottom()
207
236
  %Q[<style type="text/css">#{@css}</style>#{javascript_tag @js}].html_safe
208
237
  end
238
+
209
239
  ############################################################################
210
240
  # Creates title div for DRG CMS dialogs. Title may also contain pagination section on right side if
211
241
  # result_set is provided as parameter.
@@ -265,6 +295,11 @@ def dc_new_title()
265
295
  t( title['new'], title['new'] )
266
296
  else
267
297
  if @form['table'] == 'dc_dummy'
298
+ dc_deprecate('dc_dummy will be deprecated. Use dc_memory instead.')
299
+ @form['table'] = 'dc_memory'
300
+ end
301
+ # in memory variables
302
+ if @form['table'] == 'dc_memory'
268
303
  t( @form['title'], @form['title'] )
269
304
  else
270
305
  "#{t('drgcms.new')} : #{t_tablename(@form['table'])}"
@@ -441,7 +476,7 @@ def dc_link_for_create(opts)
441
476
  title = opts.delete('title') #
442
477
  title = t(title, title) if title
443
478
  target = opts.delete('target') || 'iframe_cms'
444
- opts['form_name'] ||= opts['table']
479
+ opts['formname'] ||= opts['table'].split(';').last
445
480
  opts['action'] = 'new'
446
481
  opts['controller'] ||= 'cmsedit'
447
482
  js = "$('##{target}').attr('src', '#{_origin.url_for(opts)}'); return false;"
@@ -453,8 +488,9 @@ end
453
488
  # Will create HTML code required to edit document.
454
489
  #
455
490
  # Parameters:
456
- # [opts] Hash. Optional parameters for url_for helper. These options must provide at least table and formname
457
- # and id parameters.
491
+ # [opts] Hash. Optional parameters for url_for helper. These options must provide
492
+ # at least table, formname and id parameters. Optional title, target and icon parameters
493
+ # can be set.
458
494
  #
459
495
  # Example:
460
496
  # html << dc_link_for_edit( @options ) if @opts[:edit_mode] > 1
@@ -465,12 +501,14 @@ end
465
501
  def dc_link_for_edit(opts)
466
502
  opts.stringify_keys!
467
503
  title = opts.delete('title') #
504
+ title = t(title)
468
505
  target = opts.delete('target') || 'iframe_cms'
506
+ icon = opts.delete('icon') || 'edit lg'
469
507
  opts['controller'] ||= 'cmsedit'
470
- opts['action'] = 'edit'
471
- opts['form_name'] ||= opts['table']
508
+ opts['action'] ||= 'edit'
509
+ opts['formname'] ||= opts['table'].split(';').last
472
510
  js = "$('##{target}').attr('src', '#{_origin.url_for(opts)}'); return false;"
473
- dc_link_to(nil, _origin.fa_icon('edit lg', class: 'dc-inline-link'), '#',
511
+ dc_link_to(nil, _origin.fa_icon(icon, class: 'dc-inline-link'), '#',
474
512
  { onclick: js, title: title, alt: 'Edit'})
475
513
  end
476
514
 
@@ -518,6 +556,7 @@ end
518
556
  # String. HTML code required for manipulation of currently processed document.
519
557
  ########################################################################
520
558
  def dc_page_edit_menu(opts=@opts)
559
+ opts[:edit_mode] ||= _origin.session[:edit_mode]
521
560
  return '' if opts[:edit_mode] < 2
522
561
  # save some data to cookie. This can not go to session.
523
562
  page = opts[:page] || @page
@@ -530,6 +569,7 @@ def dc_page_edit_menu(opts=@opts)
530
569
  }
531
570
  _origin.cookies[:record] = Marshal.dump(kukis)
532
571
  title = "#{t('drgcms.edit')}: #{page.subject}"
572
+ opts[:editparams] ||= {}
533
573
  dc_link_menu_tag(title) do |html|
534
574
  opts[:editparams].merge!( controller: 'cmsedit', action: 'edit', 'icon' => 'edit' )
535
575
  opts[:editparams].merge!( :id => page.id, :table => _origin.site.page_table, formname: opts[:formname], edit_only: 'body' )
@@ -546,7 +586,7 @@ def dc_page_edit_menu(opts=@opts)
546
586
  opts[:editparams].merge!(ids: page.id, formname: 'dc_part', 'icon' => 'plus-square-o',
547
587
  table: "#{_origin.site.page_table};dc_part" )
548
588
  html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_new_part') )
549
- end
589
+ end.html_safe
550
590
  end
551
591
 
552
592
  ########################################################################
@@ -562,9 +602,26 @@ end
562
602
  # eval: 'dc_page_class.all_pages_for_site(@parent.dc_get_site)'
563
603
  ########################################################################
564
604
  def dc_page_class()
565
- dc_get_site.page_class.classify.constantize
605
+ # dc_get_site.page_class.classify.constantize
606
+ dc_get_site.page_table.classify.constantize
566
607
  end
567
608
 
609
+ ########################################################################
610
+ # Return menu class model defined in site document menu_class field.
611
+ #
612
+ # Used in forms for providing menus class to the forms object.
613
+ #
614
+ # Example as used on form:
615
+ # 30:
616
+ # name: menu_id
617
+ # type: tree_view
618
+ # eval: 'dc_menu_class.all_menus_for_site(@parent.dc_get_site)'
619
+ ########################################################################
620
+ def dc_menu_class()
621
+ dc_get_site.menu_class.classify.constantize
622
+ end
623
+
624
+
568
625
  ####################################################################
569
626
  # Wrapper for i18 t method, with some spice added. If translation is not found English
570
627
  # translation value will be returned. And if still not found default value will be returned if passed.
@@ -984,6 +1041,11 @@ def dc_user_can_view(ctrl, policy_id)
984
1041
  #
985
1042
  site = ctrl.site
986
1043
  policies = site.dc_policies
1044
+ policies = if site.inherit_policy.blank?
1045
+ site.dc_policies
1046
+ else
1047
+ Mongoid::QueryCache.cache { DcSite.find(site.inherit_policy) }.dc_policies
1048
+ end
987
1049
  # permission defined by default policy
988
1050
  default_policy = Mongoid::QueryCache.cache { policies.find_by(is_default: true) }
989
1051
  return false, 'Default accsess policy not found for the site!' unless default_policy
@@ -1004,7 +1066,6 @@ def dc_user_can_view(ctrl, policy_id)
1004
1066
  ctrl.session[:user_roles] = [role.id]
1005
1067
  end
1006
1068
  # Check if user has any role that allows him to view part
1007
- # p h, ctrl.session[:user_roles]
1008
1069
  can_view, msg = false,''
1009
1070
  ctrl.session[:user_roles].each do |role|
1010
1071
  next unless permissions[role] # role not yet defined. Will die in next line.
@@ -1148,7 +1209,7 @@ end
1148
1209
  # Html code for edit iframe
1149
1210
  ########################################################################
1150
1211
  def dc_iframe_edit(table, opts={})
1151
- ret = if params.size > 2 and table # controller, action, path is minimal
1212
+ ret = if params.to_unsafe_h.size > 2 and table # controller, action, path is minimal
1152
1213
  params[:controller] = 'cmsedit'
1153
1214
  params[:action] = (params[:oper] and (params[:oper] == 'edit')) ? 'edit' : 'index'
1154
1215
  params[:action] = opts[:action] unless params[:oper]
@@ -50,7 +50,11 @@ end
50
50
  # Return selected topmenu level.
51
51
  ########################################################################
52
52
  def find_selected
53
- ret = @menu.dc_menu_items.find( @parent.page.menu_id ) if @parent.page.menu_id
53
+ if @parent.page.menu_id
54
+ top_menu_id = @parent.page.menu_id
55
+ top_menu_id = @parent.page.menu_id.split(';')[1] if @parent.page.menu_id.match(';')
56
+ ret = @menu.dc_menu_items.find(top_menu_id)
57
+ end
54
58
  # return first if not found (something is wrong)
55
59
  ret ||= @menu.dc_menu_items[0]
56
60
  end
@@ -128,6 +132,7 @@ def do_menu_level(menu, options={})
128
132
  opts = options.clone
129
133
  opts['ids'] = (opts['ids'] ? "#{opts['ids']};" : '') + menu._id.to_s
130
134
  opts['table'] = (opts['table'] ? "#{opts['table']};" : '') + 'dc_menu_item'
135
+ opts['formname'] = nil # must be
131
136
  end
132
137
  html << do_menu_level(item, opts)
133
138
  end
@@ -97,7 +97,7 @@ def load_parts #:nodoc:
97
97
  type = decamelize_type(part._type) || 'dc_part'
98
98
  @parent.parts << [part, @parent.page.id, type, "#{@parent.site.page_table};#{type}"]
99
99
  end
100
- # add parts in page
100
+ # add parts in site
101
101
  @parent.site.dc_parts.where(active: true).each do |part|
102
102
  type = decamelize_type(part._type) || 'dc_part'
103
103
  @parent.parts << [part, @parent.site.id, type, "dc_site;#{type}"]
@@ -0,0 +1,133 @@
1
+ #coding: utf-8
2
+ #--
3
+ # Copyright (c) 2012+ Damjan Rems
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #++
24
+
25
+ #########################################################################
26
+ # ActiveSupport::Concern definition for DcPage class.
27
+ #########################################################################
28
+ module DcPageConcern
29
+ extend ActiveSupport::Concern
30
+ included do
31
+
32
+ include Mongoid::Document
33
+ include Mongoid::Timestamps
34
+
35
+ field :subject, type: String, default: ''
36
+ field :title, type: String
37
+ field :subject_link, type: String, default: ''
38
+ field :alt_link, type: String, default: ''
39
+ field :sub_subject, type: String, default: ''
40
+ field :picture, type: String
41
+ field :gallery, type: String
42
+ field :body, type: String, default: ''
43
+ field :css, type: String, default: ''
44
+ field :script, type: String, default: ''
45
+ field :params, type: String
46
+ field :menu_id, type: String
47
+ field :author_id, type: BSON::ObjectId
48
+ field :dc_poll_id, type: BSON::ObjectId
49
+ field :author_name, type: String
50
+ field :publish_date, type: DateTime
51
+ field :user_name, type: String
52
+ field :valid_from, type: DateTime
53
+ field :valid_to, type: DateTime
54
+ field :comments, type: Integer, default: 1 # 0 => not allowed, 1 => allowed
55
+ field :active, type: Boolean, default: true
56
+ field :created_by, type: BSON::ObjectId
57
+ field :updated_by, type: BSON::ObjectId
58
+ field :kats, type: Array # Categories
59
+
60
+ field :policy_id, type: BSON::ObjectId
61
+
62
+ embeds_many :dc_parts
63
+
64
+ belongs_to :dc_site #, optional: true
65
+ belongs_to :dc_design #, optional: true
66
+
67
+ index ({ dc_site_id: 1, subject_link: 1 })
68
+ index kats: 1
69
+ index alt_link: 1
70
+
71
+ before_save :do_before_save
72
+
73
+ validates :publish_date, presence: true
74
+
75
+ ######################################################################
76
+ protected
77
+
78
+ ######################################################################
79
+ # Implementation of before_save callback.
80
+ ######################################################################
81
+ def do_before_save
82
+ if self.subject_link.empty?
83
+ self.subject_link = DcPage.clear_link(self.subject.downcase.strip)
84
+ # add id to link, but only if something is written in subject
85
+ self.subject_link << "-#{self.id.to_s}" if self.subject_link.size > 1
86
+ end
87
+ # menu_id is returned as string Array class if entered on form as tree_select object.
88
+ self.menu_id = self.menu_id.scan(/"([^"]*)"/)[0][0] if self.menu_id.to_s.match('"')
89
+ end
90
+
91
+ ######################################################################
92
+ # Clears subject link of chars that shouldn't be there and also takes care
93
+ # than link size is not larger than 100 chars.
94
+ ######################################################################
95
+ def self.clear_link(link)
96
+ link.gsub!(/\.|\?|\!\&|»|«|\,|\"|\'|\:/,'')
97
+ link.gsub!('<br>','')
98
+ link.gsub!('–','-')
99
+ link.gsub!(' ','-')
100
+ link.gsub!('---','-')
101
+ link.gsub!('--','-')
102
+ # it shall not be greater than 100 chars. Don't break in the middle of words
103
+ if link.size > 100
104
+ link = link[0,100]
105
+ link.chop! until link[-1,1] == '-' or link.size < 10 # delete until -
106
+ end
107
+ link.chop! if link[-1,1] == '-' # remove - at the end
108
+ link
109
+ end
110
+
111
+ ######################################################################
112
+ # Return all pages belonging to site ready for select input field. Used
113
+ # by dc_menu* forms, for selecting page which will be linked by menu option.
114
+ #
115
+ # Parameters:
116
+ # [site] Site document.
117
+ ######################################################################
118
+ def self.all_pages_for_site(site)
119
+ only(:subject, :subject_link).where(dc_site_id: site._id, active: true).order(subject: 1).
120
+ inject([]) { |r,page| r << [ page.subject, page.subject_link] }
121
+ end
122
+
123
+ ########################################################################
124
+ # Return filter options
125
+ ########################################################################
126
+ def self.dc_filters
127
+ {'title' => 'drgcms.filters.this_site_only', 'operation' => 'eq',
128
+ 'field' => 'dc_site_id', 'value' => '@current_site'}
129
+ end
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,57 @@
1
+ #--
2
+ # Copyright (c) 2012+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+
25
+ #########################################################################
26
+ # ActiveSupport::Concern definition for DcPiece class.
27
+ #########################################################################
28
+ module DcPieceConcern
29
+ extend ActiveSupport::Concern
30
+ included do
31
+
32
+ include Mongoid::Document
33
+ include Mongoid::Timestamps
34
+
35
+ field :name, type: String, default: ''
36
+ field :description, type: String, default: ''
37
+ field :picture, type: String
38
+ field :thumbnail, type: String
39
+ field :body, type: String, default: ''
40
+ field :css, type: String, default: ''
41
+ field :script, type: String, default: ''
42
+ field :script_type, type: String, default: ''
43
+ field :params, type: String, default: ''
44
+ field :piece_id, type: BSON::ObjectId
45
+ field :div_id, type: String
46
+ field :site_id, type: BSON::ObjectId
47
+ field :order, type: Integer, default: 0
48
+ field :active, type: Boolean, default: true
49
+ field :valid_from, type: DateTime
50
+ field :valid_to, type: DateTime
51
+
52
+ field :created_by, type: BSON::ObjectId
53
+ field :updated_by, type: BSON::ObjectId
54
+
55
+ validates :name, presence: true
56
+ end
57
+ end