drg_cms 0.6.0.3 → 0.6.0.6

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +259 -102
  3. data/app/assets/javascripts/drg_cms_cms.js +1 -1
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +314 -142
  5. data/app/assets/stylesheets/drg_cms/select-multiple.css +11 -2
  6. data/app/controllers/cmsedit_controller.rb +313 -236
  7. data/app/controllers/dc_application_controller.rb +29 -4
  8. data/app/controllers/dc_common_controller.rb +19 -16
  9. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  10. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  11. data/app/controls/dc_poll_result_control.rb +88 -0
  12. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  13. data/app/forms/all_options.yml +11 -3
  14. data/app/forms/cms_menu.yml +22 -18
  15. data/app/forms/dc_design.yml +6 -3
  16. data/app/forms/dc_filter.yml +3 -6
  17. data/app/forms/dc_poll_result.yml +74 -0
  18. data/app/forms/dc_poll_result_export.yml +35 -0
  19. data/app/helpers/cmsedit_edit_helper.rb +471 -0
  20. data/app/helpers/cmsedit_helper.rb +151 -821
  21. data/app/helpers/cmsedit_index_helper.rb +567 -0
  22. data/app/helpers/dc_application_helper.rb +48 -31
  23. data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
  24. data/app/models/dc_filter.rb +12 -5
  25. data/app/models/dc_memory.rb +8 -1
  26. data/app/models/dc_poll.rb +38 -19
  27. data/app/models/dc_poll_result.rb +44 -0
  28. data/app/models/dc_temp.rb +137 -0
  29. data/app/models/drgcms_form_fields/action.rb +61 -0
  30. data/app/models/drgcms_form_fields/comment.rb +8 -4
  31. data/app/models/drgcms_form_fields/date_picker.rb +7 -6
  32. data/app/models/drgcms_form_fields/date_select.rb +1 -1
  33. data/app/models/drgcms_form_fields/datetime_picker.rb +8 -7
  34. data/app/models/drgcms_form_fields/datetime_select.rb +1 -1
  35. data/app/models/drgcms_form_fields/drgcms_field.rb +39 -7
  36. data/app/models/drgcms_form_fields/embedded.rb +7 -2
  37. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  38. data/app/models/drgcms_form_fields/html_field.rb +1 -1
  39. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +7 -4
  40. data/app/models/drgcms_form_fields/number_field.rb +15 -6
  41. data/app/models/drgcms_form_fields/radio.rb +91 -0
  42. data/app/models/drgcms_form_fields/readonly.rb +1 -1
  43. data/app/models/drgcms_form_fields/select.rb +14 -2
  44. data/app/models/drgcms_form_fields/text_area.rb +1 -1
  45. data/app/models/drgcms_form_fields/text_autocomplete.rb +1 -1
  46. data/app/models/drgcms_form_fields/text_field.rb +1 -1
  47. data/app/models/drgcms_form_fields/text_with_select.rb +6 -3
  48. data/app/models/drgcms_form_fields/tree_select.rb +11 -3
  49. data/app/renderers/dc_poll_renderer.rb +29 -11
  50. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  51. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  52. data/app/views/cmsedit/_edit_stuff.html.erb +2 -4
  53. data/app/views/cmsedit/_form.html.erb +4 -3
  54. data/app/views/cmsedit/_result.html.erb +2 -3
  55. data/app/views/cmsedit/edit.html.erb +2 -1
  56. data/app/views/cmsedit/index.html.erb +6 -1
  57. data/app/views/cmsedit/new.html.erb +1 -1
  58. data/config/locales/drgcms_en.yml +7 -0
  59. data/config/locales/drgcms_sl.yml +8 -1
  60. data/config/locales/models_en.yml +13 -4
  61. data/config/locales/models_sl.yml +13 -2
  62. data/drg_cms.gemspec +1 -1
  63. data/lib/drg_cms.rb +1 -0
  64. data/lib/drg_cms/version.rb +1 -1
  65. data/lib/generators/new_drg_form/new_drg_form_generator.rb +7 -2
  66. metadata +20 -13
  67. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  68. data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -98,6 +98,7 @@ def dc_render(renderer, opts={})
98
98
  #
99
99
  opts[:edit_mode] = session[:edit_mode]
100
100
  opts[:editparams] = {}
101
+
101
102
  opts = @options.merge(opts) # merge options with parameters passed on site, page, design ...
102
103
  opts.symbolize_keys! # this makes lots of things easier
103
104
  # Create renderer object
@@ -260,7 +261,7 @@ end
260
261
  def dc_table_title(text, result_set=nil)
261
262
  c = %Q[<div class="dc-title">#{text}]
262
263
  if result_set and result_set.respond_to?(:current_page)
263
- c << %Q[<div class="dc-paginate">#{paginate(result_set, :params => {:action => 'index'})}</div>]
264
+ c << %Q[<div class="dc-paginate">#{paginate(result_set, :params => {action: 'index', clear: 'no'})}</div>]
264
265
  end
265
266
  c << '<div style="clear: both;"></div></div>'
266
267
  c.html_safe
@@ -273,6 +274,7 @@ end
273
274
  # String. HTML code for title.
274
275
  ############################################################################
275
276
  def dc_edit_title()
277
+ session[:form_processing] = "form:title:"
276
278
  title = @form['form']['title']
277
279
  # defined as form:title:edit
278
280
  if title and title['edit'] and !@form['readonly']
@@ -299,6 +301,7 @@ end
299
301
  # String. HTML code for title.
300
302
  ############################################################################
301
303
  def dc_new_title()
304
+ session[:form_processing] = "form:title:"
302
305
  title = @form['form']['title']
303
306
  # defined as form:title:new
304
307
  if title and title['new']
@@ -351,6 +354,21 @@ def dc_submit_tag(caption, icon, parms, rest={})
351
354
  html = icon_image || ''
352
355
  html << submit_tag(t(caption, caption), parms)
353
356
  end
357
+
358
+ ############################################################################
359
+ # Returns icon code if icon is specified
360
+ ############################################################################
361
+ def dc_icon_for_link(icon)
362
+ return nil unless icon
363
+ if icon.match(/\./)
364
+ _origin.image_tag(icon, class: 'dc-link-img dc-animate')
365
+ elsif icon.match('<i')
366
+ icon
367
+ else
368
+ _origin.fa_icon(icon)
369
+ end
370
+ end
371
+
354
372
  ############################################################################
355
373
  # Similar to rails link_to, but also takes care of link icon, translation, ...
356
374
  ############################################################################
@@ -365,16 +383,7 @@ def dc_link_to(caption, icon, parms, rest={})
365
383
  icon_pos = parms.delete('icon_pos') || 'first'
366
384
  end
367
385
  #
368
- if icon
369
- icon_image = if icon.match(/\./)
370
- _origin.image_tag(icon, class: 'dc-link-img dc-animate')
371
- elsif icon.match('<i')
372
- icon
373
- else
374
- _origin.fa_icon(icon)
375
- end
376
- end
377
- #
386
+ icon_image = dc_icon_for_link(icon)
378
387
  if caption
379
388
  caption = t(caption, caption)
380
389
  icon_image << ' ' if icon_image
@@ -391,23 +400,31 @@ end
391
400
  # String. HTML code formatted for display.
392
401
  ####################################################################
393
402
  def dc_flash_messages()
394
- err = _origin.flash[:error]
395
- war = _origin.flash[:warning]
396
- inf = _origin.flash[:info]
397
- note = _origin.flash[:note]
403
+ err = _origin.flash[:error]
404
+ war = _origin.flash[:warning]
405
+ inf = _origin.flash[:info]
406
+ note = _origin.flash[:note]
407
+ html = ''
398
408
  unless err.nil? and war.nil? and inf.nil? and note.nil?
399
- c = ''
400
- c << "<div class=\"dc-form-error\">#{err}</div>" if err
401
- c << "<div class=\"dc-form-warning\">#{war}</div>" if war
402
- c << "<div class=\"dc-form-info\">#{inf}</div>" if inf
403
- c << note if note
409
+ html << "<div class=\"dc-form-error\">#{err}</div>" if err
410
+ html << "<div class=\"dc-form-warning\">#{war}</div>" if war
411
+ html << "<div class=\"dc-form-info\">#{inf}</div>" if inf
412
+ html << note if note
404
413
  _origin.flash[:error] = nil
405
414
  _origin.flash[:warning] = nil
406
415
  _origin.flash[:info] = nil
407
416
  _origin.flash[:note] = nil
408
-
409
- c.html_safe
410
417
  end
418
+ # Update fields on the form
419
+ if _origin.flash[:update]
420
+ html << "<div class=\"dc-form-updates\">\n"
421
+ _origin.flash[:update].each do |field, value|
422
+ html << %Q[<div data-field="#{field}" data-value="#{value}"></div>\n]
423
+ end
424
+ html << '</div>'
425
+ _origin.flash[:update] = nil
426
+ end
427
+ html.html_safe
411
428
  end
412
429
 
413
430
  ########################################################################
@@ -772,9 +789,11 @@ end
772
789
  ############################################################################
773
790
  def dc_name4_id(model, field, field_name, id=nil)
774
791
  return '' if id.nil?
775
- field_name ||= 'id'
792
+ field_name = (field_name || 'id').strip.to_sym
793
+ field = field.strip.to_sym
794
+
776
795
  model = model.strip.classify.constantize if model.class == String
777
- rec = Mongoid::QueryCache.cache { model.find_by(field_name.strip.to_sym => id) }
796
+ rec = Mongoid::QueryCache.cache { model.find_by(field_name => id) }
778
797
  rec.nil? ? '' : (rec.send(field) rescue 'not defined')
779
798
  end
780
799
 
@@ -794,7 +813,7 @@ end
794
813
  # name: active
795
814
  # eval: dc_icon4_boolean
796
815
  ############################################################################
797
- def dc_icon4_boolean(value)
816
+ def dc_icon4_boolean(value=false)
798
817
  dc_dont?(value, true) ? fa_icon('square-o lg') : fa_icon('check-square-o lg')
799
818
  end
800
819
 
@@ -1313,7 +1332,7 @@ def dc_internal_var(object, var_name)
1313
1332
  'VARIABLE: UNKNOWN OBJECT'
1314
1333
  end
1315
1334
  rescue Exception => e
1316
- Rails.logger.error "Method dc_internal var. Runtime error. #{e.message}"
1335
+ logger.error "Method dc_internal_var. Runtime error. #{e.message}"
1317
1336
  'VARIABLE: ERROR'
1318
1337
  end
1319
1338
  end
@@ -1428,11 +1447,9 @@ end
1428
1447
  # [String] alt_image_name
1429
1448
  #######################################################################
1430
1449
  def dc_img_alt(file_name, text=nil)
1431
- if text.blank?
1432
- name = File.basename(file_name.to_s)
1433
- text = name[0,name.index('.')].downcase rescue name
1434
- end
1435
- text
1450
+ return text unless text.blank?
1451
+ name = File.basename(file_name.to_s)
1452
+ name[0,name.index('.')].downcase rescue name
1436
1453
  end
1437
1454
 
1438
1455
 
@@ -144,11 +144,18 @@ def self.get_filter_field(parent)
144
144
  klas = DrgcmsFormFields::const_get(klas_string) rescue nil
145
145
  return '' if klas.nil?
146
146
  # return data from object and create html code to display field
147
- object = klas.new(parent, nil, field).render
148
- js = object.js
149
- "<span class=\"filter_field\" data-url=\"#{url}\">#{object.html} " <<
150
- parent.fa_icon('filter lg', class: 'record_filter_field_icon dc-link-icon dc-animate') <<
151
- (js.size > 2 ? parent.javascript_tag(js) : '') << '</span>'
147
+ object = klas.new(parent, nil, field).render rescue nil
148
+ # Error. Forget filter and return
149
+ if object.nil?
150
+ parent.session[ parent.form['table'] ][:filter] = nil
151
+ return ''
152
+ end
153
+ js = object.js.blank? ? '' : parent.javascript_tag(object.js)
154
+ %Q[<li class="no-background">
155
+ <span class="filter_field" data-url="#{url}">#{object.html}
156
+ #{parent.fa_icon('search lg', class: 'record_filter_field_icon')}
157
+ #{js}</span>
158
+ </li>]
152
159
  end
153
160
 
154
161
  ######################################################################
@@ -74,12 +74,19 @@ def initialize(parms = {})
74
74
  end
75
75
 
76
76
  ########################################################################
77
- # Respond_to should always return true.
77
+ # Return id field
78
78
  ########################################################################
79
79
  def id()
80
80
  @internals['id']
81
81
  end
82
82
 
83
+ ########################################################################
84
+ # Respond_to should always return true.
85
+ ########################################################################
86
+ def id=(value)
87
+ @internals['id'] = value
88
+ end
89
+
83
90
  ########################################################################
84
91
  # Respond_to should always return true.
85
92
  ########################################################################
@@ -51,26 +51,45 @@
51
51
  # as DcSimpleItem embedded structure or as DRG CMS form YAML style entered into form field.
52
52
  ########################################################################
53
53
  class DcPoll
54
- include Mongoid::Document
55
- include Mongoid::Timestamps
54
+
55
+ include Mongoid::Document
56
+ include Mongoid::Timestamps
56
57
 
57
- field :name, type: String, default: ''
58
- field :title, type: String, default: ''
59
- field :sub_text, type: String, default: ''
60
- field :pre_display, type: String
61
- field :operation, type: String
62
- field :parameters, type: String
63
- field :display, type: String, default: '1'
64
- field :css, type: String
65
- field :form, type: String
66
- field :valid_from, type: DateTime
67
- field :valid_to, type: DateTime
68
- field :captcha_type, type: String
69
- field :active, type: Boolean, default: true
70
- field :created_by, type: BSON::ObjectId
71
- field :updated_by, type: BSON::ObjectId
58
+ field :name, type: String, default: ''
59
+ field :title, type: String, default: ''
60
+ field :sub_text, type: String, default: ''
61
+ field :pre_display, type: String
62
+ field :operation, type: String
63
+ field :parameters, type: String
64
+ field :display, type: String, default: '1'
65
+ field :css, type: String
66
+ field :form, type: String
67
+ field :valid_from, type: DateTime
68
+ field :valid_to, type: DateTime
69
+ field :captcha_type, type: String
70
+ field :active, type: Boolean, default: true
71
+ field :created_by, type: BSON::ObjectId
72
+ field :updated_by, type: BSON::ObjectId
72
73
 
73
- index( { name: 1 }, { unique: true } )
74
+ index( { name: 1 }, { unique: true } )
74
75
 
75
- embeds_many :dc_poll_items
76
+ embeds_many :dc_poll_items
77
+
78
+ ########################################################################
79
+ # Save poll results to DcPollResults collection
80
+ #
81
+ # Params:
82
+ # data : Hash : Records hash (params[:record])
83
+ ########################################################################
84
+ def save_results(data)
85
+ h = {}
86
+ items = self.form.blank? ? self.dc_poll_items : YAML.load(self.form.gsub('&nbsp;',' '))
87
+ items.each do |item|
88
+ next if %w(hidden_field submit_tag link_to comment).include?(item.type)
89
+ next if item.try(:options).match('hidden')
90
+ h[ item['name'] ] = data[ item['name'] ]
91
+ end
92
+ DcPollResult.create(dc_poll_id: self.id, data: h.to_yaml)
93
+ end
94
+
76
95
  end
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Copyright (c) 2020+ 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
+ # == Schema information
26
+ #
27
+ # Collection name: dc_poll_results : Pools results saved
28
+ #
29
+ # _id BSON::ObjectId _id
30
+ # dc_poll_id BSON::ObjectId poll id
31
+ # data String Data saved as YAML
32
+ #
33
+ # Results of polls saved as YAML structure.
34
+ ########################################################################
35
+ class DcPollResult
36
+ include Mongoid::Document
37
+ include Mongoid::Timestamps
38
+
39
+ field :data, type: String
40
+ belongs_to :dc_poll
41
+
42
+ index( { dc_poll_id: 1 } )
43
+
44
+ end
@@ -0,0 +1,137 @@
1
+ #--
2
+ # Copyright (c) 2020+ 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
+ # == Schema information
26
+ #
27
+ # Collection name: dc_temp : Collection used for temporary saving of any models data
28
+ #
29
+ # dc_temp collection has only two fields. Key and Data hash. Data must be populated
30
+ # prior to for display best in dc_new_record callback.
31
+ #
32
+ ########################################################################
33
+ class DcTemp
34
+ include Mongoid::Document
35
+ include Mongoid::Timestamps
36
+ field :key, type: String
37
+ field :data, type: Hash, default: {}
38
+ field :active, type: Time, default: Time.now
39
+
40
+ index key: 1
41
+
42
+ ########################################################################
43
+ # Initilize object
44
+ ########################################################################
45
+ def initialize(parms = {})
46
+ super()
47
+ parms.stringify_keys!
48
+ self.key = parms.delete('key') if parms['key']
49
+ self.key = parms.delete('active') if parms['active']
50
+ parms.each { |k, value| self.data[k] = value }
51
+ end
52
+
53
+ ########################################################################
54
+ #
55
+ ########################################################################
56
+ def __id()
57
+ self.data['id']
58
+ end
59
+
60
+ ########################################################################
61
+ # Respond_to should always return true.
62
+ ########################################################################
63
+ def respond_to?(a=nil,b=nil)
64
+ true
65
+ end
66
+
67
+ ########################################################################
68
+ # Redefine send method. Send is used to assign or access value by cmsedit controller.
69
+ ########################################################################
70
+ def send(field,value=nil)
71
+ return super(field) if field.is_a? Symbol
72
+ field = field.to_s
73
+ if field.match('=')
74
+ field.chomp!('=')
75
+ self.data[field] = value
76
+ else
77
+ self.data[field]
78
+ end
79
+ end
80
+
81
+ ########################################################################
82
+ # Redefine [] method to act similar as send method
83
+ ########################################################################
84
+ def [](field)
85
+ self.data[field.to_s]
86
+ end
87
+
88
+ ########################################################################
89
+ # Redefine [] method to act similar as send method
90
+ ########################################################################
91
+ def []=(field, value)
92
+ self.data[field.to_s] = value
93
+ end
94
+
95
+ ########################################################################
96
+ # For debugging purposes
97
+ ########################################################################
98
+ def to_s
99
+ "DcTemp: @key=#{self.key} @data=#{self.data.inspect}"
100
+ end
101
+
102
+ ########################################################################
103
+ # Method missing will return value if value defined by m parameter is saved to
104
+ # @internals array or will save field value to @internals hash if m matches '='.
105
+ ########################################################################
106
+ def method_missing(m, *args, &block) #:nodoc:
107
+ m = m.to_s
108
+ if m.match('=')
109
+ m.chomp!('=')
110
+ self.data[m] = args.first
111
+ else
112
+ self.data[m]
113
+ end
114
+ end
115
+
116
+ ########################################################################
117
+ # Remove all documents with specified key from dc_temp collection
118
+ ########################################################################
119
+ def self.clear(key)
120
+ self.where(key: key).delete
121
+ end
122
+
123
+ ########################################################################
124
+ # Prepare dc_temp for data. It first checks if data associated with the key is to
125
+ # be deleted and then yields block code.
126
+ #
127
+ # Returns: Query for the data associated with the key
128
+ ########################################################################
129
+ def self.prepare(key:, clear: nil)
130
+ unless %w(no false 0).include?(clear.to_s.strip.downcase)
131
+ self.clear(key)
132
+ yield
133
+ end
134
+ self.where(key: key)
135
+ end
136
+
137
+ end