drg_cms 0.4.58 → 0.4.61
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/README.md +1 -1
- data/app/assets/javascripts/drg_cms/drg_cms.js +29 -20
- data/app/assets/stylesheets/drg_cms/drg_cms.css +77 -86
- data/app/assets/stylesheets/drg_cms_application.css +1 -0
- data/app/assets/stylesheets/drg_cms_cms.css +1 -0
- data/app/controllers/cmsedit_controller.rb +71 -27
- data/app/forms/dc_design.yml +1 -1
- data/app/helpers/cmsedit_helper.rb +171 -60
- data/app/helpers/dc_application_helper.rb +2 -2
- data/app/helpers/dc_poll_renderer.rb +2 -2
- data/app/models/dc_piece.rb +1 -1
- data/app/models/dc_policy_rule.rb +1 -1
- data/app/models/drgcms_form_field.rb +5 -4
- data/app/models/drgcms_form_fields.rb +1027 -0
- data/app/views/cmsedit/_edit_stuff.html.erb +9 -9
- data/app/views/cmsedit/_result.html.erb +4 -1
- data/config/initializers/kaminari_patch.rb +1 -1
- data/config/locales/drgcms_en.yml +2 -1
- data/config/locales/drgcms_sl.yml +1 -0
- data/drg_cms.gemspec +1 -0
- data/lib/drg_cms.rb +48 -1
- data/lib/drg_cms/version.rb +1 -1
- metadata +18 -4
- data/app/forms/__drgcms_cms.yml +0 -28
|
@@ -76,7 +76,9 @@
|
|
|
76
76
|
# If filter method returns false user will be presented with flash error.
|
|
77
77
|
########################################################################
|
|
78
78
|
class CmseditController < DcApplicationController
|
|
79
|
-
before_action :check_authorization, :except => [:
|
|
79
|
+
before_action :check_authorization, :except => [:login]
|
|
80
|
+
before_filter :reload_patches if Rails.env.development?
|
|
81
|
+
|
|
80
82
|
layout 'cms'
|
|
81
83
|
|
|
82
84
|
########################################################################
|
|
@@ -101,6 +103,39 @@ def check_sort_options() #:nodoc:
|
|
|
101
103
|
params['sort'] = nil # otherwise there is problem with other links
|
|
102
104
|
end
|
|
103
105
|
|
|
106
|
+
########################################################################
|
|
107
|
+
# Set aditional filter options when filter is defined by filter method in control object.
|
|
108
|
+
########################################################################
|
|
109
|
+
def user_filter_options(model) #:nodoc:
|
|
110
|
+
# no filter is active or set off
|
|
111
|
+
if params[:filter] == 'off' or (params[:filter].nil? and session[:tmp_filter].nil?)
|
|
112
|
+
session[:tmp_filter] = nil
|
|
113
|
+
return model
|
|
114
|
+
end
|
|
115
|
+
#
|
|
116
|
+
table, field, oper, value = if params[:filter] == 'on'
|
|
117
|
+
[model.to_s, params[:filter_field], params[:filter_oper], params[:record][params[:filter_field]] ]
|
|
118
|
+
else
|
|
119
|
+
session[:tmp_filter].split("\t")
|
|
120
|
+
end
|
|
121
|
+
# filter set previously on other collection
|
|
122
|
+
if table != model.to_s
|
|
123
|
+
session[:tmp_filter] = nil
|
|
124
|
+
return model
|
|
125
|
+
end
|
|
126
|
+
#
|
|
127
|
+
field = '_id' if field == 'id' # must be
|
|
128
|
+
value = /#{value}/ if oper == 'like' # do regex if operation is like
|
|
129
|
+
# when field type is ObjectId transform value
|
|
130
|
+
if model.fields[field].type == BSON::ObjectId
|
|
131
|
+
value = BSON::ObjectId.from_string(value) rescue nil
|
|
132
|
+
flash[:error] = t('drgcms.not_id') if value.nil?
|
|
133
|
+
end
|
|
134
|
+
# save filter to session
|
|
135
|
+
session[:tmp_filter] = [ table, field, oper, value ].join("\t")
|
|
136
|
+
model.where(field => value)
|
|
137
|
+
end
|
|
138
|
+
|
|
104
139
|
########################################################################
|
|
105
140
|
# Will check and set current filter options for result set. Subroutine of index method.
|
|
106
141
|
########################################################################
|
|
@@ -120,25 +155,31 @@ def check_filter_options() #:nodoc:
|
|
|
120
155
|
session[table_name][:page] = 1
|
|
121
156
|
params[:filter] = nil # must be. Otherwise kaminari includes parameter on paging and everything goes wrong
|
|
122
157
|
end
|
|
123
|
-
# if data model has field dc_site_id ensure that only
|
|
124
|
-
# are selected.
|
|
125
|
-
|
|
158
|
+
# if data model has field dc_site_id ensure that only documents which belong
|
|
159
|
+
# to the site are selected.
|
|
160
|
+
model = @tables.first[0]
|
|
126
161
|
site_id = dc_get_site._id if dc_get_site
|
|
127
162
|
# dont't filter site if no dc_site_id field or user is ADMIN
|
|
128
|
-
site_id = nil if !
|
|
163
|
+
site_id = nil if !model.method_defined?('dc_site_id') or dc_user_can(DcPermission::CAN_ADMIN)
|
|
129
164
|
if session[table_name][:filter]
|
|
130
165
|
field, oper, value = session[table_name][:filter].split( "\t")
|
|
131
|
-
|
|
166
|
+
field = '_id' if field == 'id' # must be
|
|
167
|
+
value = /#{value}/ if oper == 'like' # do regex if operation is like
|
|
168
|
+
# when field type is ObjectId transform value
|
|
169
|
+
if model.fields[field].type == BSON::ObjectId
|
|
170
|
+
value = BSON::ObjectId.from_string(value) rescue nil
|
|
171
|
+
flash[:error] = t('drgcms.not_id') if value.nil?
|
|
172
|
+
end
|
|
132
173
|
@records = if site_id
|
|
133
|
-
|
|
174
|
+
model.where(dc_site_id: site_id, field => value)
|
|
134
175
|
else
|
|
135
|
-
|
|
176
|
+
model.where(field => value)
|
|
136
177
|
end
|
|
137
178
|
else
|
|
138
179
|
@records = if site_id
|
|
139
|
-
|
|
180
|
+
model.where(dc_site_id: site_id)
|
|
140
181
|
else
|
|
141
|
-
|
|
182
|
+
model
|
|
142
183
|
end
|
|
143
184
|
end
|
|
144
185
|
# pagination if required
|
|
@@ -202,11 +243,15 @@ end
|
|
|
202
243
|
# and logout actions can be directly performed by calling http://site.com/cmsedit/login
|
|
203
244
|
########################################################################
|
|
204
245
|
def show
|
|
246
|
+
=begin
|
|
205
247
|
case
|
|
206
248
|
when params[:id].in?(%w(login logout)) then # show login menu
|
|
207
249
|
session[:edit_mode] = 0
|
|
208
|
-
render action: 'show'
|
|
250
|
+
render action: 'show'#, layout: 'cms'
|
|
209
251
|
end
|
|
252
|
+
=end
|
|
253
|
+
find_record
|
|
254
|
+
render action: 'edit', layout: 'cms'
|
|
210
255
|
end
|
|
211
256
|
|
|
212
257
|
########################################################################
|
|
@@ -215,6 +260,7 @@ end
|
|
|
215
260
|
def login #:nodoc:
|
|
216
261
|
# session[:edit_mode] = 0 if params[:id].in? %w(login logout) # show login menu
|
|
217
262
|
# dc_collect_menu_forms
|
|
263
|
+
session[:edit_mode] = 0
|
|
218
264
|
render action: 'show', layout: 'cms'
|
|
219
265
|
end
|
|
220
266
|
|
|
@@ -498,10 +544,12 @@ def read_drg_cms_form
|
|
|
498
544
|
@form = forms_merge(form, @form)
|
|
499
545
|
end
|
|
500
546
|
# add readonly key to form if readonly parameter is passed in url
|
|
501
|
-
@form['readonly'] = 1 if params['readonly'] and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
|
|
547
|
+
@form['readonly'] = 1 if params['readonly'] #and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
|
|
502
548
|
# !!!!!! Always use strings for key names since @parms['table'] != @parms[:table]
|
|
503
|
-
@parms = { 'table' => table_name, 'ids' => ids, 'formname' => formname,
|
|
504
|
-
'return_to' => params['return_to'], 'edit_only' => params['edit_only']
|
|
549
|
+
@parms = { 'table' => table_name, 'ids' => params[:ids], 'formname' => formname,
|
|
550
|
+
'return_to' => params['return_to'], 'edit_only' => params['edit_only'],
|
|
551
|
+
'readonly' => params['readonly']
|
|
552
|
+
}
|
|
505
553
|
end
|
|
506
554
|
|
|
507
555
|
############################################################################
|
|
@@ -511,7 +559,8 @@ end
|
|
|
511
559
|
def check_authorization
|
|
512
560
|
params[:table] ||= params[:formname]
|
|
513
561
|
# Just show menu
|
|
514
|
-
return show if params[:action] == 'show'
|
|
562
|
+
# return show if params[:action] == 'show'
|
|
563
|
+
return login if params[:id].in?(%w(login logout))
|
|
515
564
|
# request shouldn't pass
|
|
516
565
|
if session[:user_roles].nil? or params[:table].to_s.strip.downcase.size < 3 or
|
|
517
566
|
!dc_user_can(DcPermission::CAN_VIEW)
|
|
@@ -687,7 +736,7 @@ def save_data
|
|
|
687
736
|
next if params[:edit_only] and params[:edit_only] != v['name'] # otherwise other fields would be wiped
|
|
688
737
|
next unless @record.respond_to?(v['name']) # there can be temporary fields on the form
|
|
689
738
|
# return value from form field definition
|
|
690
|
-
value =
|
|
739
|
+
value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
|
|
691
740
|
@record.send("#{v['name']}=", value)
|
|
692
741
|
end
|
|
693
742
|
#
|
|
@@ -712,19 +761,14 @@ def save_data
|
|
|
712
761
|
end
|
|
713
762
|
saved
|
|
714
763
|
end
|
|
715
|
-
|
|
716
|
-
=begin
|
|
764
|
+
|
|
717
765
|
########################################################################
|
|
718
|
-
#
|
|
719
|
-
# but I didn't found method.
|
|
720
|
-
#
|
|
721
|
-
# @param [model] Model object
|
|
722
|
-
# @param [field_name] Field name to be checked
|
|
766
|
+
# Reload patches in development.
|
|
723
767
|
########################################################################
|
|
724
|
-
def
|
|
725
|
-
|
|
726
|
-
|
|
768
|
+
def reload_patches
|
|
769
|
+
DrgCms.paths(:patches).each do |patches|
|
|
770
|
+
Dir["#{patches}/**/*.rb"].each { |path| require_dependency path }
|
|
771
|
+
end
|
|
727
772
|
end
|
|
728
|
-
=end
|
|
729
773
|
|
|
730
774
|
end
|
data/app/forms/dc_design.yml
CHANGED
|
@@ -35,7 +35,7 @@ module CmseditHelper
|
|
|
35
35
|
# Creates action div for cmsedit index action.
|
|
36
36
|
############################################################################
|
|
37
37
|
def dc_actions_for_index()
|
|
38
|
-
return '' if @form['index'].nil?
|
|
38
|
+
return '' if @form['index'].nil? or @form['readonly']
|
|
39
39
|
actions = @form['index']['actions']
|
|
40
40
|
return '' if actions.nil? or actions.size == 0
|
|
41
41
|
# Simulate standard actions
|
|
@@ -48,9 +48,11 @@ def dc_actions_for_index()
|
|
|
48
48
|
# start div with hidden spinner image
|
|
49
49
|
html = <<EOT
|
|
50
50
|
<div id="dc-action-menu">
|
|
51
|
-
<span id="dc-spinner" class="div-hidden">#{
|
|
51
|
+
<span id="dc-spinner" class="div-hidden">#{fa_icon('spinner lg spin')}"</span>
|
|
52
52
|
<ul class="dc-action-menu">
|
|
53
53
|
EOT
|
|
54
|
+
# #{fa_icon('spinner lg spin', id: 'dc-spinner', class: 'div-hidden')}
|
|
55
|
+
|
|
54
56
|
#
|
|
55
57
|
actions.each do |k,v|
|
|
56
58
|
session[:form_processing] = "index:actions: #{k}=#{v}"
|
|
@@ -84,22 +86,27 @@ EOT
|
|
|
84
86
|
choices << [ t("helpers.label.#{@form['table']}.#{s}"), s ]
|
|
85
87
|
end
|
|
86
88
|
end
|
|
87
|
-
|
|
89
|
+
fa_icon('sort-alpha-asc') + ' ' + t('drgcms.sort') + ' ' +
|
|
90
|
+
select('sort', 'sort', choices, { include_blank: true },
|
|
91
|
+
{ class: 'drgcms_sort', 'data-table' => @form['table']} )
|
|
88
92
|
|
|
89
93
|
when action == 'filter' then # filter
|
|
90
94
|
caption = t('drgcms.filter')
|
|
91
95
|
s = session[@form['table']]
|
|
92
96
|
# add checked image to filter, so user will know that data is filtered
|
|
93
|
-
caption << ' '+image_tag('drg_cms/checkbox-checked.png') if s and s[:filter]
|
|
97
|
+
# caption << ' '+image_tag('drg_cms/checkbox-checked.png') if s and s[:filter]
|
|
94
98
|
yhtml['onclick'] = "$('#drgcms_filter').toggle(300);"
|
|
95
|
-
link_to(caption.html_safe, '#', yhtml )
|
|
99
|
+
# link_to(caption.html_safe, '#', yhtml )
|
|
100
|
+
dc_link_to('drgcms.filter','filter', '#', yhtml )
|
|
101
|
+
when action == 'new' then # new
|
|
102
|
+
dc_link_to(t('drgcms.new'),'plus', url, yhtml )
|
|
96
103
|
when action == 'menu' then # menu
|
|
97
104
|
caption = t(v['caption'], v['caption'])
|
|
98
105
|
caption + eval(v['eval'])
|
|
99
106
|
else
|
|
100
107
|
caption = yaml['caption'] || yaml['text']
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
icon = yaml['icon'] ? yaml['icon'] : action
|
|
109
|
+
dc_link_to(caption, icon, url, yhtml)
|
|
103
110
|
end
|
|
104
111
|
html << '</li>'
|
|
105
112
|
end
|
|
@@ -128,11 +135,9 @@ def _get_field_div(name) #:nodoc:
|
|
|
128
135
|
# field not defined on form. Must be defined: name as form_field_type
|
|
129
136
|
filter = nil
|
|
130
137
|
if session[@form['table']] and session[@form['table']][:filter]
|
|
131
|
-
filter = session[@form['table']][:filter].split("\t")
|
|
138
|
+
filter, operation, value = session[@form['table']][:filter].split("\t")
|
|
132
139
|
end
|
|
133
|
-
|
|
134
|
-
#params[:filter_field], params[:filter_oper], params[:record][params[:filter_field]]
|
|
135
|
-
|
|
140
|
+
#
|
|
136
141
|
if name.match(' as ')
|
|
137
142
|
name, dummy, type = name.split(' ')
|
|
138
143
|
field = {"name" => name, "type" => type, "html"=>{"size"=>20}}
|
|
@@ -141,18 +146,21 @@ def _get_field_div(name) #:nodoc:
|
|
|
141
146
|
field = {"name" => name, "type" => 'text_field', "html"=>{"size"=>20}} if field.nil?
|
|
142
147
|
end
|
|
143
148
|
#
|
|
149
|
+
div_hidden = 'div-hidden'
|
|
144
150
|
if filter
|
|
151
|
+
div_hidden = '' if name == filter
|
|
145
152
|
if field['html']
|
|
146
|
-
field['html']['value'] =
|
|
153
|
+
field['html']['value'] = value
|
|
147
154
|
else
|
|
148
|
-
field['html'] = {"value"=>
|
|
155
|
+
field['html'] = { "value" => value }
|
|
149
156
|
end
|
|
150
157
|
end
|
|
151
158
|
klas_string = field['type'].camelize
|
|
152
|
-
klas =
|
|
159
|
+
klas = DrgcmsFormFields::const_get(klas_string) || nil
|
|
153
160
|
return 'error' if klas.nil?
|
|
161
|
+
#
|
|
154
162
|
o = klas.new(self, @record, field).render
|
|
155
|
-
"<span id=\"filter_#{field['name']}\" class=\"
|
|
163
|
+
"<span id=\"filter_#{field['name']}\" class=\"#{div_hidden}\">" << o.html << (o.js.size > 2 ? javascript_tag(o.js) : '') << '</span>'
|
|
156
164
|
end
|
|
157
165
|
|
|
158
166
|
############################################################################
|
|
@@ -160,9 +168,8 @@ end
|
|
|
160
168
|
############################################################################
|
|
161
169
|
def dc_div_filter()
|
|
162
170
|
choices, inputs = [], ''
|
|
163
|
-
# searching by id is added by default
|
|
164
171
|
filter = (@form['index'] and @form['index']['filter']) ? @form['index']['filter'] + ',' : ''
|
|
165
|
-
filter << 'id as text_field'
|
|
172
|
+
filter << 'id as text_field' # filter id is added by default
|
|
166
173
|
filter.split(',').each do |f|
|
|
167
174
|
f.strip!
|
|
168
175
|
name = f.match(' as ') ? f.split(' ').first : f
|
|
@@ -173,21 +180,28 @@ def dc_div_filter()
|
|
|
173
180
|
choices4_operators = t('drgcms.choices4_filter_operators').chomp.split(',').inject([]) {|r,v| r << (v.match(':') ? v.split(':') : v )}
|
|
174
181
|
s = session[@form['table']]
|
|
175
182
|
is_hidden = (s and s[:filter]) ? '' : ' class="div-hidden" '
|
|
183
|
+
#
|
|
184
|
+
if session[@form['table']] and session[@form['table']][:filter]
|
|
185
|
+
field_name, operators_value, dummy = session[@form['table']][:filter].split("\t")
|
|
186
|
+
else
|
|
187
|
+
field_name, operators_value = nil, nil
|
|
188
|
+
end
|
|
176
189
|
html =<<EOT
|
|
177
190
|
<div id="drgcms_filter" #{is_hidden}>
|
|
178
191
|
<table class="dc-menu"><td>
|
|
179
192
|
#{ form_tag :table => @form['table'], filter: :on, action: :index, method: :post }
|
|
180
|
-
#{ select(nil, 'filter_field', choices, { include_blank: true}) }
|
|
181
|
-
#{ select(nil, 'filter_oper', choices4_operators) }
|
|
193
|
+
#{ select(nil, 'filter_field', options_for_select(choices, field_name), { include_blank: true }) }
|
|
194
|
+
#{ select(nil, 'filter_oper', options_for_select(choices4_operators, operators_value)) }
|
|
182
195
|
#{ inputs }
|
|
183
196
|
</td>
|
|
184
|
-
<td class="dc-link-submit dc-animate">#{submit_tag(t('drgcms.filter_on'), :class => 'dc-submit')}</td>
|
|
185
|
-
<td class="dc-link dc-animate">#{
|
|
197
|
+
<td class="dc-link-submit dc-animate">#{fa_icon('check-square-o')} #{submit_tag(t('drgcms.filter_on'), :class => 'dc-submit')}</td>
|
|
198
|
+
<td class="dc-link dc-animate">#{dc_link_to('drgcms.filter_off','close', {action: 'index', filter: 'off', :table => @form['table']}) }</td>
|
|
186
199
|
</table>
|
|
187
200
|
</form>
|
|
188
201
|
</div>
|
|
189
202
|
|
|
190
203
|
EOT
|
|
204
|
+
# <td class="dc-link dc-animate">#{link_to t('drgcms.filter_off'), action: 'index', filter: 'off', :table => @form['table']}</td>
|
|
191
205
|
html.html_safe
|
|
192
206
|
end
|
|
193
207
|
|
|
@@ -204,14 +218,56 @@ def dc_table_title_for_result(result=nil)
|
|
|
204
218
|
dc_table_title(title, result)
|
|
205
219
|
end
|
|
206
220
|
|
|
221
|
+
############################################################################
|
|
222
|
+
# Similar to rails submit_tag, but also takes care of link icon, translation, ...
|
|
223
|
+
############################################################################
|
|
224
|
+
def dc_submit_tag(caption, icon, parms, rest={})
|
|
225
|
+
parms['class'] ||= 'dc-submit'
|
|
226
|
+
if icon
|
|
227
|
+
icon_image = if icon.match(/\./)
|
|
228
|
+
image_tag(icon, class: 'dc-animate')
|
|
229
|
+
else
|
|
230
|
+
fa_icon(icon)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
html = icon_image || ''
|
|
234
|
+
html << submit_tag(t(caption, caption), parms)
|
|
235
|
+
end
|
|
236
|
+
############################################################################
|
|
237
|
+
# Similar to rails link_to, but also takes care of link icon, translation, ...
|
|
238
|
+
############################################################################
|
|
239
|
+
def dc_link_to(caption, icon, parms, rest={})
|
|
240
|
+
rest['class'] = rest['class'].to_s + ' dc-animate'
|
|
241
|
+
if icon
|
|
242
|
+
icon_image = if icon.match(/\./)
|
|
243
|
+
image_tag(icon, class: 'dc-link-img dc-animate')
|
|
244
|
+
else
|
|
245
|
+
fa_icon(icon)
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
#
|
|
249
|
+
if caption
|
|
250
|
+
caption = t(caption, caption)
|
|
251
|
+
icon_image << ' ' if icon_image
|
|
252
|
+
end
|
|
253
|
+
link_to("#{icon_image}#{caption}".html_safe, parms, rest)
|
|
254
|
+
end
|
|
255
|
+
|
|
207
256
|
############################################################################
|
|
208
257
|
# Creates code for link or ajax action type. Subroutine of dc_actions_for_result.
|
|
209
258
|
############################################################################
|
|
210
259
|
def dc_link_or_ajax(yaml, parms) #:nodoc:
|
|
211
|
-
|
|
212
|
-
|
|
260
|
+
rest = {}
|
|
261
|
+
rest['method'] = yaml['method'] || yaml['request'] || 'get'
|
|
262
|
+
rest['caption'] = yaml['caption'] || yaml['text']
|
|
263
|
+
rest['class'] = rest['class'].to_s + ' dc-animate'
|
|
264
|
+
rest['title'] = yaml['title']
|
|
265
|
+
|
|
266
|
+
# method = yaml['method'] || yaml['request'] || 'get'
|
|
267
|
+
# caption = yaml['caption'] || yaml['text']
|
|
213
268
|
p "Form: result_set:action:text directive will be deprecated. Use caption instead of text." if yaml['text']
|
|
214
269
|
#
|
|
270
|
+
=begin
|
|
215
271
|
if yaml['type'] == 'link'
|
|
216
272
|
if yaml['icon'] # icon
|
|
217
273
|
link_to( image_tag(yaml['icon'], class: 'dc-link-img dc-link-ajax dc-animate'), parms, method: method, title: t(yaml['title'],yaml['title']) )
|
|
@@ -225,7 +281,32 @@ def dc_link_or_ajax(yaml, parms) #:nodoc:
|
|
|
225
281
|
else # caption
|
|
226
282
|
%Q[<span class="dc-link-ajax dc-animate" data-url="#{url}" data-request="#{method}">#{caption}</span>]
|
|
227
283
|
end
|
|
228
|
-
end
|
|
284
|
+
end
|
|
285
|
+
#####
|
|
286
|
+
caption = ''
|
|
287
|
+
if yaml['type'] == 'link'
|
|
288
|
+
if yaml['icon'] # icon
|
|
289
|
+
caption = if yaml['icon'].match('.')
|
|
290
|
+
image_tag(yaml['icon'], class: 'dc-link-img dc-link-ajax dc-animate')
|
|
291
|
+
else
|
|
292
|
+
fa_icon("#{yaml['icon']} 2x" , class: 'dc-link-ajax dc-animate')
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
if yaml['caption']
|
|
296
|
+
caption << ' ' if caption.size > 0
|
|
297
|
+
caption << t(yaml['caption'],yaml['caption'])
|
|
298
|
+
end
|
|
299
|
+
link_to(caption, parms, method: method, title: t(yaml['title'],yaml['title']) )
|
|
300
|
+
else
|
|
301
|
+
''
|
|
302
|
+
end
|
|
303
|
+
=end
|
|
304
|
+
if yaml['type'] == 'link'
|
|
305
|
+
dc_link_to(yaml['caption'], yaml['icon'], parms, rest )
|
|
306
|
+
else
|
|
307
|
+
''
|
|
308
|
+
end
|
|
309
|
+
|
|
229
310
|
end
|
|
230
311
|
|
|
231
312
|
############################################################################
|
|
@@ -233,7 +314,7 @@ end
|
|
|
233
314
|
############################################################################
|
|
234
315
|
def dc_actions_for_result(record)
|
|
235
316
|
actions = @form['result_set']['actions']
|
|
236
|
-
return '' if actions.nil?
|
|
317
|
+
return '' if actions.nil? or @form['readonly']
|
|
237
318
|
# standard actions
|
|
238
319
|
actions = {'standard' => true} if actions.class == String && actions == 'standard'
|
|
239
320
|
std_actions = {' 2' => 'edit', ' 3' => 'delete'}
|
|
@@ -250,23 +331,23 @@ def dc_actions_for_result(record)
|
|
|
250
331
|
when yaml['type'] == 'edit' then
|
|
251
332
|
parms['action'] = 'edit'
|
|
252
333
|
parms['id'] = record.id
|
|
253
|
-
|
|
334
|
+
dc_link_to( nil, 'pencil lg', parms )
|
|
254
335
|
when yaml['type'] == 'duplicate' then
|
|
255
336
|
parms['id'] = record.id
|
|
256
337
|
# duplicate string will be added to these fields.
|
|
257
338
|
parms['dup_fields'] = yaml['dup_fields']
|
|
258
|
-
|
|
339
|
+
dc_link_to( nil, 'copy lg', parms, data: { confirm: t('drgcms.confirm_dup') }, method: :post )
|
|
259
340
|
when yaml['type'] == 'delete' then
|
|
260
341
|
parms['action'] = 'destroy'
|
|
261
342
|
parms['id'] = record.id
|
|
262
|
-
|
|
343
|
+
dc_link_to( nil, 'remove lg', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
|
|
263
344
|
# undocumented so far
|
|
264
345
|
when yaml['type'] == 'edit_embedded'
|
|
265
346
|
parms['controller'] = 'cmsedit'
|
|
266
347
|
parms['table'] += ";#{yaml['table']}"
|
|
267
348
|
parms['ids'] ||= ''
|
|
268
349
|
parms['ids'] += "#{record.id};"
|
|
269
|
-
|
|
350
|
+
dc_link_to( nil, 'table lg', parms, method: :get )
|
|
270
351
|
when yaml['type'] == 'link' || yaml['type'] == 'ajax' then
|
|
271
352
|
if yaml['url']
|
|
272
353
|
parms['controller'] = yaml['url']
|
|
@@ -294,7 +375,7 @@ end
|
|
|
294
375
|
def dc_header_for_result()
|
|
295
376
|
c = ''
|
|
296
377
|
actions = @form['result_set']['actions']
|
|
297
|
-
c = '<th style="border-left: 0px;"> </th>' unless actions.nil?
|
|
378
|
+
c = '<th style="border-left: 0px;"> </th>' unless actions.nil? or @form['readonly']
|
|
298
379
|
|
|
299
380
|
if (columns = @form['result_set']['columns'])
|
|
300
381
|
columns.each do |k,v|
|
|
@@ -382,7 +463,11 @@ def dc_columns_for_result(document)
|
|
|
382
463
|
end
|
|
383
464
|
|
|
384
465
|
############################################################################
|
|
385
|
-
# Creates actions div for edit form
|
|
466
|
+
# Creates actions div for edit form.
|
|
467
|
+
#
|
|
468
|
+
# Displaying readonly form turned out to be challenge. For now when readonly parameter
|
|
469
|
+
# has value 2, back link will force readonly form. Value 1 or not set will result in
|
|
470
|
+
# normal link.
|
|
386
471
|
############################################################################
|
|
387
472
|
def dc_actions_for_form()
|
|
388
473
|
# create standard actions
|
|
@@ -390,7 +475,6 @@ def dc_actions_for_form()
|
|
|
390
475
|
' 3' => {'type' => 'submit', 'caption' => 'drgcms.save&back'} }
|
|
391
476
|
# when edit only
|
|
392
477
|
unless @record.id.nil?
|
|
393
|
-
# std_actions.merge!({' 4' => 'delete', ' 6' => 'new'} ) # delete is not OK here
|
|
394
478
|
std_actions.merge!({' 6' => 'new'} )
|
|
395
479
|
std_actions.merge!(@record.active ? {' 5' => 'disable'} : {' 5' => 'enable'} ) if @record.respond_to?('active')
|
|
396
480
|
end
|
|
@@ -399,6 +483,9 @@ def dc_actions_for_form()
|
|
|
399
483
|
actions = nil if actions.class == String && actions == 'standard'
|
|
400
484
|
# standard actions
|
|
401
485
|
actions = std_actions if actions.nil?
|
|
486
|
+
# readonly
|
|
487
|
+
actions = {' 1' => 'back'} if @form['readonly']
|
|
488
|
+
|
|
402
489
|
if actions['standard']
|
|
403
490
|
actions.merge!(std_actions)
|
|
404
491
|
actions['standard'] = nil
|
|
@@ -416,7 +503,8 @@ def dc_actions_for_form()
|
|
|
416
503
|
# Sort so that standard actions come first
|
|
417
504
|
actions = actions.to_a.sort {|x,y| x[0].to_s <=> y[0].to_s}
|
|
418
505
|
# Add spinner to the beginning
|
|
419
|
-
c = %Q[<td id="dc-spinner" class="div-hidden">#{
|
|
506
|
+
c = %Q[<td id="dc-spinner" class="div-hidden">#{fa_icon('spinner lg spin')}</td>]
|
|
507
|
+
|
|
420
508
|
actions.each do |element|
|
|
421
509
|
session[:form_processing] = "form:actions: #{element}"
|
|
422
510
|
v = element[1]
|
|
@@ -430,28 +518,35 @@ def dc_actions_for_form()
|
|
|
430
518
|
#
|
|
431
519
|
parms = @parms.clone
|
|
432
520
|
if v.class == String
|
|
521
|
+
next if params[:readonly] and !(v == 'back')
|
|
522
|
+
|
|
433
523
|
c << '<td class="dc-link dc-animate">'
|
|
434
524
|
c << case
|
|
435
525
|
when (v == 'back' or v == 'cancle') then
|
|
436
526
|
# If return_to is present link directly to URL
|
|
437
527
|
if parms['xreturn_to'] # disabled for now
|
|
438
|
-
|
|
528
|
+
dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
|
|
439
529
|
else
|
|
440
530
|
parms['action'] = 'index'
|
|
441
|
-
|
|
531
|
+
parms['readonly'] = parms['readonly'].to_s.to_i < 2 ? nil : 1
|
|
532
|
+
dc_link_to( 'drgcms.back','arrow-left', parms )
|
|
442
533
|
end
|
|
443
534
|
when v == 'delete' then
|
|
444
535
|
parms['operation'] = v
|
|
445
536
|
parms['id'] = @record.id
|
|
446
|
-
|
|
537
|
+
dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
|
|
447
538
|
when v == 'new' then
|
|
448
539
|
parms['action'] = v
|
|
449
|
-
|
|
450
|
-
link_to( t('drgcms.new'), parms)
|
|
540
|
+
dc_link_to( 'drgcms.new', 'plus', parms)
|
|
451
541
|
when (v == 'enable' or v == 'disable') then
|
|
452
542
|
parms['operation'] = v
|
|
453
|
-
parms['id']
|
|
454
|
-
|
|
543
|
+
parms['id'] = @record.id
|
|
544
|
+
icon = (v == 'enable' ? 'thumbs-o-up' : 'thumbs-o-down')
|
|
545
|
+
dc_link_to( "drgcms.#{v}",icon, parms, method: :delete )
|
|
546
|
+
when v == 'edit' then
|
|
547
|
+
parms['operation'] = v
|
|
548
|
+
parms['id'] = @record.id
|
|
549
|
+
dc_link_to( "drgcms.#{v}",v, parms )
|
|
455
550
|
else
|
|
456
551
|
"err1 #{element[0]}=>#{v}"
|
|
457
552
|
end
|
|
@@ -462,16 +557,18 @@ def dc_actions_for_form()
|
|
|
462
557
|
# submit button
|
|
463
558
|
when v['type'] == 'submit'
|
|
464
559
|
caption = v['caption'] || 'drgcms.save'
|
|
560
|
+
icon = v['icon'] || 'save'
|
|
465
561
|
'<td class="dc-link-submit dc-animate">' +
|
|
466
|
-
|
|
562
|
+
dc_submit_tag(caption, icon, {:data => v['params'], :title => v['title']}) +
|
|
467
563
|
'</td>'
|
|
468
564
|
# delete with some sugar added
|
|
469
565
|
when v['type'] == 'delete'
|
|
470
566
|
parms['id'] = @record.id
|
|
471
567
|
parms.merge!(v['params'])
|
|
472
568
|
caption = v['caption'] || 'drgcms.delete'
|
|
569
|
+
icon = v['icon'] || 'remove'
|
|
473
570
|
'<td class="dc-link dc-animate">' +
|
|
474
|
-
|
|
571
|
+
dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete ) +
|
|
475
572
|
'</td>'
|
|
476
573
|
# ajax or link button
|
|
477
574
|
when v['type'] == 'ajax' || v['type'] == 'link'
|
|
@@ -494,22 +591,24 @@ def dc_actions_for_form()
|
|
|
494
591
|
if parms['controller'].nil?
|
|
495
592
|
"<td>#{t('drgcms.error')}</td>"
|
|
496
593
|
else
|
|
497
|
-
v['caption'] ||= v['text']
|
|
594
|
+
v['caption'] ||= v['text']
|
|
498
595
|
caption = t("#{v['caption'].downcase}", v['caption'])
|
|
499
596
|
url = url_for(parms)
|
|
500
597
|
request = v['request'] || v['method'] || 'get'
|
|
598
|
+
icon = v['icon'] ? "#{fa_icon(v['icon'])} " : ''
|
|
501
599
|
if v['type'] == 'ajax' # ajax button
|
|
502
|
-
%Q[<td class="dc-link-ajax dc-animate" id="dc-submit-ajax" data-url="#{url}"
|
|
600
|
+
%Q[<td class="dc-link-ajax dc-animate" id="dc-submit-ajax" data-url="#{url}"
|
|
601
|
+
data-request="#{request}" title="#{v['title']}">#{icon}#{caption}</td>]
|
|
503
602
|
else # link button
|
|
504
|
-
%Q[<td class="dc-link dc-animate"><a href="#{url}">#{caption}</a></td>]
|
|
603
|
+
%Q[<td class="dc-link dc-animate" title="#{v['title']}><a href="#{url}">#{icon}#{caption}</a></td>]
|
|
505
604
|
end
|
|
506
605
|
end
|
|
507
606
|
# Javascript action
|
|
508
607
|
when v['type'] == 'script'
|
|
509
|
-
v['caption'] ||= 'Caption missing!'
|
|
510
|
-
caption = t("#{v['caption'].downcase}", v['caption'])
|
|
608
|
+
# v['caption'] ||= 'Caption missing!'
|
|
609
|
+
# caption = t("#{v['caption'].downcase}", v['caption'])
|
|
511
610
|
data = {'request' => 'script', 'script' => v['js']}
|
|
512
|
-
%Q[<td class="dc-link-ajax dc-animate">#{
|
|
611
|
+
%Q[<td class="dc-link-ajax dc-animate">#{ dc_link_to(v['caption'],v['icon'], '#', data: data ) }</td>]
|
|
513
612
|
else
|
|
514
613
|
'<td>err2</td>'
|
|
515
614
|
end
|
|
@@ -545,6 +644,7 @@ end
|
|
|
545
644
|
############################################################################
|
|
546
645
|
def dc_fields_for_tab(fields) #:nodoc:
|
|
547
646
|
@js ||= ''
|
|
647
|
+
double_field = 0
|
|
548
648
|
html = '<table class="dc-form-table">'
|
|
549
649
|
labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', ['top','left','right'])
|
|
550
650
|
reset_cycle()
|
|
@@ -556,7 +656,7 @@ def dc_fields_for_tab(fields) #:nodoc:
|
|
|
556
656
|
next if params[:edit_only] and params[:edit_only] != options['name']
|
|
557
657
|
# hidden_fields. Ignore description text, otherwise it will be seen on screen
|
|
558
658
|
if options['type'] == 'hidden_field'
|
|
559
|
-
html <<
|
|
659
|
+
html << DrgcmsFormFields::HiddenField.new(self, @record, options).render
|
|
560
660
|
next
|
|
561
661
|
end
|
|
562
662
|
# label
|
|
@@ -568,26 +668,35 @@ def dc_fields_for_tab(fields) #:nodoc:
|
|
|
568
668
|
end
|
|
569
669
|
help ||= t('helpers.help.' + @form['table'] + '.' + options['name'],' ')
|
|
570
670
|
odd_even = cycle('odd','even')
|
|
671
|
+
odd_even = cycle('odd','even') if double_field == 2 # it should be same style as first
|
|
571
672
|
# create field object from class and call its render method
|
|
572
673
|
klas_string = options['type'].camelize
|
|
573
|
-
field_html = if
|
|
574
|
-
klas =
|
|
674
|
+
field_html = if DrgcmsFormFields.const_defined?(klas_string) # check if field type is defined
|
|
675
|
+
klas = DrgcmsFormFields.const_get(klas_string)
|
|
575
676
|
field = klas.new(self, @record, options).render
|
|
576
677
|
@js << field.js
|
|
577
678
|
field.html
|
|
578
679
|
else # litle error string
|
|
579
680
|
"Error: Code for field type #{options['type']} not defined!"
|
|
580
681
|
end
|
|
682
|
+
double_field = 1 if options['double']
|
|
683
|
+
html << '<tr>' if double_field < 2
|
|
581
684
|
#
|
|
582
685
|
html << if labels_pos == 'top'
|
|
583
|
-
%Q[<
|
|
686
|
+
%Q[<td class="dc-form-label dc-color-#{odd_even} dc-align-left" title="#{help}"
|
|
687
|
+
#{double_field == 0 ? 'colspan="2"' : 'style="width:50%;"'}>
|
|
584
688
|
<div><label for="record_#{options['name']}">#{text} </label></div>
|
|
585
|
-
<div id="td_record_#{options['name']}"
|
|
689
|
+
<div id="td_record_#{options['name']}">#{field_html}</div></td>]
|
|
586
690
|
else
|
|
587
|
-
%Q[<
|
|
691
|
+
%Q[<td class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos}" title="#{help}">
|
|
588
692
|
<label for="record_#{options['name']}">#{text} </label></td>
|
|
589
|
-
<td id=\"td_record_#{options['name']}\" class=\"dc-form-field dc-color-#{odd_even}\">#{field_html}
|
|
693
|
+
<td id=\"td_record_#{options['name']}\" class=\"dc-form-field dc-color-#{odd_even}\" #{'colspan="3"' if double_field == 0 }>#{field_html}
|
|
694
|
+
</td>
|
|
695
|
+
]
|
|
590
696
|
end
|
|
697
|
+
html << '</tr>' if double_field != 1
|
|
698
|
+
double_field = 0 if double_field == 2
|
|
699
|
+
double_field = 2 if double_field == 1
|
|
591
700
|
end
|
|
592
701
|
html << '</table></table>'
|
|
593
702
|
end
|
|
@@ -653,6 +762,7 @@ end
|
|
|
653
762
|
def dc_document_statistics
|
|
654
763
|
return '' if @record.new_record? or dc_dont?(@form['form']['info'])
|
|
655
764
|
html = "<div id='dc-document-info'>#{t('drgcms.doc_info')}</div>"
|
|
765
|
+
# html = "<div id='dc-document-info'>#{fa_icon 'info-circle 2x'}</div>"
|
|
656
766
|
html << "<div id='dc-document-info-popup' class='div-hidden'><table>"
|
|
657
767
|
#
|
|
658
768
|
u = _get_user_for('created_by')
|
|
@@ -667,11 +777,12 @@ def dc_document_statistics
|
|
|
667
777
|
parms[:controller] = 'dc_common'
|
|
668
778
|
parms[:action] = 'copy_clipboard'
|
|
669
779
|
url = url_for(parms)
|
|
670
|
-
caption = image_tag('drg_cms/copy.png', title: t('drgcms.doc_copy_clipboard'))
|
|
671
|
-
html << %Q[<hr><img class="dc-link-img dc-link-ajax dc-animate" data-url="#{url}" data-request="get" #{caption}]
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
html.html_safe
|
|
780
|
+
# caption = image_tag('drg_cms/copy.png', title: t('drgcms.doc_copy_clipboard'))
|
|
781
|
+
# html << %Q[<hr><img class="dc-link-img dc-link-ajax dc-animate" data-url="#{url}" data-request="get" #{caption}]
|
|
782
|
+
html << fa_icon('copy 2x', class: 'dc-link-img dc-link-ajax dc-animate',
|
|
783
|
+
'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
|
|
784
|
+
(html << '</div>').html_safe
|
|
785
|
+
# html.html_safe
|
|
675
786
|
end
|
|
676
787
|
|
|
677
788
|
end
|