From bd5cf3a66186e2fa9df3bf544566da7257d5e516 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Mon, 6 Oct 2014 14:30:09 +0000 Subject: [PATCH] Abstract core to use standard and replaceable helpers --- app/helpers/application_helper.rb | 18 +++++++++++++----- app/helpers/block_helper.rb | 2 +- app/helpers/categories_helper.rb | 7 +++++-- app/helpers/language_helper.rb | 4 ++-- app/helpers/layout_helper.rb | 5 +++-- app/views/account/login.html.erb | 2 +- app/views/account/login_block.html.erb | 4 +--- app/views/blocks/login_block.html.erb | 2 +- app/views/blocks/profile_info_actions/_community.html.erb | 10 +++++----- app/views/blocks/profile_info_actions/_enterprise.html.erb | 4 ++-- app/views/blocks/profile_info_actions/_join_leave_community.html.erb | 4 +--- app/views/blocks/profile_info_actions/_person.html.erb | 2 +- app/views/box_organizer/_highlights_block.html.erb | 2 +- app/views/comment/_comment_actions.html.erb | 2 +- app/views/favorite_enterprises/index.html.erb | 5 +---- app/views/search/_sellers_form.html.erb | 2 +- app/views/shared/_change_image.html.erb | 2 +- app/views/shared/_select_categories.html.erb | 4 ++-- app/views/shared/_select_subcategories.html.erb | 2 +- app/views/shared/_show_thumbnail.html.erb | 2 +- app/views/tasks/index.html.erb | 2 +- test/test_helper.rb | 15 ++++++++++++--- 22 files changed, 58 insertions(+), 44 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 05bf735..37b73b4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -592,7 +592,7 @@ module ApplicationHelper extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) links = links_for_balloon(profile) content_tag('div', content_tag(tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + @@ -604,6 +604,14 @@ module ApplicationHelper :class => 'vcard'), :class => 'common-profile-list-block') end + def popover_menu(title,menu_title,links,html_options={}) + html_options[:class] = "" unless html_options[:class] + html_options[:class] << " menu-submenu-trigger" + html_options[:onclick] = "toggleSubmenu(this, '#{menu_title}', #{CGI::escapeHTML(links.to_json)}); return false" + + link_to(content_tag(:span, title), '#', html_options) + end + def gravatar_default (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm' end @@ -718,7 +726,7 @@ module ApplicationHelper class NoosferoFormBuilder < ActionView::Helpers::FormBuilder extend ActionView::Helpers::TagHelper - def self.output_field(text, field_html, field_id = nil) + def self.output_field(text, field_html, field_id = nil, options = {}) # try to guess an id if none given if field_id.nil? field_html =~ /id=['"]([^'"]*)['"]/ @@ -1050,7 +1058,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') + - link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger') + popover_menu(_('Contents menu'),'',links,:class => 'up', :id => 'submenu-contents-trigger') end alias :browse_contents_menu :search_contents_menu @@ -1066,7 +1074,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') + - link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger') + popover_menu(_('People menu'),'',links,:class => 'up', :id => 'submenu-people-trigger') end alias :browse_people_menu :search_people_menu @@ -1082,7 +1090,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') + - link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger') + popover_menu(_('Communities menu'),'',links,:class => 'up', :id => 'submenu-communities-trigger') end alias :browse_communities_menu :search_communities_menu diff --git a/app/helpers/block_helper.rb b/app/helpers/block_helper.rb index 55e1d94..a9c0bb6 100644 --- a/app/helpers/block_helper.rb +++ b/app/helpers/block_helper.rb @@ -19,7 +19,7 @@ module BlockHelper content_tag('span', _('Title')) + text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45) } - #{link_to '', '#', :class=>'button icon-button icon-delete delete-highlight', :confirm=>_('Are you sure you want to remove this highlight')} + #{button_without_text(:delete, _('Remove'), '#', class: 'delete-highlight', :confirm=>_('Are you sure you want to remove this highlight'))} " end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index d6aea24..9321a88 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -25,10 +25,13 @@ module CategoriesHelper ) end - def update_categories_link(body, category_id=nil, html_options={}) + #TODO: remove this function and, in views, use existing basic buttons + def update_categories_link(type, body, category_id=nil, html_options={}) + html_class = 'select-subcategory-link' + html_class = " icon-#{type} btn btn-primary btn-xs" if type.present? link_to body, { :action => "update_categories", :category_id => category_id, :id => @object }, - {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options) + {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options) end end diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index 081b637..9f11823 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -1,6 +1,6 @@ module LanguageHelper def language - locale + locale.to_s end def tinymce_language @@ -20,7 +20,7 @@ module LanguageHelper separator = options[:separator] || ' — ' if options[:element] == 'dropdown' - select_tag('lang', + select_tag('lang', options_for_select(locales.map{|code,name| [name, code]}, current), :onchange => "document.location.href= #{url_for(params.merge(:lang => 'LANGUAGE'))}.replace(/LANGUAGE/, this.value) ;", :help => _('The language you choose here is the language used for options, buttons, etc. It does not affect the language of the content created by other users.') diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 283a858..aec2c0b 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -31,12 +31,12 @@ module LayoutHelper plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js) } }.flatten output = '' - output += render :file => 'layouts/_javascript' - output += javascript_tag 'render_all_jquery_ui_widgets()' + output += render 'layouts/javascript' unless plugins_javascripts.empty? output += javascript_include_tag plugins_javascripts, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugins_javascripts.to_s}" end output += theme_javascript_ng.to_s + output += javascript_tag 'render_all_jquery_ui_widgets()' output end @@ -85,6 +85,7 @@ module LayoutHelper end end + def icon_theme_stylesheet_path icon_themes = [] theme_icon_themes = theme_option(:icon_theme) || [] diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index 9fd0cc0..9f3e747 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -7,7 +7,7 @@ <%= @message %> -<%= labelled_form_for :user, :url => login_url do |f| %> +<%= labelled_form_for :user, :url => login_url, :horizontal => true do |f| %> <%= f.text_field :login, :id => 'main_user_login', :onchange => 'this.value = convToValidLogin( this.value )', :value => params[:userlogin] %> diff --git a/app/views/account/login_block.html.erb b/app/views/account/login_block.html.erb index aae8c6b..85ecf78 100644 --- a/app/views/account/login_block.html.erb +++ b/app/views/account/login_block.html.erb @@ -20,9 +20,7 @@ <% button_bar do %> <%= submit_button( 'login', _('Log in') )%> <% unless @plugins.dispatch(:allow_user_registration).include?(false) %> - <%= link_to content_tag( 'span', _('New user') ), - { :controller => 'account', :action => 'signup' }, - :class => 'button with-text icon-add' %> + <%= button(:add, _('New user'), { :controller => 'account', :action => 'signup' }) %> <% end %> <% end %> diff --git a/app/views/blocks/login_block.html.erb b/app/views/blocks/login_block.html.erb index 82dfea6..ed8e1e1 100644 --- a/app/views/blocks/login_block.html.erb +++ b/app/views/blocks/login_block.html.erb @@ -6,7 +6,7 @@
  • <%= link_to _('Homepage'), user.public_profile_url %>
  • - <%= link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout' }, :class => 'button with-text icon-menu-logout' %> + <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %>
    <% else %> diff --git a/app/views/blocks/profile_info_actions/_community.html.erb b/app/views/blocks/profile_info_actions/_community.html.erb index 61392ab..a7fb8e9 100644 --- a/app/views/blocks/profile_info_actions/_community.html.erb +++ b/app/views/blocks/profile_info_actions/_community.html.erb @@ -5,11 +5,11 @@ <% if logged_in? %> <% if profile.enable_contact? %>
  • - <%= link_to content_tag('span', _('Send an e-mail')), - { :profile => profile.identifier, - :controller => 'contact', - :action => 'new' }, - {:class => 'button with-text icon-menu-mail', :title => _('Send an e-mail to the administrators')} %> + <%= button(:'menu-mail', _('Send an e-mail'), + { :profile => profile.identifier, + :controller => 'contact', + :action => 'new' }, + { :title => _('Send an e-mail to the administrators')}) %>
  • <% end %> diff --git a/app/views/blocks/profile_info_actions/_enterprise.html.erb b/app/views/blocks/profile_info_actions/_enterprise.html.erb index 34ada88..0662687 100644 --- a/app/views/blocks/profile_info_actions/_enterprise.html.erb +++ b/app/views/blocks/profile_info_actions/_enterprise.html.erb @@ -1,11 +1,11 @@