drg_cms 0.5.52.12 → 0.6.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +395 -120
  3. data/app/assets/javascripts/drg_cms/jstree.min.js +6 -6
  4. data/app/assets/javascripts/drg_cms_application.js +1 -1
  5. data/app/assets/stylesheets/drg_cms/drg_cms.css +476 -215
  6. data/app/assets/stylesheets/drg_cms/jstree.css +6 -12
  7. data/app/assets/stylesheets/drg_cms/select-multiple.css +19 -13
  8. data/app/assets/stylesheets/drg_cms_cms.css +1 -1
  9. data/app/controllers/cmsedit_controller.rb +474 -233
  10. data/app/controllers/dc_application_controller.rb +264 -41
  11. data/app/controllers/dc_common_controller.rb +75 -63
  12. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  13. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  14. data/app/controls/dc_poll_result_control.rb +88 -0
  15. data/app/controls/dc_report.rb +227 -0
  16. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  17. data/app/forms/all_options.yml +70 -12
  18. data/app/forms/cms_menu.yml +26 -17
  19. data/app/forms/dc_ad.yml +11 -22
  20. data/app/forms/dc_big_table.yml +1 -0
  21. data/app/forms/dc_big_table_value.yml +1 -0
  22. data/app/forms/dc_design.yml +19 -16
  23. data/app/forms/dc_filter.yml +3 -6
  24. data/app/forms/dc_gallery.yml +53 -0
  25. data/app/forms/dc_json_ld.yml +59 -0
  26. data/app/forms/dc_key_value.yml +32 -0
  27. data/app/forms/dc_link.yml +16 -10
  28. data/app/forms/dc_menu_item.yml +6 -0
  29. data/app/forms/dc_page.yml +2 -7
  30. data/app/forms/dc_poll.yml +16 -9
  31. data/app/forms/dc_poll_item.yml +2 -1
  32. data/app/forms/dc_poll_result.yml +83 -0
  33. data/app/forms/dc_poll_result_export.yml +35 -0
  34. data/app/forms/dc_removed_url.yml +42 -0
  35. data/app/forms/dc_seo.yml +33 -0
  36. data/app/forms/dc_site.yml +2 -6
  37. data/app/forms/json_ld_schema.yml +168 -0
  38. data/app/helpers/cms_common_helper.rb +311 -0
  39. data/app/helpers/cms_edit_helper.rb +498 -0
  40. data/app/helpers/cms_helper.rb +230 -0
  41. data/app/helpers/cms_index_helper.rb +564 -0
  42. data/app/helpers/dc_application_helper.rb +195 -268
  43. data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
  44. data/app/models/concerns/dc_page_concern.rb +31 -6
  45. data/app/models/concerns/dc_seo_concern.rb +66 -0
  46. data/app/models/concerns/dc_site_concern.rb +12 -1
  47. data/app/models/concerns/dc_user_concern.rb +5 -3
  48. data/app/models/dc_design.rb +2 -0
  49. data/app/models/dc_filter.rb +37 -20
  50. data/app/models/dc_gallery.rb +64 -0
  51. data/app/models/dc_json_ld.rb +152 -0
  52. data/app/models/dc_key_value.rb +48 -0
  53. data/app/models/dc_link.rb +1 -0
  54. data/app/models/dc_memory.rb +26 -4
  55. data/app/models/dc_page.rb +1 -2
  56. data/app/models/dc_permission.rb +30 -0
  57. data/app/models/dc_poll.rb +39 -19
  58. data/app/models/dc_poll_result.rb +46 -0
  59. data/app/models/dc_removed_url.rb +54 -0
  60. data/app/models/dc_temp.rb +140 -0
  61. data/app/models/drgcms_form_fields.rb +6 -1642
  62. data/app/models/drgcms_form_fields/action.rb +61 -0
  63. data/app/models/drgcms_form_fields/check_box.rb +72 -0
  64. data/app/models/drgcms_form_fields/comment.rb +53 -0
  65. data/app/models/drgcms_form_fields/date_picker.rb +104 -0
  66. data/app/models/drgcms_form_fields/date_select.rb +68 -0
  67. data/app/models/drgcms_form_fields/datetime_picker.rb +89 -0
  68. data/app/models/drgcms_form_fields/datetime_select.rb +73 -0
  69. data/app/models/drgcms_form_fields/drgcms_field.rb +287 -0
  70. data/app/models/drgcms_form_fields/embedded.rb +97 -0
  71. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  72. data/app/models/drgcms_form_fields/file_select.rb +70 -0
  73. data/app/models/drgcms_form_fields/hash_field.rb +86 -0
  74. data/app/models/drgcms_form_fields/hidden_field.rb +52 -0
  75. data/app/models/drgcms_form_fields/html_field.rb +70 -0
  76. data/app/models/drgcms_form_fields/journal_diff.rb +60 -0
  77. data/app/models/drgcms_form_fields/link_to.rb +69 -0
  78. data/app/models/drgcms_form_fields/method.rb +65 -0
  79. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +204 -0
  80. data/app/models/drgcms_form_fields/number_field.rb +92 -0
  81. data/app/models/drgcms_form_fields/password_field.rb +62 -0
  82. data/app/models/drgcms_form_fields/radio.rb +96 -0
  83. data/app/models/drgcms_form_fields/readonly.rb +79 -0
  84. data/app/models/drgcms_form_fields/select.rb +226 -0
  85. data/app/models/drgcms_form_fields/submit_tag.rb +58 -0
  86. data/app/models/drgcms_form_fields/text_area.rb +68 -0
  87. data/app/models/drgcms_form_fields/text_autocomplete.rb +155 -0
  88. data/app/models/drgcms_form_fields/text_field.rb +56 -0
  89. data/app/models/drgcms_form_fields/text_with_select.rb +95 -0
  90. data/app/models/drgcms_form_fields/tree_select.rb +169 -0
  91. data/app/{helpers → renderers}/dc_ad_renderer.rb +0 -0
  92. data/app/{helpers → renderers}/dc_big_menu_renderer.rb +1 -0
  93. data/app/{helpers → renderers}/dc_captcha_renderer.rb +0 -0
  94. data/app/{helpers → renderers}/dc_common_renderer.rb +0 -0
  95. data/app/renderers/dc_gallery_renderer.rb +95 -0
  96. data/app/{helpers → renderers}/dc_menu_renderer.rb +11 -4
  97. data/app/{helpers → renderers}/dc_page_renderer.rb +21 -3
  98. data/app/{helpers → renderers}/dc_part_renderer.rb +5 -4
  99. data/app/{helpers → renderers}/dc_piece_renderer.rb +1 -1
  100. data/app/{helpers → renderers}/dc_poll_renderer.rb +86 -51
  101. data/app/{helpers → renderers}/dc_renderer.rb +1 -0
  102. data/app/{helpers → renderers}/dc_simple_menu_renderer.rb +1 -0
  103. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  104. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  105. data/app/views/cmsedit/_edit_stuff.html.erb +4 -25
  106. data/app/views/cmsedit/_form.html.erb +4 -3
  107. data/app/views/cmsedit/_result.html.erb +2 -3
  108. data/app/views/cmsedit/edit.html.erb +2 -1
  109. data/app/views/cmsedit/index.html.erb +6 -1
  110. data/app/views/cmsedit/new.html.erb +1 -1
  111. data/config/locales/drgcms_en.yml +15 -3
  112. data/config/locales/drgcms_sl.yml +18 -6
  113. data/config/locales/models_en.yml +103 -19
  114. data/config/locales/models_sl.yml +102 -17
  115. data/drg_cms.gemspec +3 -3
  116. data/lib/drg_cms.rb +6 -2
  117. data/lib/drg_cms/version.rb +2 -2
  118. data/lib/generators/new_drg_form/new_drg_form_generator.rb +9 -2
  119. data/lib/tasks/database.rake +6 -56
  120. data/lib/tasks/dc_cleanup.rake +1 -1
  121. metadata +106 -61
  122. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  123. data/app/helpers/application_helper.rb +0 -2
  124. data/app/helpers/cmsedit_helper.rb +0 -844
  125. data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -0,0 +1,73 @@
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
+ ###########################################################################
27
+ # Create datetime_select form field
28
+ #
29
+ # ===Form options:
30
+ # * +type:+ datetime_select (required)
31
+ # * +name:+ Field name (required)
32
+ # * +options:+ options which apply to date_select field (optional)
33
+ # * +html:+ html options which apply to password field (optional)
34
+ #
35
+ # Form example:
36
+ # 60:
37
+ # name: end_time
38
+ # type: datetime_select
39
+ # options:
40
+ # include_blank: true
41
+ ###########################################################################
42
+ class DatetimeSelect < DrgcmsField
43
+
44
+ ###########################################################################
45
+ # Render datetime_select field html code
46
+ ###########################################################################
47
+ def render
48
+ #return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
49
+ #
50
+ @yaml['options'] ||= {}
51
+ set_initial_value('options','default')
52
+ @yaml['options'].symbolize_keys!
53
+ @yaml['html'].symbolize_keys!
54
+ #
55
+ record = record_text_for(@yaml['name'])
56
+ @html << @parent.datetime_select(record, @yaml['name'], @yaml['options'], @yaml['html'])
57
+ self
58
+ end
59
+
60
+ ####################################################################
61
+ # DatetimeSelect get_data method.
62
+ ####################################################################
63
+ def self.get_data(params, name)
64
+ begin
65
+ attrs = (1..5).map { |i| params['record']["#{name}(#{i}i)"]}
66
+ Time.zone.local(*attrs)
67
+ rescue
68
+ nil
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,287 @@
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
+ # DrgcmsFormFields module contains definitions of classes used for
26
+ # rendering data entry fields on DRG CMS forms.
27
+ #
28
+ # Every data entry field type written in lowercase in form must have its class
29
+ # defined in CamelCase in DrgcmsFormFields module.
30
+ #
31
+ # Each class must have at least render method implemented. All classes can
32
+ # inherit from DrgcmsField class which acts as abstract template class and implements
33
+ # most of surrounding code for creating custom DRG CMS form field.
34
+ #
35
+ # Render method must create html and javascript code which must be
36
+ # saved to internal @html and @js variables. Field code is then retrived by accessing
37
+ # these two internal variables.
38
+ #
39
+ # Example. How the field code is generated in form renderer:
40
+ # klas_string = yaml['type'].camelize
41
+ # if DrgcmsFormFields.const_defined?(klas_string) # check if field type class is defined
42
+ # klas = DrgcmsFormFields.const_get(klas_string)
43
+ # field = klas.new(self, @record, options).render
44
+ # javascript << field.js
45
+ # html << field.html
46
+ # end
47
+ #
48
+ # Example. How to mix DRG CMS field code in Rails views:
49
+ # <div>User:
50
+ # <%=
51
+ # opts = {'name' => 'user', 'eval' => "dc_choices4('dc_user','name')",
52
+ # 'html' => { 'include_blank' => true } }
53
+ # dt = DrgcmsFormFields::Select.new(self, {}, opts).render
54
+ # (dt.html + javascript_tag(dt.js)).html_safe
55
+ # %></div>
56
+ ###########################################################################
57
+ module DrgcmsFormFields
58
+
59
+ ###########################################################################
60
+ # Template method for DRG CMS form field definition. This is abstract class with
61
+ # most of the common code for custom form field already implemented.
62
+ ###########################################################################
63
+ class DrgcmsField
64
+ attr_reader :js
65
+ attr_reader :css
66
+
67
+ ####################################################################
68
+ # DrgcmsField initialization code.
69
+ #
70
+ # Parameters:
71
+ # [parent] Controller object. Controller object from where object is created. Usually self is send.
72
+ # [record] Document object. Document object which holds fields data.
73
+ # [yaml] Hash. Hash object holding field definition data.
74
+ #
75
+ # Returns:
76
+ # Self
77
+ ####################################################################
78
+ def initialize( parent, record, yaml )
79
+ @parent = parent
80
+ @record = record
81
+ @yaml = yaml
82
+ @form = parent.form
83
+ @yaml['html'] ||= {}
84
+ # set readonly field
85
+ @readonly = (@yaml and @yaml['readonly']) || (@form and @form['readonly'])
86
+ @yaml['html']['readonly'] = true if @readonly
87
+ # assign size to html element if not already there
88
+ @yaml['html']['size'] ||= @yaml['size'] if @yaml['size']
89
+
90
+ @html = ''
91
+ @js = ''
92
+ @css = set_css_code @yaml['css']
93
+ self
94
+ end
95
+
96
+ ####################################################################
97
+ # Returns html code together with CSS code.
98
+ ####################################################################
99
+ def html
100
+ @html
101
+ end
102
+
103
+ ####################################################################
104
+ # Wrapper for i18 t method, with some spice added. If translation is not found English
105
+ # translation value will be returned. And if still not found default value will be returned if passed.
106
+ #
107
+ # Parameters:
108
+ # [key] String. String to be translated into locale.
109
+ # [default] String. Value returned if translation is not found.
110
+ #
111
+ # Example:
112
+ # t('translate.this','Enter text for ....')
113
+ #
114
+ # Returns:
115
+ # String. Translated text.
116
+ ####################################################################
117
+ def t(key, default='')
118
+ c = I18n.t(key)
119
+ if c.match( 'translation missing' )
120
+ c = I18n.t(key, locale: 'en')
121
+ # Still not found. Return default if set
122
+ c = default unless default.blank?
123
+ end
124
+ c
125
+ end
126
+
127
+ ####################################################################
128
+ # Standard code for returning readonly field.
129
+ ####################################################################
130
+ def ro_standard(value=nil)
131
+ if value.nil?
132
+ value = if @yaml['html']['value']
133
+ @yaml['html']['value']
134
+ else
135
+ @record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
136
+ end
137
+ end
138
+ @html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
139
+ self
140
+ end
141
+
142
+ ####################################################################
143
+ # Set initial value of the field when initial value is set in url parameters..
144
+ #
145
+ # Example: Form has field named picture. Field can be initialized by
146
+ # setting value of param p_picture.
147
+ # params['p_picture'] = '/path/to_picture'
148
+ #
149
+ # When multiple initial values are assigned it is more convinient to assign them
150
+ # through flash object.
151
+ # flash[:record] = {}
152
+ # flash[:record]['picture'] = '/path/to_picture'
153
+ ####################################################################
154
+ def set_initial_value(opt1 = 'html', opt2 = 'value')
155
+ @yaml['html'] ||= {}
156
+ value_send_as = 'p_' + @yaml['name']
157
+ if @parent.params[value_send_as]
158
+ @yaml[opt1][opt2] = @parent.params[value_send_as]
159
+ elsif @parent.flash[:record] and @parent.flash[:record][@yaml['name']]
160
+ @yaml[opt1][opt2] = @parent.flash[:record][@yaml['name']]
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
177
+ end
178
+
179
+ ####################################################################
180
+ # Returns style html code for DRGForm object if style directive is present in field definition.
181
+ # Otherwise returns empty string.
182
+ #
183
+ # Style may be defined like:
184
+ # style:
185
+ # height: 400px
186
+ # width: 800px
187
+ # padding: 10px 20px
188
+ #
189
+ # or
190
+ #
191
+ # style: "height:400px; width:800px; padding: 10px 20px;"
192
+ #
193
+ # Style directive may also be defined under html directive.
194
+ # html:
195
+ # style:
196
+ # height: 400px
197
+ # width: 800px
198
+ #
199
+ #
200
+ ####################################################################
201
+ def set_style()
202
+ style = @yaml['html']['style'] || @yaml['style']
203
+ case
204
+ when style.nil? then ''
205
+ when style.class == String then "style=\"#{style}\""
206
+ when style.class == Hash then
207
+ value = style.to_a.inject([]) {|r,v| r << "#{v[0]}: #{v[1]}" }.join(';')
208
+ "style=\"#{value}\""
209
+ else ''
210
+ end
211
+ end
212
+
213
+ ####################################################################
214
+ # DEPRECATED!
215
+ #
216
+ # Returns css code for the field if specified. It replaces all occurences of '# '
217
+ # with field name id, as defined on form.
218
+ ####################################################################
219
+ def __css_code
220
+ return '' if @css.blank?
221
+ @css.gsub!('# ',"#td_record_#{@yaml['name']} ")
222
+ "\n<style type=\"text/css\">#{@css}</style>"
223
+ end
224
+
225
+ ####################################################################
226
+ # Sets css code for the field if specified. It replaces all occurences of '# '
227
+ # with field name id, as defined on form.
228
+ ####################################################################
229
+ def set_css_code(css)
230
+ return '' if css.blank?
231
+ css.gsub!('# ',"#td_record_#{@yaml['name']} ") if css.match('# ')
232
+ css
233
+ end
234
+
235
+ ####################################################################
236
+ # Will return ruby hash formated as javascript string which can be used
237
+ # for passing parameters in javascript code.
238
+ #
239
+ # Parameters:
240
+ # [Hash] Hash. Ruby hash parameters.
241
+ #
242
+ # Form example: As used in forms
243
+ # options:
244
+ # height: 400
245
+ # width: 800
246
+ # toolbar: "'basic'"
247
+ #
248
+ # => "height:400, width:800, toolbar:'basic'"
249
+ #
250
+ # Return:
251
+ # String: Options formated as javascript options.
252
+ #
253
+ ####################################################################
254
+ def hash_to_options(hash)
255
+ hash.to_a.inject([]) {|r,v| r << "#{v[0]}: #{v[1]}" }.join(',')
256
+ end
257
+
258
+ ####################################################################
259
+ # Checks if field name exists in document and alters record parameters if necesary.
260
+ # Method was added after fields that do not belong to current edited document
261
+ # were added to forms. Valid nonexisting form field names must start with underscore (_) letter.
262
+ #
263
+ # Return:
264
+ # String: 'record' or '_record' when valid nonexisting field is used
265
+ ####################################################################
266
+ def record_text_for(name)
267
+ (!@record.respond_to?(name) and name[0,1] == '_') ? '_record' : 'record'
268
+ end
269
+
270
+
271
+ ###########################################################################
272
+ # Default get_data method for retrieving data from parameters. Class method is called
273
+ # for every entry field defined on form before field value is saved to database.
274
+ #
275
+ # Parameters:
276
+ # [params] Controllers params object.
277
+ # [name] Field name
278
+ #
279
+ # Most of classes will use this default method which returns params['record'][name].
280
+ # When field data is more complex class should implement its own get_data method.
281
+ ###########################################################################
282
+ def self.get_data(params, name)
283
+ params['record'][name]
284
+ end
285
+
286
+ end
287
+ end
@@ -0,0 +1,97 @@
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 embedded DRG CMS form field.
27
+ #
28
+ # Creates html required to paint embedded object on form.
29
+ #
30
+ # ===Form options:
31
+ # * +name:+ field name (required)
32
+ # * +type:+ embedded (required)
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)
35
+ # * +html:+ html options (optional)
36
+ # * +height:+ height of embedded object in pixels (1000)
37
+ # * +width:+ width of embedded object in pixels (500)
38
+ #
39
+ # Form example:
40
+ # 10:
41
+ # name: dc_parts
42
+ # type: embedded
43
+ # form_name: dc_part
44
+ # refresh: delay
45
+ # html:
46
+ # height: 1000
47
+ ###########################################################################
48
+ class Embedded < DrgcmsField
49
+ ###########################################################################
50
+ # Render embedded field html code
51
+ ###########################################################################
52
+ def render
53
+ #return self if @record.new_record? # would be in error otherwise
54
+ # HTML defaults. Some must be set
55
+ @yaml['html'] ||= {}
56
+ @yaml['html']['height'] ||= 300
57
+ @yaml['html']['width'] ||= '99%'
58
+ @yaml['action'] ||= 'index'
59
+ # defaults both way
60
+ @yaml['table'] ||= @yaml['form_name'] if @yaml['form_name']
61
+ @yaml['form_name'] ||= @yaml['table'] if @yaml['table']
62
+ #
63
+ html = ''
64
+ @yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
65
+ #
66
+ if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
67
+ tables = @yaml['table']
68
+ ids = @record.id
69
+ else
70
+ tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
71
+ ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record.id
72
+ end
73
+ opts = { controller: 'cmsedit', action: @yaml['action'],
74
+ ids: ids, table: tables, form_name: @yaml['form_name'],
75
+ field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: @readonly }
76
+ # additional parameters if specified
77
+ @yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
78
+
79
+ @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
80
+ unless @record.new_record?
81
+ url = @parent.url_for(opts)
82
+ data = if @yaml['load'].nil? || @yaml['load'].match('default')
83
+ "src"
84
+ else
85
+ "data-src-#{@yaml['load']}"
86
+ end
87
+ @js << %Q[
88
+ $(document).ready( function() {
89
+ $('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
90
+ });]
91
+ end
92
+ self
93
+ end
94
+
95
+ end
96
+
97
+ end