drg_cms 0.6.0.6 → 0.6.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +92 -36
  3. data/app/assets/stylesheets/drg_cms/drg_cms.css +141 -101
  4. data/app/assets/stylesheets/drg_cms/select-multiple.css +9 -12
  5. data/app/assets/stylesheets/drg_cms_cms.css +1 -1
  6. data/app/controllers/cmsedit_controller.rb +100 -32
  7. data/app/controllers/dc_application_controller.rb +71 -12
  8. data/app/controls/dc_report.rb +227 -0
  9. data/app/forms/all_options.yml +24 -5
  10. data/app/forms/dc_big_table.yml +1 -0
  11. data/app/forms/dc_big_table_value.yml +1 -0
  12. data/app/forms/dc_poll.yml +12 -5
  13. data/app/forms/dc_poll_item.yml +2 -1
  14. data/app/forms/dc_poll_result.yml +9 -0
  15. data/app/forms/dc_site.yml +2 -6
  16. data/app/helpers/cms_common_helper.rb +311 -0
  17. data/app/helpers/{cmsedit_edit_helper.rb → cms_edit_helper.rb} +52 -25
  18. data/app/helpers/{cmsedit_helper.rb → cms_helper.rb} +38 -31
  19. data/app/helpers/{cmsedit_index_helper.rb → cms_index_helper.rb} +152 -155
  20. data/app/helpers/dc_application_helper.rb +20 -234
  21. data/app/models/concerns/dc_site_concern.rb +12 -1
  22. data/app/models/dc_filter.rb +10 -8
  23. data/app/models/dc_permission.rb +30 -0
  24. data/app/models/dc_poll.rb +1 -0
  25. data/app/models/dc_poll_result.rb +4 -2
  26. data/app/models/dc_temp.rb +5 -2
  27. data/app/models/drgcms_form_fields.rb +12 -1
  28. data/app/models/drgcms_form_fields/date_picker.rb +4 -3
  29. data/app/models/drgcms_form_fields/datetime_picker.rb +4 -3
  30. data/app/models/drgcms_form_fields/drgcms_field.rb +18 -4
  31. data/app/models/drgcms_form_fields/embedded.rb +17 -9
  32. data/app/models/drgcms_form_fields/file_field.rb +1 -1
  33. data/app/models/drgcms_form_fields/hidden_field.rb +1 -1
  34. data/app/models/drgcms_form_fields/method.rb +65 -0
  35. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +17 -11
  36. data/app/models/drgcms_form_fields/radio.rb +10 -5
  37. data/app/models/drgcms_form_fields/readonly.rb +1 -1
  38. data/app/models/drgcms_form_fields/select.rb +49 -32
  39. data/app/models/drgcms_form_fields/text_autocomplete.rb +21 -21
  40. data/app/renderers/dc_big_menu_renderer.rb +1 -0
  41. data/app/renderers/dc_gallery_renderer.rb +1 -0
  42. data/app/renderers/dc_menu_renderer.rb +1 -0
  43. data/app/renderers/dc_page_renderer.rb +1 -0
  44. data/app/renderers/dc_part_renderer.rb +1 -0
  45. data/app/renderers/dc_piece_renderer.rb +1 -1
  46. data/app/renderers/dc_poll_renderer.rb +43 -38
  47. data/app/renderers/dc_renderer.rb +1 -0
  48. data/app/renderers/dc_simple_menu_renderer.rb +1 -0
  49. data/config/locales/drgcms_en.yml +3 -2
  50. data/config/locales/drgcms_sl.yml +5 -4
  51. data/config/locales/models_en.yml +9 -2
  52. data/config/locales/models_sl.yml +10 -3
  53. data/lib/drg_cms/version.rb +1 -1
  54. data/lib/generators/new_drg_form/new_drg_form_generator.rb +5 -3
  55. data/lib/tasks/database.rake +6 -56
  56. metadata +35 -33
  57. data/app/helpers/application_helper.rb +0 -2
@@ -33,9 +33,11 @@
33
33
  class DcTemp
34
34
  include Mongoid::Document
35
35
  include Mongoid::Timestamps
36
+
36
37
  field :key, type: String
37
38
  field :data, type: Hash, default: {}
38
39
  field :active, type: Time, default: Time.now
40
+ field :order, type: String
39
41
 
40
42
  index key: 1
41
43
 
@@ -45,8 +47,9 @@ class DcTemp
45
47
  def initialize(parms = {})
46
48
  super()
47
49
  parms.stringify_keys!
48
- self.key = parms.delete('key') if parms['key']
49
- self.key = parms.delete('active') if parms['active']
50
+ self.key = parms.delete('key') if parms['key']
51
+ self.active = parms.delete('active') if parms['active']
52
+ self.order = parms.delete('order') if parms['order']
50
53
  parms.each { |k, value| self.data[k] = value }
51
54
  end
52
55
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2012+ Damjan Rems
2
+ # Copyright (c) 2020+ Damjan Rems
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -22,5 +22,16 @@
22
22
  #++
23
23
 
24
24
  module DrgcmsFormFields
25
+
26
+ def self.field(parent, record, options)
27
+ klass = options['type'].camelize
28
+ if DrgcmsFormFields.const_defined?(klass)
29
+ field = DrgcmsFormFields.const_get(klass).new(parent, record, options).render
30
+ [field.html + (field.js.size > 0 ? @parent.javascript_tag(field.js) : ''),field.css]
31
+ else
32
+ nil
33
+ end
34
+ end
35
+
25
36
  end
26
37
 
@@ -67,17 +67,18 @@ class DatePicker < DrgcmsField
67
67
  def render
68
68
  value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].to_date) : nil
69
69
  #return ro_standard( @parent.dc_format_value(value)) if @readonly
70
- #
70
+
71
71
  @yaml['options'] ||= {}
72
72
  set_initial_value
73
73
  @yaml['html']['size'] ||= @yaml['size'] || 10
74
74
  @yaml['html']['value'] ||= value
75
75
  @yaml['html']['autocomplete'] ||= 'off'
76
- #
76
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
77
+
77
78
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
78
79
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
79
80
  @yaml['options']['timepicker'] = false
80
- #
81
+
81
82
  record = record_text_for(@yaml['name'])
82
83
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
83
84
  @js << %Q[
@@ -53,16 +53,17 @@ class DatetimePicker < DrgcmsField
53
53
  def render
54
54
  value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].localtime) : nil
55
55
  #return ro_standard( @parent.dc_format_value(value)) if @readonly
56
- #
56
+
57
57
  @yaml['options'] ||= {}
58
58
  set_initial_value
59
59
  @yaml['html']['size'] ||= @yaml['size'] || 14
60
60
  @yaml['html']['value'] ||= value if @record[@yaml['name']]
61
61
  @yaml['html']['autocomplete'] ||= 'off'
62
- #
62
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
63
+
63
64
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
64
65
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
65
- #
66
+
66
67
  record = record_text_for(@yaml['name'])
67
68
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
68
69
  @js << %Q[
@@ -128,7 +128,6 @@ end
128
128
  # Standard code for returning readonly field.
129
129
  ####################################################################
130
130
  def ro_standard(value=nil)
131
- p @yaml['name'],value
132
131
  if value.nil?
133
132
  value = if @yaml['html']['value']
134
133
  @yaml['html']['value']
@@ -152,7 +151,7 @@ end
152
151
  # flash[:record] = {}
153
152
  # flash[:record]['picture'] = '/path/to_picture'
154
153
  ####################################################################
155
- def set_initial_value(opt1='html', opt2='value')
154
+ def set_initial_value(opt1 = 'html', opt2 = 'value')
156
155
  @yaml['html'] ||= {}
157
156
  value_send_as = 'p_' + @yaml['name']
158
157
  if @parent.params[value_send_as]
@@ -160,11 +159,26 @@ def set_initial_value(opt1='html', opt2='value')
160
159
  elsif @parent.flash[:record] and @parent.flash[:record][@yaml['name']]
161
160
  @yaml[opt1][opt2] = @parent.flash[:record][@yaml['name']]
162
161
  end
162
+ set_default_value(opt1, opt2) if @yaml['default']
163
+ end
164
+
165
+ ####################################################################
166
+ # Will set default value
167
+ ####################################################################
168
+ def set_default_value(opt1, opt2)
169
+ return if @yaml[opt1][opt2].present?
170
+ return if @record && @record[@yaml['name']].present?
171
+
172
+ @yaml[opt1][opt2] = if @yaml['default'].class == Hash
173
+ eval(@yaml['default']['eval'])
174
+ else
175
+ @yaml['default']
176
+ end
163
177
  end
164
178
 
165
179
  ####################################################################
166
180
  # Returns style html code for DRGForm object if style directive is present in field definition.
167
- # Otherwiese returns empty string.
181
+ # Otherwise returns empty string.
168
182
  #
169
183
  # Style may be defined like:
170
184
  # style:
@@ -202,7 +216,7 @@ end
202
216
  # Returns css code for the field if specified. It replaces all occurences of '# '
203
217
  # with field name id, as defined on form.
204
218
  ####################################################################
205
- def css_code
219
+ def __css_code
206
220
  return '' if @css.blank?
207
221
  @css.gsub!('# ',"#td_record_#{@yaml['name']} ")
208
222
  "\n<style type=\"text/css\">#{@css}</style>"
@@ -31,6 +31,7 @@ module DrgcmsFormFields
31
31
  # * +name:+ field name (required)
32
32
  # * +type:+ embedded (required)
33
33
  # * +form_name:+ name of form which will be used for editing
34
+ # * +load:+ when is embedded iframe loaded. default=on form load, delay=on tab select, always=every time tab is selected)
34
35
  # * +html:+ html options (optional)
35
36
  # * +height:+ height of embedded object in pixels (1000)
36
37
  # * +width:+ width of embedded object in pixels (500)
@@ -40,6 +41,7 @@ module DrgcmsFormFields
40
41
  # name: dc_parts
41
42
  # type: embedded
42
43
  # form_name: dc_part
44
+ # refresh: delay
43
45
  # html:
44
46
  # height: 1000
45
47
  ###########################################################################
@@ -49,25 +51,27 @@ class Embedded < DrgcmsField
49
51
  ###########################################################################
50
52
  def render
51
53
  #return self if @record.new_record? # would be in error otherwise
52
- # HTML defaults. Some must be set
54
+ # HTML defaults. Some must be set
53
55
  @yaml['html'] ||= {}
54
56
  @yaml['html']['height'] ||= 300
55
57
  @yaml['html']['width'] ||= '99%'
56
- # defaults both way
58
+ @yaml['action'] ||= 'index'
59
+ # defaults both way
57
60
  @yaml['table'] ||= @yaml['form_name'] if @yaml['form_name']
58
61
  @yaml['form_name'] ||= @yaml['table'] if @yaml['table']
59
- #
62
+ #
60
63
  html = ''
61
64
  @yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
62
- #
65
+ #
63
66
  if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
64
67
  tables = @yaml['table']
65
- ids = @record._id
68
+ ids = @record.id
66
69
  else
67
- tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
68
- ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record._id
70
+ tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
71
+ ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record.id
69
72
  end
70
- opts = { controller: 'cmsedit', action: 'index', ids: ids, table: tables, form_name: @yaml['form_name'],
73
+ opts = { controller: 'cmsedit', action: @yaml['action'],
74
+ ids: ids, table: tables, form_name: @yaml['form_name'],
71
75
  field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: @readonly }
72
76
  # additional parameters if specified
73
77
  @yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
@@ -75,7 +79,11 @@ def render
75
79
  @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
76
80
  unless @record.new_record?
77
81
  url = @parent.url_for(opts)
78
- data = @yaml['delay'] ? 'data-src-delay' : 'src'
82
+ data = if @yaml['load'].nil? || @yaml['load'].match('default')
83
+ "src"
84
+ else
85
+ "data-src-#{@yaml['load']}"
86
+ end
79
87
  @js << %Q[
80
88
  $(document).ready( function() {
81
89
  $('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
@@ -44,7 +44,7 @@ class FileField < DrgcmsField
44
44
  def render
45
45
  return self if @readonly
46
46
  #record = record_text_for(@yaml['name'])
47
- @html << @parent.file_field( @yaml['name'], @yaml['html'])
47
+ @html << @parent.file_field(nil,@yaml['name'], @yaml['html'])
48
48
  self
49
49
  end
50
50
 
@@ -42,7 +42,7 @@ class HiddenField < DrgcmsField
42
42
  ###########################################################################
43
43
  def render
44
44
  set_initial_value
45
- value = @yaml['html']['value'] ? @yaml['html']['value'] : @record[@yaml['name']]
45
+ value = @yaml['html']['value'] ? @yaml['html']['value'] : @record.send(@yaml['name'])
46
46
  record = record_text_for(@yaml['name'])
47
47
  @parent.hidden_field(record, @yaml['name'], value: value)
48
48
  end
@@ -0,0 +1,65 @@
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
+ module DrgcmsFormFields
24
+
25
+ ###########################################################################
26
+ # Implementation of custom DRG CMS form field. Method field will call method or class method
27
+ # defined in eval option and add returned code to HTML output code. This might prove usefull in
28
+ # cases where form contains complex dta stgructer or set of pictures which can not
29
+ # be simply displayed by any other field.
30
+ #
31
+ # Form example:
32
+ # 50:
33
+ # name: galery
34
+ # type: method
35
+ # eval: show_gallery
36
+ # or
37
+ # eval: MyClass.show_gallery
38
+ #
39
+ ###########################################################################
40
+ class Method < DrgcmsField
41
+
42
+ ###########################################################################
43
+ # Render file_select field html code
44
+ ###########################################################################
45
+ def render
46
+ # might be defined as my_method or MyClass.my_method
47
+ clas, method = @yaml['eval'].split('.')
48
+ if method.nil?
49
+ if @parent.respond_to?(clas)
50
+ @html << @parent.send(clas, @record, @yaml, @readonly)
51
+ return self
52
+ end
53
+ else
54
+ klass = clas.camelize.constantize
55
+ if klass.respond_to?(method)
56
+ @html << klass.send(method, @record, @yaml, @readonly)
57
+ return self
58
+ end
59
+ end
60
+ @html << "Error: #{@yaml['name']} : #{@yaml['eval']} not defined!"
61
+ self
62
+ end
63
+
64
+ end
65
+ end
@@ -23,7 +23,7 @@
23
23
  module DrgcmsFormFields
24
24
 
25
25
  ###########################################################################
26
- # Implementation of multitext_autocomplete DRG CMS form field.
26
+ # Implementation of multitext_autocomplete DRG Form field.
27
27
  #
28
28
  # multitext_autocomplete field is complex data entry field which uses autocomplete
29
29
  # function when selecting multiple values for MongoDB Array field. Array typically holds
@@ -33,20 +33,21 @@ module DrgcmsFormFields
33
33
  # ===Form options:
34
34
  # * +name:+ field name (required)
35
35
  # * +type:+ multitext_autocomplete (required)
36
- # * +table+ Collection (table) name. When defined search must contain field name
36
+ # * +table+ Model (table) name which must contain searched field name.
37
37
  # * +search:+ Search may consist of three parameters from which are separated either by dot (.) or comma(,)
38
38
  # * search_field_name; when table option is defined search must define field name which will be used for search query
39
39
  # * collection_name.search_field_name; Same as above except that table options must be ommited.
40
40
  # * collection_name.search_field_name.method_name; When searching is more complex custom search
41
41
  # method may be defined in CollectionName model which will provide result set for search.
42
+ # * +with_new+ Will add an icon for shortcut to add new document to collection
42
43
  #
43
44
  # Form example:
44
45
  # 90:
45
46
  # name: kats
46
47
  # type: multitext_autocomplete
47
48
  # search: dc_category.name
48
- # html:
49
- # size: 30
49
+ # with_new: model_name
50
+ # size: 30
50
51
  ###########################################################################
51
52
  class MultitextAutocomplete < DrgcmsField
52
53
 
@@ -89,7 +90,7 @@ def render
89
90
  elsif @yaml['table']['eval']
90
91
  eval @yaml['table']['eval']
91
92
  else
92
- p "Field #{@yaml['name']}: Invalid table parameter!"
93
+ @parent.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
93
94
  nil
94
95
  end
95
96
  end
@@ -97,15 +98,14 @@ def render
97
98
  @html << 'Table or search field not defined!'
98
99
  return self
99
100
  end
100
- #
101
- #return ro_standard(table, search) if @readonly
102
- # TODO check if table exists
101
+ #
102
+ # TODO check if table exists
103
103
  collection = table.classify.constantize
104
104
  unless @record.respond_to?(@yaml['name'])
105
105
  @html << "Invalid field name: #{@yaml['name']}"
106
106
  return self
107
107
  end
108
- # put field to enter search data on form
108
+ # put field to enter search data on form
109
109
  @yaml['html'] ||= {}
110
110
  @yaml['html']['value'] = '' # must be. Otherwise it will look into record and return error
111
111
  @yaml['html']['placeholder'] = t('drgcms.search_placeholder')
@@ -115,10 +115,16 @@ def render
115
115
 
116
116
  record = record_text_for(@yaml['name'])
117
117
  # text field for autocomplete
118
- @html << ' ' << @parent.text_field(record, _name, @yaml['html'])
118
+ @html << '<span class="dc-text-autocomplete">' << @parent.text_field(record, _name, @yaml['html']) << '<span></span></span>'
119
+ # direct link for adding new documents to collection
120
+ if @yaml['with_new'] and !@readonly
121
+ @html << ' ' +
122
+ @parent.fa_icon('plus-square lg', class: 'in-edit-add', title: t('drgcms.new'),
123
+ style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
124
+ end
119
125
  # div to list active selections
120
126
  @html << "<div id =\"#{record}#{@yaml['name']}\">"
121
- # find value for each field inside categories
127
+ # find value for each field inside categories
122
128
  unless @record[@yaml['name']].nil?
123
129
  @record[@yaml['name']].each do |element|
124
130
  # this is quick and dirty trick. We have model dc_big_table which can be used for retrive
@@ -61,10 +61,9 @@ module DrgcmsFormFields
61
61
  class Radio < Select
62
62
 
63
63
  ###########################################################################
64
- # Render text_with_select field html code
64
+ # Render radio DRG Form field
65
65
  ###########################################################################
66
66
  def render
67
- #return ro_standard if @readonly
68
67
  set_initial_value('html','value')
69
68
 
70
69
  record = record_text_for(@yaml['name'])
@@ -73,13 +72,19 @@ def render
73
72
  @html << "<div class=\"#{clas}\">"
74
73
  choices = get_choices
75
74
  # When error and boolean field
76
- if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
77
- choices = [[I18n.t('drgcms.true'), true], [I18n.t('drgcms.false'), false]]
75
+ #if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
76
+ # choices = [[I18n.t('drgcms.true'), true], [I18n.t('drgcms.false'), false]]
77
+ #end
78
+ # Should select first button if no value provided
79
+ value = if @record.nil? || @record[@yaml['name']].blank?
80
+ choices.first.class == String ? choices.first : choices.first.last
81
+ else
82
+ @record[@yaml['name']]
78
83
  end
79
84
  choices.each do |choice|
80
85
  choice = [choice, choice] if choice.class == String
81
86
  @html << "<div>"
82
- @html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s == @record[@yaml['name']].to_s)
87
+ @html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s == value.to_s)
83
88
  @html << choice.first
84
89
  @html << "</div>"
85
90
  end
@@ -66,7 +66,7 @@ def render
66
66
 
67
67
  # @parent.dc_name4_id(a[1], a[2], @record[ @yaml['name'] ])
68
68
  else
69
- eval( "#{@yaml['eval']} '#{@record[ @yaml['name'] ]}'")
69
+ eval( "#{@yaml['eval']} '#{@record.send(@yaml['name'])}'")
70
70
  end
71
71
  else
72
72
  @parent.dc_format_value(@record.send(@yaml['name']),@yaml['format'])
@@ -62,6 +62,8 @@ module DrgcmsFormFields
62
62
  # name: company
63
63
  # type: select
64
64
  # choices: Audi,BMW,Mercedes
65
+ # or
66
+ # choices: helpers.label.model.choices4_field
65
67
  # 60:
66
68
  # name: type
67
69
  # type: select
@@ -75,8 +77,8 @@ class Select < DrgcmsField
75
77
  # helper.label.table_name.choices_for_fieldname or
76
78
  # choices4_tablename_fieldname
77
79
  ###########################################################################
78
- def choices_in_helper(all)
79
- helper = "helpers.label.#{@form['table']}.choices4_#{@yaml['name']}"
80
+ def choices_in_helper(helper = nil)
81
+ helper ||= "helpers.label.#{@form['table']}.choices4_#{@yaml['name']}"
80
82
  c = t(helper)
81
83
  if c.match( 'translation missing' )
82
84
  helper = "choices_for_#{@form['table']}_#{@yaml['name']}"
@@ -86,10 +88,10 @@ def choices_in_helper(all)
86
88
  end
87
89
 
88
90
  ###########################################################################
89
- # Choices are defined by evaluating an exspression. This is most common class
90
- # method defined in a class. SomeClass.get_choices4.
91
+ # Choices are defined by evaluating an expression. This is most common class
92
+ # method defined in a class. eg. SomeClass.get_choices4
91
93
  ###########################################################################
92
- def choices_in_eval(e, all=false)
94
+ def choices_in_eval(e)
93
95
  e.strip!
94
96
  if @yaml['depend'].nil?
95
97
  method = e.split(/\ |\(/).first
@@ -99,19 +101,15 @@ def choices_in_eval(e, all=false)
99
101
  eval e
100
102
  else
101
103
  # add event listener to depend field
102
- @js << %Q[
104
+ @js << %(
103
105
  $(document).ready(function() {
104
106
  $('#record_#{@yaml['depend']}').change( function(e) { update_select_depend('record_#{@yaml['name']}', 'record_#{@yaml['depend']}','#{e}');});
105
107
  $('#_record_#{@yaml['depend']}').change( function(e) { update_select_depend('record_#{@yaml['name']}', '_record_#{@yaml['depend']}','#{e}');});
106
108
  });
107
- ]
108
- # depend field might be virtual field. Its value should be set in params
109
- depend_value = if @yaml['depend'][0] == '_'
110
- @parent.params["p_#{@yaml['depend']}"]
111
- else
112
- @record[@yaml['depend']]
113
- end
114
-
109
+ )
110
+ # depend field might be virtual field. It's value should be set in params
111
+ depend_value = @yaml['depend'][0] == '_' ? @parent.params["p_#{@yaml['depend']}"] : @record[@yaml['depend']]
112
+
115
113
  e << " '#{depend_value}'"
116
114
  eval e
117
115
  end
@@ -120,19 +118,19 @@ end
120
118
  ###########################################################################
121
119
  # Create choices array for select field.
122
120
  ###########################################################################
123
- def get_choices(all=false)
121
+ def get_choices
124
122
  begin
125
123
  choices = case
126
- when @yaml['choices'] then
127
- @yaml['choices']
128
- when @yaml['eval'] then
129
- choices_in_eval(@yaml['eval'], all)
130
- else
131
- choices_in_helper(all)
132
- end
124
+ when @yaml['choices'] then
125
+ @yaml['choices'].match('helpers.') ? choices_in_helper(@yaml['choices']) : @yaml['choices']
126
+ when @yaml['eval'] then
127
+ choices_in_eval(@yaml['eval'])
128
+ else
129
+ choices_in_helper()
130
+ end
133
131
  # Convert string to Array
134
132
  choices.class == String ?
135
- choices.chomp.split(',').inject([]) {|r,v| r << (v.match(':') ? v.split(':') : v )} :
133
+ choices.chomp.split(',').inject([]) { |r,v| r << (v.match(':') ? v.split(':') : v ) } :
136
134
  choices
137
135
  rescue Exception => e
138
136
  Rails.logger.debug "Error in select eval. #{e.message}\n"
@@ -140,14 +138,25 @@ def get_choices(all=false)
140
138
  end
141
139
  end
142
140
 
141
+ ###########################################################################
142
+ # Will add code to view more data about selected option in a window
143
+ ###########################################################################
144
+ def add_view_code
145
+ return '' if (data = @record.send(@yaml['name'])).blank?
146
+ ar = @yaml['view'].split(/\ |\,/).delete_if {|e| e.blank?}
147
+ table, form_name = *ar
148
+ url = @parent.url_for(controller: :cmsedit, id: data, action: :edit, table: table, form_name: form_name, readonly: true, window_close: 1 )
149
+ icon = @parent.fa_icon('eye')
150
+ %(<span class="dc-window-open" data-url="#{url}">#{icon}</span>)
151
+ end
152
+
143
153
  ###########################################################################
144
154
  # Return value when readonly is required
145
155
  ###########################################################################
146
156
  def ro_standard
147
- #value = @yaml['html']['value'] ? @yaml['html']['value'] : nil
148
- value = @record.respond_to?(@yaml['name']) ? @record[@yaml['name']] : nil
149
- return self if value.nil?
150
- #
157
+ value = @record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
158
+ return self if value.blank?
159
+
151
160
  choices = get_choices()
152
161
  if value.class == Array # multiple choices
153
162
  html = ''
@@ -178,14 +187,21 @@ end
178
187
  def render
179
188
  return ro_standard if @readonly
180
189
  set_initial_value('html','selected')
181
- #
190
+ # separate options and html part
182
191
  @yaml['html'].symbolize_keys!
192
+ html_part = {}
193
+ html_part[:class] = @yaml['html'].delete(:class) if @yaml['html'][:class]
194
+ html_part[:id] = @yaml['html'].delete(:id) if @yaml['html'][:id]
195
+ html_part[:style] = @yaml['html'].delete(:style) if @yaml['html'][:style]
183
196
  record = record_text_for(@yaml['name'])
184
- if @yaml['multiple']
185
- @html << @parent.select(record, @yaml['name'], get_choices, @yaml['html'], {multiple: true})
197
+ if @yaml['multiple']
198
+ html_part[:multiple] = true
199
+ @html << @parent.select(record, @yaml['name'], get_choices, @yaml['html'], html_part)
186
200
  @js << "$('##{record}_#{@yaml['name']}').selectMultiple();"
187
201
  else
188
- @html << @parent.select(record, @yaml['name'], get_choices, @yaml['html'])
202
+ @html << @parent.select(record, @yaml['name'], get_choices, @yaml['html'], html_part)
203
+ # add code for view more data
204
+ @html << add_view_code() if @yaml['view']
189
205
  end
190
206
  self
191
207
  end
@@ -197,7 +213,8 @@ def self.get_data(params, name)
197
213
  if params['record'][name].class == Array
198
214
  params['record'][name].delete_if {|e| e.blank? }
199
215
  return nil if params['record'][name].size == 0
200
- # convert to BSON objects
216
+
217
+ # convert to BSON objects
201
218
  is_id = BSON::ObjectId.legal?(params['record'][name].first)
202
219
  return params['record'][name].map{ |e| BSON::ObjectId.from_string(e) } if is_id
203
220
  return params['record'][name]