drg_cms 0.5.50.2 → 0.5.51.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.log +47 -0
- data/README.md +2 -1
- data/app/assets/images/32px.png +0 -0
- data/app/assets/images/drg_cms/32px.png +0 -0
- data/app/assets/images/drg_cms/40px.png +0 -0
- data/app/assets/images/drg_cms/throbber.gif +0 -0
- data/app/assets/images/throbber.gif +0 -0
- data/app/assets/javascripts/drg_cms/drg_cms.js +3 -3
- data/app/assets/javascripts/drg_cms/jstree.min.js +6 -0
- data/app/assets/javascripts/drg_cms_cms.js +2 -1
- data/app/assets/stylesheets/drg_cms/drg_cms.css +9 -0
- data/app/assets/stylesheets/drg_cms/jstree.css +1108 -0
- data/app/assets/stylesheets/drg_cms_cms.css +1 -0
- data/app/controllers/cmsedit_controller.rb +14 -12
- data/app/controllers/dc_application_controller.rb +2 -2
- data/app/controllers/dc_common_controller.rb +15 -20
- data/app/controllers/dc_page_control.rb +8 -0
- data/app/controllers/design_element_settings_control.rb +135 -0
- data/app/forms/all_options.yml +7 -1
- data/app/forms/cms_menu.yml +1 -1
- data/app/forms/dc_browse_fields.yml +1 -1
- data/app/forms/dc_browse_models.yml +2 -2
- data/app/forms/dc_category.yml +4 -4
- data/app/forms/dc_menu.yml +6 -0
- data/app/forms/dc_page.yml +22 -12
- data/app/forms/dc_simple_menu.yml +6 -0
- data/app/forms/dc_site.yml +6 -0
- data/app/helpers/cmsedit_helper.rb +12 -8
- data/app/helpers/dc_application_helper.rb +79 -18
- data/app/helpers/dc_menu_renderer.rb +6 -1
- data/app/helpers/dc_part_renderer.rb +1 -1
- data/app/models/concerns/dc_page_concern.rb +133 -0
- data/app/models/concerns/dc_piece_concern.rb +57 -0
- data/app/models/concerns/dc_policy_rule_concern.rb +78 -0
- data/app/models/concerns/dc_site_concern.rb +94 -0
- data/app/models/concerns/dc_user_concern.rb +130 -0
- data/app/models/dc_ad.rb +1 -1
- data/app/models/dc_big_menu.rb +1 -1
- data/app/models/dc_category.rb +19 -4
- data/app/models/dc_dummy.rb +3 -2
- data/app/models/dc_link.rb +1 -1
- data/app/models/dc_memory.rb +127 -0
- data/app/models/dc_menu.rb +69 -3
- data/app/models/dc_menu_item.rb +17 -0
- data/app/models/dc_page.rb +0 -106
- data/app/models/dc_part.rb +0 -1
- data/app/models/dc_piece.rb +0 -35
- data/app/models/dc_policy_rule.rb +0 -56
- data/app/models/dc_simple_menu.rb +36 -0
- data/app/models/dc_simple_menu_item.rb +0 -0
- data/app/models/dc_site.rb +1 -71
- data/app/models/dc_user.rb +0 -108
- data/app/models/drgcms_form_fields.rb +187 -26
- data/app/views/cmsedit/_result.html.erb +3 -4
- data/config/locales/models_en.yml +11 -3
- data/config/locales/models_sl.yml +7 -0
- data/lib/drg_cms.rb +1 -0
- data/lib/drg_cms/version.rb +1 -1
- data/lib/tasks/log_statistics.rb +14 -8
- metadata +16 -2
@@ -0,0 +1,78 @@
|
|
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
|
+
# ActiveSupport::Concern definition for DcPolicyRule class.
|
26
|
+
#########################################################################
|
27
|
+
module DcPolicyRuleConcern
|
28
|
+
extend ActiveSupport::Concern
|
29
|
+
included do
|
30
|
+
|
31
|
+
include Mongoid::Document
|
32
|
+
include Mongoid::Timestamps
|
33
|
+
|
34
|
+
belongs_to :dc_policy_role
|
35
|
+
|
36
|
+
field :permission, type: Integer, default: 0
|
37
|
+
|
38
|
+
embedded_in :policy_rules, polymorphic: true
|
39
|
+
|
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
|
48
|
+
#########################################################################
|
49
|
+
def self.values_for_permissions
|
50
|
+
key = 'helpers.label.dc_policy_rule.choices4_permission'
|
51
|
+
c = I18n.t(key)
|
52
|
+
c = I18n.t(key, locale: 'en') if c.class == Hash or c.match( 'translation missing' )
|
53
|
+
c.split(',').inject([]) {|r,e| r << (ar = e.split(':'); [ar.first, ar.last.to_i]) }
|
54
|
+
end
|
55
|
+
|
56
|
+
#########################################################################
|
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
|
71
|
+
#########################################################################
|
72
|
+
def self.permission_name_for_value(value)
|
73
|
+
values_for_permissions.each {|v| return v.first if v.last.to_i == value.to_i}
|
74
|
+
'error'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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
|
+
# ActiveSupport::Concern definition for DcSite class.
|
26
|
+
#########################################################################
|
27
|
+
module DcSiteConcern
|
28
|
+
extend ActiveSupport::Concern
|
29
|
+
included do
|
30
|
+
include Mongoid::Document
|
31
|
+
include Mongoid::Timestamps
|
32
|
+
|
33
|
+
field :name, type: String
|
34
|
+
field :description, type: String
|
35
|
+
field :homepage_link, type: String
|
36
|
+
field :error_link, type: String
|
37
|
+
field :header, type: String, default: ''
|
38
|
+
field :css, type: String, default: ''
|
39
|
+
field :route_name, type: String, default: ''
|
40
|
+
field :page_title, type: String
|
41
|
+
field :document_extension, type: String
|
42
|
+
field :page_table, type: String
|
43
|
+
field :page_class, type: String, default: 'DcPage'
|
44
|
+
field :site_layout, type: String, default: 'content'
|
45
|
+
field :menu_class, type: String, default: 'DcSimpleMenu'
|
46
|
+
field :request_processor, type: String
|
47
|
+
field :files_directory, type: String
|
48
|
+
field :logo, type: String
|
49
|
+
field :active, type: Boolean, default: true
|
50
|
+
field :created_by, type: BSON::ObjectId
|
51
|
+
field :updated_by, type: BSON::ObjectId
|
52
|
+
field :menu_name, type: String
|
53
|
+
field :settings, type: String
|
54
|
+
field :alias_for, type: String
|
55
|
+
field :rails_view, type: String, default: ''
|
56
|
+
field :design, type: String, default: ''
|
57
|
+
field :inherit_policy, type: BSON::ObjectId
|
58
|
+
|
59
|
+
embeds_many :dc_policies
|
60
|
+
embeds_many :dc_parts
|
61
|
+
|
62
|
+
index( { name: 1 }, { unique: true } )
|
63
|
+
index( { alias_for: 1 } )
|
64
|
+
|
65
|
+
validates :name, presence: true
|
66
|
+
validates :name, uniqueness: true
|
67
|
+
|
68
|
+
########################################################################
|
69
|
+
# Returns value of site setting. If no value is send as parameter it returns
|
70
|
+
# all settings hash object.
|
71
|
+
########################################################################
|
72
|
+
def params(what=nil)
|
73
|
+
@params ||= self.settings.to_s.size > 5 ? YAML.load(self.settings) : {}
|
74
|
+
what.nil? ? @params : @params[what.to_s]
|
75
|
+
end
|
76
|
+
|
77
|
+
########################################################################
|
78
|
+
# Return choices for select for site_id
|
79
|
+
########################################################################
|
80
|
+
def self.choices4_site
|
81
|
+
all.inject([]) { |r,site| r << [ (site.active ? '' : t('drgcms.disabled') ) + site.name, site._id] }
|
82
|
+
end
|
83
|
+
|
84
|
+
########################################################################
|
85
|
+
# Return choices for selecting policies for the site
|
86
|
+
########################################################################
|
87
|
+
def self.choices4_policies
|
88
|
+
site = ApplicationController.dc_get_site_()
|
89
|
+
#all.inject([]) { |r,site| r << [ (site.active ? '' : t('drgcms.disabled') ) + site.name, site._id] }
|
90
|
+
[['a','b']]
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,130 @@
|
|
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
|
+
# ActiveSupport::Concern definition for DcUser class.
|
26
|
+
#########################################################################
|
27
|
+
module DcUserConcern
|
28
|
+
extend ActiveSupport::Concern
|
29
|
+
included do
|
30
|
+
@@countries = nil
|
31
|
+
|
32
|
+
include Mongoid::Document
|
33
|
+
include Mongoid::Timestamps
|
34
|
+
include ActiveModel::SecurePassword
|
35
|
+
|
36
|
+
field :username, type: String, default: ''
|
37
|
+
field :title, type: String, default: ''
|
38
|
+
field :first_name, type: String, default: ''
|
39
|
+
field :middle_name, type: String, default: ''
|
40
|
+
field :last_name, type: String, default: ''
|
41
|
+
field :name, type: String
|
42
|
+
field :company, type: String, default: ''
|
43
|
+
field :address, type: String
|
44
|
+
field :post, type: String
|
45
|
+
field :country, type: String
|
46
|
+
field :phone, type: String
|
47
|
+
field :email, type: String
|
48
|
+
field :www, type: String
|
49
|
+
field :picture, type: String
|
50
|
+
field :birthdate, type: Date
|
51
|
+
field :about, type: String
|
52
|
+
field :last_visit, type: Time
|
53
|
+
field :active, type: Boolean, default: true
|
54
|
+
field :valid_from, type: Date
|
55
|
+
field :valid_to, type: Date
|
56
|
+
field :created_by, type: BSON::ObjectId
|
57
|
+
field :updated_by, type: BSON::ObjectId
|
58
|
+
|
59
|
+
field :type, type: Integer, default: 0 # 0 => User, 1 => Group
|
60
|
+
field :members, type: Array
|
61
|
+
|
62
|
+
embeds_many :dc_user_roles
|
63
|
+
|
64
|
+
# for forum
|
65
|
+
field :signature, type: String
|
66
|
+
field :interests, type: String
|
67
|
+
field :job_occup, type: String
|
68
|
+
field :description, type: String
|
69
|
+
field :reg_date, type: Date
|
70
|
+
|
71
|
+
field :password_digest, type: String
|
72
|
+
has_secure_password
|
73
|
+
|
74
|
+
index( { username: 1 }, { unique: true } )
|
75
|
+
index( { email: 1 }, { unique: true } )
|
76
|
+
index 'dc_user_roles.dc_policy_role_id' => 1
|
77
|
+
|
78
|
+
index 'members' => 1
|
79
|
+
|
80
|
+
validates_length_of :username, minimum: 4
|
81
|
+
before_save :do_before_save
|
82
|
+
|
83
|
+
##########################################################################
|
84
|
+
# before_save callback takes care of name field and ensures that e-mail is unique
|
85
|
+
# when entry is left empty.
|
86
|
+
##########################################################################
|
87
|
+
def do_before_save
|
88
|
+
self.name = "#{self.title} #{self.first_name} #{self.middle_name + ' ' unless self.middle_name.blank?}#{self.last_name}".strip
|
89
|
+
# to ensure unique e-mail
|
90
|
+
self.email = "unknown@#{self.id}" if self.email.to_s.strip.size < 5
|
91
|
+
end
|
92
|
+
|
93
|
+
##########################################################################
|
94
|
+
# Will return all possible values for country field ready for input in select field.
|
95
|
+
# Values are loaded from github when method is first called.
|
96
|
+
##########################################################################
|
97
|
+
def self.choices4_country()
|
98
|
+
if @@countries.nil?
|
99
|
+
uri = URI.parse("https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/en/country.json")
|
100
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
101
|
+
http.use_ssl = true
|
102
|
+
|
103
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
104
|
+
response = http.request(request)
|
105
|
+
@@countries = JSON.parse(response.body).to_a.inject([]) {|result, e| result << [e[1], e[0]] }
|
106
|
+
end
|
107
|
+
@@countries
|
108
|
+
end
|
109
|
+
|
110
|
+
##########################################################################
|
111
|
+
# Performs ligically test on passed email parameter.
|
112
|
+
#
|
113
|
+
# Parameters:
|
114
|
+
# [email] String: e-mail address
|
115
|
+
#
|
116
|
+
# Returns:
|
117
|
+
# Boolean: True if parameter is logically valid email address.
|
118
|
+
#
|
119
|
+
# Example:
|
120
|
+
# if !DcUser.is_email?(params[:email])
|
121
|
+
# flash[:error] = 'e-Mail address is not valid!'
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
##########################################################################
|
125
|
+
def self.is_email?(email)
|
126
|
+
email.to_s =~ /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/app/models/dc_ad.rb
CHANGED
data/app/models/dc_big_menu.rb
CHANGED
data/app/models/dc_category.rb
CHANGED
@@ -53,7 +53,7 @@ class DcCategory
|
|
53
53
|
field :order, type: Integer, default: 0
|
54
54
|
field :created_by, type: BSON::ObjectId
|
55
55
|
field :updated_by, type: BSON::ObjectId
|
56
|
-
field :dc_site_id,
|
56
|
+
field :dc_site_id, type: BSON::ObjectId
|
57
57
|
|
58
58
|
validates :name, :presence => true
|
59
59
|
|
@@ -62,10 +62,12 @@ class DcCategory
|
|
62
62
|
index site_id: 1
|
63
63
|
|
64
64
|
#########################################################################
|
65
|
-
# Returns all values
|
65
|
+
# Returns all values vhich can be used as parent select field.
|
66
66
|
#########################################################################
|
67
|
-
def self.values_for_parent #:nodoc:
|
68
|
-
where(
|
67
|
+
def self.values_for_parent(site_id=nil) #:nodoc:
|
68
|
+
qry = where(active: true)
|
69
|
+
qry = qry.and(dc_site_id: site_id.id) if site_id
|
70
|
+
qry.sort(name: 1).inject([]) {|r,v| r << [v.name, v._id]}
|
69
71
|
end
|
70
72
|
|
71
73
|
#########################################################################
|
@@ -84,5 +86,18 @@ def self.choices4_ctype(site_id=nil)
|
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
89
|
+
#########################################################################
|
90
|
+
# Returns choices for all categories, prepared for tree_select input field
|
91
|
+
#########################################################################
|
92
|
+
def self.choices4_categories(site_id=nil)
|
93
|
+
qry = where(active: true)
|
94
|
+
#
|
95
|
+
ar = [nil]
|
96
|
+
ar << site_id.id if site_id
|
97
|
+
qry = qry.in(dc_site_id: ar)
|
98
|
+
#
|
99
|
+
qry.inject([]) { |result, category| result << [category.name, category.id, category.parent, category.order] }
|
100
|
+
end
|
101
|
+
|
87
102
|
|
88
103
|
end
|
data/app/models/dc_dummy.rb
CHANGED
@@ -56,8 +56,9 @@
|
|
56
56
|
# type: date_picker
|
57
57
|
# caption: End date
|
58
58
|
#
|
59
|
-
# And suppose your report saved data to file named public/report.pdf.
|
60
|
-
#
|
59
|
+
# And suppose your report saved data to file named public/report.pdf.
|
60
|
+
# Put this line at the end of do_some_report method:
|
61
|
+
#
|
61
62
|
# render inline: { :window_report => '/report.pdf' }.to_json, formats: 'js'
|
62
63
|
#
|
63
64
|
# As result report.pdf file will be opened in new browser window.
|
data/app/models/dc_link.rb
CHANGED
@@ -0,0 +1,127 @@
|
|
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
|
+
# == Schema information
|
26
|
+
#
|
27
|
+
# Collection name: dc_memory : Collection name used when form does not belong to database model.
|
28
|
+
#
|
29
|
+
# _id BSON::ObjectId _id
|
30
|
+
#
|
31
|
+
# Which is not collection at all. DcMemory model is used for entering data on forms
|
32
|
+
# where data will not be saved to database but will instead be saved only to memory as
|
33
|
+
# temporary variable and processed by custom made methods.
|
34
|
+
# For example, define start and end date when making a timeline report.
|
35
|
+
#
|
36
|
+
# Example (as used in forms):
|
37
|
+
#
|
38
|
+
# table: dc_memory
|
39
|
+
# title: Enter time period
|
40
|
+
#
|
41
|
+
# form:
|
42
|
+
# actions:
|
43
|
+
# 1:
|
44
|
+
# type: ajax
|
45
|
+
# method: post
|
46
|
+
# controller: reports
|
47
|
+
# action: do_some_report
|
48
|
+
# caption: Run report
|
49
|
+
#
|
50
|
+
# fields:
|
51
|
+
# 10:
|
52
|
+
# name: date_start
|
53
|
+
# type: date_picker
|
54
|
+
# caption: Start date
|
55
|
+
# 20:
|
56
|
+
# name: date_end
|
57
|
+
# type: date_picker
|
58
|
+
# caption: End date
|
59
|
+
#
|
60
|
+
# And suppose your report saved data to file named public/report.pdf.
|
61
|
+
# Put this line at the end of do_some_report method:
|
62
|
+
#
|
63
|
+
# render inline: { :window_report => '/report.pdf' }.to_json, formats: 'js'
|
64
|
+
#
|
65
|
+
# As result report.pdf file will be opened in new browser window.
|
66
|
+
########################################################################
|
67
|
+
class DcMemory
|
68
|
+
include Mongoid::Document
|
69
|
+
|
70
|
+
########################################################################
|
71
|
+
# Respond_to should always return true.
|
72
|
+
########################################################################
|
73
|
+
def respond_to?(m)
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
########################################################################
|
78
|
+
# Redefine send method. Send is used to assign value by cmsedit controller.
|
79
|
+
########################################################################
|
80
|
+
def send(field,value=nil)
|
81
|
+
field = field.to_s
|
82
|
+
if field.match('=')
|
83
|
+
field.chomp!('=')
|
84
|
+
@internals ||= {}
|
85
|
+
@internals[field] = value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
########################################################################
|
90
|
+
# Redefine [] method to act similar as send method
|
91
|
+
########################################################################
|
92
|
+
def [](field)
|
93
|
+
return nil unless @internals
|
94
|
+
@internals[field.to_s]
|
95
|
+
end
|
96
|
+
|
97
|
+
########################################################################
|
98
|
+
# Redefine [] method to act similar as send method
|
99
|
+
########################################################################
|
100
|
+
def []=(field, value)
|
101
|
+
@internals ||= {}
|
102
|
+
@internals[field.to_s] = value
|
103
|
+
end
|
104
|
+
|
105
|
+
########################################################################
|
106
|
+
# For debugging purposes
|
107
|
+
########################################################################
|
108
|
+
def to_s
|
109
|
+
"DcMemory: @internals=#{@internals}"
|
110
|
+
end
|
111
|
+
|
112
|
+
########################################################################
|
113
|
+
# Method missing will return value if value defined by m parameter is saved to
|
114
|
+
# @internals array or will save field value to @internals hash if m matches '='.
|
115
|
+
########################################################################
|
116
|
+
def method_missing(m, *args, &block) #:nodoc:
|
117
|
+
@internals ||= {}
|
118
|
+
m = m.to_s
|
119
|
+
if m.match('=')
|
120
|
+
m.chomp!('=')
|
121
|
+
@internals[m] = args.first
|
122
|
+
else
|
123
|
+
@internals[m]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|