drg_cms 0.4.39 → 0.4.53
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -0
- data/app/assets/images/drg_cms/file_manager.png +0 -0
- data/app/assets/javascripts/drg_cms/drg_cms.js +8 -8
- data/app/assets/stylesheets/drg_cms/drg_cms.css +22 -20
- data/app/controllers/cmsedit_controller.rb +170 -114
- data/app/controllers/dc_application_controller.rb +142 -56
- data/app/controllers/dc_common_controller.rb +56 -34
- data/app/controllers/dc_main_controller.rb +1 -4
- data/app/controllers/drgcms_controls/dc_page_controls.rb +3 -0
- data/app/forms/all_options.yml +3 -0
- data/app/forms/cms_menu.yml +100 -117
- data/app/forms/dc_design.yml +1 -1
- data/app/forms/dc_ident.yml +37 -0
- data/app/forms/dc_menu_item.yml +1 -1
- data/app/forms/dc_permission.yml +1 -1
- data/app/forms/dc_site.yml +4 -0
- data/app/helpers/cmsedit_helper.rb +44 -80
- data/app/helpers/dc_ad_renderer.rb +27 -15
- data/app/helpers/dc_application_helper.rb +433 -196
- data/app/helpers/dc_big_menu_renderer.rb +40 -40
- data/app/helpers/dc_captcha_renderer.rb +38 -25
- data/app/helpers/dc_common_renderer.rb +15 -48
- data/app/helpers/dc_menu_renderer.rb +30 -20
- data/app/helpers/dc_page_renderer.rb +14 -18
- data/app/helpers/dc_part_renderer.rb +45 -16
- data/app/helpers/dc_piece_renderer.rb +23 -29
- data/app/helpers/dc_poll_renderer.rb +31 -20
- data/app/helpers/dc_renderer.rb +5 -4
- data/app/helpers/dc_simple_menu_renderer.rb +90 -68
- data/app/models/{__dc_global_data.rb → __dc_stat.rb} +20 -21
- data/app/models/dc_ad.rb +13 -1
- data/app/models/dc_ad_stat.rb +6 -0
- data/app/models/dc_big_menu.rb +15 -2
- data/app/models/dc_big_table.rb +27 -4
- data/app/models/dc_big_table_locale.rb +7 -0
- data/app/models/dc_big_table_value.rb +7 -0
- data/app/models/dc_category.rb +9 -3
- data/app/models/dc_design.rb +50 -0
- data/app/models/dc_dummy.rb +41 -1
- data/app/models/dc_folder_permission.rb +9 -2
- data/app/models/{dc_global_data.rb → dc_ident.rb} +20 -22
- data/app/models/dc_journal.rb +9 -1
- data/app/models/dc_key_value_store.rb +41 -4
- data/app/models/dc_link.rb +7 -0
- data/app/models/dc_menu.rb +20 -3
- data/app/models/dc_menu_item.rb +7 -0
- data/app/models/dc_page.rb +31 -12
- data/app/models/dc_part.rb +34 -4
- data/app/models/dc_permission.rb +32 -12
- data/app/models/dc_piece.rb +32 -4
- data/app/models/dc_policy.rb +17 -11
- data/app/models/dc_policy_role.rb +12 -7
- data/app/models/dc_policy_rule.rb +32 -4
- data/app/models/dc_poll.rb +8 -0
- data/app/models/dc_poll_item.rb +6 -0
- data/app/models/dc_simple_menu.rb +18 -3
- data/app/models/dc_simple_menu_item.rb +20 -2
- data/app/models/dc_site.rb +13 -3
- data/app/models/dc_stat.rb +8 -1
- data/app/models/dc_user.rb +18 -2
- data/app/models/dc_user_role.rb +7 -0
- data/app/models/dc_visit.rb +5 -0
- data/app/{helpers → models}/drgcms_form_field.rb +171 -73
- data/app/views/__dc_at_the_beginning/create.html.erb +9 -0
- data/app/views/__dc_at_the_beginning/index.html.erb +19 -0
- data/app/views/cmsedit/_edit_stuff.html.erb +2 -0
- data/app/views/cmsedit/_form.html.erb +0 -1
- data/app/views/dc_mail/subscribe.html.erb +0 -0
- data/config/initializers/kaminari_patch.rb +5 -4
- data/config/locales/drgcms_en.yml +4 -0
- data/config/locales/drgcms_sl.yml +1 -0
- data/config/locales/models_en.yml +14 -3
- data/config/locales/models_sl.yml +13 -4
- data/drg_cms.gemspec +4 -4
- data/lib/drg_cms.rb +37 -8
- data/lib/drg_cms/engine.rb +2 -2
- data/lib/drg_cms/version.rb +3 -2
- data/lib/tasks/at_the_beginning.yml +0 -0
- data/lib/tasks/dc_at_the_beginning.rake +118 -0
- data/lib/tasks/dc_cleanup.rake +19 -7
- data/lib/tasks/log_statistics.rb +66 -0
- data/lib/tasks/site_statistics.rake +29 -12
- data/test/dummy/app/controllers/application_controller.rb +1 -1
- data/test/dummy/app/helpers/application_helper.rb +1 -1
- metadata +15 -26
- data/README.rdoc +0 -3
- data/app/controllers/dc_at_the_beginning_controller.rb +0 -120
- data/app/controllers/dc_mail_controller.rb +0 -89
- data/app/forms/dc_forum_cat.yml +0 -54
- data/app/forms/dc_forum_forum.yml +0 -53
- data/app/forms/dc_forum_msg.yml +0 -124
- data/app/forms/dc_forum_privmsg.yml +0 -125
- data/app/forms/dc_forum_topic.yml +0 -131
- data/app/forms/dc_mail.yml +0 -88
- data/app/forms/dc_mail_address.yml +0 -56
- data/app/forms/dc_mail_list.yml +0 -44
- data/app/forms/dc_mail_list_member.yml +0 -42
- data/app/helpers/dc_mail_renderer.rb +0 -76
- data/app/models/dc_mail.rb +0 -64
- data/app/models/dc_mail_address.rb +0 -69
- data/app/models/dc_mail_list.rb +0 -48
- data/app/models/dc_mail_list_member.rb +0 -34
- data/app/models/dc_sendmail.rb +0 -48
@@ -21,8 +21,12 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
25
|
-
#
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_policy_roles collection.
|
26
|
+
#
|
27
|
+
# Documents in this model define all available user roles in the application. Roles
|
28
|
+
# are defined by unique name which is valid for current application or as alternative name (system_name)
|
29
|
+
# which can be persistent, when application is used as Rails plugin.
|
26
30
|
#########################################################################
|
27
31
|
class DcPolicyRole
|
28
32
|
include Mongoid::Document
|
@@ -32,16 +36,17 @@ class DcPolicyRole
|
|
32
36
|
field :system_name, type: String
|
33
37
|
field :active, type: Boolean, default: true
|
34
38
|
|
39
|
+
index( { name: 1 }, { unique: true } )
|
40
|
+
index( system_name: 1 )
|
41
|
+
|
35
42
|
validates :name, :length => { :minimum => 4 }
|
36
|
-
|
37
|
-
index name: 1
|
38
|
-
index system_name: 1
|
43
|
+
validates :name, uniqueness: true
|
39
44
|
|
40
45
|
########################################################################
|
41
|
-
# Return choices for select
|
46
|
+
# Return all defined roles as choices for use in select field.
|
42
47
|
########################################################################
|
43
48
|
def self.choices4_roles
|
44
|
-
|
49
|
+
where(active: true).order_by(name: 1).inject([]) { |r,role| r << [ role.name, role._id] }
|
45
50
|
end
|
46
51
|
|
47
52
|
end
|
@@ -21,6 +21,9 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
+
#########################################################################
|
25
|
+
# ActiveSupport::Concern definition for DcPolicyRule class.
|
26
|
+
#########################################################################
|
24
27
|
module DcPolicyRuleConcern
|
25
28
|
extend ActiveSupport::Concern
|
26
29
|
included do
|
@@ -30,14 +33,18 @@ module DcPolicyRuleConcern
|
|
30
33
|
|
31
34
|
belongs_to :dc_policy_role
|
32
35
|
|
33
|
-
field :permission,
|
36
|
+
field :permission, type: Integer, default: 0
|
34
37
|
|
35
|
-
# embedded_in :dc_policy
|
36
|
-
# embedded_in :dc_permission
|
37
38
|
embedded_in :policy_rules, polymorphic: true
|
38
39
|
|
39
40
|
#########################################################################
|
40
41
|
# Returns values for permissions ready to be used in select field.
|
42
|
+
#
|
43
|
+
# Example (as used in DRG CMS form):
|
44
|
+
# 20:
|
45
|
+
# name: permission
|
46
|
+
# type: select
|
47
|
+
# eval: DcPolicyRule.values_for_permissions
|
41
48
|
#########################################################################
|
42
49
|
def self.values_for_permissions
|
43
50
|
key = 'helpers.label.dc_policy_rule.choices4_permission'
|
@@ -47,7 +54,20 @@ def self.values_for_permissions
|
|
47
54
|
end
|
48
55
|
|
49
56
|
#########################################################################
|
50
|
-
# Will return permission name for value.
|
57
|
+
# Will return translated permission name for value.
|
58
|
+
#
|
59
|
+
# Parameters:
|
60
|
+
# [value] Integer. Permission value
|
61
|
+
#
|
62
|
+
# Example (as used in DRG CMS form):
|
63
|
+
# result_set:
|
64
|
+
# columns:
|
65
|
+
# 2:
|
66
|
+
# name: permission
|
67
|
+
# eval: DcPolicyRule.permission_name_for_value
|
68
|
+
#
|
69
|
+
# Returns:
|
70
|
+
# String. Name (description) for value
|
51
71
|
#########################################################################
|
52
72
|
def self.permission_name_for_value(value)
|
53
73
|
values_for_permissions.each {|v| return v.first if v.last.to_i == value.to_i}
|
@@ -58,7 +78,15 @@ end
|
|
58
78
|
end
|
59
79
|
|
60
80
|
#########################################################################
|
81
|
+
# Mongoid::Document model for dc_policy_rule documents embedded into documents.
|
82
|
+
#
|
83
|
+
# DcPolicyRule documents define policies for accessing data. DRG CMS uses policy rules for
|
84
|
+
# defining policies in DcSite, DcPermission and DcFolderPermission documents.
|
85
|
+
#
|
86
|
+
# Since they are defined as polymorphic they can be embedded into any
|
87
|
+
# application specific model by specifying this line in the model:
|
61
88
|
#
|
89
|
+
# embeds_many :dc_policy_rules, as: :policy_rules
|
62
90
|
#########################################################################
|
63
91
|
class DcPolicyRule
|
64
92
|
include DcPolicyRuleConcern
|
data/app/models/dc_poll.rb
CHANGED
@@ -20,6 +20,14 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
+
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_poll documents.
|
26
|
+
#
|
27
|
+
# DcPoll documents are used for different questionaries and formulars which can
|
28
|
+
# be accessed independent or connected with DcPage documents. Entry fields can be defined
|
29
|
+
# as DcSimpleItem embedded structure or as DRG CMS form YAML style entered into form field.
|
30
|
+
########################################################################
|
23
31
|
class DcPoll
|
24
32
|
include Mongoid::Document
|
25
33
|
include Mongoid::Timestamps
|
data/app/models/dc_poll_item.rb
CHANGED
@@ -20,6 +20,12 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
+
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_poll_item embedded documents.
|
26
|
+
#
|
27
|
+
# DcPollItems define entry fields on poll questionary and formulars.
|
28
|
+
########################################################################
|
23
29
|
class DcPollItem
|
24
30
|
include Mongoid::Document
|
25
31
|
include Mongoid::Timestamps
|
@@ -20,6 +20,13 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
+
|
24
|
+
#########################################################################
|
25
|
+
# Mongoid::Document model for dc_simple_menus collection.
|
26
|
+
#
|
27
|
+
# Simple menus were first menu system developed for DRG CMS. They can be only two menu
|
28
|
+
# levels deep. Menus are described in dc_simple_menu_items embedded documents.
|
29
|
+
#########################################################################
|
23
30
|
class DcSimpleMenu
|
24
31
|
include Mongoid::Document
|
25
32
|
include Mongoid::Timestamps
|
@@ -35,12 +42,21 @@ class DcSimpleMenu
|
|
35
42
|
index( { name: 1 }, { unique: true } )
|
36
43
|
|
37
44
|
embeds_many :dc_simple_menu_items
|
38
|
-
# belongs_to :dc_site
|
39
45
|
|
40
46
|
validates_length_of :description, minimum: 10
|
41
47
|
|
42
48
|
#######################################################################
|
43
|
-
#
|
49
|
+
# Will return all top level menu items of specified menu. Used in DcPage document for
|
50
|
+
# selecting top level selected menu, when document displayed in browser.
|
51
|
+
#
|
52
|
+
# Called from DcApplicationHelper :dc_choices4_menu: method.
|
53
|
+
#
|
54
|
+
# Parameters:
|
55
|
+
# [Site] DcSite document. Site for which menu belongs to. If site is not specified
|
56
|
+
# all current menus in collection will be returned.
|
57
|
+
#
|
58
|
+
# Returns:
|
59
|
+
# Array. Of choices prepared for select input field.
|
44
60
|
#######################################################################
|
45
61
|
def self.choices4_menu(site)
|
46
62
|
rez = []
|
@@ -48,7 +64,6 @@ class DcSimpleMenu
|
|
48
64
|
menus.each do |menu|
|
49
65
|
rez << [menu.name, nil]
|
50
66
|
menu.dc_simple_menu_items.where(active: true).order_by(:order => 1).each do |menu_item|
|
51
|
-
# next unless menu_item.active
|
52
67
|
rez << ['-- ' + menu_item.caption, menu_item._id]
|
53
68
|
end
|
54
69
|
end
|
@@ -20,6 +20,24 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
+
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_simple_menu_items embedded documents.
|
26
|
+
#
|
27
|
+
# DcMenuItem documents are embedded in the DcSimpleMenu document and define top
|
28
|
+
# level item of menu system. Submenus are simply defined as YAML text in the submenu field.
|
29
|
+
#
|
30
|
+
# Submenu example:
|
31
|
+
# 1:
|
32
|
+
# title: Zadnja številka
|
33
|
+
# link: /zadnjastevilka
|
34
|
+
# 2:
|
35
|
+
# title: Arhiv
|
36
|
+
# link: /arhivrevij
|
37
|
+
# 3:
|
38
|
+
# title: Naročam
|
39
|
+
# link: /clanek/podjetnik-narocilnica
|
40
|
+
########################################################################
|
23
41
|
class DcSimpleMenuItem
|
24
42
|
include Mongoid::Document
|
25
43
|
include Mongoid::Timestamps
|
@@ -30,10 +48,10 @@ class DcSimpleMenuItem
|
|
30
48
|
field :target, type: String
|
31
49
|
field :order, type: Integer, default: 10
|
32
50
|
field :submenu, type: String
|
51
|
+
field :policy_id, type: BSON::ObjectId
|
33
52
|
field :css, type: String
|
53
|
+
|
34
54
|
field :active, type: Boolean, default: true
|
35
|
-
field :policy_id, type: BSON::ObjectId
|
36
55
|
|
37
56
|
embedded_in :dc_simple_menu
|
38
|
-
|
39
57
|
end
|
data/app/models/dc_site.rb
CHANGED
@@ -21,7 +21,10 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
24
|
+
#########################################################################
|
25
|
+
# ActiveSupport::Concern definition for DcSite class.
|
26
|
+
#########################################################################
|
27
|
+
module DcSiteConcern
|
25
28
|
extend ActiveSupport::Concern
|
26
29
|
included do
|
27
30
|
include Mongoid::Document
|
@@ -85,8 +88,15 @@ end
|
|
85
88
|
|
86
89
|
|
87
90
|
######################################################################
|
88
|
-
#
|
91
|
+
# Mongoid::Document model for dc_sites collection.
|
92
|
+
#
|
93
|
+
# Since DRG CMS can handle multiple sites on single ROR instance, every document
|
94
|
+
# in dc_sites collection defines data which defines a site.
|
95
|
+
#
|
96
|
+
# Sites can be aliased which is very usefull in development and test environment.
|
97
|
+
# If 'site.name' document is not found application will search for 'test' document and
|
98
|
+
# continue searching with value found in alias_for field.
|
89
99
|
######################################################################
|
90
100
|
class DcSite
|
91
|
-
include
|
101
|
+
include DcSiteConcern
|
92
102
|
end
|
data/app/models/dc_stat.rb
CHANGED
@@ -20,7 +20,14 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
-
|
23
|
+
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_stat documents.
|
26
|
+
#
|
27
|
+
#
|
28
|
+
########################################################################
|
29
|
+
|
30
|
+
class DcStat #:nodoc:
|
24
31
|
include Mongoid::Document
|
25
32
|
include Mongoid::Timestamps
|
26
33
|
|
data/app/models/dc_user.rb
CHANGED
@@ -21,7 +21,10 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
24
|
+
#########################################################################
|
25
|
+
# ActiveSupport::Concern definition for DcUser class.
|
26
|
+
#########################################################################
|
27
|
+
module DcUserConcern
|
25
28
|
extend ActiveSupport::Concern
|
26
29
|
included do
|
27
30
|
|
@@ -76,6 +79,9 @@ index 'members' => 1
|
|
76
79
|
validates_length_of :username, minimum: 4
|
77
80
|
before_save :do_before_save
|
78
81
|
|
82
|
+
##########################################################################
|
83
|
+
# before_save callback takes care of name field and ensures that e-mail is unique
|
84
|
+
# when entry is left empty.
|
79
85
|
##########################################################################
|
80
86
|
def do_before_save
|
81
87
|
self.name = "#{self.title} #{self.first_name} #{self.middle_name + ' ' unless self.middle_name.blank?}#{self.last_name}".strip
|
@@ -86,6 +92,16 @@ end
|
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
95
|
+
########################################################################
|
96
|
+
# Mongoid::Document model for dc_user documents.
|
97
|
+
#
|
98
|
+
# dc_users collection holds data about regitered users. Passwords are encrypted
|
99
|
+
# with bcrypt gem.
|
100
|
+
#
|
101
|
+
# This model defines basic fields required for evidence of
|
102
|
+
# registerred users. Since it is implemented as ActiveSupport::Concern you are
|
103
|
+
# encouraged to further expand model with your own data structures.
|
104
|
+
########################################################################
|
89
105
|
class DcUser
|
90
|
-
include
|
106
|
+
include DcUserConcern
|
91
107
|
end
|
data/app/models/dc_user_role.rb
CHANGED
@@ -21,11 +21,18 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
+
########################################################################
|
25
|
+
# Mongoid::Document model for dc_user_role embedded documents.
|
26
|
+
#
|
27
|
+
# DcUserRole documents are embedded in DcUser model and define user roles which
|
28
|
+
# belong to user.
|
29
|
+
########################################################################
|
24
30
|
class DcUserRole
|
25
31
|
include Mongoid::Document
|
26
32
|
include Mongoid::Timestamps
|
27
33
|
|
28
34
|
belongs_to :dc_policy_role
|
35
|
+
|
29
36
|
field :valid_from, type: Date
|
30
37
|
field :valid_to, type: Date
|
31
38
|
field :active, type: Boolean, default: true
|
data/app/models/dc_visit.rb
CHANGED
@@ -21,6 +21,11 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
+
######################################################################
|
25
|
+
# Mongoid::Document model for dc_visit collection.
|
26
|
+
#
|
27
|
+
# DcVisit documents are used to record visits to web site.
|
28
|
+
######################################################################
|
24
29
|
class DcVisit
|
25
30
|
include Mongoid::Document
|
26
31
|
|
@@ -20,14 +20,60 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
+
|
24
|
+
###########################################################################
|
25
|
+
# DrgcmsFormField 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 DrgcmsFormField 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.
|
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 DrgcmsFormField.const_defined?(klas_string) # check if field type class is defined
|
42
|
+
# klas = DrgcmsFormField.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 = DrgcmsFormField::Select.new(self, {}, opts).render
|
54
|
+
# (dt.html + javascript_tag(dt.js)).html_safe
|
55
|
+
# %></div>
|
56
|
+
###########################################################################
|
23
57
|
module DrgcmsFormField
|
24
58
|
|
25
59
|
###########################################################################
|
26
|
-
#
|
60
|
+
# Template method for DRG CMS form field definition. This is abstract class with
|
61
|
+
# most of the common code already implemented.
|
27
62
|
###########################################################################
|
28
63
|
class DrgcmsField
|
29
64
|
attr_reader :html, :js
|
30
65
|
|
66
|
+
####################################################################
|
67
|
+
# DrgcmsField initialization code.
|
68
|
+
#
|
69
|
+
# Parameters:
|
70
|
+
# [parent] Controller object. Controller object from where object is created. Usually self is send.
|
71
|
+
# [record] Document object. Document object which holds fields data.
|
72
|
+
# [yaml] Hash. Hash object holding field definition data.
|
73
|
+
#
|
74
|
+
# Returns:
|
75
|
+
# Self
|
76
|
+
####################################################################
|
31
77
|
def initialize( parent, record, yaml )
|
32
78
|
@parent = parent
|
33
79
|
@record = record
|
@@ -40,7 +86,18 @@ def initialize( parent, record, yaml )
|
|
40
86
|
end
|
41
87
|
|
42
88
|
####################################################################
|
43
|
-
# Wrapper for i18 t method, with some spice added
|
89
|
+
# Wrapper for i18 t method, with some spice added. If translation is not found English
|
90
|
+
# translation value will be returned. And if still not found default value will be returned if passed.
|
91
|
+
#
|
92
|
+
# Parameters:
|
93
|
+
# [key] String. String to be translated into locale.
|
94
|
+
# [default] String. Value returned if translation is not found.
|
95
|
+
#
|
96
|
+
# Example:
|
97
|
+
# t('translate.this','Enter text for ....')
|
98
|
+
#
|
99
|
+
# Returns:
|
100
|
+
# String. Translated text.
|
44
101
|
####################################################################
|
45
102
|
def t(key, default='')
|
46
103
|
c = I18n.t(key)
|
@@ -53,18 +110,16 @@ def t(key, default='')
|
|
53
110
|
end
|
54
111
|
|
55
112
|
####################################################################
|
56
|
-
# Standard code for
|
113
|
+
# Standard code for returning readonly field.
|
57
114
|
####################################################################
|
58
115
|
def ro_standard(value=nil)
|
59
|
-
# @html << "<span class='dc-readonly'>#{@record[@yaml['name']]}</span>" if @record.respond_to?(@yaml['name'])
|
60
116
|
value = @record[@yaml['name']] if value.nil? and @record.respond_to?(@yaml['name'])
|
61
117
|
@html << "<table class='dc-readonly'><td>#{value}</td></table>"
|
62
118
|
self
|
63
119
|
end
|
64
120
|
|
65
121
|
####################################################################
|
66
|
-
# Set value of the field when value is
|
67
|
-
# intialized by setting params with name of the field preceding by p_.
|
122
|
+
# Set initial value of the field when initial value is set in url parameters..
|
68
123
|
#
|
69
124
|
# Example: Form has field named picture. Field can be initialized by
|
70
125
|
# setting value of param p_picture.
|
@@ -76,8 +131,23 @@ def set_initial_value(opt1='html', opt2='value')
|
|
76
131
|
end
|
77
132
|
|
78
133
|
####################################################################
|
79
|
-
# Will return ruby hash formated as javascript
|
134
|
+
# Will return ruby hash formated as javascript string which can be used
|
80
135
|
# for passing parameters in javascript code.
|
136
|
+
#
|
137
|
+
# Parameters:
|
138
|
+
# [Hash] Hash. Ruby hash parameters.
|
139
|
+
#
|
140
|
+
# Example: As used in forms
|
141
|
+
# options:
|
142
|
+
# height: 400
|
143
|
+
# width: 800
|
144
|
+
# toolbar: "'basic'"
|
145
|
+
#
|
146
|
+
# => "height:400, width:800, toolbar:'basic'"
|
147
|
+
#
|
148
|
+
# Return:
|
149
|
+
# String: Options formated as javascript options.
|
150
|
+
#
|
81
151
|
####################################################################
|
82
152
|
def hash_to_options(hash)
|
83
153
|
options = hash.to_a.inject('') do |r,v|
|
@@ -87,8 +157,15 @@ def hash_to_options(hash)
|
|
87
157
|
end
|
88
158
|
|
89
159
|
###########################################################################
|
90
|
-
# Default get_data method for retrieving data from
|
91
|
-
#
|
160
|
+
# Default get_data method for retrieving data from parameters. Class method is called
|
161
|
+
# for every entry field defined on form before field value is saved to database.
|
162
|
+
#
|
163
|
+
# Parameters:
|
164
|
+
# [params] Controllers params object.
|
165
|
+
# [name] Field name
|
166
|
+
#
|
167
|
+
# Most of classes will use this default method which returns params['record'][name].
|
168
|
+
# When field data is more complex class should implement its own get_data method.
|
92
169
|
###########################################################################
|
93
170
|
def self.get_data(params, name)
|
94
171
|
params['record'][name]
|
@@ -97,10 +174,15 @@ end
|
|
97
174
|
end
|
98
175
|
|
99
176
|
###########################################################################
|
100
|
-
#
|
177
|
+
# Implementation of readonly DRG CMS form field.
|
178
|
+
#
|
179
|
+
# Readonly field value is just painted on form.
|
101
180
|
###########################################################################
|
102
181
|
class Readonly < DrgcmsField
|
103
|
-
|
182
|
+
###########################################################################
|
183
|
+
# Render readonly field html code
|
184
|
+
###########################################################################
|
185
|
+
def render
|
104
186
|
@html << @parent.hidden_field('record', @yaml['name']) # retain field as hidden field
|
105
187
|
@html << '<table class="dc-readonly"><td>'
|
106
188
|
|
@@ -120,10 +202,15 @@ end
|
|
120
202
|
end
|
121
203
|
|
122
204
|
###########################################################################
|
123
|
-
#
|
205
|
+
# Implementation of hidden DRG CMS form field.
|
206
|
+
#
|
207
|
+
# Will create hidden_field on form.
|
124
208
|
###########################################################################
|
125
209
|
class HiddenField < DrgcmsField
|
126
|
-
|
210
|
+
###########################################################################
|
211
|
+
# Render hidden_field field html code
|
212
|
+
###########################################################################
|
213
|
+
def render
|
127
214
|
set_initial_value
|
128
215
|
value = @yaml['html']['value'] ? @yaml['html']['value'] : @record[@yaml['name']]
|
129
216
|
@parent.hidden_field('record', @yaml['name'], value: value)
|
@@ -131,22 +218,24 @@ end
|
|
131
218
|
end
|
132
219
|
|
133
220
|
###########################################################################
|
134
|
-
#
|
221
|
+
# Implementation of embedded DRG CMS form field.
|
222
|
+
#
|
223
|
+
# Creates html required to paint embedded object on form.
|
135
224
|
###########################################################################
|
136
225
|
class Embedded < DrgcmsField
|
137
|
-
|
138
|
-
|
226
|
+
###########################################################################
|
227
|
+
# Render embedded field html code
|
228
|
+
###########################################################################
|
229
|
+
def render
|
139
230
|
return self if @record.new_record? # would be in error
|
140
231
|
# HTML defaults. Some must be set
|
141
232
|
@yaml['html'] ||= {}
|
142
233
|
@yaml['html']['height'] ||= 300
|
143
234
|
@yaml['html']['width'] ||= '99%'
|
144
235
|
# defaults both way
|
145
|
-
# p '**********************'
|
146
|
-
# p [@yaml['table'],@yaml['formname']]
|
147
236
|
@yaml['table'] ||= @yaml['formname'] if @yaml['formname']
|
148
237
|
@yaml['formname'] ||= @yaml['table'] if @yaml['table']
|
149
|
-
#
|
238
|
+
#
|
150
239
|
html = ''
|
151
240
|
@yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
|
152
241
|
#
|
@@ -166,16 +255,15 @@ end
|
|
166
255
|
end
|
167
256
|
|
168
257
|
###########################################################################
|
169
|
-
#
|
258
|
+
# Implementation of journal_diff DRG CMS form field.
|
259
|
+
#
|
260
|
+
# journal_diff field is used to show differences between two fields in DcJournal collection.
|
170
261
|
###########################################################################
|
171
|
-
class
|
172
|
-
end
|
173
|
-
|
262
|
+
class JournalDiff < DrgcmsField
|
174
263
|
###########################################################################
|
175
|
-
#
|
264
|
+
# Render journal_diff field html code
|
176
265
|
###########################################################################
|
177
|
-
|
178
|
-
def render
|
266
|
+
def render
|
179
267
|
@yaml['name'] = 'old' if @record[@yaml['name']].nil?
|
180
268
|
@html << '<table width="99%">'
|
181
269
|
JSON.parse(@record[@yaml['name']]).each do |k,v|
|
@@ -189,12 +277,15 @@ end
|
|
189
277
|
end
|
190
278
|
|
191
279
|
###########################################################################
|
192
|
-
#
|
280
|
+
# Implementation of multitext_autocomplete DRG CMS form field.
|
281
|
+
#
|
282
|
+
# multitext_autocomplete field is complex data entry field which uses autocomplete
|
283
|
+
# function when selecting multiple values for Array MongoDB field.
|
193
284
|
###########################################################################
|
194
285
|
class MultitextAutocomplete < DrgcmsField
|
195
286
|
|
196
287
|
###########################################################################
|
197
|
-
#
|
288
|
+
# Returns value for readonly field
|
198
289
|
###########################################################################
|
199
290
|
def ro_standard(table, search)
|
200
291
|
result = ''
|
@@ -207,9 +298,9 @@ def ro_standard(table, search)
|
|
207
298
|
end
|
208
299
|
|
209
300
|
###########################################################################
|
210
|
-
#
|
301
|
+
# Render multitext_autocomplete field html code
|
211
302
|
###########################################################################
|
212
|
-
def render
|
303
|
+
def render
|
213
304
|
# search field name
|
214
305
|
if @yaml['search'].match(/\./)
|
215
306
|
table, search = @yaml['search'].split('.')
|
@@ -304,7 +395,7 @@ EOJS
|
|
304
395
|
end
|
305
396
|
|
306
397
|
###########################################################################
|
307
|
-
#
|
398
|
+
# Class method for retrieving data from multitext_autocomplete form field.
|
308
399
|
###########################################################################
|
309
400
|
def self.get_data(params, name)
|
310
401
|
r = []
|
@@ -319,12 +410,12 @@ end
|
|
319
410
|
end
|
320
411
|
|
321
412
|
###########################################################################
|
322
|
-
#
|
413
|
+
# Implementation of select DRG CMS form field.
|
323
414
|
###########################################################################
|
324
415
|
class Select < DrgcmsField
|
325
416
|
|
326
417
|
###########################################################################
|
327
|
-
# Return values, when choices options will be returned by
|
418
|
+
# Return values, when choices options will be returned by evaluating expression
|
328
419
|
###########################################################################
|
329
420
|
def do_eval(e)
|
330
421
|
e.strip!
|
@@ -336,7 +427,7 @@ def do_eval(e)
|
|
336
427
|
end
|
337
428
|
|
338
429
|
###########################################################################
|
339
|
-
#
|
430
|
+
# Crete choices array for select field.
|
340
431
|
###########################################################################
|
341
432
|
def get_choices
|
342
433
|
begin
|
@@ -359,7 +450,7 @@ def get_choices
|
|
359
450
|
end
|
360
451
|
|
361
452
|
###########################################################################
|
362
|
-
# Return value
|
453
|
+
# Return value when readonly is required
|
363
454
|
###########################################################################
|
364
455
|
def ro_standard
|
365
456
|
value = @record.respond_to?(@yaml['name']) ? @record[@yaml['name']] : nil
|
@@ -376,7 +467,7 @@ def ro_standard
|
|
376
467
|
end
|
377
468
|
|
378
469
|
###########################################################################
|
379
|
-
#
|
470
|
+
# Render select field html code
|
380
471
|
###########################################################################
|
381
472
|
def render
|
382
473
|
return ro_standard if @readonly
|
@@ -390,12 +481,12 @@ end
|
|
390
481
|
end
|
391
482
|
|
392
483
|
###########################################################################
|
393
|
-
#
|
484
|
+
# Implementation of check_box DRG CMS form field.
|
394
485
|
###########################################################################
|
395
486
|
class CheckBox < DrgcmsField
|
396
487
|
|
397
488
|
###########################################################################
|
398
|
-
#
|
489
|
+
# Render check_box field html code
|
399
490
|
###########################################################################
|
400
491
|
def render
|
401
492
|
set_initial_value('html','default')
|
@@ -416,12 +507,12 @@ end
|
|
416
507
|
end
|
417
508
|
|
418
509
|
###########################################################################
|
419
|
-
#
|
510
|
+
# Implementation of comment DRG CMS form field.
|
420
511
|
###########################################################################
|
421
512
|
class Comment < DrgcmsField
|
422
513
|
|
423
514
|
###########################################################################
|
424
|
-
#
|
515
|
+
# Render comment field html code
|
425
516
|
###########################################################################
|
426
517
|
def render
|
427
518
|
@html << @yaml['text']
|
@@ -430,16 +521,16 @@ end
|
|
430
521
|
end
|
431
522
|
|
432
523
|
###########################################################################
|
433
|
-
#
|
524
|
+
# Implementation of link_to DRG CMS form field.
|
434
525
|
###########################################################################
|
435
526
|
class LinkTo < DrgcmsField
|
436
527
|
|
437
528
|
###########################################################################
|
438
|
-
#
|
529
|
+
# Render link_to field html code
|
439
530
|
###########################################################################
|
440
531
|
def render
|
441
532
|
@yaml['html'] ||= {}
|
442
|
-
@yaml['html']['class'] ||= 'dc-
|
533
|
+
@yaml['html']['class'] ||= 'dc-link dc-animate'
|
443
534
|
@yaml['html'].symbolize_keys!
|
444
535
|
#
|
445
536
|
url = @yaml['url'] || "#{@yaml[:controller]}/#{@yaml[:action]}/#{@yaml[:id]}"
|
@@ -447,7 +538,8 @@ def render
|
|
447
538
|
url = '/' + @yaml['url'] unless url[0,1] == '/' # no leading /
|
448
539
|
url.chop if url[0,-1] == '/' # remove trailing /
|
449
540
|
#
|
450
|
-
|
541
|
+
caption = @yaml['caption'] || @yaml['text']
|
542
|
+
@html << @parent.link_to(caption, url, @yaml['html'])
|
451
543
|
self
|
452
544
|
end
|
453
545
|
end
|
@@ -458,7 +550,7 @@ end
|
|
458
550
|
class SubmitTag < DrgcmsField
|
459
551
|
|
460
552
|
###########################################################################
|
461
|
-
#
|
553
|
+
# Render submit_tag field html code
|
462
554
|
###########################################################################
|
463
555
|
def render
|
464
556
|
@yaml['html'] ||= {}
|
@@ -473,12 +565,12 @@ end
|
|
473
565
|
end
|
474
566
|
|
475
567
|
###########################################################################
|
476
|
-
#
|
568
|
+
# Implementation of password DRG CMS form field.
|
477
569
|
###########################################################################
|
478
570
|
class PasswordField < DrgcmsField
|
479
571
|
|
480
572
|
###########################################################################
|
481
|
-
#
|
573
|
+
# Render password field html code
|
482
574
|
###########################################################################
|
483
575
|
def render
|
484
576
|
return self if @readonly
|
@@ -489,12 +581,12 @@ end
|
|
489
581
|
end
|
490
582
|
|
491
583
|
###########################################################################
|
492
|
-
#
|
584
|
+
# Implementation of date_select DRG CMS form field.
|
493
585
|
###########################################################################
|
494
586
|
class DateSelect < DrgcmsField
|
495
587
|
|
496
588
|
###########################################################################
|
497
|
-
#
|
589
|
+
# Render date_select field html code
|
498
590
|
###########################################################################
|
499
591
|
def render
|
500
592
|
# return ro_standard if @readonly
|
@@ -510,7 +602,7 @@ def render
|
|
510
602
|
end
|
511
603
|
|
512
604
|
####################################################################
|
513
|
-
# Get data for
|
605
|
+
# Get data for DateSelect field
|
514
606
|
# According to https://gist.github.com/315227
|
515
607
|
####################################################################
|
516
608
|
def self.get_data(params, name)
|
@@ -521,7 +613,7 @@ def self.get_data(params, name)
|
|
521
613
|
end.compact.sort_by(&:first).map(&:last)
|
522
614
|
# Return nil if error
|
523
615
|
begin
|
524
|
-
Time.zone.local(*attrs) unless attrs.empty?
|
616
|
+
Time.zone.local(*attrs) #unless attrs.empty?
|
525
617
|
rescue
|
526
618
|
nil
|
527
619
|
end
|
@@ -530,12 +622,12 @@ end
|
|
530
622
|
end
|
531
623
|
|
532
624
|
###########################################################################
|
533
|
-
# Create
|
625
|
+
# Create datetime_select form field
|
534
626
|
###########################################################################
|
535
627
|
class DatetimeSelect < DrgcmsField
|
536
628
|
|
537
629
|
###########################################################################
|
538
|
-
#
|
630
|
+
# Render datetime_select field html code
|
539
631
|
###########################################################################
|
540
632
|
def render
|
541
633
|
return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
|
@@ -550,7 +642,7 @@ def render
|
|
550
642
|
end
|
551
643
|
|
552
644
|
###########################################################################
|
553
|
-
#
|
645
|
+
# DatetimeSelect get_data method.
|
554
646
|
###########################################################################
|
555
647
|
def self.get_data(params, name)
|
556
648
|
DateSelect.get_data(params, name)
|
@@ -559,12 +651,12 @@ end
|
|
559
651
|
end
|
560
652
|
|
561
653
|
###########################################################################
|
562
|
-
#
|
654
|
+
# Implementation of date_picker DRG CMS form field.
|
563
655
|
###########################################################################
|
564
656
|
class DatePicker < DrgcmsField
|
565
657
|
|
566
658
|
###########################################################################
|
567
|
-
#
|
659
|
+
# Render date_picker field html code
|
568
660
|
###########################################################################
|
569
661
|
def render
|
570
662
|
# return ro_standard if @readonly
|
@@ -592,7 +684,7 @@ EOJS
|
|
592
684
|
end
|
593
685
|
|
594
686
|
###########################################################################
|
595
|
-
#
|
687
|
+
# DatePicker get_data method.
|
596
688
|
###########################################################################
|
597
689
|
def self.get_data(params, name)
|
598
690
|
t = params['record'][name].to_datetime
|
@@ -601,12 +693,12 @@ end
|
|
601
693
|
|
602
694
|
end
|
603
695
|
###########################################################################
|
604
|
-
#
|
696
|
+
# Implementation of date_time_picker DRG CMS form field.
|
605
697
|
###########################################################################
|
606
698
|
class DatetimePicker < DrgcmsField
|
607
699
|
|
608
700
|
###########################################################################
|
609
|
-
#
|
701
|
+
# Render date_time_picker field html code
|
610
702
|
###########################################################################
|
611
703
|
def render
|
612
704
|
# return ro_standard if @readonly
|
@@ -633,7 +725,7 @@ EOJS
|
|
633
725
|
end
|
634
726
|
|
635
727
|
###########################################################################
|
636
|
-
#
|
728
|
+
# DateTimePicker get_data method.
|
637
729
|
###########################################################################
|
638
730
|
def self.get_data(params, name)
|
639
731
|
t = params['record'][name].to_datetime
|
@@ -643,12 +735,12 @@ end
|
|
643
735
|
end
|
644
736
|
|
645
737
|
###########################################################################
|
646
|
-
#
|
738
|
+
# Implementation of text_autocomplete DRG CMS form field.
|
647
739
|
###########################################################################
|
648
740
|
class TextAutocomplete < DrgcmsField
|
649
741
|
|
650
742
|
###########################################################################
|
651
|
-
#
|
743
|
+
# Render text_autocomplete field html code
|
652
744
|
###########################################################################
|
653
745
|
def render
|
654
746
|
# Return descriptive text and put it into input field
|
@@ -735,12 +827,12 @@ end
|
|
735
827
|
end
|
736
828
|
|
737
829
|
###########################################################################
|
738
|
-
#
|
830
|
+
# Implementation of text_area DRG CMS form field.
|
739
831
|
###########################################################################
|
740
832
|
class TextArea < DrgcmsField
|
741
833
|
|
742
834
|
###########################################################################
|
743
|
-
#
|
835
|
+
# Render text_area field html code
|
744
836
|
###########################################################################
|
745
837
|
def render
|
746
838
|
return ro_standard if @readonly
|
@@ -754,12 +846,12 @@ end
|
|
754
846
|
end
|
755
847
|
|
756
848
|
###########################################################################
|
757
|
-
#
|
849
|
+
# Implementation of text_field DRG CMS form field.
|
758
850
|
###########################################################################
|
759
851
|
class TextField < DrgcmsField
|
760
852
|
|
761
853
|
###########################################################################
|
762
|
-
#
|
854
|
+
# Render text_field field html code
|
763
855
|
###########################################################################
|
764
856
|
def render
|
765
857
|
return ro_standard if @readonly
|
@@ -771,12 +863,14 @@ end
|
|
771
863
|
end
|
772
864
|
|
773
865
|
###########################################################################
|
774
|
-
#
|
866
|
+
# Implementation of text_with_select DRG CMS form field.
|
867
|
+
#
|
868
|
+
# Create text_field with select dropdown box with optional values for the field
|
775
869
|
###########################################################################
|
776
870
|
class TextWithSelect < Select
|
777
871
|
|
778
872
|
###########################################################################
|
779
|
-
#
|
873
|
+
# Render text_with_select field html code
|
780
874
|
###########################################################################
|
781
875
|
def render
|
782
876
|
return ro_standard if @readonly
|
@@ -803,16 +897,16 @@ end
|
|
803
897
|
end
|
804
898
|
|
805
899
|
###########################################################################
|
806
|
-
#
|
900
|
+
# Implementation of html_field DRG CMS form field.
|
807
901
|
#
|
808
|
-
#
|
902
|
+
# HtmlField class implements redirection for calling actual html edit field code.
|
809
903
|
# This can be drg_default_html_editor's ckeditor or any other code defined
|
810
904
|
# by dc_site.settings html_editor setting.
|
811
905
|
###########################################################################
|
812
906
|
class HtmlField < DrgcmsField
|
813
907
|
|
814
908
|
###########################################################################
|
815
|
-
#
|
909
|
+
# Render html_field field html code
|
816
910
|
###########################################################################
|
817
911
|
def render
|
818
912
|
return ro_standard if @readonly
|
@@ -834,12 +928,16 @@ end
|
|
834
928
|
end
|
835
929
|
|
836
930
|
###########################################################################
|
837
|
-
#
|
931
|
+
# Implementation of file_select DRG CMS form field.
|
932
|
+
#
|
933
|
+
# FileSelect like HtmlField implements redirection for calling document manager edit field code.
|
934
|
+
# This can be drg_default_html_editor's elfinder or any other code defined
|
935
|
+
# by dc_site.settings file_select setting.
|
838
936
|
###########################################################################
|
839
937
|
class FileSelect < DrgcmsField
|
840
938
|
|
841
939
|
###########################################################################
|
842
|
-
#
|
940
|
+
# Render file_select field html code
|
843
941
|
###########################################################################
|
844
942
|
def render
|
845
943
|
return ro_standard if @readonly
|