summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-05-30 18:02:20 +0200
committerazul <azul@leap.se>2014-05-30 18:02:20 +0200
commit9f04e4c8e50f1dc5a7ff6f2e58974254731a6bc4 (patch)
tree84db71a6e52c47bc2f2f1aabce578ce367fcb0e8 /app
parent568a5c243f0a0ef90807c96b19643ec341994bbb (diff)
parent9e3be686ff2751707369894382293924420830d0 (diff)
Merge pull request #167 from azul/feature/i18n-for-ticket-system0.5.2-rc
Feature/i18n for ticket system
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb10
-rw-r--r--app/controllers/controller_extension/flash.rb43
-rw-r--r--app/helpers/application_helper.rb3
-rw-r--r--app/helpers/link_helper.rb49
-rw-r--r--app/views/common/_action_buttons.html.haml12
-rw-r--r--app/views/common/_download_button.html.haml4
-rw-r--r--app/views/common/_home_page_buttons.html.haml4
-rw-r--r--app/views/errors/not_found.html.haml6
-rw-r--r--app/views/errors/server_error.html.haml6
-rw-r--r--app/views/layouts/_header.html.haml4
-rw-r--r--app/views/layouts/_messages.html.haml2
-rw-r--r--app/views/layouts/_navigation.html.haml2
-rw-r--r--app/views/pages/pricing.html.haml2
-rw-r--r--app/views/pages/terms-of-service.en.md4
-rw-r--r--app/views/users/_destroy_account.html.haml6
-rw-r--r--app/views/users/_overview.html.haml24
-rw-r--r--app/views/users/new.html.haml2
-rw-r--r--app/views/users/show.html.haml37
18 files changed, 151 insertions, 69 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 35d6cb4..a4560e2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -23,16 +23,6 @@ class ApplicationController < ActionController::Base
json: {error: "The server failed to process your request. We'll look into it."}
end
- #
- # Allows us to pass through bold text to flash messages. See format_flash() for where this is reversed.
- #
- # TODO: move to core
- #
- def bold(str)
- "[b]#{str}[/b]"
- end
- helper_method :bold
-
##
## LOCALE
##
diff --git a/app/controllers/controller_extension/flash.rb b/app/controllers/controller_extension/flash.rb
new file mode 100644
index 0000000..1642141
--- /dev/null
+++ b/app/controllers/controller_extension/flash.rb
@@ -0,0 +1,43 @@
+module ControllerExtension::Flash
+ extend ActiveSupport::Concern
+
+ protected
+
+ def flash_for(resource, options = {})
+ return unless resource.changed?
+ add_flash_message_for resource
+ add_flash_errors_for resource if options[:with_errors]
+ end
+
+ def add_flash_message_for(resource)
+ message = flash_message_for(resource)
+ type = flash_type_for(resource)
+ if message.present?
+ flash[type] = message
+ end
+ end
+
+ def flash_message_for(resource)
+ I18n.t flash_i18n_key(resource),
+ scope: :flash,
+ cascade: true,
+ resource: resource.class.model_name.human
+ end
+
+ def flash_i18n_key(resource)
+ namespace = [action_name]
+ namespace += controller_path.split('/')
+ namespace << flash_type_for(resource)
+ namespace.join(".")
+ end
+
+ def flash_type_for(resource)
+ resource.valid? ? :success : :error
+ end
+
+ def add_flash_errors_for(resource)
+ return if resource.valid?
+ flash[:error] += "<br>"
+ flash[:error] += resource.errors.full_messages.join(". <br>")
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 90e649a..6de5e1b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -40,8 +40,9 @@ module ApplicationHelper
end
end
+ # fairly strict sanitation for flash messages
def format_flash(msg)
- html_escape(msg).gsub('[b]', '<b>').gsub('[/b]', '</b>').html_safe
+ sanitize(msg, tags: %w(em strong b br), attributes: [])
end
end
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb
new file mode 100644
index 0000000..55e392b
--- /dev/null
+++ b/app/helpers/link_helper.rb
@@ -0,0 +1,49 @@
+module LinkHelper
+
+ #
+ # markup for bootstrap button
+ #
+ # takes same arguments as link_to and adds a 'btn' class.
+ # In addition:
+ # * the name will be translated if it is a symbol
+ # * html_options[:type] will be converted into a btn-type class
+ #
+ # example:
+ # btn :home, home_path, type: [:large, :primary]
+ #
+ def btn(*args, &block)
+ html_options = extract_html_options!(args, &block)
+ type = Array(html_options.delete(:type))
+ type.map! {|t| "btn-#{t}"}
+ html_options[:class] = concat_classes(html_options[:class], 'btn', type)
+ args[0] = t(args[0]) if args[0].is_a?(Symbol)
+ link_to *args, html_options, &block
+ end
+
+ def destroy_btn(*args, &block)
+ html_options = extract_html_options!(args, &block)
+ confirmation = t "#{controller_symbol}.confirm.destroy.are_you_sure",
+ cascade: true
+ html_options.merge! method: :delete, confirm: confirmation
+ btn *args, html_options, &block
+ end
+
+ #
+ # concat_classes will combine classes in a fairly flexible way.
+ # it can handle nil, arrays, space separated strings
+ # it returns a space separated string of classes.
+ def concat_classes(*classes)
+ classes.compact!
+ classes.map {|c| c.respond_to?(:split) ? c.split(' ') : c }
+ classes.flatten!
+ classes.join ' '
+ end
+
+ def extract_html_options!(args)
+ if args.count > 2 or args.count > 1 && block_given?
+ args.extract_options!
+ else
+ {}
+ end
+ end
+end
diff --git a/app/views/common/_action_buttons.html.haml b/app/views/common/_action_buttons.html.haml
index c74fcd1..266abe1 100644
--- a/app/views/common/_action_buttons.html.haml
+++ b/app/views/common/_action_buttons.html.haml
@@ -1,11 +1,11 @@
.home-buttons
.row-fluid.second
.login.span4
- %span.link= link_to(icon('ok-sign', icon_color) + t(:login), login_path, :class => 'btn')
- %span.info= t(:login_info)
+ %span.link= btn icon('ok-sign') + t(:login), login_path
+ %span.info= t(:login_info, default: "")
.signup.span4
- %span.link= link_to(icon('user', icon_color) + t(:signup), signup_path, :class => 'btn')
- %span.info= t(:signup_info)
+ %span.link= btn icon('user') + t(:signup), signup_path
+ %span.info= t(:signup_info, default: "")
.help.span4
- %span.link= link_to(icon('question-sign', icon_color) + t(:get_help), new_ticket_path, :class => 'btn')
- %span.info= t(:help_info)
+ %span.link= btn icon('question-sign') + t(:get_help), new_ticket_path
+ %span.info= t(:support_info, default: "")
diff --git a/app/views/common/_download_button.html.haml b/app/views/common/_download_button.html.haml
index e57c56b..9c26860 100644
--- a/app/views/common/_download_button.html.haml
+++ b/app/views/common/_download_button.html.haml
@@ -2,7 +2,7 @@
.row-fluid.first
.span2
.download.span8
- = link_to client_download_url, class: "btn btn-large btn-primary" do
+ = btn client_download_url, type: [:large, :primary] do
= big_icon('download')
- = t(:download_client)
+ = t(:download_bitmask)
.span2
diff --git a/app/views/common/_home_page_buttons.html.haml b/app/views/common/_home_page_buttons.html.haml
index 8c47983..fc6348e 100644
--- a/app/views/common/_home_page_buttons.html.haml
+++ b/app/views/common/_home_page_buttons.html.haml
@@ -1,8 +1,6 @@
-- icon_color = :black
-
= render 'common/download_button'
- if local_assigns[:divider]
.row-fluid
.span12
= render local_assigns[:divider]
-= render 'common/action_buttons', icon_color: icon_color
+= render 'common/action_buttons'
diff --git a/app/views/errors/not_found.html.haml b/app/views/errors/not_found.html.haml
index 75cb889..c7fec22 100644
--- a/app/views/errors/not_found.html.haml
+++ b/app/views/errors/not_found.html.haml
@@ -1,7 +1,7 @@
.hero-unit
- %h1=t :not_found_title
- %h2=t :not_found_subtitle
- %p.lead=t :not_found_lead
+ %h1=t 'errors.title.page_not_found'
+ %h2=t 'errors.subtitle.page_not_found', default: ''
+ %p.lead=t 'errors.text.page_not_found', default: ''
%a.btn.btn-primary.btn-large{href:'/'}
%i.icon-home.icon-white
=t :home
diff --git a/app/views/errors/server_error.html.haml b/app/views/errors/server_error.html.haml
index 68baf20..a4133da 100644
--- a/app/views/errors/server_error.html.haml
+++ b/app/views/errors/server_error.html.haml
@@ -1,7 +1,7 @@
.hero-unit
- %h1=t :server_error_title
- %h2=t :server_error_subtitle
- %p.lead=t :server_error_lead
+ %h1=t 'errors.title.server_error'
+ %h2=t 'errors.subtitle.server_error', default: ''
+ %p.lead=t 'errors.text.server_error', default: ''
%a.btn.btn-primary.btn-large{href:'/'}
%i.icon-home.icon-white
=t :home
diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml
index a1dd47a..e827f60 100644
--- a/app/views/layouts/_header.html.haml
+++ b/app/views/layouts/_header.html.haml
@@ -2,9 +2,9 @@
%ul.nav.nav-tabs
= # this navigation isn't quite right. also, we will want to active for an identity controller once it is added.
%li{:class => ("active" if controller?('users', 'overviews') || params[:user_id])}
- = link_to t(:users), users_path
+ = link_to t(".users"), users_path
%li{:class => ("active" if controller?('tickets') && !params[:user_id])}
- = link_to t(:tickets), tickets_path
+ = link_to t(".tickets", cascade: true), tickets_path
%li
= link_to t(:logout), logout_path, :method => :delete
- if @user && @show_navigation
diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml
index 7ff985f..18be54f 100644
--- a/app/views/layouts/_messages.html.haml
+++ b/app/views/layouts/_messages.html.haml
@@ -1,6 +1,6 @@
#messages
- flash.each do |name, msg|
- if msg.is_a?(String)
- %div{:class => "alert alert-#{name == :notice ? "success" : "error"}"}
+ %div{:class => "alert alert-#{name == :notice ? "success" : name}"}
%a.close{"data-dismiss" => "alert"} ×
= content_tag :div, format_flash(msg), :id => "flash_#{name}"
diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml
index b81c43d..94f71f7 100644
--- a/app/views/layouts/_navigation.html.haml
+++ b/app/views/layouts/_navigation.html.haml
@@ -2,6 +2,6 @@
= link_to_navigation t(:overview), @user, :active => (controller?(:users) && action?(:show))
= link_to_navigation t(:account_settings), edit_user_path(@user), :active => (controller?(:users) && !action?(:show))
- # will want link for identity settings
- = link_to_navigation t(:support_tickets), auto_tickets_path, :active => controller?(:tickets)
+ = link_to_navigation t(".tickets"), auto_tickets_path, :active => controller?(:tickets)
= link_to_navigation t(:billing_settings), billing_top_link(@user), :active => controller?(:customer, :payments, :subscriptions, :credit_card_info) if APP_CONFIG[:billing]
= link_to_navigation t(:logout), logout_path, :method => :delete
diff --git a/app/views/pages/pricing.html.haml b/app/views/pages/pricing.html.haml
index e339d27..983501e 100644
--- a/app/views/pages/pricing.html.haml
+++ b/app/views/pages/pricing.html.haml
@@ -1,5 +1,5 @@
%h1= t(:pricing)
-%p= link_to(icon('user') + t(:signup), signup_path, :class => 'btn')
+%p= btn icon('user') + t(:signup), signup_path
- levels = APP_CONFIG[:service_levels]
- if levels
diff --git a/app/views/pages/terms-of-service.en.md b/app/views/pages/terms-of-service.en.md
index 7b57027..93490b7 100644
--- a/app/views/pages/terms-of-service.en.md
+++ b/app/views/pages/terms-of-service.en.md
@@ -3,8 +3,8 @@
This document is our Terms of Service, which describes what activities are allowed, under what conditions we may terminate your account, and asserts our limited liability. It applies to all interactions with **<%=APP_CONFIG[:domain]%>**. Your use of **<%=APP_CONFIG[:domain]%>** services will constitute your agreement to these Terms of Service.
<p class="alert alert-info">
- <b>Summary:</b><br/>
- (1) If you do anything truly evil, we will terminate your account.<br/>
+ <b>Summary:</b><br>
+ (1) If you do anything truly evil, we will terminate your account.<br>
(2) We are not liable for any damages related to the use of this service.
</p>
diff --git a/app/views/users/_destroy_account.html.haml b/app/views/users/_destroy_account.html.haml
index 445f3c4..a2c4ddd 100644
--- a/app/views/users/_destroy_account.html.haml
+++ b/app/views/users/_destroy_account.html.haml
@@ -8,20 +8,20 @@
- else
= t(:admin_destroy_account, :username => @user.login)
%p= t(:destroy_account_info)
-= link_to user_path(@user), :method => :delete, :confirm => t(:are_you_sure), :class => "btn btn-danger" do
+= destroy_btn user_path(@user), :type => "danger" do
%i.icon-remove.icon-white
= t(:destroy_my_account)
- if @user != current_user and @user.enabled?
%legend
= t(:deactivate_account, :username => @user.login)
%p= t(:deactivate_description)
- = link_to deactivate_user_path(@user), :method => :post, :class => "btn btn-warning" do
+ = btn deactivate_user_path(@user), :method => :post, :type => "warning" do
%i.icon-pause.icon-white
= t(:deactivate)
- elsif @user != current_user and !@user.enabled?
%legend
= t(:enable_account, :username => @user.login)
%p= t(:enable_description)
- = link_to enable_user_path(@user), :method => :post, :class => "btn btn-warning" do
+ = btn enable_user_path(@user), :method => :post, :type => "warning" do
%i.icon-ok.icon-white
= t(:enable)
diff --git a/app/views/users/_overview.html.haml b/app/views/users/_overview.html.haml
new file mode 100644
index 0000000..e38fdc8
--- /dev/null
+++ b/app/views/users/_overview.html.haml
@@ -0,0 +1,24 @@
+.overview
+
+ %h2.first= t(".welcome", username: @user.login, cascade: true)
+
+ - if admin?
+ %p
+ = t(:created)
+ = @user.created_at
+ %br
+ = t(:updated)
+ = @user.updated_at
+ %br
+ = t(:enabled)
+ = @user.enabled?
+
+ %p= t(:overview_intro, default: "")
+
+ %ul.unstyled
+ %li= icon('user') + link_to(t(".account"), edit_user_path(@user))
+ - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly}
+ %li= icon('question-sign') + link_to(t(".tickets"), user_tickets_path(@user))
+ %li= icon('shopping-cart') + link_to(t(".billing"), billing_top_link(@user)) if APP_CONFIG[:billing]
+
+
diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml
index bc36068..41a9d55 100644
--- a/app/views/users/new.html.haml
+++ b/app/views/users/new.html.haml
@@ -17,5 +17,5 @@
= f.input :login, :label => t(:username), :required => false, :input_html => { :id => :srp_username }
= f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password }
= f.input :password_confirmation, :required => false, :validate => true, :input_html => { :id => :srp_password_confirmation }
- = f.button :wrapped, value: t(:signup), cancel: home_path
+ = f.button :wrapped, cancel: home_path
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index ddc33ab..da8e467 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -1,30 +1,7 @@
-.overview
-
- %h2.first= t(:overview_welcome, :username => @user.login)
-
- - if admin?
- %p
- = t(:created)
- = @user.created_at
- %br
- = t(:updated)
- = @user.updated_at
- %br
- = t(:enabled)
- = @user.enabled?
-
- %p= t(:overview_intro)
-
- %ul.unstyled
- %li= icon('user') + link_to(t(:overview_account), edit_user_path(@user))
- - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly}
- %li= icon('question-sign') + link_to(t(:overview_tickets), user_tickets_path(@user))
- %li= icon('shopping-cart') + link_to(t(:overview_billing), billing_top_link(@user)) if APP_CONFIG[:billing]
-
-
- .container-fluid
- .row-fluid
- %h4 To use bitmask services:
- = link_to client_download_url, class: "btn btn-primary" do
- %i.icon-arrow-down.icon-white
- = t(:download_client)
+= render 'overview'
+.container-fluid
+ .row-fluid
+ %h4 To use bitmask services:
+ = btn client_download_url, type: "primary" do
+ %i.icon-arrow-down.icon-white
+ = t(:download_bitmask)