drg_cms 0.4.61 → 0.5.0
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 +4 -4
- data/app/assets/javascripts/drg_cms/drg_cms.js +10 -14
- data/app/assets/stylesheets/drg_cms/drg_cms.css +19 -17
- data/app/controllers/cmsedit_controller.rb +7 -13
- data/app/controllers/dc_application_controller.rb +48 -0
- data/app/controllers/dc_common_controller.rb +1 -1
- data/app/forms/all_options.yml +5 -1
- data/app/forms/dc_category.yml +0 -2
- data/app/forms/dc_design.yml +3 -3
- data/app/helpers/cmsedit_helper.rb +10 -42
- data/app/helpers/dc_application_helper.rb +100 -57
- data/app/models/drgcms_form_fields.rb +385 -49
- data/config/locales/drgcms_en.yml +1 -0
- data/config/locales/drgcms_sl.yml +1 -0
- data/drg_cms.gemspec +2 -3
- data/lib/drg_cms/version.rb +1 -1
- metadata +5 -5
- data/app/models/drgcms_form_field.rb +0 -1027
@@ -47,6 +47,15 @@ attr_reader :options
|
|
47
47
|
# all parts read from page, design, ...
|
48
48
|
attr_accessor :parts
|
49
49
|
|
50
|
+
|
51
|
+
############################################################################
|
52
|
+
# When @parent is present then helper methods are called from parent class otherwise
|
53
|
+
# from self.
|
54
|
+
############################################################################
|
55
|
+
def _origin #:nodoc:
|
56
|
+
@parent ? @parent : self
|
57
|
+
end
|
58
|
+
|
50
59
|
############################################################################
|
51
60
|
# This is main method used for render parts of design into final HTML document.
|
52
61
|
#
|
@@ -142,11 +151,13 @@ end
|
|
142
151
|
def dc_edit_title()
|
143
152
|
title = @form['form']['title']
|
144
153
|
# defined as form:title:edit
|
145
|
-
if title and title['edit']
|
154
|
+
if title and title['edit'] and !@form['readonly']
|
146
155
|
t( title['edit'], title['edit'] )
|
156
|
+
elsif title and title['show'] and @form['readonly']
|
157
|
+
t( title['show'], title['show'] )
|
147
158
|
else
|
148
159
|
# concatenate title
|
149
|
-
c =
|
160
|
+
c = (@form['readonly'] ? t('drgcms.show') : t('drgcms.edit')) + " : "
|
150
161
|
c << (@form['title'] ? t( @form['title'], @form['title'] ) : t_tablename(@form['table'])) + ' : '
|
151
162
|
title = (title and title['field']) ? title['field'] : @form['form']['edit_title']
|
152
163
|
c << "#{@record[ title ]} : " if title and @record.respond_to?(title)
|
@@ -191,6 +202,51 @@ eot
|
|
191
202
|
c.html_safe
|
192
203
|
end
|
193
204
|
|
205
|
+
############################################################################
|
206
|
+
# Similar to rails submit_tag, but also takes care of link icon, translation, ...
|
207
|
+
############################################################################
|
208
|
+
def dc_submit_tag(caption, icon, parms, rest={})
|
209
|
+
parms['class'] ||= 'dc-submit'
|
210
|
+
if icon
|
211
|
+
icon_image = if icon.match(/\./)
|
212
|
+
image_tag(icon, class: 'dc-animate')
|
213
|
+
elsif icon.match('<i')
|
214
|
+
icon
|
215
|
+
else
|
216
|
+
fa_icon(icon)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
html = icon_image || ''
|
220
|
+
html << submit_tag(t(caption, caption), parms)
|
221
|
+
end
|
222
|
+
############################################################################
|
223
|
+
# Similar to rails link_to, but also takes care of link icon, translation, ...
|
224
|
+
############################################################################
|
225
|
+
def dc_link_to(caption, icon, parms, rest={})
|
226
|
+
if parms.class == Hash
|
227
|
+
parms.stringify_keys!
|
228
|
+
rest.stringify_keys!
|
229
|
+
rest['class'] = rest['class'].to_s + ' dc-animate'
|
230
|
+
rest['target'] ||= parms.delete('target')
|
231
|
+
end
|
232
|
+
#
|
233
|
+
if icon
|
234
|
+
icon_image = if icon.match(/\./)
|
235
|
+
_origin.image_tag(icon, class: 'dc-link-img dc-animate')
|
236
|
+
elsif icon.match('<i')
|
237
|
+
icon
|
238
|
+
else
|
239
|
+
_origin.fa_icon(icon)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
#
|
243
|
+
if caption
|
244
|
+
caption = t(caption, caption)
|
245
|
+
icon_image << ' ' if icon_image
|
246
|
+
end
|
247
|
+
_origin.link_to("#{icon_image}#{caption}".html_safe, parms, rest)
|
248
|
+
end
|
249
|
+
|
194
250
|
####################################################################
|
195
251
|
# Returns flash messages formatted for display on message div.
|
196
252
|
#
|
@@ -198,27 +254,21 @@ end
|
|
198
254
|
# String. HTML code formatted for display.
|
199
255
|
####################################################################
|
200
256
|
def dc_flash_messages()
|
201
|
-
err =
|
202
|
-
war =
|
203
|
-
inf =
|
204
|
-
note =
|
257
|
+
err = _origin.flash[:error]
|
258
|
+
war = _origin.flash[:warning]
|
259
|
+
inf = _origin.flash[:info]
|
260
|
+
note = _origin.flash[:note]
|
205
261
|
unless err.nil? and war.nil? and inf.nil? and note.nil?
|
206
262
|
c = ''
|
207
263
|
c << "<div class=\"dc-form-error\">#{err}</div>" if err
|
208
264
|
c << "<div class=\"dc-form-warning\">#{war}</div>" if war
|
209
265
|
c << "<div class=\"dc-form-info\">#{inf}</div>" if inf
|
210
266
|
c << note if note
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
else
|
217
|
-
flash[:error] = nil
|
218
|
-
flash[:warning] = nil
|
219
|
-
flash[:info] = nil
|
220
|
-
flash[:note] = nil
|
221
|
-
end
|
267
|
+
_origin.flash[:error] = nil
|
268
|
+
_origin.flash[:warning] = nil
|
269
|
+
_origin.flash[:info] = nil
|
270
|
+
_origin.flash[:note] = nil
|
271
|
+
|
222
272
|
c.html_safe
|
223
273
|
end
|
224
274
|
end
|
@@ -280,7 +330,7 @@ end
|
|
280
330
|
# Boolean. True if in edit mode
|
281
331
|
####################################################################
|
282
332
|
def dc_edit_mode?
|
283
|
-
|
333
|
+
_origin.session[:edit_mode] > 1
|
284
334
|
end
|
285
335
|
|
286
336
|
####################################################################
|
@@ -300,18 +350,14 @@ end
|
|
300
350
|
# String. HTML code which includes add image and javascript to invoke new document create action.
|
301
351
|
####################################################################
|
302
352
|
def dc_link_for_create(opts)
|
303
|
-
|
353
|
+
opts.stringify_keys!
|
354
|
+
title = opts.delete('title') #
|
304
355
|
title = t(title, title) if title
|
305
|
-
target = opts.delete(
|
306
|
-
opts[
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
@parent.image_tag('drg_cms/add.png', { onclick: js, style: 'cursor: pointer;', title: title, alt: 'Create'})
|
311
|
-
else
|
312
|
-
image_tag('drg_cms/add.png', { onclick: js, style: 'cursor: pointer;', title: title, alt: 'Create'})
|
313
|
-
end
|
314
|
-
html.html_safe
|
356
|
+
target = opts.delete('target') || 'iframe_cms'
|
357
|
+
opts['action'] = 'new'
|
358
|
+
js = "$('##{target}').attr('src', '#{_origin.url_for(opts)}'); return false;"
|
359
|
+
dc_link_to(nil, _origin.fa_icon('plus-circle lg', class: 'dc-inline-link'), '#',
|
360
|
+
{ onclick: js, title: title, alt: 'Create'}).html_safe
|
315
361
|
end
|
316
362
|
|
317
363
|
####################################################################
|
@@ -328,19 +374,14 @@ end
|
|
328
374
|
# String. HTML code which includes edit image and javascript to invoke edit document action.
|
329
375
|
####################################################################
|
330
376
|
def dc_link_for_edit(opts)
|
331
|
-
|
332
|
-
title
|
333
|
-
target = opts.delete(
|
334
|
-
opts[
|
335
|
-
opts[
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
@parent.image_tag('drg_cms/edit.png', { onclick: js, style: 'cursor: pointer;', title: title, alt: 'Edit'})
|
340
|
-
else
|
341
|
-
image_tag('drg_cms/edit.png', { onclick: js, style: 'cursor: pointer;', title: title, alt: 'Edit'})
|
342
|
-
end
|
343
|
-
html.html_safe
|
377
|
+
opts.stringify_keys!
|
378
|
+
title = opts.delete('title') #
|
379
|
+
target = opts.delete('target') || 'iframe_cms'
|
380
|
+
opts['action'] = 'edit'
|
381
|
+
opts['controller'] ||= 'cmsedit'
|
382
|
+
js = "$('##{target}').attr('src', '#{_origin.url_for(opts)}'); return false;"
|
383
|
+
dc_link_to(nil, _origin.fa_icon('edit lg', class: 'dc-inline-link'), '#',
|
384
|
+
{ onclick: js, title: title, alt: 'Edit'})
|
344
385
|
end
|
345
386
|
|
346
387
|
####################################################################
|
@@ -349,7 +390,8 @@ end
|
|
349
390
|
def dc_link_menu_tag(title) #:nodoc:
|
350
391
|
html =<<EOT
|
351
392
|
<dl>
|
352
|
-
<dt><div class='drgcms_popmenu' href="#"
|
393
|
+
<dt><div class='drgcms_popmenu' href="#">
|
394
|
+
#{_origin.fa_icon('edit lg', class: 'dc-inline-link', title: title)}</div></dt>
|
353
395
|
<dd>
|
354
396
|
<ul class=' div-hidden drgcms_popmenu_class'>
|
355
397
|
EOT
|
@@ -361,8 +403,10 @@ end
|
|
361
403
|
# Create one option in page edit link. Subroutine of dc_page_edit_menu.
|
362
404
|
####################################################################
|
363
405
|
def dc_link_for_edit1(opts, link_text) #:nodoc:
|
364
|
-
|
365
|
-
|
406
|
+
icon = opts.delete('icon')
|
407
|
+
url = @parent.url_for(opts)
|
408
|
+
"<li><div class='drgcms_popmenu_item' style='cursor: pointer;' data-url='#{url}'>
|
409
|
+
#{_origin.fa_icon(icon)} #{link_text}</div></li>\n"
|
366
410
|
end
|
367
411
|
|
368
412
|
########################################################################
|
@@ -396,17 +440,20 @@ def dc_page_edit_menu(opts=@opts)
|
|
396
440
|
@parent.cookies[:record] = Marshal.dump(kukis)
|
397
441
|
title = "#{t('drgcms.edit')}: #{@page.subject}"
|
398
442
|
dc_link_menu_tag(title) do |html|
|
399
|
-
opts[:editparams].merge!( :
|
443
|
+
opts[:editparams].merge!( controller: 'cmsedit', action: 'edit', 'icon' => 'edit' )
|
400
444
|
opts[:editparams].merge!( :id => @page.id, :table => @parent.site.page_table, formname: nil, edit_only: 'body' )
|
401
445
|
html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_content') )
|
402
446
|
|
403
|
-
opts[:editparams][:edit_only] = nil
|
447
|
+
# opts[:editparams][:edit_only] = nil
|
448
|
+
opts[:editparams].merge!( edit_only: nil, 'icon' => 'pencil' )
|
404
449
|
html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_advanced') )
|
405
450
|
|
406
|
-
opts[:editparams][:action] = 'new'
|
451
|
+
# opts[:editparams][:action] = 'new'
|
452
|
+
opts[:editparams].merge!( action: 'new', 'icon' => 'plus' )
|
407
453
|
html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_new_page') )
|
408
454
|
|
409
|
-
opts[:editparams].merge!(ids: @page.id, formname: 'dc_part',
|
455
|
+
opts[:editparams].merge!(ids: @page.id, formname: 'dc_part', 'icon' => 'plus-square-o',
|
456
|
+
table: "#{@parent.site.page_table};dc_part" )
|
410
457
|
html << dc_link_for_edit1( opts[:editparams], t('drgcms.edit_new_part') )
|
411
458
|
end
|
412
459
|
end
|
@@ -594,7 +641,7 @@ end
|
|
594
641
|
def dc_get_site()
|
595
642
|
return @site if @site # already cached
|
596
643
|
#
|
597
|
-
req =
|
644
|
+
req = _origin.request.url # different when called from renderer
|
598
645
|
uri = URI.parse(req)
|
599
646
|
@site = DcSite.find_by(name: uri.host)
|
600
647
|
# Site can be aliased
|
@@ -859,12 +906,8 @@ end
|
|
859
906
|
# Boolean. True if user has required role.
|
860
907
|
####################################################################
|
861
908
|
def dc_user_has_role( role, user=nil, roles=nil )
|
862
|
-
if roles.nil?
|
863
|
-
|
864
|
-
end
|
865
|
-
if user.nil?
|
866
|
-
user = (@parent ? @parent.session : session)[:user_id]
|
867
|
-
end
|
909
|
+
roles = _origin.session[:user_roles] if roles.nil?
|
910
|
+
user = _origin.session[:user_id] if user.nil?
|
868
911
|
return false if user.nil?
|
869
912
|
#
|
870
913
|
if role.class == String
|
@@ -891,7 +934,7 @@ end
|
|
891
934
|
####################################################################
|
892
935
|
def dc_dont?(what, default=false)
|
893
936
|
return default if what.nil?
|
894
|
-
%w(0 no - false).include?(what.to_s.downcase.strip)
|
937
|
+
%w(0 no - false none).include?(what.to_s.downcase.strip)
|
895
938
|
end
|
896
939
|
|
897
940
|
############################################################################
|
@@ -30,7 +30,7 @@
|
|
30
30
|
#
|
31
31
|
# Each class must have at least render method implemented. All classes can
|
32
32
|
# inherit from DrgcmsField class which acts as abstract template class and implements
|
33
|
-
# most of surrounding code.
|
33
|
+
# most of surrounding code for creating custom DRG CMS form field.
|
34
34
|
#
|
35
35
|
# Render method must create html and javascript code which must be
|
36
36
|
# saved to internal @html and @js variables. Field code is then retrived by accessing
|
@@ -58,7 +58,7 @@ module DrgcmsFormFields
|
|
58
58
|
|
59
59
|
###########################################################################
|
60
60
|
# Template method for DRG CMS form field definition. This is abstract class with
|
61
|
-
# most of the common code already implemented.
|
61
|
+
# most of the common code for custom form field already implemented.
|
62
62
|
###########################################################################
|
63
63
|
class DrgcmsField
|
64
64
|
attr_reader :html, :js
|
@@ -137,7 +137,7 @@ end
|
|
137
137
|
# Parameters:
|
138
138
|
# [Hash] Hash. Ruby hash parameters.
|
139
139
|
#
|
140
|
-
#
|
140
|
+
# Form example: As used in forms
|
141
141
|
# options:
|
142
142
|
# height: 400
|
143
143
|
# width: 800
|
@@ -190,6 +190,25 @@ end
|
|
190
190
|
# Implementation of readonly DRG CMS form field.
|
191
191
|
#
|
192
192
|
# Readonly field value is just painted on form.
|
193
|
+
#
|
194
|
+
# ===Form options:
|
195
|
+
# * +name:+ field name
|
196
|
+
# * +type:+ readonly
|
197
|
+
# * +eval:+ value will be provided by evaluating expression. Usually dc_name4_id helper
|
198
|
+
# can be used to get value. Example: dc_name4_id,model_name_in_lower_case,field_name
|
199
|
+
#
|
200
|
+
# * +readonly:+ yes (can be applied to any field type)
|
201
|
+
#
|
202
|
+
# Form example:
|
203
|
+
# 10:
|
204
|
+
# name: user
|
205
|
+
# type: readonly
|
206
|
+
# html:
|
207
|
+
# size: 50
|
208
|
+
# 20:
|
209
|
+
# name: created_by
|
210
|
+
# type: readonly
|
211
|
+
# eval: dc_name4_id,dc_user,name
|
193
212
|
###########################################################################
|
194
213
|
class Readonly < DrgcmsField
|
195
214
|
###########################################################################
|
@@ -218,6 +237,15 @@ end
|
|
218
237
|
# Implementation of hidden DRG CMS form field.
|
219
238
|
#
|
220
239
|
# Will create hidden_field on form.
|
240
|
+
#
|
241
|
+
# ===Form options:
|
242
|
+
# * +name:+ field name
|
243
|
+
# * +type:+ hidden_field
|
244
|
+
#
|
245
|
+
# Form example:
|
246
|
+
# 10:
|
247
|
+
# name: im_hidden
|
248
|
+
# type: hidden_field
|
221
249
|
###########################################################################
|
222
250
|
class HiddenField < DrgcmsField
|
223
251
|
###########################################################################
|
@@ -235,6 +263,22 @@ end
|
|
235
263
|
# Implementation of embedded DRG CMS form field.
|
236
264
|
#
|
237
265
|
# Creates html required to paint embedded object on form.
|
266
|
+
#
|
267
|
+
# ===Form options:
|
268
|
+
# * +name:+ field name (required)
|
269
|
+
# * +type:+ embedded (required)
|
270
|
+
# * +formname:+ name of form which will be used for editing
|
271
|
+
# * +html:+ html options (optional)
|
272
|
+
# * +height:+ height of embedded object in pixels (1000)
|
273
|
+
# * +width:+ width of embedded object in pixels (500)
|
274
|
+
#
|
275
|
+
# Form example:
|
276
|
+
# 10:
|
277
|
+
# name: dc_parts
|
278
|
+
# type: embedded
|
279
|
+
# formname: dc_part
|
280
|
+
# html:
|
281
|
+
# height: 1000
|
238
282
|
###########################################################################
|
239
283
|
class Embedded < DrgcmsField
|
240
284
|
###########################################################################
|
@@ -269,9 +313,19 @@ end
|
|
269
313
|
end
|
270
314
|
|
271
315
|
###########################################################################
|
272
|
-
# Implementation of journal_diff DRG CMS form field.
|
316
|
+
# Implementation of journal_diff DRG CMS form field. journal_diff field is used to
|
317
|
+
# show differences between two fields in DcJournal collection.
|
273
318
|
#
|
274
|
-
#
|
319
|
+
# ===Form options:
|
320
|
+
# * +name:+ field name (required)
|
321
|
+
# * +type:+ journal_diff (required)
|
322
|
+
#
|
323
|
+
# Form example:
|
324
|
+
# 10:
|
325
|
+
# name: diff
|
326
|
+
# type: journal_diff
|
327
|
+
# html:
|
328
|
+
# size: 100x25
|
275
329
|
###########################################################################
|
276
330
|
class JournalDiff < DrgcmsField
|
277
331
|
###########################################################################
|
@@ -298,15 +352,23 @@ end
|
|
298
352
|
# id's of selected documents and control typically displays value of the field name
|
299
353
|
# defined by search options.
|
300
354
|
#
|
301
|
-
# Form options:
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
#
|
355
|
+
# ===Form options:
|
356
|
+
# * +name:+ field name (required)
|
357
|
+
# * +type:+ multitext_autocomplete (required)
|
358
|
+
# * +table+ Collection (table) name. When defined search must contain field name
|
359
|
+
# * +search:+ Search may consist of three parameters from which are separated either by dot (.) or comma(,)
|
360
|
+
# * search_field_name; when table option is defined search must define field name which will be used for search query
|
361
|
+
# * collection_name.search_field_name; Same as above except that table options must be ommited.
|
362
|
+
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
363
|
+
# method may be defined in CollectionName model which will provide result set for search.
|
364
|
+
#
|
365
|
+
# Form example:
|
366
|
+
# 90:
|
367
|
+
# name: kats
|
368
|
+
# type: multitext_autocomplete
|
369
|
+
# search: dc_category.name
|
370
|
+
# html:
|
371
|
+
# size: 30
|
310
372
|
###########################################################################
|
311
373
|
class MultitextAutocomplete < DrgcmsField
|
312
374
|
|
@@ -447,22 +509,37 @@ end
|
|
447
509
|
###########################################################################
|
448
510
|
# Implementation of select DRG CMS form field.
|
449
511
|
#
|
450
|
-
# Form options:
|
451
|
-
#
|
452
|
-
#
|
453
|
-
#
|
512
|
+
# ===Form options:
|
513
|
+
# * +name:+ field name (required)
|
514
|
+
# * +type:+ select (required)
|
515
|
+
# * +choices:+ Values for choices separated by comma. Values can also be specified like description:value.
|
516
|
+
# In the example description will be shown to user, but value will be saved to document.
|
454
517
|
# choices: 'OK:0,Ready:1,Error:2'
|
455
518
|
# choices: Ruby,Pyton,PHP
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
519
|
+
# * +eval:+ Choices will be provided by evaluating expression
|
520
|
+
# * eval: dc_choices4('model_name','description_field_name','_id'); dc_choices4 helper will provide data for select field.
|
521
|
+
# * eval: ModelName.choices4_field; ModelName class will define method choices4_field which
|
522
|
+
# will provide data for select field.
|
523
|
+
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
524
|
+
# method may be defined in CollectionName model which will provide result set for search.
|
525
|
+
# * If choices or eval is not defined choices will be provided from translation helpers. For example:
|
526
|
+
# Collection has field status choices for field may be provided by en.helpers.model_name.choices4_status
|
527
|
+
# entry of english translation. English is of course default translation. If you provide translations in
|
528
|
+
# your local language then select choices will be localized.
|
529
|
+
# en.helpers.model_name.choices4_status: 'OK:0,Ready:1,Error:2'
|
463
530
|
# sl.helpers.model_name.choices4_status: 'V redu:0,Pripravljen:1,Napaka:2'
|
464
|
-
#
|
465
|
-
#
|
531
|
+
# * +html:+ html options which apply to select field (optional)
|
532
|
+
#
|
533
|
+
# Form example:
|
534
|
+
# 30:
|
535
|
+
# name: type
|
536
|
+
# type: select
|
537
|
+
# 40:
|
538
|
+
# name: parent
|
539
|
+
# type: select
|
540
|
+
# eval: DcCategory.values_for_parent
|
541
|
+
# html:
|
542
|
+
# include_blank: true
|
466
543
|
###########################################################################
|
467
544
|
class Select < DrgcmsField
|
468
545
|
|
@@ -537,6 +614,23 @@ end
|
|
537
614
|
|
538
615
|
###########################################################################
|
539
616
|
# Implementation of check_box DRG CMS form field.
|
617
|
+
#
|
618
|
+
# ===Form options:
|
619
|
+
# * +name:+ field name (required)
|
620
|
+
# * +type:+ check_box (required)
|
621
|
+
# * +choices:+ Values check_box separated by comma (1,0) (yes,no)
|
622
|
+
# * +checked_value:+ 1 or yes or approved
|
623
|
+
# * +unchecked_value:+ 0 or no or not approved
|
624
|
+
# * +html:+ html options which apply to check_box field (optional)
|
625
|
+
#
|
626
|
+
# Form example:
|
627
|
+
# 30:
|
628
|
+
# name: active
|
629
|
+
# type: check_box
|
630
|
+
# 40:
|
631
|
+
# name: status
|
632
|
+
# type: check_box
|
633
|
+
# choices: yes,no
|
540
634
|
###########################################################################
|
541
635
|
class CheckBox < DrgcmsField
|
542
636
|
|
@@ -563,7 +657,18 @@ end
|
|
563
657
|
end
|
564
658
|
|
565
659
|
###########################################################################
|
566
|
-
# Implementation of comment DRG CMS form field.
|
660
|
+
# Implementation of comment DRG CMS form field. Comments may also be written
|
661
|
+
# on the place of form field.
|
662
|
+
#
|
663
|
+
# ===Form options:
|
664
|
+
# * +text:+ any text. Text will be translated if key is found in translations. (required)
|
665
|
+
# * +type:+ comment (required)
|
666
|
+
#
|
667
|
+
# Form example:
|
668
|
+
# 30:
|
669
|
+
# name: active
|
670
|
+
# type: check_box
|
671
|
+
|
567
672
|
###########################################################################
|
568
673
|
class Comment < DrgcmsField
|
569
674
|
|
@@ -571,14 +676,32 @@ class Comment < DrgcmsField
|
|
571
676
|
# Render comment field html code
|
572
677
|
###########################################################################
|
573
678
|
def render
|
574
|
-
@html << @yaml['text']
|
679
|
+
@html << t(@yaml['text'], @yaml['text'])
|
575
680
|
self
|
576
681
|
end
|
577
682
|
end
|
578
683
|
|
579
684
|
###########################################################################
|
580
685
|
# Implementation of link_to DRG CMS form field. link_to form field is mostly used by polls but can
|
581
|
-
# be also incorporated
|
686
|
+
# be also incorporated anywhere on the form.
|
687
|
+
#
|
688
|
+
# ===Form options:
|
689
|
+
# * +type:+ link_to (required)
|
690
|
+
# * +caption:+ Link caption
|
691
|
+
# * +icon:+ Link icon
|
692
|
+
# * +url:+ direct url link
|
693
|
+
# * +controller:+ controller name
|
694
|
+
# * +action:+ action name
|
695
|
+
# * +html:+ html options which apply to link_to (optional)
|
696
|
+
#
|
697
|
+
# Form example:
|
698
|
+
# 30:
|
699
|
+
# type: link_to
|
700
|
+
# caption: Some action
|
701
|
+
# icon: cogs
|
702
|
+
# controller: my_controller
|
703
|
+
# action: my_action
|
704
|
+
# id: id # will be replaced by record._id
|
582
705
|
###########################################################################
|
583
706
|
class LinkTo < DrgcmsField
|
584
707
|
|
@@ -590,13 +713,14 @@ def render
|
|
590
713
|
@yaml['html']['class'] ||= 'dc-link dc-animate'
|
591
714
|
@yaml['html'].symbolize_keys!
|
592
715
|
#
|
716
|
+
@yaml[:id] = record._id if @yaml[:id] == 'id'
|
593
717
|
url = @yaml['url'] || "#{@yaml[:controller]}/#{@yaml[:action]}/#{@yaml[:id]}"
|
594
718
|
url.gsub!('//','/') # no action and id
|
595
719
|
url = '/' + @yaml['url'] unless url[0,1] == '/' # no leading /
|
596
720
|
url.chop if url[0,-1] == '/' # remove trailing /
|
597
721
|
#
|
598
722
|
caption = @yaml['caption'] || @yaml['text']
|
599
|
-
@html << @parent.
|
723
|
+
@html << @parent.dc_link_to(caption, @yaml['icon'], url, @yaml['html'])
|
600
724
|
self
|
601
725
|
end
|
602
726
|
end
|
@@ -604,6 +728,18 @@ end
|
|
604
728
|
###########################################################################
|
605
729
|
# Create submit_tag form field. submit_tag form field is mostly used by polls but can
|
606
730
|
# be also incorporated in the middle of form.
|
731
|
+
#
|
732
|
+
# ===Form options:
|
733
|
+
# * +type:+ submit_tag (required)
|
734
|
+
# * +caption:+ Submit field caption
|
735
|
+
# * +icon:+ Icon
|
736
|
+
# * +html:+ html options which apply to link_to (optional)
|
737
|
+
#
|
738
|
+
# Form example:
|
739
|
+
# 40:
|
740
|
+
# type: submit_tag
|
741
|
+
# caption: translate.this
|
742
|
+
# icon: check
|
607
743
|
###########################################################################
|
608
744
|
class SubmitTag < DrgcmsField
|
609
745
|
|
@@ -624,11 +760,31 @@ end
|
|
624
760
|
|
625
761
|
###########################################################################
|
626
762
|
# Implementation of password DRG CMS form field.
|
763
|
+
#
|
764
|
+
# ===Form options:
|
765
|
+
# * +type:+ password_field (required)
|
766
|
+
# * +name:+ Field name (required)
|
767
|
+
# * +html:+ html options which apply to password field (optional)
|
768
|
+
#
|
769
|
+
# Form example:
|
770
|
+
# 20:
|
771
|
+
# name: password
|
772
|
+
# type: pasword_field
|
773
|
+
# html:
|
774
|
+
# size: 20
|
775
|
+
#
|
776
|
+
# 30:
|
777
|
+
# name: password_confirmation
|
778
|
+
# type: pasword_field
|
779
|
+
# html:
|
780
|
+
# size: 20
|
781
|
+
#
|
627
782
|
###########################################################################
|
628
783
|
class PasswordField < DrgcmsField
|
629
784
|
|
630
785
|
###########################################################################
|
631
786
|
# Render password field html code
|
787
|
+
#
|
632
788
|
###########################################################################
|
633
789
|
def render
|
634
790
|
return self if @readonly
|
@@ -641,6 +797,21 @@ end
|
|
641
797
|
|
642
798
|
###########################################################################
|
643
799
|
# Implementation of date_select DRG CMS form field.
|
800
|
+
#
|
801
|
+
# ===Form options:
|
802
|
+
# * +type:+ date_select (required)
|
803
|
+
# * +name:+ Field name (required)
|
804
|
+
# * +options:+ options which apply to date_select field (optional)
|
805
|
+
# * +html:+ html options which apply to password field (optional)
|
806
|
+
#
|
807
|
+
# Form example:
|
808
|
+
# 50:
|
809
|
+
# name: valid_from
|
810
|
+
# type: date_select
|
811
|
+
# options:
|
812
|
+
# include_blank: true
|
813
|
+
# html:
|
814
|
+
# class: my-date-class
|
644
815
|
###########################################################################
|
645
816
|
class DateSelect < DrgcmsField
|
646
817
|
|
@@ -648,9 +819,7 @@ class DateSelect < DrgcmsField
|
|
648
819
|
# Render date_select field html code
|
649
820
|
###########################################################################
|
650
821
|
def render
|
651
|
-
# return ro_standard if @readonly
|
652
822
|
return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
|
653
|
-
|
654
823
|
#
|
655
824
|
@yaml['options'] ||= {}
|
656
825
|
set_initial_value('options','default')
|
@@ -683,6 +852,19 @@ end
|
|
683
852
|
|
684
853
|
###########################################################################
|
685
854
|
# Create datetime_select form field
|
855
|
+
#
|
856
|
+
# ===Form options:
|
857
|
+
# * +type:+ date_select (required)
|
858
|
+
# * +name:+ Field name (required)
|
859
|
+
# * +options:+ options which apply to date_select field (optional)
|
860
|
+
# * +html:+ html options which apply to password field (optional)
|
861
|
+
#
|
862
|
+
# Form example:
|
863
|
+
# 60:
|
864
|
+
# name: end_time
|
865
|
+
# type: date_time_select
|
866
|
+
# options:
|
867
|
+
# include_blank: true
|
686
868
|
###########################################################################
|
687
869
|
class DatetimeSelect < DrgcmsField
|
688
870
|
|
@@ -712,7 +894,41 @@ end
|
|
712
894
|
end
|
713
895
|
|
714
896
|
###########################################################################
|
715
|
-
# Implementation of date_picker DRG CMS form field.
|
897
|
+
# Implementation of date_picker DRG CMS form field with help of jQuery DateTimePicker plugin.
|
898
|
+
#
|
899
|
+
# Since javascript date(time) format differs from ruby date(time) format localization
|
900
|
+
# must be provided in order for date_picker object works as expected. For example:
|
901
|
+
#
|
902
|
+
# en:
|
903
|
+
# datetimepicker:
|
904
|
+
# formats:
|
905
|
+
# date: 'Y/m/d'
|
906
|
+
# datetime: 'Y/m/d H:i'
|
907
|
+
#
|
908
|
+
# sl:
|
909
|
+
# datetimepicker:
|
910
|
+
# formats:
|
911
|
+
# date: 'd.m.Y'
|
912
|
+
# datetime: 'd.m.Y H:i'
|
913
|
+
#
|
914
|
+
# ===Form options:
|
915
|
+
# * +type:+ date_picker (required)
|
916
|
+
# * +name:+ Field name (required)
|
917
|
+
# * +options:+ options which apply to date_picker field. All options can be found here http://xdsoft.net/jqplugins/datetimepicker/ .
|
918
|
+
# Options can be defined in single line like:
|
919
|
+
# * options: 'inline: true,lang: "sl"' or
|
920
|
+
#
|
921
|
+
# * options:
|
922
|
+
# * inline: true
|
923
|
+
# * lang: '"sl"'
|
924
|
+
#
|
925
|
+
# * +html:+ html options which apply to date_picker field (optional)
|
926
|
+
#
|
927
|
+
# Form example:
|
928
|
+
# 10:
|
929
|
+
# name: created
|
930
|
+
# type: date_picker
|
931
|
+
# options: 'inline: true,lang: "sl"'
|
716
932
|
###########################################################################
|
717
933
|
class DatePicker < DrgcmsField
|
718
934
|
|
@@ -720,13 +936,13 @@ class DatePicker < DrgcmsField
|
|
720
936
|
# Render date_picker field html code
|
721
937
|
###########################################################################
|
722
938
|
def render
|
723
|
-
|
724
|
-
return ro_standard( @parent.dc_format_value(
|
939
|
+
value = @record[@yaml['name']] ? I18n.localize(@record[@yaml['name']].localtime.to_date) : nil
|
940
|
+
return ro_standard( @parent.dc_format_value(value)) if @readonly
|
725
941
|
#
|
726
942
|
@yaml['options'] ||= {}
|
727
943
|
set_initial_value
|
728
944
|
@yaml['html']['size'] ||= 10
|
729
|
-
@yaml['html']['value'] =
|
945
|
+
@yaml['html']['value'] = value
|
730
946
|
#
|
731
947
|
@yaml['options']['lang'] ||= "'#{I18n.locale}'"
|
732
948
|
@yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
|
@@ -755,7 +971,27 @@ end
|
|
755
971
|
|
756
972
|
end
|
757
973
|
###########################################################################
|
758
|
-
# Implementation of date_time_picker DRG CMS form field
|
974
|
+
# Implementation of date_time_picker DRG CMS form field with help of jQuery DateTimePicker plugin
|
975
|
+
#
|
976
|
+
# ===Form options:
|
977
|
+
# * +type:+ date_time_picker (required)
|
978
|
+
# * +name:+ Field name (required)
|
979
|
+
# * +options:+ options which apply to date_picker field. All options can be found here http://xdsoft.net/jqplugins/datetimepicker/ .
|
980
|
+
# Options can be defined in single line like:
|
981
|
+
# * options: 'step: 15,inline: true,lang: "sl"' or
|
982
|
+
#
|
983
|
+
# * options:
|
984
|
+
# * step: 15
|
985
|
+
# * inline: true
|
986
|
+
# * lang: '"sl"'
|
987
|
+
#
|
988
|
+
# * +html:+ html options which apply to date_time_picker field (optional)
|
989
|
+
#
|
990
|
+
# Form example:
|
991
|
+
# 10:
|
992
|
+
# name: valid_to
|
993
|
+
# type: date_time_picker
|
994
|
+
# options: 'step: 60'
|
759
995
|
###########################################################################
|
760
996
|
class DatetimePicker < DrgcmsField
|
761
997
|
|
@@ -763,13 +999,13 @@ class DatetimePicker < DrgcmsField
|
|
763
999
|
# Render date_time_picker field html code
|
764
1000
|
###########################################################################
|
765
1001
|
def render
|
766
|
-
|
767
|
-
return ro_standard( @parent.dc_format_value(
|
1002
|
+
value = @record[@yaml['name']] ? I18n.localize(@record[@yaml['name']].localtime) : nil
|
1003
|
+
return ro_standard( @parent.dc_format_value(value)) if @readonly
|
768
1004
|
#
|
769
1005
|
@yaml['options'] ||= {}
|
770
1006
|
set_initial_value
|
771
|
-
@yaml['html']['size'] ||=
|
772
|
-
@yaml['html']['value'] =
|
1007
|
+
@yaml['html']['size'] ||= 14
|
1008
|
+
@yaml['html']['value'] = value if @record[@yaml['name']]
|
773
1009
|
#
|
774
1010
|
@yaml['options']['lang'] ||= "'#{I18n.locale}'"
|
775
1011
|
@yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
|
@@ -799,9 +1035,27 @@ end
|
|
799
1035
|
|
800
1036
|
###########################################################################
|
801
1037
|
# Implementation of text_autocomplete DRG CMS form field.
|
1038
|
+
#
|
1039
|
+
# ===Form options:
|
1040
|
+
# * +name:+ field name (required)
|
1041
|
+
# * +type:+ text_autocomplete (required)
|
1042
|
+
# * +table+ Collection (table) name. When defined search must contain field name
|
1043
|
+
# * +search:+ Search may consist of three parameters from which are separated either by dot (.) or comma(,)
|
1044
|
+
# * search_field_name; when table option is defined search must define field name which will be used for search query
|
1045
|
+
# * collection_name.search_field_name; Same as above except that table options must be ommited.
|
1046
|
+
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
1047
|
+
# method may be defined in CollectionName model which will provide result set for search.
|
1048
|
+
#
|
1049
|
+
# Form example:
|
1050
|
+
# 10:
|
1051
|
+
# name: user_id
|
1052
|
+
# type: text_autocomplete
|
1053
|
+
# search: dc_user.name
|
1054
|
+
# html:
|
1055
|
+
# size: 30
|
802
1056
|
###########################################################################
|
803
1057
|
class TextAutocomplete < DrgcmsField
|
804
|
-
|
1058
|
+
|
805
1059
|
###########################################################################
|
806
1060
|
# Render text_autocomplete field html code
|
807
1061
|
###########################################################################
|
@@ -890,6 +1144,18 @@ end
|
|
890
1144
|
|
891
1145
|
###########################################################################
|
892
1146
|
# Implementation of text_area DRG CMS form field.
|
1147
|
+
#
|
1148
|
+
# ===Form options:
|
1149
|
+
# * +type:+ text_area (required)
|
1150
|
+
# * +name:+ Field name (required)
|
1151
|
+
# * +html:+ html options which apply to text_area field (optional)
|
1152
|
+
#
|
1153
|
+
# Form example:
|
1154
|
+
# 10:
|
1155
|
+
# name: css
|
1156
|
+
# type: text_area
|
1157
|
+
# html:
|
1158
|
+
# size: 100x30
|
893
1159
|
###########################################################################
|
894
1160
|
class TextArea < DrgcmsField
|
895
1161
|
|
@@ -911,6 +1177,18 @@ end
|
|
911
1177
|
|
912
1178
|
###########################################################################
|
913
1179
|
# Implementation of text_field DRG CMS form field.
|
1180
|
+
#
|
1181
|
+
# ===Form options:
|
1182
|
+
# * +type:+ text_field (required)
|
1183
|
+
# * +name:+ Field name (required)
|
1184
|
+
# * +html:+ html options which apply to text_field field (optional)
|
1185
|
+
#
|
1186
|
+
# Form example:
|
1187
|
+
# 10:
|
1188
|
+
# name: title
|
1189
|
+
# type: text_field
|
1190
|
+
# html:
|
1191
|
+
# size: 30
|
914
1192
|
###########################################################################
|
915
1193
|
class TextField < DrgcmsField
|
916
1194
|
|
@@ -928,9 +1206,39 @@ end
|
|
928
1206
|
end
|
929
1207
|
|
930
1208
|
###########################################################################
|
931
|
-
# Implementation of text_with_select DRG CMS form field.
|
1209
|
+
# Implementation of text_with_select DRG CMS form field. Field will provide
|
1210
|
+
# text_field entry field with select dropdown box with optional values for the field.
|
1211
|
+
# Form options are mostly same as in select field.
|
1212
|
+
#
|
1213
|
+
# ===Form options:
|
1214
|
+
# * +name:+ field name (required)
|
1215
|
+
# * +type:+ text_with_select (required)
|
1216
|
+
# * +choices:+ Values for choices separated by comma. Values can also be specified like description:value.
|
1217
|
+
# In this case description will be shown to user, but value will be saved to document.
|
1218
|
+
# * choices: 'OK:0,Ready:1,Error:2'
|
1219
|
+
# * choices: Ruby,Pyton,PHP
|
1220
|
+
# * +eval:+ Choices will be provided by evaluating expression
|
1221
|
+
# * eval: dc_choices4('model_name','description_field_name','_id'); dc_choices4 helper will provide data for select field.
|
1222
|
+
# * eval: ModelName.choices4_field; ModelName class will define method choices4_field which
|
1223
|
+
# will provide data for select field. Since expression is evaluated in the context of Form Field object
|
1224
|
+
# even session session variables can be accessed. Ex. +eval: 'MyClass.method(@parent.session[:user_id])'+
|
1225
|
+
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
1226
|
+
# method may be defined in CollectionName model which will provide result set for search.
|
1227
|
+
# * If choices or eval is not defined choices will be provided from translation helpers. For example:
|
1228
|
+
# Collection has field status choices for field may be provided by en.helpers.model_name.choices4_status
|
1229
|
+
# entry of english translation. English is of course default translation. If you provide translations in
|
1230
|
+
# your local language then select choices will be localized.
|
1231
|
+
# * en.helpers.model_name.choices4_status: 'OK:0,Ready:1,Error:2'
|
1232
|
+
# * sl.helpers.model_name.choices4_status: 'V redu:0,Pripravljen:1,Napaka:2'
|
1233
|
+
# * +html:+ html options which apply to select and text_field fields (optional)
|
932
1234
|
#
|
933
|
-
#
|
1235
|
+
# Form example:
|
1236
|
+
# 10:
|
1237
|
+
# name: link
|
1238
|
+
# type: text_with_select
|
1239
|
+
# eval: '@parent.dc_page_class.all_pages_for_site(@parent.dc_get_site)'
|
1240
|
+
# html:
|
1241
|
+
# size: 50
|
934
1242
|
###########################################################################
|
935
1243
|
class TextWithSelect < Select
|
936
1244
|
|
@@ -963,11 +1271,25 @@ end
|
|
963
1271
|
end
|
964
1272
|
|
965
1273
|
###########################################################################
|
966
|
-
# Implementation of html_field DRG CMS form field.
|
1274
|
+
# Implementation of html_field DRG CMS form field.
|
1275
|
+
#
|
1276
|
+
# HtmlField class only implements code for calling actual html edit field code.
|
1277
|
+
# This is by default drg_default_html_editor gem which uses CK editor javascript plugin
|
1278
|
+
# or any other plugin. Which plugin will be used as html editor is defined by
|
1279
|
+
# dc_site.settings html_editor setting.
|
967
1280
|
#
|
968
|
-
#
|
969
|
-
#
|
970
|
-
#
|
1281
|
+
# Example of dc_site.setting used for drg_default_html_editor gem.
|
1282
|
+
# html_editor: ckeditor
|
1283
|
+
# ck_editor:
|
1284
|
+
# config_file: /files/ck_config.js
|
1285
|
+
# css_file: /files/ck_css.css
|
1286
|
+
# file_select: elfinder
|
1287
|
+
#
|
1288
|
+
# Form example:
|
1289
|
+
# 10:
|
1290
|
+
# name: body
|
1291
|
+
# type: html_field
|
1292
|
+
# options: "height: 500, width: 550, toolbar: 'basic'"
|
971
1293
|
###########################################################################
|
972
1294
|
class HtmlField < DrgcmsField
|
973
1295
|
|
@@ -999,6 +1321,20 @@ end
|
|
999
1321
|
# FileSelect like HtmlField implements redirection for calling document manager edit field code.
|
1000
1322
|
# This can be drg_default_html_editor's elfinder or any other code defined
|
1001
1323
|
# by dc_site.settings file_select setting.
|
1324
|
+
#
|
1325
|
+
# Example of dc_site.setting used for drg_default_html_editor gem.
|
1326
|
+
# html_editor: ckeditor
|
1327
|
+
# ck_editor:
|
1328
|
+
# config_file: /files/ck_config.js
|
1329
|
+
# css_file: /files/ck_css.css
|
1330
|
+
# file_select: elfinder
|
1331
|
+
#
|
1332
|
+
# Form example:
|
1333
|
+
# 60:
|
1334
|
+
# name: picture
|
1335
|
+
# type: file_select
|
1336
|
+
# html:
|
1337
|
+
# size: 50
|
1002
1338
|
###########################################################################
|
1003
1339
|
class FileSelect < DrgcmsField
|
1004
1340
|
|