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,61 @@
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 action DRG CMS form field. Actions can also be inserted on
27
+ # the form like just like on action pane.
28
+ #
29
+ # ===Form options:
30
+ # * +type:+ action (required)
31
+ # * +action_type:+ link, submit or ajax action (default link)
32
+ # * +caption:+ Caption for action
33
+ # * +icon:+ Action icon
34
+ # * +url:+ direct url link
35
+ # * +controller:+ controller name
36
+ # * +action:+ action name
37
+ # * +html:+ html options which apply to link_to (optional)
38
+ #
39
+ # Form example:
40
+ # 30:
41
+ # type: link_to
42
+ # caption: Some action
43
+ # icon: cogs
44
+ # controller: my_controller
45
+ # action: my_action
46
+ # id: id # will be replaced by record._id
47
+ ###########################################################################
48
+ class Action < DrgcmsField
49
+
50
+ ###########################################################################
51
+ # Render link_to field html code
52
+ ###########################################################################
53
+ def render
54
+ @yaml['type'] = @yaml['action_type'] || 'link'
55
+ #
56
+ @html << '<ul class="action">' + @parent.dc_link_ajax_window_submit_action(@yaml,@record) + '</ul>'
57
+ self
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,72 @@
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 check_box DRG CMS form field.
27
+ #
28
+ # ===Form options:
29
+ # * +name:+ field name (required)
30
+ # * +type:+ check_box (required)
31
+ # * +choices:+ Values check_box separated by comma (1,0) (yes,no)
32
+ # * +checked_value:+ 1 or yes or approved
33
+ # * +label:+ displayed right to square field
34
+ # * +unchecked_value:+ 0 or no or not approved
35
+ # * +html:+ html options which apply to check_box field (optional)
36
+ #
37
+ # Form example:
38
+ # 30:
39
+ # name: active
40
+ # type: check_box
41
+ # 40:
42
+ # name: status
43
+ # type: check_box
44
+ # choices: yes,no
45
+ # label: label
46
+ ###########################################################################
47
+ class CheckBox < DrgcmsField
48
+
49
+ ###########################################################################
50
+ # Render check_box field html code
51
+ ###########################################################################
52
+ def render
53
+ set_initial_value('html','default')
54
+ # checked flag must be set
55
+ @yaml['html']['checked'] = !@parent.dc_dont?(@yaml['html']['default']) if @yaml['html']['default']
56
+ # disable it if readonly
57
+ @yaml['html']['disabled'] = @readonly ? true : nil
58
+ # If choices are present split them to set checked and unchecked value
59
+ @yaml['checked_value'], @yaml['unchecked_value'] = @yaml['choices'].split(',') if @yaml['choices']
60
+ @yaml['html'].symbolize_keys!
61
+ record = record_text_for(@yaml['name'])
62
+ @html << if @yaml['checked_value']
63
+ @parent.check_box(record, @yaml['name'], @yaml['html'], @yaml['checked_value'], @yaml['unchecked_value'] || '0')
64
+ else
65
+ @parent.check_box(record, @yaml['name'], @yaml['html'])
66
+ end
67
+ @html << "<label for=\"record_#{@yaml['name']}\">#{@yaml['label']}</label>" if @yaml['label']
68
+ self
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,53 @@
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 comment DRG CMS form field. Comments may also be written
27
+ # on the place of form field.
28
+ #
29
+ # ===Form options:
30
+ # * +text:+ any text. Text will be translated if key is found in translations. (required)
31
+ # * +type:+ comment (required)
32
+ # * +caption:+ Caption text written in label place. If set to false comment
33
+ # will occupy whole row. (required)
34
+ #
35
+ # Form example:
36
+ # 30:
37
+ # type: comment
38
+ # text: myapp.comment_text
39
+ # caption: false
40
+ ###########################################################################
41
+ class Comment < DrgcmsField
42
+
43
+ ###########################################################################
44
+ # Render comment field html code
45
+ ###########################################################################
46
+ def render
47
+ comment = @yaml['comment'] || @yaml['text']
48
+ @html << "<div class=\"dc-comment\">#{t(comment, comment).gsub("\n",'<br>')}</div>"
49
+ self
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,104 @@
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 date_picker DRG CMS form field with help of jQuery DateTimePicker plugin.
27
+ #
28
+ # Since javascript date(time) format differs from ruby date(time) format localization
29
+ # must be provided in order for date_picker object works as expected. For example:
30
+ #
31
+ # en:
32
+ # datetimepicker:
33
+ # formats:
34
+ # date: 'Y/m/d'
35
+ # datetime: 'Y/m/d H:i'
36
+ #
37
+ # sl:
38
+ # datetimepicker:
39
+ # formats:
40
+ # date: 'd.m.Y'
41
+ # datetime: 'd.m.Y H:i'
42
+ #
43
+ # ===Form options:
44
+ # * +type:+ date_picker (required)
45
+ # * +name:+ Field name (required)
46
+ # * +options:+ options which apply to date_picker field. All options can be found here http://xdsoft.net/jqplugins/datetimepicker/ .
47
+ # Options can be defined in single line like:
48
+ # * options: 'inline: true,lang: "sl"' or
49
+ #
50
+ # * options:
51
+ # * inline: true
52
+ # * lang: '"sl"'
53
+ #
54
+ # * +html:+ html options which apply to date_picker field (optional)
55
+ #
56
+ # Form example:
57
+ # 10:
58
+ # name: created
59
+ # type: date_picker
60
+ # options: 'inline: true,lang: "sl"'
61
+ ###########################################################################
62
+ class DatePicker < DrgcmsField
63
+
64
+ ###########################################################################
65
+ # Render date_picker field html code
66
+ ###########################################################################
67
+ def render
68
+ value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].to_date) : nil
69
+ #return ro_standard( @parent.dc_format_value(value)) if @readonly
70
+
71
+ @yaml['options'] ||= {}
72
+ set_initial_value
73
+ @yaml['html']['size'] ||= @yaml['size'] || 10
74
+ @yaml['html']['value'] ||= value
75
+ @yaml['html']['autocomplete'] ||= 'off'
76
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
77
+
78
+ @yaml['options']['lang'] ||= "'#{I18n.locale}'"
79
+ @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
80
+ @yaml['options']['timepicker'] = false
81
+
82
+ record = record_text_for(@yaml['name'])
83
+ @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
84
+ @js << %Q[
85
+ $(document).ready(function() {
86
+ $("##{record}_#{@yaml['name']}").datetimepicker( {
87
+ #{hash_to_options(@yaml['options'])}
88
+ });
89
+ });
90
+ ] unless @readonly
91
+
92
+ self
93
+ end
94
+
95
+ ###########################################################################
96
+ # DatePicker get_data method.
97
+ ###########################################################################
98
+ def self.get_data(params, name)
99
+ t = params['record'][name] ? params['record'][name].to_datetime : nil
100
+ t ? Time.zone.local(t.year, t.month, t.day) : nil
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,68 @@
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 date_select DRG CMS form field.
27
+ #
28
+ # ===Form options:
29
+ # * +type:+ date_select (required)
30
+ # * +name:+ Field name (required)
31
+ # * +options:+ options which apply to date_select field (optional)
32
+ # * +html:+ html options which apply to password field (optional)
33
+ #
34
+ # Form example:
35
+ # 50:
36
+ # name: valid_from
37
+ # type: date_select
38
+ # options:
39
+ # include_blank: true
40
+ # html:
41
+ # class: my-date-class
42
+ ###########################################################################
43
+ class DateSelect < DrgcmsField
44
+
45
+ ###########################################################################
46
+ # Render date_select field html code
47
+ ###########################################################################
48
+ def render
49
+ #return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
50
+ #
51
+ @yaml['options'] ||= {}
52
+ set_initial_value('options','default')
53
+ @yaml['options'].symbolize_keys!
54
+ @yaml['html'].symbolize_keys!
55
+ record = record_text_for(@yaml['name'])
56
+ @html << @parent.date_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
+ DatetimeSelect.get_data(params, name).to_date rescue nil
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,89 @@
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 date_time_picker DRG CMS form field with help of jQuery DateTimePicker plugin
27
+ #
28
+ # ===Form options:
29
+ # * +type:+ datetime_picker (required)
30
+ # * +name:+ Field name (required)
31
+ # * +options:+ options which apply to date_picker field. All options can be found here http://xdsoft.net/jqplugins/datetimepicker/ .
32
+ # Options can be defined in single line like:
33
+ # * options: 'step: 15,inline: true,lang: "sl"' or
34
+ #
35
+ # * options:
36
+ # * step: 15
37
+ # * inline: true
38
+ # * lang: '"sl"'
39
+ #
40
+ # * +html:+ html options which apply to date_time_picker field (optional)
41
+ #
42
+ # Form example:
43
+ # 10:
44
+ # name: valid_to
45
+ # type: datetime_picker
46
+ # options: 'step: 60'
47
+ ###########################################################################
48
+ class DatetimePicker < DrgcmsField
49
+
50
+ ###########################################################################
51
+ # Render date_time_picker field html code
52
+ ###########################################################################
53
+ def render
54
+ value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].localtime) : nil
55
+ #return ro_standard( @parent.dc_format_value(value)) if @readonly
56
+
57
+ @yaml['options'] ||= {}
58
+ set_initial_value
59
+ @yaml['html']['size'] ||= @yaml['size'] || 14
60
+ @yaml['html']['value'] ||= value if @record[@yaml['name']]
61
+ @yaml['html']['autocomplete'] ||= 'off'
62
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
63
+
64
+ @yaml['options']['lang'] ||= "'#{I18n.locale}'"
65
+ @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
66
+
67
+ record = record_text_for(@yaml['name'])
68
+ @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
69
+ @js << %Q[
70
+ $(document).ready(function() {
71
+ $("##{record}_#{@yaml['name']}").datetimepicker( {
72
+ #{hash_to_options(@yaml['options'])}
73
+ });
74
+ });
75
+ ] unless @readonly
76
+
77
+ self
78
+ end
79
+
80
+ ###########################################################################
81
+ # DateTimePicker get_data method.
82
+ ###########################################################################
83
+ def self.get_data(params, name)
84
+ t = params['record'][name] ? params['record'][name].to_datetime : nil
85
+ t ? Time.zone.local(t.year, t.month, t.day, t.hour, t.min) : nil
86
+ end
87
+
88
+ end
89
+ end