From 54c2e24359b490712e25a4a90aa01e5d38665838 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Wed, 17 Jun 2015 13:30:52 -0300 Subject: [PATCH] responsive: add some helpers and improve form helpers --- plugins/responsive/lib/ext/application_helper.rb | 2 ++ plugins/responsive/lib/ext/chat_helper.rb | 41 +++++++++++++++++++++++++++++++++++++++++ plugins/responsive/lib/ext/form_builder.rb | 8 ++++++-- plugins/responsive/lib/ext/forms_helper.rb | 20 ++++++++++++++------ plugins/responsive/lib/responsive_helper.rb | 3 +++ plugins/responsive/views/layouts/_profile_title.html.erb | 2 +- plugins/responsive/views/templates/_boxes_2leftbars.html.erb | 4 ++-- 7 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 plugins/responsive/lib/ext/chat_helper.rb create mode 100644 plugins/responsive/lib/responsive_helper.rb diff --git a/plugins/responsive/lib/ext/application_helper.rb b/plugins/responsive/lib/ext/application_helper.rb index ce49ff1..0346968 100644 --- a/plugins/responsive/lib/ext/application_helper.rb +++ b/plugins/responsive/lib/ext/application_helper.rb @@ -251,6 +251,8 @@ module ApplicationHelper #control_panel link output += '
  • ' + link_to('' + _('Control panel') + '', user.admin_url, class: 'ctrl-panel', title: _("Configure your personal account and content")) + '
  • ' + output += chat_user_status_menu('icon-menu-offline', _('Offline')) + #manage_enterprises manage_enterprises_str = manage_enterprises output += manage_enterprises_str.present? ? '
  • ' + manage_enterprises_str + '
  • ' : '' diff --git a/plugins/responsive/lib/ext/chat_helper.rb b/plugins/responsive/lib/ext/chat_helper.rb new file mode 100644 index 0000000..87f49ec --- /dev/null +++ b/plugins/responsive/lib/ext/chat_helper.rb @@ -0,0 +1,41 @@ +require_dependency 'chat_helper' +require_relative 'application_helper' + +module ChatHelper + + extend ActiveSupport::Concern + protected + + module ResponsiveMethods + + def chat_user_status_menu icon_class, status + return super unless theme_responsive? + + links = [ + ['icon-menu-online', _('Online'), 'chat-connect'], + ['icon-menu-busy', _('Busy'), 'chat-busy'], + ['icon-menu-offline', _('Sign out of chat'), 'chat-disconnect'], + ] + tag(:li, class: 'divider') + content_tag(:li, _('Chat'), class: 'dropdown-header') + + links.map do |link| + content_tag :li, + link_to(content_tag(:i, nil, class: link[0]) + content_tag(:strong, link[1]), '#', id: link[2], 'data-jid' => user.jid) + end.join + end + end + + include ResponsiveChecks + included do + include ResponsiveMethods + end + + protected + +end + +module ApplicationHelper + + include ChatHelper::ResponsiveMethods + +end + diff --git a/plugins/responsive/lib/ext/form_builder.rb b/plugins/responsive/lib/ext/form_builder.rb index 66e3fd3..b9900cb 100644 --- a/plugins/responsive/lib/ext/form_builder.rb +++ b/plugins/responsive/lib/ext/form_builder.rb @@ -1,10 +1,14 @@ class ResponsiveFormBuilder < ActionView::Helpers::FormBuilder - %w[file_field text_field text_area password_field submit button].each do |method| + %w[file_field text_field text_area number_field password_field].each do |method| define_method method do |*args, &block| options = args.extract_options! - options[:class] = "#{options[:class]} form-control" + if options['class'] + options['class'] = "#{options['class']} form-control" + else + options[:class] = "#{options[:class]} form-control" + end super(*(args << options), &block) end end diff --git a/plugins/responsive/lib/ext/forms_helper.rb b/plugins/responsive/lib/ext/forms_helper.rb index e8dfbac..d0e753d 100644 --- a/plugins/responsive/lib/ext/forms_helper.rb +++ b/plugins/responsive/lib/ext/forms_helper.rb @@ -9,7 +9,7 @@ module FormsHelper module ResponsiveMethods # add -inline class - def labelled_radio_button( human_name, name, value, checked = false, options = {} ) + def labelled_radio_button human_name, name, value, checked = false, options = {} return super unless theme_responsive? options[:id] ||= 'radio-' + FormsHelper.next_id_number @@ -18,7 +18,7 @@ module FormsHelper end # add -inline class - def labelled_check_box( human_name, name, value = "1", checked = false, options = {} ) + def labelled_check_box human_name, name, value = "1", checked = false, options = {} return super unless theme_responsive? options[:id] ||= 'checkbox-' + FormsHelper.next_id_number @@ -26,7 +26,7 @@ module FormsHelper content_tag( 'label', check_box_tag( name, value, checked, options ) + ' ' + human_name, for: options[:id], class: 'checkbox-inline') end - def submit_button(type, label, html_options = {}) + def submit_button type, label, html_options = {} return super unless theme_responsive? bt_cancel = html_options[:cancel] ? button(:cancel, _('Cancel'), html_options[:cancel]) : '' @@ -48,18 +48,26 @@ module FormsHelper bt_submit + bt_cancel end - %w[select select_tag text_field_tag password_field_tag].each do |method| + %w[select select_tag text_field_tag number_field_tag password_field_tag].each do |method| define_method method do |*args, &block| #return super(*args, &block) unless theme_responsive? options = args.extract_options! - options[:class] = "#{options[:class]} form-control" + if options['class'] + options['class'] = "#{options['class']} form-control" + else + options[:class] = "#{options[:class]} form-control" + end super(*(args << options), &block) end end %w[select_month select_year].each do |method| define_method method do |date, options={}, html_options={}| - html_options[:class] = "#{html_options[:class]} form-control" + if html_options['class'] + html_options['class'] = "#{html_options['class']} form-control" + else + html_options[:class] = "#{html_options[:class]} form-control" + end super date, options, html_options end end diff --git a/plugins/responsive/lib/responsive_helper.rb b/plugins/responsive/lib/responsive_helper.rb new file mode 100644 index 0000000..5b4aacb --- /dev/null +++ b/plugins/responsive/lib/responsive_helper.rb @@ -0,0 +1,3 @@ +module ResponsiveHelper + +end diff --git a/plugins/responsive/views/layouts/_profile_title.html.erb b/plugins/responsive/views/layouts/_profile_title.html.erb index 8d90008..0f98504 100644 --- a/plugins/responsive/views/layouts/_profile_title.html.erb +++ b/plugins/responsive/views/layouts/_profile_title.html.erb @@ -1,4 +1,4 @@ -
    +

    <%= profile.short_name %> diff --git a/plugins/responsive/views/templates/_boxes_2leftbars.html.erb b/plugins/responsive/views/templates/_boxes_2leftbars.html.erb index 3afbd4a..5e51847 100644 --- a/plugins/responsive/views/templates/_boxes_2leftbars.html.erb +++ b/plugins/responsive/views/templates/_boxes_2leftbars.html.erb @@ -5,12 +5,12 @@

    <% end %> <% if box = boxes[1] %> -
    +
    <%= display_box_content box, main_content %>
    <% end %> <% if box = boxes[2] %> -
    +
    <%= display_box_content box, main_content %>
    <% end %> -- libgit2 0.21.2