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.
- checksums.yaml +5 -5
- data/app/assets/javascripts/drg_cms/drg_cms.js +395 -120
- data/app/assets/javascripts/drg_cms/jstree.min.js +6 -6
- data/app/assets/javascripts/drg_cms_application.js +1 -1
- data/app/assets/stylesheets/drg_cms/drg_cms.css +476 -215
- data/app/assets/stylesheets/drg_cms/jstree.css +6 -12
- data/app/assets/stylesheets/drg_cms/select-multiple.css +19 -13
- data/app/assets/stylesheets/drg_cms_cms.css +1 -1
- data/app/controllers/cmsedit_controller.rb +474 -233
- data/app/controllers/dc_application_controller.rb +264 -41
- data/app/controllers/dc_common_controller.rb +75 -63
- data/app/{controllers → controls}/browse_models_control.rb +0 -0
- data/app/{controllers → controls}/dc_page_control.rb +24 -8
- data/app/controls/dc_poll_result_control.rb +88 -0
- data/app/controls/dc_report.rb +227 -0
- data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
- data/app/forms/all_options.yml +70 -12
- data/app/forms/cms_menu.yml +26 -17
- data/app/forms/dc_ad.yml +11 -22
- data/app/forms/dc_big_table.yml +1 -0
- data/app/forms/dc_big_table_value.yml +1 -0
- data/app/forms/dc_design.yml +19 -16
- data/app/forms/dc_filter.yml +3 -6
- data/app/forms/dc_gallery.yml +53 -0
- data/app/forms/dc_json_ld.yml +59 -0
- data/app/forms/dc_key_value.yml +32 -0
- data/app/forms/dc_link.yml +16 -10
- data/app/forms/dc_menu_item.yml +6 -0
- data/app/forms/dc_page.yml +2 -7
- data/app/forms/dc_poll.yml +16 -9
- data/app/forms/dc_poll_item.yml +2 -1
- data/app/forms/dc_poll_result.yml +83 -0
- data/app/forms/dc_poll_result_export.yml +35 -0
- data/app/forms/dc_removed_url.yml +42 -0
- data/app/forms/dc_seo.yml +33 -0
- data/app/forms/dc_site.yml +2 -6
- data/app/forms/json_ld_schema.yml +168 -0
- data/app/helpers/cms_common_helper.rb +311 -0
- data/app/helpers/cms_edit_helper.rb +498 -0
- data/app/helpers/cms_helper.rb +230 -0
- data/app/helpers/cms_index_helper.rb +564 -0
- data/app/helpers/dc_application_helper.rb +195 -268
- data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
- data/app/models/concerns/dc_page_concern.rb +31 -6
- data/app/models/concerns/dc_seo_concern.rb +66 -0
- data/app/models/concerns/dc_site_concern.rb +12 -1
- data/app/models/concerns/dc_user_concern.rb +5 -3
- data/app/models/dc_design.rb +2 -0
- data/app/models/dc_filter.rb +37 -20
- data/app/models/dc_gallery.rb +64 -0
- data/app/models/dc_json_ld.rb +152 -0
- data/app/models/dc_key_value.rb +48 -0
- data/app/models/dc_link.rb +1 -0
- data/app/models/dc_memory.rb +26 -4
- data/app/models/dc_page.rb +1 -2
- data/app/models/dc_permission.rb +30 -0
- data/app/models/dc_poll.rb +39 -19
- data/app/models/dc_poll_result.rb +46 -0
- data/app/models/dc_removed_url.rb +54 -0
- data/app/models/dc_temp.rb +140 -0
- data/app/models/drgcms_form_fields.rb +6 -1642
- data/app/models/drgcms_form_fields/action.rb +61 -0
- data/app/models/drgcms_form_fields/check_box.rb +72 -0
- data/app/models/drgcms_form_fields/comment.rb +53 -0
- data/app/models/drgcms_form_fields/date_picker.rb +104 -0
- data/app/models/drgcms_form_fields/date_select.rb +68 -0
- data/app/models/drgcms_form_fields/datetime_picker.rb +89 -0
- data/app/models/drgcms_form_fields/datetime_select.rb +73 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +287 -0
- data/app/models/drgcms_form_fields/embedded.rb +97 -0
- data/app/models/drgcms_form_fields/file_field.rb +52 -0
- data/app/models/drgcms_form_fields/file_select.rb +70 -0
- data/app/models/drgcms_form_fields/hash_field.rb +86 -0
- data/app/models/drgcms_form_fields/hidden_field.rb +52 -0
- data/app/models/drgcms_form_fields/html_field.rb +70 -0
- data/app/models/drgcms_form_fields/journal_diff.rb +60 -0
- data/app/models/drgcms_form_fields/link_to.rb +69 -0
- data/app/models/drgcms_form_fields/method.rb +65 -0
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +204 -0
- data/app/models/drgcms_form_fields/number_field.rb +92 -0
- data/app/models/drgcms_form_fields/password_field.rb +62 -0
- data/app/models/drgcms_form_fields/radio.rb +96 -0
- data/app/models/drgcms_form_fields/readonly.rb +79 -0
- data/app/models/drgcms_form_fields/select.rb +226 -0
- data/app/models/drgcms_form_fields/submit_tag.rb +58 -0
- data/app/models/drgcms_form_fields/text_area.rb +68 -0
- data/app/models/drgcms_form_fields/text_autocomplete.rb +155 -0
- data/app/models/drgcms_form_fields/text_field.rb +56 -0
- data/app/models/drgcms_form_fields/text_with_select.rb +95 -0
- data/app/models/drgcms_form_fields/tree_select.rb +169 -0
- data/app/{helpers → renderers}/dc_ad_renderer.rb +0 -0
- data/app/{helpers → renderers}/dc_big_menu_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_captcha_renderer.rb +0 -0
- data/app/{helpers → renderers}/dc_common_renderer.rb +0 -0
- data/app/renderers/dc_gallery_renderer.rb +95 -0
- data/app/{helpers → renderers}/dc_menu_renderer.rb +11 -4
- data/app/{helpers → renderers}/dc_page_renderer.rb +21 -3
- data/app/{helpers → renderers}/dc_part_renderer.rb +5 -4
- data/app/{helpers → renderers}/dc_piece_renderer.rb +1 -1
- data/app/{helpers → renderers}/dc_poll_renderer.rb +86 -51
- data/app/{helpers → renderers}/dc_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_simple_menu_renderer.rb +1 -0
- data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
- data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
- data/app/views/cmsedit/_edit_stuff.html.erb +4 -25
- data/app/views/cmsedit/_form.html.erb +4 -3
- data/app/views/cmsedit/_result.html.erb +2 -3
- data/app/views/cmsedit/edit.html.erb +2 -1
- data/app/views/cmsedit/index.html.erb +6 -1
- data/app/views/cmsedit/new.html.erb +1 -1
- data/config/locales/drgcms_en.yml +15 -3
- data/config/locales/drgcms_sl.yml +18 -6
- data/config/locales/models_en.yml +103 -19
- data/config/locales/models_sl.yml +102 -17
- data/drg_cms.gemspec +3 -3
- data/lib/drg_cms.rb +6 -2
- data/lib/drg_cms/version.rb +2 -2
- data/lib/generators/new_drg_form/new_drg_form_generator.rb +9 -2
- data/lib/tasks/database.rake +6 -56
- data/lib/tasks/dc_cleanup.rake +1 -1
- metadata +106 -61
- data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
- data/app/helpers/application_helper.rb +0 -2
- data/app/helpers/cmsedit_helper.rb +0 -844
- data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012+ Damjan Rems
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
module DrgcmsFormFields
|
24
|
+
|
25
|
+
###########################################################################
|
26
|
+
# Implementation of custom DRG CMS form field. Method field will call method or class method
|
27
|
+
# defined in eval option and add returned code to HTML output code. This might prove usefull in
|
28
|
+
# cases where form contains complex dta stgructer or set of pictures which can not
|
29
|
+
# be simply displayed by any other field.
|
30
|
+
#
|
31
|
+
# Form example:
|
32
|
+
# 50:
|
33
|
+
# name: galery
|
34
|
+
# type: method
|
35
|
+
# eval: show_gallery
|
36
|
+
# or
|
37
|
+
# eval: MyClass.show_gallery
|
38
|
+
#
|
39
|
+
###########################################################################
|
40
|
+
class Method < DrgcmsField
|
41
|
+
|
42
|
+
###########################################################################
|
43
|
+
# Render file_select field html code
|
44
|
+
###########################################################################
|
45
|
+
def render
|
46
|
+
# might be defined as my_method or MyClass.my_method
|
47
|
+
clas, method = @yaml['eval'].split('.')
|
48
|
+
if method.nil?
|
49
|
+
if @parent.respond_to?(clas)
|
50
|
+
@html << @parent.send(clas, @record, @yaml, @readonly)
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
else
|
54
|
+
klass = clas.camelize.constantize
|
55
|
+
if klass.respond_to?(method)
|
56
|
+
@html << klass.send(method, @record, @yaml, @readonly)
|
57
|
+
return self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@html << "Error: #{@yaml['name']} : #{@yaml['eval']} not defined!"
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,204 @@
|
|
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 multitext_autocomplete DRG Form field.
|
27
|
+
#
|
28
|
+
# multitext_autocomplete field is complex data entry field which uses autocomplete
|
29
|
+
# function when selecting multiple values for MongoDB Array field. Array typically holds
|
30
|
+
# id's of selected documents and control typically displays value of the field name
|
31
|
+
# defined by search options.
|
32
|
+
#
|
33
|
+
# ===Form options:
|
34
|
+
# * +name:+ field name (required)
|
35
|
+
# * +type:+ multitext_autocomplete (required)
|
36
|
+
# * +table+ Model (table) name which must contain searched field name.
|
37
|
+
# * +search:+ Search may consist of three parameters from which are separated either by dot (.) or comma(,)
|
38
|
+
# * search_field_name; when table option is defined search must define field name which will be used for search query
|
39
|
+
# * collection_name.search_field_name; Same as above except that table options must be ommited.
|
40
|
+
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
41
|
+
# method may be defined in CollectionName model which will provide result set for search.
|
42
|
+
# * +with_new+ Will add an icon for shortcut to add new document to collection
|
43
|
+
#
|
44
|
+
# Form example:
|
45
|
+
# 90:
|
46
|
+
# name: kats
|
47
|
+
# type: multitext_autocomplete
|
48
|
+
# search: dc_category.name
|
49
|
+
# with_new: model_name
|
50
|
+
# size: 30
|
51
|
+
###########################################################################
|
52
|
+
class MultitextAutocomplete < DrgcmsField
|
53
|
+
|
54
|
+
###########################################################################
|
55
|
+
# Returns value for readonly field
|
56
|
+
###########################################################################
|
57
|
+
def ro_standard(table, search)
|
58
|
+
result = ''
|
59
|
+
table = table.classify.constantize
|
60
|
+
return self if @record[@yaml['name']].nil?
|
61
|
+
# when field name and method are defined together
|
62
|
+
search = search.split('.').first if search.match('.')
|
63
|
+
@record[@yaml['name']].each do |element|
|
64
|
+
result << table.find(element)[search] + '<br>'
|
65
|
+
end
|
66
|
+
super(result)
|
67
|
+
end
|
68
|
+
|
69
|
+
###########################################################################
|
70
|
+
# Render multitext_autocomplete field html code
|
71
|
+
###########################################################################
|
72
|
+
def render
|
73
|
+
# search field name
|
74
|
+
if @yaml['search'].class == Hash
|
75
|
+
table = @yaml['search']['table']
|
76
|
+
field_name = @yaml['search']['field']
|
77
|
+
method = @yaml['search']['method']
|
78
|
+
search = method.nil? ? field_name : "#{field_name}.#{method}"
|
79
|
+
elsif @yaml['search'].to_s.match(/\./)
|
80
|
+
table, field_name, method = @yaml['search'].split(/\.|\,/)
|
81
|
+
search = method.nil? ? field_name : "#{field_name}.#{method}"
|
82
|
+
else # search and table name are separated
|
83
|
+
search = field_name = @yaml['search']
|
84
|
+
end
|
85
|
+
# determine table name
|
86
|
+
if @yaml['table']
|
87
|
+
table = if @yaml['table'].class == String
|
88
|
+
@yaml['table']
|
89
|
+
# eval(how_to_get_my_table_name)
|
90
|
+
elsif @yaml['table']['eval']
|
91
|
+
eval @yaml['table']['eval']
|
92
|
+
else
|
93
|
+
@parent.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
unless (table and search)
|
98
|
+
@html << 'Table or search field not defined!'
|
99
|
+
return self
|
100
|
+
end
|
101
|
+
#
|
102
|
+
# TODO check if table exists
|
103
|
+
collection = table.classify.constantize
|
104
|
+
unless @record.respond_to?(@yaml['name'])
|
105
|
+
@html << "Invalid field name: #{@yaml['name']}"
|
106
|
+
return self
|
107
|
+
end
|
108
|
+
# put field to enter search data on form
|
109
|
+
@yaml['html'] ||= {}
|
110
|
+
@yaml['html']['value'] = '' # must be. Otherwise it will look into record and return error
|
111
|
+
@yaml['html']['placeholder'] = t('drgcms.search_placeholder')
|
112
|
+
_name = '_' + @yaml['name']
|
113
|
+
@html << '<div class="ui-autocomplete-border">'
|
114
|
+
@html << @parent.link_to(@parent.fa_icon('plus-square lg', class: 'dc-animate dc-green'), '#',onclick: 'return false;') # dummy add. But it is usefull.
|
115
|
+
|
116
|
+
record = record_text_for(@yaml['name'])
|
117
|
+
# text field for autocomplete
|
118
|
+
@html << '<span class="dc-text-autocomplete">' << @parent.text_field(record, _name, @yaml['html']) << '<span></span></span>'
|
119
|
+
# direct link for adding new documents to collection
|
120
|
+
if @yaml['with_new'] and !@readonly
|
121
|
+
@html << ' ' +
|
122
|
+
@parent.fa_icon('plus-square lg', class: 'in-edit-add', title: t('drgcms.new'),
|
123
|
+
style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
|
124
|
+
end
|
125
|
+
# div to list active selections
|
126
|
+
@html << "<div id =\"#{record}#{@yaml['name']}\">"
|
127
|
+
# find value for each field inside categories
|
128
|
+
unless @record[@yaml['name']].nil?
|
129
|
+
@record[@yaml['name']].each do |element|
|
130
|
+
# this is quick and dirty trick. We have model dc_big_table which can be used for retrive
|
131
|
+
# more complicated options
|
132
|
+
# TODO retrieve choices from big_table
|
133
|
+
rec = if table == 'dc_big_table'
|
134
|
+
collection.find(@yaml['name'], @parent.session)
|
135
|
+
else
|
136
|
+
collection.find(element)
|
137
|
+
end
|
138
|
+
# Related data is missing. It happends.
|
139
|
+
@html << if rec
|
140
|
+
link = @parent.link_to(@parent.fa_icon('remove lg', class: 'dc-animate dc-red'), '#',
|
141
|
+
onclick: "$('##{rec.id}').hide(); var v = $('##{record}_#{@yaml['name']}_#{rec.id}'); v.val(\"-\" + v.val());return false;")
|
142
|
+
link = @parent.fa_icon('check lg', class: 'dc-green') if @readonly
|
143
|
+
field = @parent.hidden_field(record, "#{@yaml['name']}_#{rec.id}", value: element)
|
144
|
+
"<div id=\"#{rec.id}\" style=\"padding:4px;\">#{link} #{rec.send(field_name)}<br>#{field}</div>"
|
145
|
+
else
|
146
|
+
'** error **'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
@html << "</div></div>"
|
151
|
+
# Create text for div to be added when new category is selected
|
152
|
+
link = @parent.link_to(@parent.fa_icon('remove lg', class: 'dc-animate dc-red'), '#',
|
153
|
+
onclick: "$('#rec_id').hide(); var v = $('##{record}_#{@yaml['name']}_rec_id'); v.val(\"-\" + v.val());return false;")
|
154
|
+
field = @parent.hidden_field(record, "#{@yaml['name']}_rec_id", value: 'rec_id')
|
155
|
+
one_div = "<div id=\"rec_id\" style=\"padding:4px;\">#{link} rec_search<br>#{field}</div>"
|
156
|
+
|
157
|
+
# JS stuff
|
158
|
+
@js << <<EOJS
|
159
|
+
$(document).ready(function() {
|
160
|
+
$("##{record}_#{_name}").autocomplete( {
|
161
|
+
source: function(request, response) {
|
162
|
+
$.ajax({
|
163
|
+
url: "#{ @parent.url_for( controller: 'dc_common', action: 'autocomplete' )}",
|
164
|
+
type: "POST",
|
165
|
+
dataType: "json",
|
166
|
+
data: { input: request.term, table: "#{table}", search: "#{search}" #{(',id: "'+@yaml['id'] + '"') if @yaml['id']} },
|
167
|
+
success: function(data) {
|
168
|
+
response( $.map( data, function(key) {
|
169
|
+
return key;
|
170
|
+
}));
|
171
|
+
}
|
172
|
+
});
|
173
|
+
},
|
174
|
+
change: function (event, ui) {
|
175
|
+
var div = '#{one_div}';
|
176
|
+
div = div.replace(/rec_id/g, ui.item.id)
|
177
|
+
div = div.replace('rec_search', ui.item.value)
|
178
|
+
$("##{record}#{@yaml['name']}").append(div);
|
179
|
+
$("##{record}_#{_name}").val('');
|
180
|
+
$("##{record}_#{_name}").focus();
|
181
|
+
},
|
182
|
+
minLength: 2
|
183
|
+
});
|
184
|
+
});
|
185
|
+
EOJS
|
186
|
+
|
187
|
+
self
|
188
|
+
end
|
189
|
+
|
190
|
+
###########################################################################
|
191
|
+
# Class method for retrieving data from multitext_autocomplete form field.
|
192
|
+
###########################################################################
|
193
|
+
def self.get_data(params, name)
|
194
|
+
r = []
|
195
|
+
params['record'].each do |k,v|
|
196
|
+
# if it starts with - then it was removed
|
197
|
+
r << BSON::ObjectId.from_string(v) if k.match("#{name}_") and v[0,1] != '-'
|
198
|
+
end
|
199
|
+
r.uniq!
|
200
|
+
r
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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 number_field DRG CMS form field. Number fields can be
|
27
|
+
# formated for display with thousands delimiters and decimal separators and
|
28
|
+
# can have currency symbol.
|
29
|
+
#
|
30
|
+
# ===Form options:
|
31
|
+
# * +type:+ number_field (required)
|
32
|
+
# * +name:+ Field name (required)
|
33
|
+
# * +format:+ Format options
|
34
|
+
# * +decimals:+ No of decimal places
|
35
|
+
# * +separator:+ decimal separator (yes no , .) Default yes if decimals > 0
|
36
|
+
# * +delimiter:+ Thousands delimiter (yes no , .) Default defind by locals
|
37
|
+
# * +currency:+ Currency sign (yes no sign) Default no. If yes defined by locals
|
38
|
+
# * +html:+ html options which apply to text_field field (optional)
|
39
|
+
#
|
40
|
+
# Form example:
|
41
|
+
# 10:
|
42
|
+
# name: title
|
43
|
+
# type: number_field
|
44
|
+
# size: 10
|
45
|
+
# format:
|
46
|
+
# decimals: 2
|
47
|
+
# delimiter: false
|
48
|
+
###########################################################################
|
49
|
+
class NumberField < DrgcmsField
|
50
|
+
|
51
|
+
###########################################################################
|
52
|
+
# Render text_field field html code
|
53
|
+
###########################################################################
|
54
|
+
def render
|
55
|
+
#return ro_standard if @readonly
|
56
|
+
set_initial_value
|
57
|
+
#
|
58
|
+
record = record_text_for(@yaml['name'])
|
59
|
+
@yaml['html'] ||= {}
|
60
|
+
@yaml['html']['class'] = 'dc-number'
|
61
|
+
if @yaml['format'].class == String
|
62
|
+
format = @yaml['format']
|
63
|
+
@yaml['format'] = {}
|
64
|
+
@yaml['format']['decimal'] = format[1].blank? ? 2 : format[1].to_i
|
65
|
+
@yaml['format']['separator'] = format[2].blank? ? I18n.t('number.currency.format.separator') : format[2]
|
66
|
+
@yaml['format']['delimiter'] = format[3].blank? ? I18n.t('number.currency.format.delimiter') : format[3]
|
67
|
+
end
|
68
|
+
@yaml['html']['data-decimal'] = @yaml.dig('format','decimal') || 2
|
69
|
+
@yaml['html']['data-delimiter'] = @yaml.dig('format','delimiter') || I18n.t('number.currency.format.delimiter')
|
70
|
+
@yaml['html']['data-separator'] = @yaml.dig('format','separator') || I18n.t('number.currency.format.separator')
|
71
|
+
# @yaml['html']['data-currency'] = @yaml.dig('format','currency') == 'yes' ? I18n.t('number.currency.format.currency') : @yaml.dig('format','currency')
|
72
|
+
value = @record[@yaml['name']] || 0
|
73
|
+
@yaml['html']['value'] = @parent.dc_format_number(value, @yaml['html']['data-decimal'], @yaml['html']['data-separator'], @yaml['html']['data-delimiter'] )
|
74
|
+
|
75
|
+
return ro_standard(@yaml['html']['value']) if @readonly
|
76
|
+
|
77
|
+
@yaml['html']['autocomplete'] ||= 'off'
|
78
|
+
@html << @parent.hidden_field( record, @yaml['name'], value: value )
|
79
|
+
@html << @parent.text_field( nil,"record_#{@yaml['name']}_", @yaml['html'])
|
80
|
+
self
|
81
|
+
end
|
82
|
+
|
83
|
+
###########################################################################
|
84
|
+
# Return value. Return nil if input field is empty
|
85
|
+
###########################################################################
|
86
|
+
def self.get_data(params, name)
|
87
|
+
return 0 if params['record'][name].blank?
|
88
|
+
params['record'][name].match('.') ? params['record'][name].to_f : Integer.new(params['record'][name])
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 password DRG CMS form field.
|
27
|
+
#
|
28
|
+
# ===Form options:
|
29
|
+
# * +type:+ password_field (required)
|
30
|
+
# * +name:+ Field name (required)
|
31
|
+
# * +html:+ html options which apply to password field (optional)
|
32
|
+
#
|
33
|
+
# Form example:
|
34
|
+
# 20:
|
35
|
+
# name: password
|
36
|
+
# type: pasword_field
|
37
|
+
# html:
|
38
|
+
# size: 20
|
39
|
+
#
|
40
|
+
# 30:
|
41
|
+
# name: password_confirmation
|
42
|
+
# type: pasword_field
|
43
|
+
# html:
|
44
|
+
# size: 20
|
45
|
+
#
|
46
|
+
###########################################################################
|
47
|
+
class PasswordField < DrgcmsField
|
48
|
+
|
49
|
+
###########################################################################
|
50
|
+
# Render password field html code
|
51
|
+
#
|
52
|
+
###########################################################################
|
53
|
+
def render
|
54
|
+
return self if @readonly
|
55
|
+
@yaml['html'] ||= {}
|
56
|
+
record = record_text_for(@yaml['name'])
|
57
|
+
@html << @parent.password_field(record, @yaml['name'], @yaml['html'])
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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 radio DRG CMS form field. Field provides radio button input
|
27
|
+
# structure.
|
28
|
+
# Form options are mostly same as in select field.
|
29
|
+
#
|
30
|
+
# ===Form options:
|
31
|
+
# * +name:+ field name (required)
|
32
|
+
# * +type:+ radio (required)
|
33
|
+
# * +choices:+ Values for choices separated by comma. Values can also be specified like description:value.
|
34
|
+
# In this case description will be shown to user, but value will be saved to document.
|
35
|
+
# choices: 'OK:0,Ready:1,Error:2'
|
36
|
+
# choices: Ruby,Pyton,PHP
|
37
|
+
# * +eval:+ Choices will be provided by evaluating expression
|
38
|
+
# eval: dc_choices4('model_name','description_field_name','_id'); dc_choices4 helper will provide data for select field.
|
39
|
+
# eval: ModelName.choices4_field; ModelName class will define method choices4_field which
|
40
|
+
# will provide data for select field. Since expression is evaluated in the context of Form Field object
|
41
|
+
# Even session session variables can be accessed.
|
42
|
+
# eval: 'MyClass.method(@parent.session[:user_id])'
|
43
|
+
# When searching is more complex custom search method may be defined in CollectionName
|
44
|
+
# model which will provide result set for search.
|
45
|
+
# eval: collection_name.search_field_name.method_name;
|
46
|
+
# If choices or eval is not defined choices will be provided from translation helpers. For example:
|
47
|
+
# Collection has field status. Choices for field will be provided by en.helpers.model_name.choices4_status
|
48
|
+
# entry of english translation. English is of course default translation. If you provide translations in
|
49
|
+
# your local language then select choices will be localized.
|
50
|
+
# en.helpers.model_name.choices4_status: 'OK:0,Ready:1,Error:2'
|
51
|
+
# sl.helpers.model_name.choices4_status: 'V redu:0,Pripravljen:1,Napaka:2'
|
52
|
+
# * +inline:+ Radio buttons will be presented inline instead of stacked on each other.
|
53
|
+
#
|
54
|
+
# Form example:
|
55
|
+
# 10:
|
56
|
+
# name: hifi
|
57
|
+
# type: radio
|
58
|
+
# choices: 'Marantz:1,Sony:2,Bose:3,Pioneer:4'
|
59
|
+
# inline: true
|
60
|
+
###########################################################################
|
61
|
+
class Radio < Select
|
62
|
+
|
63
|
+
###########################################################################
|
64
|
+
# Render radio DRG Form field
|
65
|
+
###########################################################################
|
66
|
+
def render
|
67
|
+
set_initial_value('html','value')
|
68
|
+
|
69
|
+
record = record_text_for(@yaml['name'])
|
70
|
+
@yaml['html'].symbolize_keys!
|
71
|
+
clas = 'dc-radio' + ( @yaml['inline'] ? ' dc-inline' : '')
|
72
|
+
@html << "<div class=\"#{clas}\">"
|
73
|
+
choices = get_choices
|
74
|
+
# When error and boolean field
|
75
|
+
#if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
|
76
|
+
# choices = [[I18n.t('drgcms.true'), true], [I18n.t('drgcms.false'), false]]
|
77
|
+
#end
|
78
|
+
# Should select first button if no value provided
|
79
|
+
value = if @record.nil? || @record[@yaml['name']].blank?
|
80
|
+
choices.first.class == String ? choices.first : choices.first.last
|
81
|
+
else
|
82
|
+
@record[@yaml['name']]
|
83
|
+
end
|
84
|
+
choices.each do |choice|
|
85
|
+
choice = [choice, choice] if choice.class == String
|
86
|
+
@html << "<div>"
|
87
|
+
@html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s == value.to_s)
|
88
|
+
@html << choice.first
|
89
|
+
@html << "</div>"
|
90
|
+
end
|
91
|
+
@html << "</div>\n"
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|