drg_cms 0.4.54 → 0.4.57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/app/assets/javascripts/drg_cms/drg_cms.js +4 -4
- data/app/assets/stylesheets/drg_cms/drg_cms.css +121 -68
- data/app/controllers/cmsedit_controller.rb +16 -15
- data/app/controllers/dc_application_controller.rb +1 -1
- data/app/controllers/dc_common_controller.rb +6 -2
- data/app/forms/all_options.yml +15 -30
- data/app/forms/dc_menu.yml +5 -0
- data/app/forms/dc_menu_item.yml +7 -7
- data/app/forms/dc_simple_menu.yml +5 -0
- data/app/forms/dc_simple_menu_item.yml +10 -5
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/cmsedit_helper.rb +22 -8
- data/app/helpers/dc_application_helper.rb +49 -9
- data/app/helpers/dc_common_renderer.rb +9 -0
- data/app/helpers/dc_menu_renderer.rb +18 -4
- data/app/helpers/dc_simple_menu_renderer.rb +43 -13
- data/app/models/dc_menu.rb +1 -0
- data/app/models/dc_menu_item.rb +1 -0
- data/app/models/dc_simple_menu.rb +1 -0
- data/app/models/dc_simple_menu_item.rb +1 -0
- data/app/models/dc_user.rb +18 -0
- data/app/models/drgcms_form_field.rb +66 -38
- data/app/views/dc_common/_iframe_edit.html.erb +2 -0
- data/config/locales/drgcms_en.yml +1 -1
- data/config/locales/models_en.yml +12 -0
- data/config/locales/models_sl.yml +13 -1
- data/lib/drg_cms/version.rb +1 -1
- metadata +4 -2
@@ -287,7 +287,7 @@ def dc_process_default_request()
|
|
287
287
|
# Add edit menu
|
288
288
|
layout = 'content'
|
289
289
|
if session[:edit_mode] > 0
|
290
|
-
layout = 'cms'
|
290
|
+
# layout = 'cms'
|
291
291
|
session[:site_id] = @site.id
|
292
292
|
session[:site_page_table] = @site.page_table
|
293
293
|
session[:page_id] = @page.id
|
@@ -149,7 +149,10 @@ end
|
|
149
149
|
####################################################################
|
150
150
|
def restore_from_journal
|
151
151
|
# Only administrators can perform this operation
|
152
|
-
|
152
|
+
unless dc_user_has_role('admin')
|
153
|
+
{ 'msg_info' => (t ('drgcms.not_authorized')) }
|
154
|
+
return render inline: result.to_json, formats: 'js'
|
155
|
+
end
|
153
156
|
# selected fields to hash
|
154
157
|
restore = params[:select].inject({}) {|r,v| r[v.first] = 0 if v.last == '1'; r}
|
155
158
|
result = if restore.size == 0
|
@@ -248,7 +251,8 @@ def update_json(json, is_update=false) #:nodoc:
|
|
248
251
|
result = {}
|
249
252
|
json.each do |k,v|
|
250
253
|
if v.class == Hash
|
251
|
-
result[k] = v['$oid']
|
254
|
+
result[k] = v['$oid'] unless is_update
|
255
|
+
#TODO Double check if unless works as expected
|
252
256
|
elsif v.class == Array
|
253
257
|
result[k] = []
|
254
258
|
v.each {|e| result[k] << update_json(e, is_update)}
|
data/app/forms/all_options.yml
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
extend: form_name
|
4
4
|
table: table_name
|
5
5
|
title: Some title
|
6
|
+
controls: controls_file
|
7
|
+
readonly: 1
|
8
|
+
permissions:
|
9
|
+
can_view: role_name
|
6
10
|
|
7
11
|
index:
|
8
12
|
filter: name, id as text_field
|
@@ -87,11 +91,18 @@ form:
|
|
87
91
|
action: priprava_odlocbe
|
88
92
|
method: (get),put,post
|
89
93
|
caption: Priprava odločbe
|
94
|
+
6:
|
95
|
+
type: script
|
96
|
+
caption: Cancle
|
97
|
+
js: parent.reload();
|
98
|
+
|
90
99
|
tabs:
|
91
100
|
tab1:
|
92
101
|
10:
|
93
102
|
name: name
|
94
103
|
type: text_field
|
104
|
+
type: hidden_field
|
105
|
+
type: readonly
|
95
106
|
html:
|
96
107
|
size: 50
|
97
108
|
40:
|
@@ -102,42 +113,15 @@ form:
|
|
102
113
|
html:
|
103
114
|
include_blank: true
|
104
115
|
|
105
|
-
|
106
|
-
name:
|
107
|
-
type:
|
108
|
-
html:
|
109
|
-
size: 50
|
116
|
+
40:
|
117
|
+
name: operation
|
118
|
+
type: select
|
110
119
|
|
111
120
|
30:
|
112
121
|
name: sub_text
|
113
122
|
type: html_field
|
114
123
|
options: 'height: 400'
|
115
124
|
|
116
|
-
35:
|
117
|
-
name: pre_display
|
118
|
-
type: text_field
|
119
|
-
html:
|
120
|
-
size: 50
|
121
|
-
40:
|
122
|
-
name: operation
|
123
|
-
type: select
|
124
|
-
|
125
|
-
50:
|
126
|
-
name: display
|
127
|
-
type: select
|
128
|
-
|
129
|
-
60:
|
130
|
-
name: parameters
|
131
|
-
type: text_field
|
132
|
-
html:
|
133
|
-
size: 50
|
134
|
-
|
135
|
-
70:
|
136
|
-
name: captcha_type
|
137
|
-
type: text_field
|
138
|
-
html:
|
139
|
-
size: 10
|
140
|
-
|
141
125
|
80:
|
142
126
|
name: valid_from
|
143
127
|
type: datetime_select
|
@@ -159,6 +143,7 @@ form:
|
|
159
143
|
110:
|
160
144
|
name: active
|
161
145
|
type: check_box
|
146
|
+
|
162
147
|
tab2:
|
163
148
|
10:
|
164
149
|
name: form
|
data/app/forms/dc_menu.yml
CHANGED
data/app/forms/dc_menu_item.yml
CHANGED
@@ -46,18 +46,18 @@ form:
|
|
46
46
|
eval: '@parent.dc_page_class.all_pages_for_site(@parent.dc_get_site)'
|
47
47
|
html:
|
48
48
|
size: 50
|
49
|
-
#
|
50
|
-
# 30:
|
51
|
-
# name: link
|
52
|
-
# type: text_field
|
53
|
-
# html:
|
54
|
-
# size: 50
|
55
49
|
40:
|
50
|
+
name: link_prepend
|
51
|
+
type: text_field
|
52
|
+
html:
|
53
|
+
size: 20
|
54
|
+
|
55
|
+
50:
|
56
56
|
name: target
|
57
57
|
type: text_field
|
58
58
|
html:
|
59
59
|
size: 10
|
60
|
-
|
60
|
+
60:
|
61
61
|
name: order
|
62
62
|
type: text_field
|
63
63
|
html:
|
@@ -43,32 +43,37 @@ form:
|
|
43
43
|
html:
|
44
44
|
size: 50
|
45
45
|
30:
|
46
|
+
name: link_prepend
|
47
|
+
type: text_field
|
48
|
+
html:
|
49
|
+
size: 20
|
50
|
+
40:
|
46
51
|
name: link
|
47
52
|
type: text_with_select
|
48
53
|
eval: '@parent.dc_page_class.all_pages_for_site(@parent.dc_get_site)'
|
49
54
|
html:
|
50
55
|
size: 50
|
51
|
-
|
56
|
+
50:
|
52
57
|
name: target
|
53
58
|
type: text_field
|
54
59
|
html:
|
55
60
|
size: 10
|
56
|
-
|
61
|
+
60:
|
57
62
|
name: order
|
58
63
|
type: text_field
|
59
64
|
html:
|
60
65
|
size: 2
|
61
|
-
|
66
|
+
70:
|
62
67
|
name: submenu
|
63
68
|
type: text_area
|
64
69
|
html:
|
65
70
|
size: 60x20
|
66
|
-
|
71
|
+
80:
|
67
72
|
name: css
|
68
73
|
type: text_area
|
69
74
|
html:
|
70
75
|
size: 60x10
|
71
|
-
|
76
|
+
90:
|
72
77
|
name: policy_id
|
73
78
|
type: select
|
74
79
|
eval: dc_choices4_site_policies
|
@@ -84,7 +84,7 @@ EOT
|
|
84
84
|
choices << [ t("helpers.label.#{@form['table']}.#{s}"), s ]
|
85
85
|
end
|
86
86
|
end
|
87
|
-
t('drgcms.sort') + select('sort', 'sort', choices, { include_blank: true }, { class: 'drgcms_sort', 'data-table' => @form['table']} )
|
87
|
+
t('drgcms.sort')+ ' ' + select('sort', 'sort', choices, { include_blank: true }, { class: 'drgcms_sort', 'data-table' => @form['table']} )
|
88
88
|
|
89
89
|
when action == 'filter' then # filter
|
90
90
|
caption = t('drgcms.filter')
|
@@ -126,6 +126,13 @@ end
|
|
126
126
|
############################################################################
|
127
127
|
def _get_field_div(name) #:nodoc:
|
128
128
|
# field not defined on form. Must be defined: name as form_field_type
|
129
|
+
filter = nil
|
130
|
+
if session[@form['table']] and session[@form['table']][:filter]
|
131
|
+
filter = session[@form['table']][:filter].split("\t")
|
132
|
+
end
|
133
|
+
|
134
|
+
#params[:filter_field], params[:filter_oper], params[:record][params[:filter_field]]
|
135
|
+
|
129
136
|
if name.match(' as ')
|
130
137
|
name, dummy, type = name.split(' ')
|
131
138
|
field = {"name" => name, "type" => type, "html"=>{"size"=>20}}
|
@@ -133,6 +140,14 @@ def _get_field_div(name) #:nodoc:
|
|
133
140
|
field = _get_field_def(name)
|
134
141
|
field = {"name" => name, "type" => 'text_field', "html"=>{"size"=>20}} if field.nil?
|
135
142
|
end
|
143
|
+
#
|
144
|
+
if filter
|
145
|
+
if field['html']
|
146
|
+
field['html']['value'] = filter[2]
|
147
|
+
else
|
148
|
+
field['html'] = {"value"=>filter[2]}
|
149
|
+
end
|
150
|
+
end
|
136
151
|
klas_string = field['type'].camelize
|
137
152
|
klas = DrgcmsFormField::const_get(klas_string)
|
138
153
|
o = klas.new(self, @record, field).render
|
@@ -155,14 +170,16 @@ def dc_div_filter()
|
|
155
170
|
inputs << _get_field_div(f)
|
156
171
|
end
|
157
172
|
choices4_operators = t('drgcms.choices4_filter_operators').chomp.split(',').inject([]) {|r,v| r << (v.match(':') ? v.split(':') : v )}
|
173
|
+
s = session[@form['table']]
|
174
|
+
is_hidden = (s and s[:filter]) ? '' : ' class="div-hidden" '
|
158
175
|
html =<<EOT
|
159
|
-
<div id="drgcms_filter">
|
176
|
+
<div id="drgcms_filter" #{is_hidden}>
|
177
|
+
<table class="dc-menu"><td>
|
160
178
|
#{ form_tag :table => @form['table'], filter: :on, action: :index, method: :post }
|
161
179
|
#{ select(nil, 'filter_field', choices, { include_blank: true}) }
|
162
180
|
#{ select(nil, 'filter_oper', choices4_operators) }
|
163
181
|
#{ inputs }
|
164
|
-
|
165
|
-
<table class="dc-menu">
|
182
|
+
</td>
|
166
183
|
<td class="dc-link-submit dc-animate">#{submit_tag(t('drgcms.filter_on'), :class => 'dc-submit')}</td>
|
167
184
|
<td class="dc-link dc-animate">#{link_to t('drgcms.filter_off'), action: 'index', filter: 'off', :table => @form['table']}</td>
|
168
185
|
</table>
|
@@ -488,7 +505,7 @@ def dc_actions_for_form()
|
|
488
505
|
end
|
489
506
|
# Javascript action
|
490
507
|
when v['type'] == 'script'
|
491
|
-
v['caption'] ||=
|
508
|
+
v['caption'] ||= 'Caption missing!'
|
492
509
|
caption = t("#{v['caption'].downcase}", v['caption'])
|
493
510
|
data = {'request' => 'script', 'script' => v['js']}
|
494
511
|
%Q[<td class="dc-link-ajax dc-animate">#{ link_to(caption, '#', data: data ) }</td>]
|
@@ -578,9 +595,6 @@ end
|
|
578
595
|
# Creates edit form div.
|
579
596
|
############################################################################
|
580
597
|
def dc_fields_for_form()
|
581
|
-
if @form['edit']
|
582
|
-
p "@form['edit']['title'] directive will be depricated. Use edit_title in form directive instead! #{@form['table']}"
|
583
|
-
end
|
584
598
|
html, tabs, tdata = '',[], ''
|
585
599
|
# Only fields defined
|
586
600
|
if (fields = @form['form']['fields'])
|
@@ -140,11 +140,18 @@ end
|
|
140
140
|
# String. HTML code for title.
|
141
141
|
############################################################################
|
142
142
|
def dc_edit_title()
|
143
|
-
|
144
|
-
|
145
|
-
title
|
146
|
-
|
147
|
-
|
143
|
+
title = @form['form']['title']
|
144
|
+
# defined as form:title:edit
|
145
|
+
if title and title['edit']
|
146
|
+
t( title['edit'], title['edit'] )
|
147
|
+
else
|
148
|
+
# concatenate title
|
149
|
+
c = "#{t('drgcms.edit')} : "
|
150
|
+
c << (@form['title'] ? t( @form['title'], @form['title'] ) : t_tablename(@form['table'])) + ' : '
|
151
|
+
title = (title and title['field']) ? title['field'] : @form['form']['edit_title']
|
152
|
+
c << "#{@record[ title ]} : " if title and @record.respond_to?(title)
|
153
|
+
c << @record._id
|
154
|
+
end
|
148
155
|
end
|
149
156
|
|
150
157
|
############################################################################
|
@@ -154,10 +161,16 @@ end
|
|
154
161
|
# String. HTML code for title.
|
155
162
|
############################################################################
|
156
163
|
def dc_new_title()
|
157
|
-
|
158
|
-
|
164
|
+
title = @form['form']['title']
|
165
|
+
# defined as form:title:new
|
166
|
+
if title and title['new']
|
167
|
+
t( title['new'], title['new'] )
|
159
168
|
else
|
160
|
-
|
169
|
+
if @form['table'] == 'dc_dummy'
|
170
|
+
t( @form['title'], @form['title'] )
|
171
|
+
else
|
172
|
+
"#{t('drgcms.new')} : #{t_tablename(@form['table'])}"
|
173
|
+
end
|
161
174
|
end
|
162
175
|
end
|
163
176
|
|
@@ -431,7 +444,9 @@ def t(key, default='')
|
|
431
444
|
if c.class == Hash or c.match( 'translation missing' )
|
432
445
|
c = I18n.t(key, locale: 'en')
|
433
446
|
# Still not found. Return default if set
|
434
|
-
c
|
447
|
+
if c.class == Hash or c.match( 'translation missing' )
|
448
|
+
c = default.blank? ? key : default
|
449
|
+
end
|
435
450
|
end
|
436
451
|
c
|
437
452
|
end
|
@@ -938,4 +953,29 @@ def dc_big_table(key)
|
|
938
953
|
ret
|
939
954
|
end
|
940
955
|
|
956
|
+
########################################################################
|
957
|
+
# Will return html code required for open edit form in iframe. If parameters
|
958
|
+
# are found in url iframe will be initial loaded with url parameters thus
|
959
|
+
# enabling forms load on page display.
|
960
|
+
########################################################################
|
961
|
+
def iframe_edit1()
|
962
|
+
# default_table = params[:table] if default_table.nil?
|
963
|
+
# p params
|
964
|
+
parms = {}
|
965
|
+
ret = if params.size > 2 #and default_table # controller, action, path is minimum
|
966
|
+
parms[:controller] = 'cmsedit'
|
967
|
+
parms[:action] = params[:oper] ? params[:oper] : 'index'
|
968
|
+
parms[:table] = params[:table]
|
969
|
+
parms[:formname] = params[:formname] || params[:table]
|
970
|
+
parms[:id] = params[:idp]
|
971
|
+
p '**************', url_for(parms)
|
972
|
+
"<iframe id='iframe_edit' name='iframe_edit' src='#{url_for parms}'></iframe>"
|
973
|
+
else
|
974
|
+
"<iframe id='iframe_edit' name='iframe_edit'></iframe>"
|
975
|
+
end
|
976
|
+
#bla
|
977
|
+
p ret
|
978
|
+
ret.html_safe
|
979
|
+
end
|
980
|
+
|
941
981
|
end
|
@@ -88,6 +88,15 @@ EOT
|
|
88
88
|
html.html_safe
|
89
89
|
end
|
90
90
|
|
91
|
+
########################################################################
|
92
|
+
# Will return html code required for open edit form in iframe. If parameters
|
93
|
+
# are found in url iframe will be initial loaded with url parameters thus
|
94
|
+
# enabling forms load on page display.
|
95
|
+
########################################################################
|
96
|
+
def iframe_edit()
|
97
|
+
@parent.render(partial: 'dc_common/iframe_edit', formats: [:html])
|
98
|
+
end
|
99
|
+
|
91
100
|
########################################################################
|
92
101
|
# Return HTML part of code.
|
93
102
|
########################################################################
|
@@ -73,17 +73,31 @@ end
|
|
73
73
|
# Returns html code required to create single link in a menu. Subroutine of do_menu_level.
|
74
74
|
########################################################################
|
75
75
|
def link_4menu(item)
|
76
|
-
#
|
77
|
-
|
76
|
+
# prepand to link
|
77
|
+
link = if !item.link_prepend.blank?
|
78
|
+
item.link_prepend
|
79
|
+
elsif !@menu.link_prepend.blank?
|
80
|
+
@menu.link_prepend
|
81
|
+
else
|
82
|
+
''
|
83
|
+
end
|
84
|
+
|
85
|
+
if item.link.match('http')
|
86
|
+
link = item.link
|
87
|
+
else
|
88
|
+
link += (item.link[0] == '/' ? '' : '/') + item.link
|
89
|
+
link = '/' + link unless link[0] == '/' # link should start with '/'
|
90
|
+
end
|
91
|
+
|
78
92
|
target = item.target.blank? ? nil : item.target
|
79
93
|
# - in first place won't write caption text
|
80
94
|
caption = item.caption[0] == '-' ? '' : item.caption.to_s
|
81
95
|
img_title = item.caption.to_s.sub('-','')
|
82
96
|
# add picture if picture is not blank
|
83
97
|
(item.picture.blank? ? '' :
|
84
|
-
@parent.link_to( @parent.image_tag(item.picture),
|
98
|
+
@parent.link_to( @parent.image_tag(item.picture), link, {title: img_title, target: target} )) +
|
85
99
|
(caption.blank? ? '' :
|
86
|
-
@parent.link_to(caption,
|
100
|
+
@parent.link_to(caption, link, {target: target}) )
|
87
101
|
end
|
88
102
|
|
89
103
|
########################################################################
|
@@ -79,19 +79,28 @@ end
|
|
79
79
|
# [item] SimpleMenuItem.
|
80
80
|
########################################################################
|
81
81
|
def link_4menu(item)
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@parent.link_to( @parent.image_tag(item.caption.sub('pic:','')), item.link, {target: target} )
|
82
|
+
# prepand to link
|
83
|
+
link = if !item.link_prepend.blank?
|
84
|
+
item.link_prepend
|
85
|
+
elsif !@menu.link_prepend.blank?
|
86
|
+
@menu.link_prepend
|
88
87
|
else
|
89
|
-
|
90
|
-
caption = item.caption[0] == '-' ? '' : item.caption.to_s
|
91
|
-
img_title = item.caption.to_s.sub('-','')
|
92
|
-
(item.picture.blank? ? '' : @parent.link_to( @parent.image_tag(item.picture), item.link, {title: img_title, target: target} )) +
|
93
|
-
( caption.blank? ? '' : @parent.link_to(caption, item.link, {target: target}))
|
88
|
+
''
|
94
89
|
end
|
90
|
+
|
91
|
+
if item.link.match('http')
|
92
|
+
link = item.link
|
93
|
+
else
|
94
|
+
link += (item.link[0] == '/' ? '' : '/') + item.link
|
95
|
+
link = '/' + link unless link[0] == '/' # link should start with '/'
|
96
|
+
end
|
97
|
+
|
98
|
+
target = item.target.blank? ? nil : item.target
|
99
|
+
# - in first place won't write caption text
|
100
|
+
caption = item.caption[0] == '-' ? '' : item.caption.to_s
|
101
|
+
img_title = item.caption.to_s.sub('-','')
|
102
|
+
(item.picture.blank? ? '' : @parent.link_to( @parent.image_tag(item.picture), link, {title: img_title, target: target} )) +
|
103
|
+
( caption.blank? ? '' : @parent.link_to(caption, link, {target: target}))
|
95
104
|
end
|
96
105
|
|
97
106
|
########################################################################
|
@@ -106,8 +115,7 @@ def as_table
|
|
106
115
|
# use div_name if specified otherwise menu.name
|
107
116
|
div_name = (@menu.div_name.to_s.size > 2 ? @menu.div_name : @menu.name).downcase
|
108
117
|
html << "<table class=\"#{div_name}\"><tr>"
|
109
|
-
#
|
110
|
-
# items = @menu.dc_simple_menu_items.sort {|a,b| a.order <=> b.order}
|
118
|
+
#
|
111
119
|
items = @menu.dc_simple_menu_items.where(active: true).order(order: 1)
|
112
120
|
items.each do |item|
|
113
121
|
# menu can be hidden from user
|
@@ -119,6 +127,28 @@ def as_table
|
|
119
127
|
end
|
120
128
|
html << "</table>"
|
121
129
|
end
|
130
|
+
########################################################################
|
131
|
+
# Renders menu as table. This is single level menu only and uses table elements to
|
132
|
+
# display menu options evenly justified.
|
133
|
+
########################################################################
|
134
|
+
def as_responsive
|
135
|
+
html = link_4edit
|
136
|
+
return "#{html}#{@opts[:name]}<br>Menu not found!" if @menu.nil?
|
137
|
+
#
|
138
|
+
@selected = find_selected
|
139
|
+
klas = @opts[:classes] ? @opts[:classes] : 'small-2 middle-4 large-6 columns'
|
140
|
+
klas << ' columns' unless klas.match('column')
|
141
|
+
klas=''
|
142
|
+
#
|
143
|
+
items = @menu.dc_simple_menu_items.where(active: true).order(order: 1)
|
144
|
+
items.each do |item|
|
145
|
+
# menu can be hidden from user
|
146
|
+
can_view, msg = dc_user_can_view(@parent, item)
|
147
|
+
next unless can_view
|
148
|
+
html << "<li class=\"#{klas}#{(item.id == @selected.id) ? 'selected' : 'item'}\">#{ link_4menu(item) }</li>" #
|
149
|
+
end
|
150
|
+
html
|
151
|
+
end
|
122
152
|
|
123
153
|
########################################################################
|
124
154
|
# Creates menu with single level dropdown menu. This is older version of method which
|