Commit 98751743 authored by azul's avatar azul

cleanup: app/helpers/common/ui unused functions

went through all the helpers with < 80% test coverage
and removed all functions that i could not find calls for.
parent 56b5c9ab
module Common::Ui::AssetsHelper
# this is currently unused - assets come in lists now.
def asset_rows
render partial: 'common/assets/asset_as_row',
collection: (@assets || @page.assets)
end
def remove_asset_button(asset, options = {}, html_options = {})
options.reverse_merge!(url: asset_path(asset.id),
method: :delete,
......@@ -14,18 +8,4 @@ module Common::Ui::AssetsHelper
html_options.reverse_merge!(confirm: :destroy_confirmation.t(thing: 'attachment'))
link_to_with_confirm('', options, html_options)
end
def update_cover_asset_checkbox(asset)
checked = asset ? @page.cover == asset : false
opts = {}
unless checked
opts[:onclick] = remote_function(
url: { controller: 'base_page/assets', action: 'update', id: asset.id, page_id: @page.id },
loading: show_spinner('popup'),
complete: hide_spinner('popup')
)
end
radio_button_tag 'cover_id', asset.id, checked, opts
end
end
......@@ -3,50 +3,6 @@
##
module Common::Ui::FormHelper
def option_empty(label = '')
%(<option value=''>#{label}</option>)
end
# DROP DOWN LIST
#
# use this as:
#
# drop_down("Title", {"Option 1" => some_place_path, "Option 2" => "js: alert('hello')"}, optionally_index_for_selected_option)
#
# <label for="select_id">Title</label>
# <select id="select_id">
# <option value="/some/place">Option 1</option>
# <option value="alert('hello')">Option 2</option>
# </select>
#
# Actions happen on the onchange event
#
def drop_down(select_title, items, selected_index = 0)
select_id = "select_#{select_title.gsub(/[^a-zA-Z]+/, '')}"
text_label = content_tag(:label, I18n.t(:view_label), for: select_id) if !select_title.nil? && !select_title.blank?
current_index = 0
options = items.map do |title, perform|
selected = selected_index == current_index ? { selected: 'selected' } : {}
current_index += 1
perform = url_for(perform) if perform.is_a?(Hash)
option_id = "option_#{title.gsub(/[^a-zA-Z]+/, '')}"
value = drop_down_action(perform)
content_tag :option, title, { value: value, id: option_id }.merge(selected)
end.join("\n")
content_tag(:div, text_label + select_tag(select_id, options, onchange: 'javascript: eval(this.options[this.selectedIndex].value)'), id: 'pages_view')
end
def drop_down_action(perform)
if perform =~ /^js\:/
perform.gsub(/^js\:/, '')
else
"window.location = '#{perform}';"
end
end
#
# add a row of radio buttons with labels
# using a similar api to select and select_tag
......
......@@ -69,16 +69,6 @@ module Common::Ui::JavascriptHelper
function
end
##
## dom basics
##
def dom_loaded
concat "document.observe('dom:loaded',function(){"
yield
concat '});'
end
##
## visibility
##
......@@ -114,88 +104,10 @@ module Common::Ui::JavascriptHelper
format("$('%s').show();", spinner_id(id))
end
def activate_panel_row(item, load_url_function)
loader = case load_url_function
when String
load_url_function
when Proc
url = load_url_function.call(item)
remote_function(url: url, method: :get) + ";\n"
else
''
end
loader + "activatePanelRow('#{dom_id(item)}');".html_safe
end
#
# called when a user clicks on a row in a 'sliding list'
# sliding list is currently deprecated
#
def activate_sliding_row(url)
format("window.location.href = '%s'", url)
end
#
# returns a string that will get a prototype extended dom element.
#
def get_dom_element(identifier, context = nil)
case identifier
when ActiveRecord::Base
"$('#{dom_id(identifier, context)}')"
when nil
'$(this)'
when /^\$\(/ # already uses prototype
identifier
when String
"$('#{identifier}')"
end
end
##
## classes
##
def replace_class_name(element_id, old_class, new_class)
if element_id.is_a? String
element_id = "$('" + element_id + "')" if element_id != 'this'
else
element_id = "$('" + dom_id(element_id) + "')"
end
"replaceClassName(#{element_id}, '#{old_class}', '#{new_class}');"
end
def add_class_name(element_id, class_name)
element_id = dom_id(element_id) unless element_id.is_a? String
format("$('%s').addClassName('%s');", element_id, class_name)
end
def remove_class_name(element_id, class_name)
element_id = dom_id(element_id) unless element_id.is_a? String
format("$('%s').removeClassName('%s');", element_id, class_name)
end
##
## MISC
##
def replace_html(element_id, html)
element_id = dom_id(element_id) unless element_id.is_a?(String)
format(%[$('%s').update(%s);], element_id, html.inspect)
end
def dom_loaded_javascript_tag(javascript)
javascript_tag %[
document.observe('dom:loaded', function() {
#{javascript}
})
]
end
def reset_form(id)
"$('#{id}').reset();"
# "Form.getInputs($('#{id}'), 'submit').each(function(x){x.disabled=false}.bind(this));"
end
# submits the named formed and eats the event.
# e.g. :onkeydown => submit_form(x)
def submit_form(id)
......@@ -208,16 +120,6 @@ module Common::Ui::JavascriptHelper
'return(!enterPressed(event));'
end
# used with text input elements that have some value set which acts like help text
# it disappears when user focues on the input
def show_default_value
"if(this.value=='') this.value=this.defaultValue;"
end
def hide_default_value
"if(this.value==this.defaultValue) this.value='';"
end
def focus_form(id)
javascript_tag "Form.focusFirstElement('#{id}');"
end
......
......@@ -4,23 +4,6 @@
module Common::Ui::LinkHelper
##
## FORMS
##
def submit_link(label, options = {})
name = options.delete(:name) || 'commit'
value = options.delete(:value) || label
accesskey = shortcut_key label
onclick = %<submitForm(this, "#{name}", "#{value}");>
if options[:confirm]
onclick = %<if(confirm("#{options[:confirm]}")){#{onclick};}else{return
false;}>
end
%(<span class='#{options[:class]}'><a href='#' onclick='#{onclick}' style
='#{options[:style]}' class='#{options[:class]}' accesskey='#{accesskey}'>#{label}</a></span>).html_safe
end
# looks like a link but is a form so people with no-script can still
# logout.
def logout_link
......@@ -111,11 +94,6 @@ module Common::Ui::LinkHelper
private
def shortcut_key(label)
label.gsub!(/\[(.)\]/, '<u>\1</u>')
/<u>(.)<\/u>/.match(label).to_a[1]
end
def link_char(links)
if links.first.is_a? Symbol
char = links.shift
......
#
# There is a lot of navigation code through crabgrass, done in really different
# ways. This helper is to bring some uniformity and sanity to how we specify
# navigation sidebars, tabs, menus, and sets of links.
#
# label
# icon
# url
# function
# active
module Common::Ui::NavigationHelper
protected
def active_top_nav
current_theme.navigation.root.currently_active_item
end
def breadcrumb_divider
'<span class="divider">&raquo;</span>'.html_safe
end
end
module Common::Ui::PostHelper
def created_date(created, _modified = nil, href = nil)
created_date = friendly_date(created)
link_to_function created_date,
'var parent = this.up("div");
parent.toggleClassName("hide");
parent.siblings().last().toggleClassName("hide")',
href: href, class: 'dotted'
end
def created_modified_date(created, modified = nil, href = nil)
return created_date(created, modified, href) unless modified and (modified > created + 30.minutes)
created_date = friendly_date(created)
......
module Common::Ui::TextHelper
protected
#
# simply makes a string bold. for use with i18n,
# like :created_by_user.t(:user => bold(user.name))
#
def bold(str)
"<b>#{h(str)}</b>".html_safe
end
# convert greencloth marktup to html
def to_html(str)
## FIXME: add 'html_safe' in GreenCloth's to_html instead of here
str.present? ? GreenCloth.new(str).to_html.html_safe : ''
end
def header_with_more(tag, klass, text, more_url = nil)
span = more_url ? ' ' + content_tag(:span, '&bull; ' + link_to((I18n.t(:see_more_link) + ARROW).html_safe, more_url)) : ''
content_tag tag, text + span, class: klass
end
# where is this used? what does it do? not sure where to put it?
# show link with totals for a collection that belongs to an object
def totalize_with_link(object, collection, controller = nil, action = nil)
action ||= 'list'
controller ||= url_for(controller: object.class.name.pluralize.underscore, action: action)
link_if_may(I18n.t(:total, count: collection.size.to_s),
controller, action, object) or
I18n.t(:total, count: collection.size.to_s)
end
#
# Text with a more link
#
# :options[:url] = the url for more link
# :options[:length] = the max lenght to display
#
def text_with_more(text, options = {})
length = options[:length] || 50
omission = options[:omission] || '... '
if options[:url]
link = link_to((' ' + I18n.t(:see_more_link) + ARROW).html_safe, options[:url])
else
link = ''
end
truncate(text, length: length, omission: omission + link)
end
end
......@@ -5,45 +5,6 @@
#
module Common::Ui::ThemeHelper
##
## COLUMN LAYOUT
##
#
# returns the width, in pixels, of the sidecolumn.
#
def sidecolumn_width
@sidecolumn_width ||= begin
current_theme.columns_width(current_theme.local_sidecolumn_width)
end
end
#
# returns the width, in pixels, of the inside of the sidecolumn,
# assuming the application of local_content_padding.
#
def sidecolumn_inside_width
@sidecolumn_inside_width ||= begin
sidecolumn_width - 2 * current_theme.resolve_width(current_theme.local_content_padding)
end
end
##
## BANNER
##
def banner_width
@banner_width ||= begin
current_theme.columns_width(current_theme.grid_column_count)
end
end
def banner_height
@banner_height ||= begin
current_theme.int_var(:banner_padding) * 2 + current_theme.int_var(:icon_large) + 4
end
end
def link_to_banner_title(entity)
link_to_entity(entity, class: 'title', format: :full)
end
......
-#
-#
-# THIS IS DEPRECATED AND NOT CURRENTLY USED
-#
-# display a fancy clickable sliding list
-#
-# requires:
-# items -- e.g. '@reqs'
-# path_method -- e.g. 'request_path'
-#
-# optional:
-# header -- html that goes in the left panel, above the list itself.
-#
- items_name = items.sub('@','')
- item_name = items_name.singularize.to_sym
- @items = eval(items)
.sliding-list-clip
#sliding-list
.left-panel
= local_assigns[:header]
%ul.clickable.round
- @items.each do |item|
%li{onmousedown: activate_sliding_row(self.send(path_method, item)), class: (once?(:clickable) ? 'first round-top' : '')}
= render partial, item_name => item
.p.last= local_assigns[:footer]
.right-panel
#sliding-item
= big_spinner
-#
-# required local assigns:
-#
-# :items -- the name of a variable, like @reqs, to list in the split panel.
-# it must NOT be empty.
-# :left_panel --
-# :right_panel --
-# :right_url --
-#
- items_name = items.sub('@','')
- item_name = items_name.singularize.to_sym
- @items = eval(items)
- right_panel = local_assigns[:right_panel]
- load_url = local_assigns[:load_url]
- current = local_assigns[:current] || @items.first
.split_panel
.panel_left
- for item in @items
.big_screen
.panel_arrow[item, :panel_arrow]
.row[item, :panel_left]{onmousedown:activate_panel_row(item, load_url)}
.content
= render left_panel, item_name => item
.panel_right
- for item in @items
.row[item, :panel_right]{ style: 'display:none'}
- if right_panel
= render right_panel, item_name => item
- else
= big_spinner
- content_for :dom_loaded do
= activate_panel_row(current, load_url)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment