drg_cms 0.6.0.8 → 0.6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/drg_cms/drg_cms.js +100 -58
- data/app/assets/stylesheets/drg_cms/drg_cms.css +177 -43
- data/app/controllers/cmsedit_controller.rb +149 -145
- data/app/controllers/dc_application_controller.rb +235 -113
- data/app/controllers/dc_common_controller.rb +32 -3
- data/app/controls/dc_help_control.rb +126 -0
- data/app/controls/dc_report.rb +5 -7
- data/app/forms/all_options.yml +10 -4
- data/app/forms/cms_menu.yml +7 -1
- data/app/forms/dc_category.yml +2 -1
- data/app/forms/dc_design.yml +1 -0
- data/app/forms/dc_help_1.yml +109 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +2 -0
- data/app/forms/dc_menu_item.yml +1 -0
- data/app/forms/dc_page.yml +2 -0
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_poll.yml +3 -0
- data/app/forms/dc_simple_menu.yml +2 -0
- data/app/forms/dc_site.yml +2 -6
- data/app/forms/dc_user.yml +27 -11
- data/app/forms/dc_user_role.yml +3 -0
- data/app/helpers/cms_common_helper.rb +69 -4
- data/app/helpers/cms_edit_helper.rb +32 -24
- data/app/helpers/cms_helper.rb +64 -26
- data/app/helpers/cms_index_helper.rb +84 -72
- data/app/helpers/dc_application_helper.rb +33 -24
- data/app/models/concerns/dc_page_concern.rb +11 -2
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_site_concern.rb +56 -44
- data/app/models/concerns/dc_user_concern.rb +57 -18
- data/app/models/dc_design.rb +29 -19
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_permission.rb +19 -9
- data/app/models/dc_policy.rb +25 -14
- data/app/models/dc_policy_role.rb +22 -11
- data/app/models/dc_temp.rb +1 -1
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields/embedded.rb +5 -8
- data/app/models/drgcms_form_fields/file_field.rb +1 -1
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +11 -7
- data/app/models/drgcms_form_fields/link_to.rb +2 -2
- data/app/models/drgcms_form_fields/method.rb +5 -4
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +1 -1
- data/app/models/drgcms_form_fields/select.rb +10 -9
- data/app/models/drgcms_form_fields/text_autocomplete.rb +2 -2
- data/app/views/cmsedit/edit.html.erb +2 -0
- data/app/views/cmsedit/index.html.erb +2 -1
- data/app/views/cmsedit/new.html.erb +2 -0
- data/app/views/dc_common/_help.html.erb +8 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +12 -0
- data/config/locales/drgcms_sl.yml +15 -0
- data/config/locales/models_en.yml +5 -5
- data/config/locales/models_sl.yml +7 -6
- data/lib/drg_cms.rb +58 -0
- data/lib/drg_cms/version.rb +1 -1
- metadata +5 -3
- data/app/models/__dc_dummy.rb +0 -102
@@ -88,7 +88,7 @@ def index
|
|
88
88
|
@form['result_set'] ||= {}
|
89
89
|
redirected = (@form['table'] == 'dc_memory' ? process_in_memory : process_collections)
|
90
90
|
return if redirected
|
91
|
-
|
91
|
+
|
92
92
|
call_callback_method(@form['result_set']['footer'] || 'dc_footer')
|
93
93
|
respond_to do |format|
|
94
94
|
format.html { render action: :index }
|
@@ -108,9 +108,9 @@ end
|
|
108
108
|
########################################################################
|
109
109
|
def show
|
110
110
|
find_record
|
111
|
+
# before_show callback
|
111
112
|
if (m = callback_method('before_show') )
|
112
113
|
ret = call_callback_method(m)
|
113
|
-
# Don't do anything if return is false
|
114
114
|
if ret.class == FalseClass
|
115
115
|
@form['readonly'] = nil # must be
|
116
116
|
return index
|
@@ -148,20 +148,21 @@ def logout
|
|
148
148
|
end
|
149
149
|
|
150
150
|
########################################################################
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
151
|
+
# Shortcut for setting currently selected site in development. Will search
|
152
|
+
# for dc_site document with site name 'test' and set alias_for to site
|
153
|
+
# url parameter.
|
154
154
|
########################################################################
|
155
155
|
def set_test_site
|
156
156
|
# only in development
|
157
|
-
return dc_render_404
|
157
|
+
return dc_render_404 unless Rails.env.development?
|
158
|
+
|
158
159
|
alias_site = DcSite.find_by(:name => params[:site])
|
159
160
|
return dc_render_404 unless alias_site
|
161
|
+
|
160
162
|
# update alias for
|
161
|
-
site
|
163
|
+
site = DcSite.find_by(:name => 'test')
|
162
164
|
site.alias_for = params[:site]
|
163
165
|
site.save
|
164
|
-
# redirect to root
|
165
166
|
redirect_to '/'
|
166
167
|
end
|
167
168
|
|
@@ -169,17 +170,17 @@ end
|
|
169
170
|
# New action.
|
170
171
|
########################################################################
|
171
172
|
def new
|
172
|
-
# clear flash messages.
|
173
|
+
# clear flash messages.
|
173
174
|
flash[:error] = flash[:warning] = flash[:info] = nil
|
174
175
|
create_new_empty_record
|
176
|
+
# before_new callback
|
175
177
|
if (m = callback_method('before_new') )
|
176
178
|
ret = call_callback_method(m)
|
177
|
-
# Don't do anything if return is false
|
178
179
|
return index if ret.class == FalseClass
|
179
180
|
end
|
180
181
|
table = @tables.last[1] + '.'
|
181
|
-
# initial values set on page
|
182
|
-
if cookies[:record]
|
182
|
+
# initial values set on page
|
183
|
+
if cookies[:record] && cookies[:record].size > 0
|
183
184
|
Marshal.load(cookies[:record]).each do |k,v|
|
184
185
|
k = k.to_s
|
185
186
|
if k.match(table)
|
@@ -188,15 +189,14 @@ def new
|
|
188
189
|
end
|
189
190
|
end
|
190
191
|
end
|
191
|
-
# initial values set in url
|
192
|
+
# initial values set in url (params)
|
192
193
|
params.each do |k,v|
|
193
194
|
if k.match(table)
|
194
195
|
field = k.split('.').last
|
195
196
|
@record.send("#{field}=", v) if @record.respond_to?(field)
|
196
197
|
end
|
197
198
|
end
|
198
|
-
#
|
199
|
-
#dc_new_record() if respond_to?('dc_new_record')
|
199
|
+
# new_record callback. Set default values for new record
|
200
200
|
if (m = callback_method('new_record') ) then call_callback_method(m) end
|
201
201
|
@parms['action'] = 'create'
|
202
202
|
end
|
@@ -204,19 +204,21 @@ end
|
|
204
204
|
########################################################################
|
205
205
|
# Duplicate embedded document. Since embedded documents are returned differently
|
206
206
|
# then top level document. Subroutine of duplicate_socument.
|
207
|
+
#
|
208
|
+
#TODO Works for two embedded levels. Dies with third and more levels.
|
207
209
|
########################################################################
|
208
210
|
def duplicate_embedded(source) #:nodoc:
|
209
|
-
# TODO Works for two embedded levels. Dies with third and more levels.
|
210
211
|
dest = {}
|
211
212
|
source.each do |attribute_name, value|
|
212
213
|
next if attribute_name == '_id' # don't duplicate _id
|
214
|
+
|
213
215
|
if value.class == Array
|
214
216
|
dest[attribute_name] = []
|
215
217
|
value.each do |ar|
|
216
218
|
dest[attribute_name] << duplicate_embedded(ar)
|
217
219
|
end
|
218
|
-
else
|
219
|
-
# if duplicate string
|
220
|
+
else
|
221
|
+
# if duplicate, string dup is added. For unique fields
|
220
222
|
add_duplicate = params['dup_fields'].to_s.match(attribute_name + ',')
|
221
223
|
dest[attribute_name] = value
|
222
224
|
dest[attribute_name] << ' dup' if add_duplicate
|
@@ -229,20 +231,22 @@ end
|
|
229
231
|
|
230
232
|
########################################################################
|
231
233
|
# Will create duplicate document of source document. This method is used for
|
232
|
-
# duplicating document and is
|
234
|
+
# duplicating document and is subroutine of create action.
|
233
235
|
########################################################################
|
234
236
|
def duplicate_document(source)
|
235
237
|
dest = {}
|
236
238
|
source.attribute_names.each do |attribute_name|
|
237
239
|
next if attribute_name == '_id' # don't duplicate _id
|
238
|
-
|
240
|
+
|
241
|
+
# if duplicate, string dup is added. For unique fields
|
239
242
|
add_duplicate = params['dup_fields'].to_s.match(attribute_name + ',')
|
240
243
|
dest[attribute_name] = source[attribute_name]
|
241
244
|
dest[attribute_name] << ' dup' if add_duplicate
|
242
245
|
end
|
243
|
-
# embedded documents
|
246
|
+
# embedded documents
|
244
247
|
source.embedded_relations.keys.each do |embedded_name|
|
245
248
|
next if source[embedded_name].nil? # it happens
|
249
|
+
|
246
250
|
dest[embedded_name] = []
|
247
251
|
source[embedded_name].each do |embedded|
|
248
252
|
dest[embedded_name] << duplicate_embedded(embedded)
|
@@ -257,32 +261,35 @@ end
|
|
257
261
|
# Create (or duplicate) action. Action is also used for turning filter on.
|
258
262
|
########################################################################
|
259
263
|
def create
|
260
|
-
# abusing create for turning filter on
|
264
|
+
# abusing create for turning filter on
|
261
265
|
return index if params[:filter].to_s == 'on'
|
262
|
-
|
266
|
+
|
267
|
+
# not authorized
|
263
268
|
unless dc_user_can(DcPermission::CAN_CREATE)
|
264
269
|
flash[:error] = t('drgcms.not_authorized')
|
265
270
|
return index
|
266
271
|
end
|
267
|
-
|
268
|
-
|
269
|
-
|
272
|
+
|
273
|
+
# create document
|
274
|
+
if params['id'].nil?
|
275
|
+
# Prevent double form submit
|
270
276
|
params[:form_time_stamp] = params[:form_time_stamp].to_i
|
271
277
|
session[:form_time_stamp] ||= 0
|
272
278
|
return index if params[:form_time_stamp] <= session[:form_time_stamp]
|
279
|
+
|
273
280
|
session[:form_time_stamp] = params[:form_time_stamp]
|
274
|
-
#
|
275
281
|
create_new_empty_record
|
276
282
|
if save_data
|
277
283
|
flash[:info] = t('drgcms.doc_saved')
|
278
284
|
params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
|
279
285
|
return process_return_to(params[:return_to]) if params[:return_to]
|
280
286
|
|
281
|
-
@parms['id']
|
282
|
-
params[:id]
|
287
|
+
@parms['id'] = @record.id # must be set, for proper update link
|
288
|
+
params[:id] = @record.id # must be set, for find_record
|
283
289
|
edit
|
284
290
|
else # error
|
285
291
|
return process_return_to(params[:return_to]) if params[:return_to]
|
292
|
+
|
286
293
|
render action: :new
|
287
294
|
end
|
288
295
|
else # duplicate record
|
@@ -304,7 +311,7 @@ def edit
|
|
304
311
|
find_record
|
305
312
|
if (m = callback_method('before_edit') )
|
306
313
|
ret = call_callback_method(m)
|
307
|
-
#
|
314
|
+
# don't do anything if return is false
|
308
315
|
return index if ret.class == FalseClass
|
309
316
|
end
|
310
317
|
@parms['action'] = 'update'
|
@@ -316,29 +323,27 @@ end
|
|
316
323
|
########################################################################
|
317
324
|
def update
|
318
325
|
find_record
|
319
|
-
# check if record was not updated in mean time
|
326
|
+
# check if record was not updated in mean time
|
320
327
|
if @record.respond_to?(:updated_at)
|
321
328
|
if params[:last_updated_at].to_i != @record.updated_at.to_i
|
322
329
|
flash[:error] = t('drgcms.updated_by_other')
|
323
330
|
return render(action: :edit)
|
324
331
|
end
|
325
332
|
end
|
326
|
-
|
333
|
+
|
327
334
|
if dc_user_can(DcPermission::CAN_EDIT_ALL) or
|
328
335
|
( @record.respond_to?('created_by') and
|
329
336
|
@record.created_by == session[:user_id] and
|
330
337
|
dc_user_can(DcPermission::CAN_EDIT) )
|
331
|
-
|
338
|
+
|
332
339
|
if save_data
|
333
340
|
params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
|
334
341
|
@parms['action'] = 'update'
|
335
|
-
# Process return_to
|
342
|
+
# Process return_to
|
336
343
|
return process_return_to(params[:return_to]) if params[:return_to]
|
337
344
|
else
|
338
345
|
# do not forget before_edit callback
|
339
|
-
if m = callback_method('before_edit')
|
340
|
-
call_callback_method(m)
|
341
|
-
end
|
346
|
+
if m = callback_method('before_edit') then call_callback_method(m) end
|
342
347
|
return render action: :edit
|
343
348
|
end
|
344
349
|
else
|
@@ -352,7 +357,7 @@ end
|
|
352
357
|
########################################################################
|
353
358
|
def destroy
|
354
359
|
find_record
|
355
|
-
#
|
360
|
+
# check permission required to delete
|
356
361
|
permission = if params['operation'].nil?
|
357
362
|
if @record.respond_to?('created_by') # needs can_delete_all if created_by is present and not owner
|
358
363
|
(@record.created_by == session[:user_id]) ? DcPermission::CAN_DELETE : DcPermission::CAN_DELETE_ALL
|
@@ -367,38 +372,39 @@ def destroy
|
|
367
372
|
end
|
368
373
|
end
|
369
374
|
ok2delete = dc_user_can(permission)
|
370
|
-
|
375
|
+
|
371
376
|
case
|
372
|
-
# not authorized
|
377
|
+
# not authorized
|
373
378
|
when !ok2delete then
|
374
379
|
flash[:error] = t('drgcms.not_authorized')
|
375
380
|
return index
|
376
|
-
|
381
|
+
|
382
|
+
# delete document
|
377
383
|
when params['operation'].nil? then
|
378
|
-
#
|
384
|
+
# before_delete callback
|
379
385
|
if (m = callback_method('before_delete') )
|
380
386
|
ret = call_callback_method(m)
|
381
|
-
#
|
387
|
+
# don't do anything if return is false
|
382
388
|
return index if ret.class == FalseClass
|
383
389
|
end
|
384
|
-
|
390
|
+
|
385
391
|
if @record.destroy
|
386
392
|
save_journal(:delete)
|
387
393
|
flash[:info] = t('drgcms.record_deleted')
|
388
|
-
#
|
394
|
+
# after_delete callback
|
389
395
|
if (m = callback_method('after_delete') )
|
390
396
|
call_callback_method(m)
|
391
397
|
elsif params['after-delete'].to_s.match('return_to')
|
392
398
|
params[:return_to] = params['after-delete']
|
393
399
|
end
|
394
|
-
# Process return_to link
|
400
|
+
# Process return_to link
|
395
401
|
return process_return_to(params[:return_to]) if params[:return_to]
|
396
402
|
else
|
397
403
|
flash[:error] = dc_error_messages_for(@record)
|
398
404
|
end
|
399
405
|
return index
|
400
406
|
|
401
|
-
#
|
407
|
+
# deactivate document
|
402
408
|
when params['operation'] == 'disable' then
|
403
409
|
if @record.respond_to?('active')
|
404
410
|
@record.active = false
|
@@ -408,7 +414,7 @@ def destroy
|
|
408
414
|
flash[:info] = t('drgcms.doc_disabled')
|
409
415
|
end
|
410
416
|
|
411
|
-
#
|
417
|
+
# reactivate document
|
412
418
|
when params['operation'] == 'enable' then
|
413
419
|
if @record.respond_to?('active')
|
414
420
|
@record.active = true
|
@@ -418,11 +424,11 @@ def destroy
|
|
418
424
|
flash[:info] = t('drgcms.doc_enabled')
|
419
425
|
end
|
420
426
|
|
421
|
-
# reorder documents
|
427
|
+
#TODO reorder documents
|
422
428
|
when params['operation'] == 'reorder' then
|
423
429
|
|
424
430
|
end
|
425
|
-
|
431
|
+
|
426
432
|
@parms['action'] = 'update'
|
427
433
|
render action: :edit
|
428
434
|
end
|
@@ -498,7 +504,7 @@ def user_has_permission?(permission, collection_name)
|
|
498
504
|
end
|
499
505
|
|
500
506
|
########################################################################
|
501
|
-
# Merges two forms when current form extends other form. Subroutine of
|
507
|
+
# Merges two forms when current form extends other form. Subroutine of read_drg_form.
|
502
508
|
# With a little help of https://www.ruby-forum.com/topic/142809
|
503
509
|
########################################################################
|
504
510
|
def forms_merge(hash1, hash2)
|
@@ -510,8 +516,8 @@ def forms_merge(hash1, hash2)
|
|
510
516
|
end
|
511
517
|
target[key] = hash2[key] == '/' ? nil : hash2[key]
|
512
518
|
end
|
513
|
-
# delete keys with nil value
|
514
|
-
target.delete_if{ |k,v| v.nil? }
|
519
|
+
# delete keys with nil value
|
520
|
+
target.delete_if { |k, v| v.nil? }
|
515
521
|
end
|
516
522
|
|
517
523
|
########################################################################
|
@@ -521,13 +527,13 @@ end
|
|
521
527
|
# [Parameters:]
|
522
528
|
# [extend_option] : Value of @form['extend'] option
|
523
529
|
########################################################################
|
524
|
-
def
|
530
|
+
def extend_drg_form(extend_option)
|
525
531
|
form_file_name = dc_find_form_file(extend_option)
|
526
|
-
@form_js <<
|
532
|
+
@form_js << read_js_drg_form(form_file_name)
|
527
533
|
form = YAML.load_file( form_file_name )
|
528
534
|
@form = forms_merge(form, @form)
|
529
|
-
# If combined form contains tabs and fields options, merge fields into tabs
|
530
|
-
if @form['form']['tabs']
|
535
|
+
# If combined form contains tabs and fields options, merge fields into tabs
|
536
|
+
if @form['form']['tabs'] && @form['form']['fields']
|
531
537
|
@form['form']['tabs']['fields'] = @form['form']['fields']
|
532
538
|
@form['form']['fields'] = nil
|
533
539
|
end
|
@@ -540,54 +546,59 @@ end
|
|
540
546
|
# [Parameters:]
|
541
547
|
# [include_option] : Value of @form['include'] option
|
542
548
|
########################################################################
|
543
|
-
def
|
549
|
+
def include_drg_form(include_option)
|
544
550
|
includes = include_option.class == Array ? include_option : include_option.split(/\,|\;/)
|
545
551
|
includes.each do |include_file|
|
546
552
|
form_file_name = dc_find_form_file(include_file)
|
547
|
-
@form_js <<
|
553
|
+
@form_js << read_js_drg_form(form_file_name)
|
548
554
|
form = YAML.load_file(form_file_name)
|
549
555
|
@form = forms_merge(@form, form)
|
550
556
|
end
|
551
557
|
end
|
552
558
|
|
553
559
|
########################################################################
|
554
|
-
# Will read data from form_file_name.js if
|
560
|
+
# Will read data from form_file_name.js if exists.
|
555
561
|
#
|
556
562
|
# [Parameters:]
|
557
563
|
# [form_file_name] : Physical form filename
|
558
564
|
########################################################################
|
559
|
-
def
|
565
|
+
def read_js_drg_form(form_file_name)
|
560
566
|
js_form_file_name = form_file_name.sub('.yml','.js')
|
561
567
|
File.read(js_form_file_name) rescue ''
|
562
568
|
end
|
563
569
|
|
564
570
|
########################################################################
|
565
|
-
# Read
|
571
|
+
# Read DRG form into @form object. Subroutine of check_authorization.
|
566
572
|
########################################################################
|
567
|
-
def
|
573
|
+
def read_drg_form
|
568
574
|
table_name = decamelize_type(params[:table].strip)
|
569
575
|
@tables = table_name.split(';').inject([]) { |r,v| r << [(v.classify.constantize rescue nil), v] }
|
570
|
-
|
576
|
+
|
577
|
+
# split ids passed when embedded document
|
571
578
|
ids = params[:ids].to_s.strip.downcase
|
572
579
|
@ids = ids.split(';').inject([]) { |r,v| r << v }
|
573
|
-
|
580
|
+
|
581
|
+
# form_name defaults to last table specified
|
574
582
|
form_name = params[:form_name] || @tables.last[1]
|
575
583
|
@form_js = ''
|
576
|
-
|
584
|
+
|
585
|
+
# dynamically generated form
|
577
586
|
@form = if params[:form_name] == 'method'
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
+
dc_eval_class_method(params[:form_method], params)
|
588
|
+
else
|
589
|
+
form_file_name = dc_find_form_file(form_name)
|
590
|
+
@form_js = read_js_drg_form(form_file_name)
|
591
|
+
YAML.load_file(form_file_name)
|
592
|
+
end
|
593
|
+
|
594
|
+
# form includes or extends another form file
|
595
|
+
include_drg_form(@form['include']) if @form['include']
|
596
|
+
extend_drg_form(@form['extend']) if @form['extend']
|
587
597
|
@form['script'] = (@form['script'].blank? ? @form_js : @form['script'] + @form_js)
|
588
|
-
# add readonly key to form if readonly parameter is passed in url
|
598
|
+
# add readonly key to form if readonly parameter is passed in url
|
589
599
|
@form['readonly'] = 1 if params['readonly'] #and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
|
590
|
-
|
600
|
+
|
601
|
+
# !!!!!! Always use strings for key names since @parms['table'] != @parms[:table]
|
591
602
|
@parms = { 'table' => table_name, 'ids' => params[:ids], 'form_name' => form_name,
|
592
603
|
'return_to' => params['return_to'], 'edit_only' => params['edit_only'],
|
593
604
|
'readonly' => params['readonly']
|
@@ -643,7 +654,7 @@ def check_authorization
|
|
643
654
|
(table.size < 3 or !dc_user_can(DcPermission::CAN_VIEW))
|
644
655
|
return render(action: 'error', locals: { error: t('drgcms.not_authorized')} )
|
645
656
|
end
|
646
|
-
|
657
|
+
read_drg_form
|
647
658
|
return render( plain: t('drgcms.form_error') ) if @form.nil?
|
648
659
|
|
649
660
|
# Permissions can be also defined on form
|
@@ -672,7 +683,7 @@ end
|
|
672
683
|
########################################################################
|
673
684
|
# Creates new empty record for new and create action.
|
674
685
|
########################################################################
|
675
|
-
def create_new_empty_record(initial_data=nil) #:nodoc:
|
686
|
+
def create_new_empty_record(initial_data = nil) #:nodoc:
|
676
687
|
if @tables.size == 1
|
677
688
|
@record = @tables.first[0].new(initial_data)
|
678
689
|
else
|
@@ -689,9 +700,9 @@ def update_standards(record = @record)
|
|
689
700
|
record.updated_by = session[:user_id] if record.respond_to?('updated_by')
|
690
701
|
if record.new_record?
|
691
702
|
record.created_by = session[:user_id] if record.respond_to?('created_by')
|
692
|
-
# set this only initialy. Allow to be set to nil on updates.
|
693
|
-
# and will be directly visible only to admins
|
694
|
-
record.dc_site_id = dc_get_site.
|
703
|
+
# set this only initialy. Allow to be set to nil on updates. Document can then belong to all sites
|
704
|
+
# and will be directly visible only to admins
|
705
|
+
record.dc_site_id = dc_get_site.id if record.respond_to?('dc_site_id') && record.dc_site_id.nil?
|
695
706
|
end
|
696
707
|
end
|
697
708
|
|
@@ -703,17 +714,15 @@ end
|
|
703
714
|
# [changes] Current document changed fields.
|
704
715
|
########################################################################
|
705
716
|
def save_journal(operation, changes = {})
|
706
|
-
# return unless session[:save_journal]
|
707
717
|
if operation == :delete
|
708
718
|
@record.attributes.each {|k,v| changes[k] = v}
|
709
|
-
# elsif operation == :new
|
710
|
-
# changes = {}
|
711
719
|
end
|
712
|
-
|
713
|
-
if (operation != :update)
|
714
|
-
# determine site_id
|
720
|
+
|
721
|
+
if (operation != :update) || changes.size > 0
|
722
|
+
# determine site_id
|
715
723
|
site_id = @record.site_id if @record.respond_to?('site_id')
|
716
|
-
site_id = dc_get_site._id if site_id.nil?
|
724
|
+
site_id = dc_get_site._id if site_id.nil? && dc_get_site
|
725
|
+
|
717
726
|
DcJournal.create(site_id: site_id,
|
718
727
|
operation: operation,
|
719
728
|
user_id: session[:user_id],
|
@@ -731,23 +740,23 @@ end
|
|
731
740
|
# Returns callback method name or nil if not defined.
|
732
741
|
########################################################################
|
733
742
|
def callback_method(key) #:nodoc:
|
734
|
-
data_key = key.gsub('_','-') #
|
735
|
-
|
743
|
+
data_key = key.gsub('_','-') # convert _ to -
|
744
|
+
callback = case
|
736
745
|
when params['data'] && params['data'][data_key] then params['data'][data_key]
|
737
|
-
#
|
746
|
+
# dc_ + key method is present then call it automatically
|
738
747
|
when @form['form'][key] then @form['form'][key]
|
739
748
|
when respond_to?('dc_' + key) then 'dc_' + key
|
740
749
|
when params[data_key] then params[data_key]
|
741
750
|
else nil
|
742
751
|
end
|
743
|
-
|
752
|
+
|
744
753
|
ret = case
|
745
|
-
when
|
746
|
-
when
|
747
|
-
when
|
748
|
-
params[:return_to] =
|
754
|
+
when callback.nil? then callback # otherwise there will be errors in next lines
|
755
|
+
when callback.match('eval ') then callback.sub('eval ','')
|
756
|
+
when callback.match('return_to ')
|
757
|
+
params[:return_to] = callback.sub('return_to ','')
|
749
758
|
return nil
|
750
|
-
else
|
759
|
+
else callback
|
751
760
|
end
|
752
761
|
ret
|
753
762
|
end
|
@@ -786,16 +795,16 @@ end
|
|
786
795
|
|
787
796
|
########################################################################
|
788
797
|
# Since tabs have been introduced on form it is a little more complicated
|
789
|
-
# to
|
798
|
+
# to collect all edit fields on form. This method does it. Subroutine of save_data.
|
790
799
|
########################################################################
|
791
|
-
def fields_on_form
|
800
|
+
def fields_on_form #:nodoc:
|
792
801
|
form_fields = []
|
793
802
|
if @form['form']['fields']
|
794
|
-
# read only field elements (key is Integer)
|
795
|
-
@form['form']['fields'].each {|key,options| form_fields << options if key.class == Integer }
|
803
|
+
# read only field elements (key is Integer)
|
804
|
+
@form['form']['fields'].each { |key, options| form_fields << options if key.class == Integer }
|
796
805
|
else
|
797
806
|
@form['form']['tabs'].keys.each do |tab|
|
798
|
-
@form['form']['tabs'][tab].each {|key,options| form_fields << options if key.class == Integer }
|
807
|
+
@form['form']['tabs'][tab].each { |key, options| form_fields << options if key.class == Integer }
|
799
808
|
end
|
800
809
|
end
|
801
810
|
form_fields
|
@@ -808,7 +817,7 @@ end
|
|
808
817
|
def save_data
|
809
818
|
form_fields = fields_on_form()
|
810
819
|
return true if form_fields.size == 0
|
811
|
-
|
820
|
+
|
812
821
|
form_fields.each do |v|
|
813
822
|
session[:form_processing] = v['name'] # for debuging
|
814
823
|
next if v['type'].nil? or v['name'].nil? or
|
@@ -821,20 +830,21 @@ def save_data
|
|
821
830
|
value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
|
822
831
|
@record.send("#{v['name']}=", value)
|
823
832
|
end
|
824
|
-
#
|
833
|
+
# before_save callback
|
825
834
|
if (m = callback_method('before_save') )
|
826
835
|
ret = call_callback_method(m)
|
827
|
-
#
|
836
|
+
# don't save if callback returns false
|
828
837
|
return false if ret.class == FalseClass
|
829
838
|
end
|
830
|
-
|
839
|
+
|
840
|
+
# save data
|
831
841
|
changes = @record.changes
|
832
842
|
update_standards() if changes.size > 0 # update only if there has been some changes
|
833
843
|
if (saved = @record.save)
|
834
844
|
operation = @record.new_record? ? :new : :update
|
835
845
|
save_journal(operation, changes)
|
836
|
-
# callback
|
837
|
-
if (m = callback_method('after_save') ) then call_callback_method(m)
|
846
|
+
# after_save callback
|
847
|
+
if (m = callback_method('after_save') ) then call_callback_method(m) end
|
838
848
|
end
|
839
849
|
saved
|
840
850
|
end
|
@@ -844,20 +854,18 @@ end
|
|
844
854
|
# in select_fields and deny_fields
|
845
855
|
########################################################################
|
846
856
|
def separated_to_symbols(data)
|
847
|
-
data.chomp.split(',').
|
857
|
+
data.chomp.split(',').map { |e| e.strip.downcase.to_sym }
|
848
858
|
end
|
849
859
|
|
850
860
|
########################################################################
|
851
|
-
# Will process select_fields and deny_fields
|
861
|
+
# Will process only (select_fields) and without (deny_fields) option
|
852
862
|
########################################################################
|
853
863
|
def process_select_and_deny_fields
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
if
|
859
|
-
@records = @records.without( separated_to_symbols(@form['result_set']['deny_fields']) )
|
860
|
-
end
|
864
|
+
only = @form['result_set']['select_fields'] || @form['result_set']['only']
|
865
|
+
@records = @records.only( separated_to_symbols(only) ) if only
|
866
|
+
|
867
|
+
without = @form['result_set']['deny_fields'] || @form['result_set']['without']
|
868
|
+
@records = @records.without( separated_to_symbols(without) ) if without
|
861
869
|
end
|
862
870
|
|
863
871
|
########################################################################
|
@@ -867,18 +875,18 @@ def check_sort_options() #:nodoc:
|
|
867
875
|
table_name = @tables.first[1]
|
868
876
|
old_sort = session[table_name][:sort].to_s
|
869
877
|
sort, direction = old_sort.split(' ')
|
870
|
-
|
878
|
+
|
871
879
|
if params['sort']
|
872
880
|
# reverse sort if same selected
|
873
881
|
if params['sort'] == sort
|
874
882
|
direction = (direction == '1') ? '-1' : '1'
|
875
883
|
end
|
876
|
-
direction ||= 1
|
884
|
+
direction ||= '1'
|
877
885
|
sort = params[:sort]
|
878
886
|
session[table_name][:sort] = "#{params['sort']} #{direction}"
|
879
887
|
session[table_name][:page] = 1
|
880
888
|
end
|
881
|
-
@records.sort( sort => direction.to_i ) if session[table_name][:sort]
|
889
|
+
@records.sort( sort => direction.to_i ) if session[table_name][:sort] && @records.class == Mongoid::Criteria
|
882
890
|
params['sort'] = nil # otherwise there is problem with other links
|
883
891
|
end
|
884
892
|
|
@@ -921,45 +929,45 @@ def set_session_filter(table_name)
|
|
921
929
|
return if params[:filter_oper] && params[:filter_field].blank?
|
922
930
|
|
923
931
|
filter_value = if params[:filter_value].nil?
|
924
|
-
#
|
932
|
+
#NIL indicates that no filtering is needed
|
925
933
|
'#NIL'
|
926
934
|
else
|
927
935
|
if params[:filter_value].class == String and params[:filter_value][0] == '@'
|
928
|
-
# Internal value. Remove leading @ and evaluate expression
|
936
|
+
# Internal value. Remove leading @ and evaluate expression
|
929
937
|
expression = DcInternals.get(params[:filter_value])
|
930
938
|
eval(expression) rescue nil
|
931
939
|
else
|
932
|
-
# No filter when empty
|
940
|
+
# No filter when empty
|
933
941
|
params[:filter_value] == '' ? '#NIL' : params[:filter_value]
|
934
942
|
end
|
935
943
|
end
|
936
|
-
# if filter field parameter is omitted then just set filter value
|
944
|
+
# if filter field parameter is omitted then just set filter value
|
937
945
|
session[table_name][:filter] =
|
938
946
|
if params[:filter_field].nil?
|
939
947
|
saved = YAML.load(session[table_name][:filter])
|
940
948
|
saved['value'] = filter_value
|
941
949
|
saved.to_yaml
|
942
950
|
else
|
943
|
-
#
|
951
|
+
# as field defined. Split name and alternative input field
|
944
952
|
field = if params[:filter_field].match(' as ')
|
945
953
|
params[:filter_input] = params[:filter_field].split(' as ').last.strip
|
946
954
|
params[:filter_field].split(' as ').first.strip
|
947
955
|
else
|
948
956
|
params[:filter_field]
|
949
957
|
end
|
950
|
-
|
958
|
+
|
951
959
|
{'field' => field,
|
952
960
|
'operation' => params[:filter_oper],
|
953
961
|
'value' => filter_value,
|
954
962
|
'input' => params[:filter_input],
|
955
963
|
'table' => table_name }.to_yaml
|
956
964
|
end
|
957
|
-
# must be. Otherwise kaminari includes
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
965
|
+
# must be. Otherwise kaminari includes parames on paging links
|
966
|
+
params[:filter] = nil
|
967
|
+
params[:filter_id] = nil
|
968
|
+
params[:filter_oper] = nil
|
969
|
+
params[:filter_input] = nil
|
970
|
+
params[:filter_field] = nil
|
963
971
|
end
|
964
972
|
|
965
973
|
########################################################################
|
@@ -969,31 +977,27 @@ def check_filter_options() #:nodoc:
|
|
969
977
|
table_name = @tables.first[1]
|
970
978
|
model = @tables.first[0]
|
971
979
|
session[table_name] ||= {}
|
972
|
-
#
|
980
|
+
# page is set
|
973
981
|
session[table_name][:page] = params[:page] if params[:page]
|
974
|
-
# new filter is applied
|
982
|
+
# new filter is applied
|
975
983
|
if params[:filter]
|
976
984
|
set_session_filter(table_name)
|
977
985
|
session[table_name][:page] = 1
|
978
986
|
end
|
979
|
-
# if data model has field dc_site_id ensure that only documents which belong to the site are selected.
|
987
|
+
# if data model has field dc_site_id ensure that only documents which belong to the site are selected.
|
980
988
|
site_id = dc_get_site._id if dc_get_site
|
981
|
-
|
989
|
+
|
990
|
+
# don't filter site if no dc_site_id field or user is ADMIN
|
982
991
|
site_id = nil if !model.method_defined?('dc_site_id') or dc_user_can(DcPermission::CAN_ADMIN)
|
983
992
|
site_id = nil if session[table_name][:filter].to_s.match('dc_site_id')
|
984
|
-
|
993
|
+
|
985
994
|
if @records = DcFilter.get_filter(session[table_name][:filter])
|
986
995
|
@records = @records.and(dc_site_id: site_id) if site_id
|
987
996
|
else
|
988
|
-
@records =
|
989
|
-
model.where(dc_site_id: site_id)
|
990
|
-
else
|
991
|
-
model
|
992
|
-
end
|
997
|
+
@records = site_id ? model.where(dc_site_id: site_id) : model
|
993
998
|
end
|
994
|
-
# select only fields or deny fields specified
|
995
999
|
process_select_and_deny_fields
|
996
|
-
# pagination if required
|
1000
|
+
# pagination if required
|
997
1001
|
per_page = (@form['result_set']['per_page'] || 30).to_i
|
998
1002
|
@records = @records.page(session[table_name][:page]).per(per_page) if per_page > 0
|
999
1003
|
end
|