diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/images/icons/user.png | bin | 0 -> 2800 bytes | |||
| -rw-r--r-- | app/assets/stylesheets/organisations.css.scss | 4 | ||||
| -rw-r--r-- | app/assets/stylesheets/subscriptions.css.scss | 9 | ||||
| -rw-r--r-- | app/controllers/chouette_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/referentials_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/subscriptions_controller.rb | 20 | ||||
| -rw-r--r-- | app/helpers/users_helper.rb | 11 | ||||
| -rw-r--r-- | app/models/subscription.rb | 43 | ||||
| -rw-r--r-- | app/models/user.rb | 2 | ||||
| -rw-r--r-- | app/views/organisations/show.html.erb | 6 | ||||
| -rw-r--r-- | app/views/subscriptions/new.html.erb | 24 | ||||
| -rw-r--r-- | app/views/users/_form.html.erb | 9 | ||||
| -rw-r--r-- | app/views/users/show.html.erb | 4 |
13 files changed, 133 insertions, 8 deletions
diff --git a/app/assets/images/icons/user.png b/app/assets/images/icons/user.png Binary files differnew file mode 100644 index 000000000..06d0cd593 --- /dev/null +++ b/app/assets/images/icons/user.png diff --git a/app/assets/stylesheets/organisations.css.scss b/app/assets/stylesheets/organisations.css.scss index 13a078bd4..cb794940a 100644 --- a/app/assets/stylesheets/organisations.css.scss +++ b/app/assets/stylesheets/organisations.css.scss @@ -26,6 +26,10 @@ padding-right: 10px; position: relative; + img.preview { + width: 64px; + height: 64px; + } } } diff --git a/app/assets/stylesheets/subscriptions.css.scss b/app/assets/stylesheets/subscriptions.css.scss new file mode 100644 index 000000000..ca94fd80a --- /dev/null +++ b/app/assets/stylesheets/subscriptions.css.scss @@ -0,0 +1,9 @@ +// Place all the styles related to the lines controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +@import "common"; + +#workspace.subscriptions.create, #workspace.subscriptions.new +{ +} + diff --git a/app/controllers/chouette_controller.rb b/app/controllers/chouette_controller.rb index 1b9f30a85..bc74f72fc 100644 --- a/app/controllers/chouette_controller.rb +++ b/app/controllers/chouette_controller.rb @@ -7,7 +7,7 @@ class ChouetteController < InheritedResources::Base end def referential - @referential ||= Referential.find params[:referential_id] + @referential ||= current_organisation.referentials.find params[:referential_id] end end diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index face0663f..6ee744413 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -6,5 +6,12 @@ class ReferentialsController < InheritedResources::Base show! end + protected + def resource + @referential ||= current_organisation.referentials.find_by_id(params[:id]) + end + def collection + @referentials ||= current_organisation.referentials + end end diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb new file mode 100644 index 000000000..e860e94ec --- /dev/null +++ b/app/controllers/subscriptions_controller.rb @@ -0,0 +1,20 @@ +class SubscriptionsController < Devise::RegistrationsController + + def new + @subscription = Subscription.new + end + def create + @subscription = Subscription.new(params[:subscription]) + + if @subscription.save + sign_in @subscription.user + flash[:notice] = t('subscriptions.success') + redirect_to referentials_path + else + flash[:error] = t('subscriptions.failure') + render :action => "new" + end + end + +end + diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..ad45433c1 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,11 @@ +module UsersHelper + + def user_gravatar_image_tag(user) + gravatar_image_tag user.email, :alt => user.name, :class => "preview", :gravatar => { :default => user_default_avatar, :size => 64 } + end + + def user_default_avatar + "#{root_url}#{image_path('icons/user.png')}" + end + +end diff --git a/app/models/subscription.rb b/app/models/subscription.rb new file mode 100644 index 000000000..8b2b025de --- /dev/null +++ b/app/models/subscription.rb @@ -0,0 +1,43 @@ +class Subscription + include ActiveModel::Validations + include ActiveModel::Conversion + extend ActiveModel::Naming + + attr_accessor :organisation_name, :user_name, :email, :password, :password_confirmation + + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end + end + + def persisted? + false + end + + def user + @user ||= organisation.users.build :email => email, :password => password, :password_confirmation => password_confirmation + end + + def organisation + @organisation ||= Organisation.new :name => organisation_name + end + + def valid? + unless organisation.valid? + self.errors.add( :organisation_name, organisation.errors[:name]) if organisation.errors[:name] + end + unless user.valid? + self.errors.add( :password, user.errors[:password]) if user.errors[:password] + self.errors.add( :email, user.errors[:email]) if user.errors[:email] + end + self.errors.empty? + end + + def save + if valid? + organisation.save and user.save + end + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 53853530f..4d6f72c0e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ class User < ActiveRecord::Base :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model - attr_accessible :email, :password, :password_confirmation, :remember_me + attr_accessible :email, :password, :password_confirmation, :remember_me, :name belongs_to :organisation diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index da895ea87..c407f56f9 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -2,8 +2,10 @@ <div class="users"> <% @organisation.users.each do |user| %> - <%= div_for(user) do %> - <li><%= link_to "#{user.email}", organisation_user_path(user) %></li> + <%= div_for user do %> + <%= user_gravatar_image_tag user %> + <%= link_to user.name, organisation_user_path(user) %> + <div class="info"><%= user.email %></div> <% end %> <% end %> </div> diff --git a/app/views/subscriptions/new.html.erb b/app/views/subscriptions/new.html.erb new file mode 100644 index 000000000..3d137a0d3 --- /dev/null +++ b/app/views/subscriptions/new.html.erb @@ -0,0 +1,24 @@ +<%= title_tag t('devise.registrations.new.title') %> + +<%= semantic_form_for @subscription, :url => subscription_path do |form| %> + <%= form.inputs do %> + <%= form.input :organisation_name %> + <%= form.input :email %> + <%= form.input :password, :as => :password %> + <%= form.input :password_confirmation, :as => :password %> + <% end %> + + <%= form.actions do %> + <%= form.action :submit, :as => :button, :label => t('devise.registrations.new.title') %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> + +<% content_for :sidebar do %> +<ul class="actions"> + <li> + <%= link_to t('devise.shared.sign_in'), new_user_session_path %> + </li> +</ul> +<% end %> + diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 2894b5c90..3b19dddf2 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -1,10 +1,11 @@ <%= semantic_form_for [:organisation, @user] do |form| %> <%= form.inputs do %> + <%= form.input :name %> <%= form.input :email %> <% end %> - <%= form.actions do %> - <%= form.action :submit, :as => :button %> - <%= form.action :cancel, :as => :link %> - <% end %> + <%= form.actions do %> + <%= form.action :submit, :as => :button %> + <%= form.action :cancel, :as => :link %> + <% end %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 30f5cc4ba..10c369bf4 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,6 +2,10 @@ <div class="user"> <p> +<label><%= User.human_attribute_name("name") %>: </label> +<%= @user.name %> +</p> +<p> <label><%= User.human_attribute_name("email") %>: </label> <%= @user.email %> </p> |
