From a302123c6bf4a636a50422be82f55d10a719315c Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 16 Jul 2014 11:20:11 +0200 Subject: [PATCH] Basic site flow improvements and devise handling --- app/assets/javascripts/theme1/application.js | 18 -------- .../javascripts/theme1/application.js.coffee | 5 ++ .../stylesheets/theme1/application.css.sass | 1 + .../theme1/elements/_devise.css.sass | 3 ++ .../theme1/elements/_flash.css.sass | 7 +++ .../theme1/elements/_forms.css.sass | 46 +++++++++++++++++++ app/controllers/application_controller.rb | 6 ++- app/controllers/pages_controller.rb | 2 +- app/helpers/devise_helper.rb | 6 ++- app/models/supplier.rb | 3 +- app/views/devise/_links.html.slim | 2 +- app/views/layouts/theme1-home.html.slim | 8 ++-- app/views/layouts/theme1.html.slim | 8 ++-- .../suppliers/confirmations/new.html.slim | 11 ++--- app/views/suppliers/passwords/edit.html.slim | 16 +++---- app/views/suppliers/passwords/new.html.slim | 10 ++-- .../suppliers/registrations/new.html.slim | 27 ++++++----- app/views/suppliers/sessions/new.html.slim | 25 ++++------ config/initializers/custom_form_builder.rb | 8 ++++ config/locales/devise.nl.yml | 7 +-- 20 files changed, 134 insertions(+), 85 deletions(-) delete mode 100644 app/assets/javascripts/theme1/application.js create mode 100644 app/assets/javascripts/theme1/application.js.coffee create mode 100644 app/assets/stylesheets/theme1/elements/_devise.css.sass create mode 100644 app/assets/stylesheets/theme1/elements/_flash.css.sass create mode 100644 app/assets/stylesheets/theme1/elements/_forms.css.sass diff --git a/app/assets/javascripts/theme1/application.js b/app/assets/javascripts/theme1/application.js deleted file mode 100644 index a7b99b69..00000000 --- a/app/assets/javascripts/theme1/application.js +++ /dev/null @@ -1,18 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// -// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD -// GO AFTER THE REQUIRES BELOW. -// -//= require jquery -//= require jquery_ujs -//= require jquery-ui -//= require_directory . -//= require_self - diff --git a/app/assets/javascripts/theme1/application.js.coffee b/app/assets/javascripts/theme1/application.js.coffee new file mode 100644 index 00000000..a89230aa --- /dev/null +++ b/app/assets/javascripts/theme1/application.js.coffee @@ -0,0 +1,5 @@ +#= require jquery +#= require jquery_ujs +#= require_directory . +#= require_self +$(document).on 'click', '.flash-box', -> $(@).slideUp() diff --git a/app/assets/stylesheets/theme1/application.css.sass b/app/assets/stylesheets/theme1/application.css.sass index 2dd818d1..77a5e05f 100644 --- a/app/assets/stylesheets/theme1/application.css.sass +++ b/app/assets/stylesheets/theme1/application.css.sass @@ -1,4 +1,5 @@ //= require_self //= require_directory . @import ./foundation_and_overrides +@import ./elements/* @import ./structure diff --git a/app/assets/stylesheets/theme1/elements/_devise.css.sass b/app/assets/stylesheets/theme1/elements/_devise.css.sass new file mode 100644 index 00000000..32324508 --- /dev/null +++ b/app/assets/stylesheets/theme1/elements/_devise.css.sass @@ -0,0 +1,3 @@ +ul.devise-nav + +inline-list + diff --git a/app/assets/stylesheets/theme1/elements/_flash.css.sass b/app/assets/stylesheets/theme1/elements/_flash.css.sass new file mode 100644 index 00000000..66e75578 --- /dev/null +++ b/app/assets/stylesheets/theme1/elements/_flash.css.sass @@ -0,0 +1,7 @@ +.flash-box + &.alert + +alert($bg: $alert-color) + &.notice + +alert + .close + +alert-close diff --git a/app/assets/stylesheets/theme1/elements/_forms.css.sass b/app/assets/stylesheets/theme1/elements/_forms.css.sass new file mode 100644 index 00000000..39a9075e --- /dev/null +++ b/app/assets/stylesheets/theme1/elements/_forms.css.sass @@ -0,0 +1,46 @@ +.form-row + @extend .row + .form-label + @media #{$small-only} + +grid-column($columns:10, $center:true) + @media #{$medium-only} + +grid-column($columns:4, $offset:1) + @media #{$large-up} + +grid-column(3) + .form-field + @media #{$small-only} + +grid-column($columns:10, $center:true, $last-column:true) + @media #{$medium-only} + +grid-column($columns:4, $last-column:true) + @media #{$large-up} + +grid-column($columns: 3, $last-column:true) + &.full + @media #{$large-up} + +grid-column($columns: 9, $last-column:true) + &.form-actions + padding-top: 12px + +.form-errors + $form-error-color: #822 + color: $form-error-color + h3 + color: $form-error-color + font-size: 1.2em +body + label + &.number + display: inline-block + padding: 4px 10px + input + &.number + width: 60px + display: inline-block + .apply-filter + +button($bg: $primary-color, $padding: $button-tny) + .error + input, textarea + border-color: $alert-color + .new-session-button + +button + input[type="number"] + text-align: right diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bfc4469d..83aac28e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,10 @@ class ApplicationController < ActionController::Base before_action :force_reloads end layout :layout_by_resource + #before_action do + #flash.now[:notice] = "Test notice" + #flash.now[:alert] = "Test alert" + #end #protect_from_forgery rescue_from SimplyStored::RecordNotFound, with: :show_404 @@ -26,7 +30,7 @@ private I18n.locale = (params[:locale].presence || I18n.default_locale).to_sym end - def layout_by_resource + def layout_by_resource(*args) #if devise_controller? #return 'obtain_token' if session[:user_return_to].present? # resource_name == :user ???? #return 'theme1' if session[:supplier_return_to].present? diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index f81ac73c..41c6656b 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,3 +1,3 @@ -class PagesController < ApplicationController +class PagesController < ::ApplicationController include Cmtool::Includes::PagesController end diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index 17fad922..5cf0b9b0 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -1,7 +1,11 @@ module DeviseHelper def devise_error_messages! if resource.errors.present? - content_tag(:div, content_tag(:h2, t("errors.messages.not_saved.#{resource.errors.size == 1 ? 'one' : 'other'}", count: resource.errors.size)) +content_tag(:ul, resource.errors.full_messages.map{|m| content_tag(:li, m)}.join.html_safe), class: 'alert alert-error') + content_tag(:div, + content_tag(:h3, t("errors.messages.not_saved.#{resource.errors.size == 1 ? 'one' : 'other'}", count: resource.errors.size)) + + content_tag(:ul, resource.errors.full_messages.map{|m| content_tag(:li, m)}.join.html_safe), + class: 'form-errors' + ) end end end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 66b59480..47176da1 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -39,8 +39,9 @@ class Supplier view :by_email, key: :email validates :name, presence: true + validates :email, email: true validates :iens_profile, numericality: {allow_blank: true} - validates :password, confirmation: true + validates :password, confirmation: true, presence: {if: ->(r){ r.new_record? }} def location=(val) lat, lng = val.is_a?(Array) ? val : val.strip.split(/[ ,]+/).map(&:to_f) diff --git a/app/views/devise/_links.html.slim b/app/views/devise/_links.html.slim index 689d28c9..8b0b88cb 100644 --- a/app/views/devise/_links.html.slim +++ b/app/views/devise/_links.html.slim @@ -1,4 +1,4 @@ -ul.nav.nav-pills +ul.nav.nav-pills.devise-nav - if controller_name != 'sessions' li= link_to t('devise.sessions.button'), new_session_path(resource_name), class: [:devise, :btn] diff --git a/app/views/layouts/theme1-home.html.slim b/app/views/layouts/theme1-home.html.slim index bb1c6e3f..d0a3423b 100644 --- a/app/views/layouts/theme1-home.html.slim +++ b/app/views/layouts/theme1-home.html.slim @@ -10,6 +10,7 @@ html lang="en" /[if lt IE 9] = javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js" = stylesheet_link_tag "theme1/application", :media => "all" + = javascript_include_tag 'theme1/application' link href="/favicon.ico" rel="shortcut icon" link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css' @@ -45,11 +46,11 @@ html lang="en" .main-inner .general-alerts - if flash[:alert].present? - .alert-box.warning + .flash-box.alert div= flash[:alert] a.close data-dismiss="alert" × - if flash[:notice].present? - .alert-box + .flash-box.notice div= flash[:notice] a.close data-dismiss="alert" × = yield :page_title @@ -58,5 +59,4 @@ html lang="en" .footer-shadow .container .footer-content= render 'footer' - .footer-bottom © Qwaiter 2013 - = javascript_include_tag "application" + .footer-bottom © Qwaiter 2014 diff --git a/app/views/layouts/theme1.html.slim b/app/views/layouts/theme1.html.slim index 6e03dcd6..2d0bb628 100644 --- a/app/views/layouts/theme1.html.slim +++ b/app/views/layouts/theme1.html.slim @@ -40,13 +40,13 @@ html lang="en" .container .main-inner - if flash[:alert].present? - .alert.alert-error - a.close data-dismiss="alert" × + .flash-box.alert div= flash[:alert] - - if flash[:notice].present? - .alert.alert-success a.close data-dismiss="alert" × + - if flash[:notice].present? + .flash-box.notice div= flash[:notice] + a.close data-dismiss="alert" × - if @page && @page.title.present? h1.page-title= @page.title = yield diff --git a/app/views/suppliers/confirmations/new.html.slim b/app/views/suppliers/confirmations/new.html.slim index 1dab33e4..e459d4ff 100644 --- a/app/views/suppliers/confirmations/new.html.slim +++ b/app/views/suppliers/confirmations/new.html.slim @@ -2,11 +2,8 @@ h2= t('devise.confirmations.title') = form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), html: { method: :post, class: 'form-horizontal' }) do |f| = devise_error_messages! - .control-group - = f.label :email, class: 'control-label' - .controls - = f.email_field :email - - .control-group - .controls= f.submit t('devise.confirmations.submit_text'), class: 'btn-primary' + = f.row :email do + .form-label= f.label :email, class: 'control-label' + .form-field= f.email_field :email + .form-row.form-actions= f.submit t('devise.confirmations.submit_text'), class: 'button' = render "links" diff --git a/app/views/suppliers/passwords/edit.html.slim b/app/views/suppliers/passwords/edit.html.slim index 6a71746c..e6ec6029 100644 --- a/app/views/suppliers/passwords/edit.html.slim +++ b/app/views/suppliers/passwords/edit.html.slim @@ -2,13 +2,11 @@ h2= t('devise.passwords.edit.title') = form_for(resource, :as => resource_name, :url => password_path(resource_name), html: {class: 'form-horizontal', method: :put}) do |f| = devise_error_messages! = f.hidden_field :reset_password_token - .control-group - = f.label :password, class: 'control-label' - .controls= f.password_field :password - .control-group - = f.label :password_confirmation, class: 'control-label' - .controls= f.password_field :password_confirmation - .control-group - .controls - = f.submit t('devise.passwords.edit.button'), class: 'btn btn-primary' + .form-row + .form-label= f.label :password + .form-field= f.password_field :password + = f.row :password_confirmation do + .form-label= f.label :password_confirmation + .form-field= f.password_field :password_confirmation + .form-row= f.submit t('devise.passwords.edit.button'), class: 'button' = render "links" diff --git a/app/views/suppliers/passwords/new.html.slim b/app/views/suppliers/passwords/new.html.slim index c0304fc9..549eb8dd 100644 --- a/app/views/suppliers/passwords/new.html.slim +++ b/app/views/suppliers/passwords/new.html.slim @@ -1,10 +1,8 @@ h2= t('devise.passwords.title') = form_for(resource, :as => resource_name, :url => password_path(resource_name), html: {class: 'form-horizontal'}) do |f| = devise_error_messages! - .control-group - = f.label :email, class: 'control-label' - .controls= f.email_field :email - .control-group - .controls - = f.submit t('devise.passwords.button'), class: 'btn btn-primary' + = f.row :email do + .form-label= f.label :email, class: 'control-label' + .form-field= f.email_field :email + .form-row.form-actions= f.submit t('devise.passwords.button'), class: 'button' = render "links" diff --git a/app/views/suppliers/registrations/new.html.slim b/app/views/suppliers/registrations/new.html.slim index 0dd0684a..fac18dfd 100644 --- a/app/views/suppliers/registrations/new.html.slim +++ b/app/views/suppliers/registrations/new.html.slim @@ -6,18 +6,17 @@ p = form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: 'form-horizontal'}) do |f| = devise_error_messages! .control-group - = f.label :name, class: 'control-label' - .controls= f.text_field :name - .control-group - = f.label :email, class: 'control-label' - .controls= f.email_field :email - .control-group - = f.label :password, class: 'control-label' - .controls= f.password_field :password - .control-group - = f.label :password_confirmation, class: 'control-label' - .controls= f.password_field :password_confirmation - .control-group - .controls - = f.submit t('devise.registrations.button'), class: 'btn btn-primary' + = f.row :name do + .form-label= f.label :name, class: 'control-label' + .form-field= f.text_field :name + = f.row :email do + .form-label= f.label :email, class: 'control-label' + .form-field= f.email_field :email + = f.row :password do + .form-label= f.label :password, class: 'control-label' + .form-field= f.password_field :password + = f.row :password_confirmation do + .form-label= f.label :password_confirmation, class: 'control-label' + .form-field= f.password_field :password_confirmation + .form-row.form-actions= f.submit t('devise.registrations.button'), class: 'button' = render "links" diff --git a/app/views/suppliers/sessions/new.html.slim b/app/views/suppliers/sessions/new.html.slim index bda31ea2..45a082f7 100644 --- a/app/views/suppliers/sessions/new.html.slim +++ b/app/views/suppliers/sessions/new.html.slim @@ -1,19 +1,14 @@ h2= t('devise.sessions.title') = form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: 'form-horizontal'}) do |f| = devise_error_messages! - .control-group - = f.label :email, class: 'control-label' - .controls= f.email_field :email - .control-group - = f.label :password, class: 'control-label' - .controls= f.password_field :password - .control-group - .controls - = f.label :remember_me do - = f.check_box :remember_me - |  - = t('devise.sessions.remember_me') - .control-group - .controls - = f.submit t('devise.sessions.button'), class: 'btn btn-primary' + = f.row :email do + .form-label= f.label :email + .form-field= f.email_field :email + .form-row + = f.label :remember_me do + = f.check_box :remember_me + |  + = t('devise.sessions.remember_me') + .form-row + = f.submit t('devise.sessions.button'), class: 'new-session-button' = render "links" diff --git a/config/initializers/custom_form_builder.rb b/config/initializers/custom_form_builder.rb index b5067920..be1e3f7a 100644 --- a/config/initializers/custom_form_builder.rb +++ b/config/initializers/custom_form_builder.rb @@ -11,5 +11,13 @@ class CustomFormBuilder < ActionView::Helpers::FormBuilder ) t.content_tag(:div, elements.inject(&:+), class: 'form-actions') end + def row(attribute, options={}, &block) + t = @template + classes = [] + classes << 'form-row' + classes << attribute + classes << 'error' if object.errors[attribute].present? + t.content_tag(:div, t.capture(&block), class: classes) + end end ActionView::Base.default_form_builder = CustomFormBuilder diff --git a/config/locales/devise.nl.yml b/config/locales/devise.nl.yml index 9670c166..1e1386d6 100644 --- a/config/locales/devise.nl.yml +++ b/config/locales/devise.nl.yml @@ -29,7 +29,7 @@ nl: inactive: 'Your account was not activated yet.' not_found_in_database: "Je bent nog niet bij ons bekend. Meld je aan om Qwaiter te kunnen gebruiken!" sessions: - title: Inloggen + title: Inloggen voor horeca button: Inloggen signed_in: Succesvol ingelogd signed_out: Succesvol uitgelogd @@ -44,13 +44,14 @@ nl: send_instructions: 'U ontvangt binnen enkele minuten een e-mail met instructies voor het resetten van uw wachtwoord' updated: 'Uw wachtwoord is succesvol gewijzigd. U bent nu ingelogd.' forgot_password: Wachtwoord vergeten? + no_token: Geen token gegeven send_instructions_button: Stuur mij reset instructies edit: title: Verander je wachtwoord button: Verander wachtwoord registrations: - title: Aanmelden - button: Aanmelden + title: Nieuwe aanmelding als horeca + button: Nieuwe aanmelding als horeca signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'