app/helpers/cmsedit_helper.rb in drg_cms-0.6.0.1 vs app/helpers/cmsedit_helper.rb in drg_cms-0.6.0.3
- old
+ new
@@ -204,13 +204,13 @@
# Creates title div for cmsedit index result set records. Title div also includes paging
# options.
############################################################################
def dc_table_title_for_result(result=nil)
title = if @form['title'] # form has title section
- t(@form['title'],@form['title'])
+ t(@form['title'], @form['title'])
else # get name from translations
- t('helpers.label.' + @form['table'] + '.tabletitle', @form['table'])
+ t("helpers.label.#{@form['table']}.tabletitle", @form['table'])
end
dc_table_title(title, result)
end
############################################################################
@@ -279,10 +279,11 @@
parms['action'] = 'create'
dc_link_to( nil, 'copy lg', parms, data: { confirm: t('drgcms.confirm_dup') }, method: :post )
when yaml['type'] == 'delete' then
parms['action'] = 'destroy'
parms['id'] = document.id
+ parms['return_to'] = request.url
dc_link_to( nil, 'remove lg', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
# undocumented so far
when yaml['type'] == 'edit_embedded'
parms['controller'] = 'cmsedit'
parms['table'] += ";#{yaml['table']}"
@@ -550,11 +551,10 @@
actions.each do |element|
session[:form_processing] = "form:actions: #{element}"
v = element[1]
next if v.nil? # yes it happends
- p "Using text option in actions_for form is replaced with caption. Table #{@form['table']}" if v['text']
# on_save_ok should't go inside td tags
if (element[0] == 'on_save_ok') then
c << hidden_field_tag(:on_save_ok, v)
next
end
@@ -637,13 +637,14 @@
parms['table'] = v['table']
parms['form_name'] = v['form_name']
end
# add current id to parameters
parms['id'] = dc_document_path(@record)
- # additional parameters
+ # overwrite with or add additional parameters when params defined
v['params'].each { |k,v| parms[k] = dc_value_for_parameter(v) } if v['params']
- # Error if controller parameter is missing
+ parms['table'] = parms['table'].underscore if parms['table'] # might be CamelCase
+ # error if controller parameter is missing
if parms['controller'].nil?
"<li>#{t('drgcms.error')}</li>"
else
v['caption'] ||= v['text']
caption = t("#{v['caption'].downcase}", v['caption'])
@@ -716,11 +717,11 @@
end
############################################################################
# Creates top or bottom horizontal line on form.
############################################################################
-def top_bottom_line(yaml, columns=2)
+def top_bottom_line(options)
'<div class="dc-separator"></div>'
end
############################################################################
# Creates input fields for one tab. Subroutine of dc_fields_for_form.
@@ -747,12 +748,13 @@
if options['type'] == 'hidden_field'
hidden_fields << DrgcmsFormFields::HiddenField.new(self, @record, options).render
next
end
# label
- text = if options['text']
- t(options['text'], options['text'])
+ caption = options['caption'] || options['text']
+ label = if !caption.blank?
+ t(caption, caption)
elsif options['name']
t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
end
# help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
help = if options['help']
@@ -780,21 +782,21 @@
end
#
html << if labels_pos == 'top'
%Q[
<div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
- <label for="record_#{options['name']}">#{text} </label>
+ <label for="record_#{options['name']}">#{label} </label>
<div id="td_record_#{options['name']}">#{field_html}</div>
</div> ]
else
label_width = 14
# less place for label when more then 1 field per row
label_width = 10 if group_option > 1 and group_option != group_count
data_width = (94 - 10*group_option)/group_option
%Q[
<div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos}" style="width:#{label_width}%;" title="#{help}">
- <label for="record_#{options['name']}">#{text} </label>
+ <label for="record_#{options['name']}">#{label} </label>
</div>
<div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even}" style="width:#{data_width}%;">#{field_html}</div>
]
end
# check if must go to next row
@@ -807,44 +809,47 @@
############################################################################
# Creates edit form div.
############################################################################
def dc_fields_for_form()
- html, tabs, tdata = '',[], ''
+ html, tabs, tab_data = '',[], ''
# Only fields defined
if (form_fields = @form['form']['fields'])
html << "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
html << dc_fields_for_tab(form_fields) + '</div>'
else
# there are multiple tabs on form
first = true # first tab
- @form['form']['tabs'].keys.sort.each do |tabname|
- next if tabname.match('actions')
+ @form['form']['tabs'].keys.sort.each do |tab_name|
+ next if tab_name.match('actions')
# Tricky. If field name is not on the tab skip to next tab
if params[:edit_only]
is_on_tab = false
- @form['form']['tabs'][tabname].each {|k,v| is_on_tab = true if params[:edit_only] == v['name'] }
+ @form['form']['tabs'][tab_name].each {|k,v| is_on_tab = true if params[:edit_only] == v['name'] }
next unless is_on_tab
end
-# first div is displayed all other are hidden
- tdata << "<div id='data_#{tabname.delete("\s\n")}'"
- tdata << ' class="div-hidden"' unless first
- tdata << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
- tdata << ">#{dc_fields_for_tab(@form['form']['tabs'][tabname])}</div>"
- tabs << tabname
+# first div is displayed, all others are hidden
+ tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
+ tab_data << ' class="div-hidden"' unless first
+ tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
+ tab_data << ">#{dc_fields_for_tab(@form['form']['tabs'][tab_name])}</div>"
+ tab_label = @form['form']['tabs'][tab_name]['caption'] || tab_name
+ tabs << [tab_name, tab_label]
first = false
end
# make it all work together
html << '<ul class="dc-form-ul" >'
first = true # first tab must be selected
- tabs.each do |tab|
- html << "<li id='li_#{tab}' data-div='#{tab.delete("\s\n")}' class='dc-form-li #{'dc-form-li-selected' if first }'>#{t_name(tab, tab)}</li>"
+ tabs.each do |tab_name, tab_label|
+ html << "<li id=\"li_#{tab_name}\" data-div=\"#{tab_name.delete("\s\n")}\" class=\"dc-form-li"
+ html << ' dc-form-li-selected' if first
+ html << "\">#{t(tab_label, t_name(tab_label))}</li>"
first = false
end
html << '</ul>'
- html << tdata
+ html << tab_data
end
- # add last_updated_at hidden field so controller can check if record was updated in during editing
+ # add last_updated_at hidden field so controller can check if record was updated in db during editing
html << hidden_field(nil, :last_updated_at, value: @record.updated_at.to_i) if @record.respond_to?(:updated_at)
# add form time stamp to prevent double form submit
html << hidden_field(nil, :form_time_stamp, value: Time.now.to_i)
html.html_safe
end