app/helpers/cmsedit_helper.rb in drg_cms-0.5.52.5 vs app/helpers/cmsedit_helper.rb in drg_cms-0.5.52.7
- old
+ new
@@ -46,11 +46,11 @@
actions['standard'] = nil
end
# start div with hidden spinner image
html = <<EOT
<div id="dc-action-menu">
- <span id="dc-spinner" class="div-hidden">#{fa_icon('spinner lg spin')}</span>
+ <span class="dc-spinner div-hidden">#{fa_icon('spinner lg spin')}</span>
<ul class="dc-action-menu">
EOT
# Remove actions settings and sort
only_actions = []
actions.each { |key, value| only_actions << [key, value] if key.class == Integer }
@@ -153,19 +153,18 @@
#{ form_tag :table => @form['table'], filter: :on, filter_input: 1, action: :index, method: :post }
url = url_for(:table => @form['table'], filter: :on, filter_input: 1, action: :index, controller: :cmsedit)
html =<<EOT
<div id="drgcms_filter" class="div-hidden">
<h1>#{t('drgcms.filter_set')}</h1>
- <table class="dc-menu"><td>
+
#{ select(nil, 'filter_field1', options_for_select(choices, field_name), { include_blank: true }) }
#{ select(nil, 'filter_oper', options_for_select(choices4_operators, operators_value)) }
-
- </td>
- <td class="dc-link dc-animate drgcms_popup_submit" data-url="#{url}">#{fa_icon('check-square-o')} #{t('drgcms.filter_on')}</td>
- <td class="dc-link dc-animate">#{dc_link_to('drgcms.filter_off','close', {action: :index, filter: 'off', table: @form['table'], form_name: params['form_name']}) }</td>
- </table>
-</div>
+ <div class="dc-menu">
+ <div class="dc-link dc-animate drgcms_popup_submit" data-url="#{url}">#{fa_icon('check-square-o')} #{t('drgcms.filter_on')}</div>
+ <div class="dc-link dc-animate">#{dc_link_to('drgcms.filter_off','close', {action: :index, filter: 'off', table: @form['table'], form_name: params['form_name']}) }</div>
+ </div>
+ </div>
EOT
html.html_safe
end
############################################################################
@@ -201,22 +200,31 @@
fa_icon(yaml['icon'], rest )
end
end
############################################################################
-# Creates actions that could be performed on single row of result set.
+# Determines actions and width of actions column
############################################################################
-def dc_actions_for_result(document)
+def dc_actions_column()
actions = @form['result_set']['actions']
- return '' if actions.nil? or @form['readonly']
# standard actions
actions = {'standard' => true} if actions.class == String && actions == 'standard'
std_actions = {' 2' => 'edit', ' 3' => 'delete'}
actions.merge!(std_actions) if actions['standard']
#
width = @form['result_set']['actions_width'] || 20*actions.size
- html = "<td style=\"width: #{width}px;\">"
+ [ actions, "<div class=\"actions\" style=\"width: #{width}px;\">" ]
+end
+
+############################################################################
+# Creates actions that could be performed on single row of result set.
+############################################################################
+def dc_actions_for_result(document)
+ actions = @form['result_set']['actions']
+ return '' if actions.nil? or @form['readonly']
+#
+ actions, html = dc_actions_column()
actions.each do |k,v|
session[:form_processing] = "result_set:actions: #{k}=#{v}"
next if k == 'standard' # ignore standard definition
parms = @parms.clone
yaml = v.class == String ? {'type' => v} : v # if single definition simulate type parameter
@@ -257,49 +265,52 @@
dc_link_or_ajax(yaml, parms)
else # error.
yaml['type'].to_s
end
end
- html << '</td>'
+ html << '</div>'
html.html_safe
end
############################################################################
# Creates header div for result set.
############################################################################
def dc_header_for_result()
- c = ''
- actions = @form['result_set']['actions']
- c = '<th> </th>' unless actions.nil? or @form['readonly']
+ html = '<div class="dc-result-header">'
+ if @form['result_set']['actions'] and !@form['readonly']
+ ignore, code = dc_actions_column()
+ html << code + '</div>'
+ end
# preparation for sort icon
sort_field, sort_direction = nil, nil
if session[@form['table']]
sort_field, sort_direction = session[@form['table']][:sort].to_s.split(' ')
end
#
if (columns = @form['result_set']['columns'])
columns.each do |k,v|
session[:form_processing] = "result_set:columns: #{k}=#{v}"
- th = '<th '
- v = {'name' => v} if v.class == String
+#
+ th = %Q[<div class="th" style="width: #{v['width'] || '15%'};text-align: #{v['align'] || 'left'};"]
+ v = {'name' => v} if v.class == String
caption = v['caption'] || t("helpers.label.#{@form['table']}.#{v['name']}")
# no sorting when embedded documents or custom filter is active
sort_ok = @form['result_set'].nil? || (@form['result_set'] && @form['result_set']['filter'].nil?)
sort_ok = sort_ok || (@form['index'] && @form['index']['sort'])
if @tables.size == 1 and sort_ok
icon = 'sort lg'
if v['name'] == sort_field
icon = sort_direction == '1' ? 'sort-alpha-asc lg' : 'sort-alpha-desc lg'
end
- th << ">#{dc_link_to(caption, icon, sort: v['name'], table: params[:table], form_name: params[:form_name], action: :index )}</th>"
+ th << ">#{dc_link_to(caption, icon, sort: v['name'], table: params[:table], form_name: params[:form_name], action: :index, icon_pos: :last )}</div>"
else
- th << ">#{caption}</th>"
+ th << ">#{caption}</div>"
end
- c << th
+ html << "<div class=\"spacer\"></div>" + th
end
end
- c.html_safe
+ (html << '</div>').html_safe
end
############################################################################
# Creates link for single or double click on result column
############################################################################
@@ -345,11 +356,11 @@
############################################################################
# Defines style or class for row (tr) or column (td)
############################################################################
def dc_style_or_class(selector, yaml, value, record)
return '' if yaml.nil?
-# alias record and value so both names can be used
+# alias record and value so both names can be used in eval
field = value
document = record
html = selector ? "#{selector}=\"" : ''
html << if yaml.class == String
yaml
@@ -362,13 +373,13 @@
############################################################################
# Creates tr code for each row of result set.
############################################################################
def dc_row_for_result(document)
- clas = "dc-#{cycle('odd','even')} " + dc_style_or_class(nil,@form['result_set']['tr_class'],nil,document)
- style = dc_style_or_class('style',@form['result_set']['tr_style'],nil,document)
- "<tr class=\"#{clas}\" #{dc_clicks_for_result(document)} #{style}>".html_safe
+ clas = "dc-#{cycle('odd','even')} " + dc_style_or_class(nil, @form['result_set']['tr_class'], nil, document)
+ style = dc_style_or_class('style', @form['result_set']['tr_style'], nil, document)
+ "<div class=\"dc-result-data #{clas}\" #{dc_clicks_for_result(document)} #{style}>".html_safe
end
############################################################################
# Creates column for each field of result set document.
############################################################################
@@ -417,14 +428,23 @@
# error
else
"!!! #{v['name']}"
end
#
- td = '<td '
- td << dc_style_or_class('class',v['td_class'],value,document)
- td << dc_style_or_class('style',v['td_style'] || v['style'],value,document)
- html << "#{td}>#{value}</td>"
+ td = '<div class="spacer"></div><div class="td" '
+ td << dc_style_or_class('class', v['td_class'], value, document)
+
+ width_align = %Q[width: #{v['width'] || '15%'};text-align: #{v['align'] || 'left'};]
+ style = dc_style_or_class('style', v['td_style'] || v['style'], value, document)
+ style = if style.size > 1
+ # remove trailing " add width and add trailing " back
+ style.slice(0..-1) + width_align + '"'
+ else
+ # create style string
+ "style=\"#{width_align}\""
+ end
+ html << "#{td} #{style}>#{value}</div>"
end
html.html_safe
end
############################################################################
@@ -468,11 +488,11 @@
end
end
# Sort so that standard actions come first
actions = actions.to_a.sort {|x,y| x[0].to_s <=> y[0].to_s}
# Add spinner to the beginning
- c = %Q[<td id="dc-spinner" class="div-hidden">#{fa_icon('spinner lg spin')}</td>]
+ c = %Q[<span class="dc-spinner div-hidden">#{fa_icon('spinner lg spin')}</span><ul class="dc-menu">]
actions.each do |element|
session[:form_processing] = "form:actions: #{element}"
v = element[1]
next if v.nil? # yes it happends
@@ -485,11 +505,11 @@
#
parms = @parms.clone
if v.class == String
next if params[:readonly] and !(v == 'back')
- c << '<td class="dc-link dc-animate">'
+ c << '<li class="dc-link dc-animate">'
c << case
when (v == 'back' or v == 'cancle') then
# If return_to is present link directly to URL
if parms['xreturn_to'] # disabled for now
dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
@@ -523,22 +543,22 @@
c << case
# submit button
when v['type'] == 'submit'
caption = v['caption'] || 'drgcms.save'
icon = v['icon'] || 'save'
- '<td class="dc-link-submit dc-animate">' +
+ '<li class="dc-link-submit dc-animate">' +
dc_submit_tag(caption, icon, {:data => v['params'], :title => v['title']}) +
- '</td>'
+ '</li>'
# delete with some sugar added
when v['type'] == 'delete'
parms['id'] = @record.id
parms.merge!(v['params'])
caption = v['caption'] || 'drgcms.delete'
icon = v['icon'] || 'remove'
- '<td class="dc-link dc-animate">' +
+ '<li class="dc-link dc-animate">' +
dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete ) +
- '</td>'
+ '</li>'
# ajax or link button
when v['type'] == 'ajax' || v['type'] == 'link'
parms = {}
# direct url
if v['url']
@@ -554,52 +574,51 @@
# additional parameters
v['params'].each { |k,v| parms[k] = v } if v['params']
end
# Error if controller param is missing
if parms['controller'].nil?
- "<td>#{t('drgcms.error')}</td>"
+ "<li>#{t('drgcms.error')}</li>"
else
v['caption'] ||= v['text']
caption = t("#{v['caption'].downcase}", v['caption'])
url = url_for(parms)
request = v['request'] || v['method'] || 'get'
icon = v['icon'] ? "#{fa_icon(v['icon'])} " : ''
if v['type'] == 'ajax' # ajax button
- %Q[<td class="dc-link-ajax dc-animate" id="dc-submit-ajax" data-url="#{url}"
- data-request="#{request}" title="#{v['title']}">#{icon}#{caption}</td>]
+ %Q[<li class="dc-link-ajax dc-animate" id="dc-submit-ajax" data-url="#{url}"
+ data-request="#{request}" title="#{v['title']}">#{icon}#{caption}</li>]
else # link button
# %Q[<td class="dc-link dc-animate" title="#{v['title']}><a href="#{url}">#{icon}#{caption}</a></td>]
- %Q[<td class="dc-link dc-animate">#{dc_link_to(v['caption'],v['icon'], parms)}</td>]
+ %Q[<li class="dc-link dc-animate">#{dc_link_to(v['caption'],v['icon'], parms)}</li>]
end
end
# Javascript action
when v['type'] == 'script'
# v['caption'] ||= 'Caption missing!'
# caption = t("#{v['caption'].downcase}", v['caption'])
data = {'request' => 'script', 'script' => v['js']}
- %Q[<td class="dc-link-ajax dc-animate">#{ dc_link_to(v['caption'],v['icon'], '#', data: data ) }</td>]
+ %Q[<li class="dc-link-ajax dc-animate">#{ dc_link_to(v['caption'],v['icon'], '#', data: data ) }</li>]
else
- '<td>err2</td>'
+ '<li>err2</li>'
end
end
end
- c.html_safe
+ (c << '</ul>').html_safe
end
############################################################################
# Create background div and table definitions for result set.
############################################################################
def dc_background_for_result(start)
if start == :start
html = '<div class="dc-result-div" '
- html << (@form['result_set']['table_style'] ? "style=\"overflow-x: scroll;\" >" : '>')
- html << "\n"
+ html << (@form['result_set']['table_style'] ? 'style="overflow-x: scroll;" >' : '>')
#
- html << "<table class=\"dc-result #{@form['result_set']['table_class']}\" "
+ html << "\n<div class=\"dc-result #{@form['result_set']['table_class']}\" "
html << (@form['result_set']['table_style'] ? "style=\"#{@form['result_set']['table_style']}\" >" : '>')
else
- html = '</table></div>'
+ html = '</div></div>'
end
html.html_safe
end
############################################################################
@@ -774,31 +793,24 @@
# Creates current document statistics div (created_by, created_at, ....) at the bottom of edit form.
# + lots of more. At the moment also adds icon for dumping current document as json text.
############################################################################
def dc_document_statistics
return '' if @record.new_record? or dc_dont?(@form['form']['info'])
- html = "<div id='dc-document-info'>#{t('drgcms.doc_info')}</div>"
-# html = "<div id='dc-document-info'>#{fa_icon 'info-circle 2x'}</div>"
- html = '<div id="dc-document-info">' + fa_icon('info-circle lg') + '</div>'
+ html = %Q[<div id="dc-document-info">#{fa_icon('info-circle lg')}</div> <div id="dc-document-info-popup" class="div-hidden"> ]
#
- html << "<div id='dc-document-info-popup' class='div-hidden'><table>"
u = _get_user_for('created_by')
- html << "<tr><td>#{t('drgcms.created_by', 'Created by')}: </td><td><b>#{u}</td></tr>" if u
+ html << %Q[<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>] if u
u = _get_user_for('updated_by')
- html << "<tr><td>#{t('drgcms.updated_by', 'Updated by')}: </td><td><b>#{u}</td></tr>" if u
- html << "<tr><td>#{t('drgcms.created_at', 'Created at')}: </td><td><b>#{dc_format_value(@record.created_at)}</td></tr>" if @record['created_at']
- html << "<tr><td>#{t('drgcms.updated_at', 'Updated at')}: </td><td><b>#{dc_format_value(@record.updated_at)}</td></tr>" if @record['updated_at']
- html << '</table>'
-# Copy to clipboard icon
+ html << %Q[<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>] if u
+ html << %Q[<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>] if @record['created_at']
+ html << %Q[<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>] if @record['updated_at']
+# copy to clipboard icon
parms = params.clone
parms[:controller] = 'dc_common'
parms[:action] = 'copy_clipboard'
url = url_for(parms.permit!)
-# caption = image_tag('drg_cms/copy.png', title: t('drgcms.doc_copy_clipboard'))
-# html << %Q[<hr><img class="dc-link-img dc-link-ajax dc-animate" data-url="#{url}" data-request="get" #{caption}]
html << fa_icon('copy 2x', class: 'dc-link-img dc-link-ajax dc-animate',
'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
- (html << '</div>').html_safe
-# html.html_safe
+ (html << '</div></div>').html_safe
end
end