summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
Diffstat (limited to 'users/app')
-rw-r--r--users/app/assets/javascripts/users.js.coffee8
-rw-r--r--users/app/controllers/email_aliases_controller.rb25
-rw-r--r--users/app/controllers/users_controller.rb2
-rw-r--r--users/app/helpers/users_helper.rb5
-rw-r--r--users/app/models/email.rb8
-rw-r--r--users/app/models/user.rb4
-rw-r--r--users/app/views/emails/_email.html.haml3
-rw-r--r--users/app/views/users/edit.html.haml4
8 files changed, 33 insertions, 26 deletions
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee
index 0c1fb55..86bacee 100644
--- a/users/app/assets/javascripts/users.js.coffee
+++ b/users/app/assets/javascripts/users.js.coffee
@@ -24,7 +24,15 @@ srp.error = (message) ->
pollUsers = (query, process) ->
$.get( "/users.json", query: query).done(process)
+followLocationHash = ->
+ location = window.location.hash
+ if location
+ href_select = 'a[href="' + location + '"]'
+ link = $(href_select)
+ link.tab('show') if link
+
$(document).ready ->
+ followLocationHash()
$('#new_user').submit preventDefault
$('#new_user').submit srp.signup
$('#new_session').submit preventDefault
diff --git a/users/app/controllers/email_aliases_controller.rb b/users/app/controllers/email_aliases_controller.rb
index 751df85..3b0d5ac 100644
--- a/users/app/controllers/email_aliases_controller.rb
+++ b/users/app/controllers/email_aliases_controller.rb
@@ -4,29 +4,10 @@ class EmailAliasesController < ApplicationController
respond_to :html
- # get a list of email aliases for the given user?
- def index
- @aliases = @user.email_aliases
- respond_with @aliases
- end
-
- def create
- @alias = @user.add_email_alias(params[:email_alias])
- flash[:notice] = t(:email_alias_created_successfully) unless @alias.errors
- respond_with @alias, :location => edit_user_path(@user, :anchor => :email)
- end
-
- def update
- @alias = @user.get_email_alias(params[:id])
- @alias.set_email(params[:email_alias])
- flash[:notice] = t(:email_alias_updated_successfully) unless @alias.errors
- respond_with @alias, :location => edit_user_path(@user, :anchor => :email)
- end
-
def destroy
- @alias = @user.get_email_alias(params[:id])
- flash[:notice] = t(:email_alias_destroyed_successfully)
- @alias.destroy
+ @alias = @user.email_aliases.delete(params[:id])
+ @user.save
+ flash[:notice] = t(:email_alias_destroyed_successfully, :alias => @alias)
redirect_to edit_user_path(@user, :anchor => :email)
end
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 811e8e5..feb66c8 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -36,7 +36,7 @@ class UsersController < ApplicationController
else
flash[:error] = @user.errors.full_messages
end
- respond_with @user, :location => edit_user_path(@user)
+ respond_with @user, :location => edit_user_path(@user, :anchor => :email)
end
def destroy
diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb
index b017bca..6d76d6f 100644
--- a/users/app/helpers/users_helper.rb
+++ b/users/app/helpers/users_helper.rb
@@ -29,4 +29,9 @@ module UsersHelper
classes << (@user.new_record? ? 'new' : 'edit')
classes.compact
end
+
+ def email_settings?
+ params[:user] &&
+ params[:user].keys.detect{|key| key.index('email')}
+ end
end
diff --git a/users/app/models/email.rb b/users/app/models/email.rb
index 4b01838..0745fda 100644
--- a/users/app/models/email.rb
+++ b/users/app/models/email.rb
@@ -14,4 +14,12 @@ class Email
def to_s
email
end
+
+ def ==(other)
+ other.is_a?(String) ? self.email == other : super
+ end
+
+ def to_param
+ email
+ end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 10f358d..d66b0e9 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -45,6 +45,7 @@ class User < CouchRest::Model::Base
view :by_login
view :by_created_at
view :by_email
+
view :by_email_alias,
:map => <<-EOJS
function(doc) {
@@ -56,6 +57,7 @@ class User < CouchRest::Model::Base
});
}
EOJS
+
view :by_email_or_alias,
:map => <<-EOJS
function(doc) {
@@ -70,6 +72,7 @@ class User < CouchRest::Model::Base
});
}
EOJS
+
end
class << self
@@ -127,6 +130,7 @@ class User < CouchRest::Model::Base
end
end
+
##
# Validation Functions
##
diff --git a/users/app/views/emails/_email.html.haml b/users/app/views/emails/_email.html.haml
index f182ed9..f5eb2d0 100644
--- a/users/app/views/emails/_email.html.haml
+++ b/users/app/views/emails/_email.html.haml
@@ -1,4 +1,5 @@
%li.pull-right
%code= email
- %i.icon-remove
+ = link_to(user_email_alias_path(@user, email), :method => :delete) do
+ %i.icon-remove
.clearfix
diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml
index 92ab71b..a2a0942 100644
--- a/users/app/views/users/edit.html.haml
+++ b/users/app/views/users/edit.html.haml
@@ -1,9 +1,9 @@
.span8.offset2
%h2=t :settings
%ul.nav.nav-tabs
- %li.active
+ %li{:class => email_settings? ? :inactive : :active}
%a{:href => '#account', 'data-toggle' => 'tab'}Account
- %li
+ %li{:class => email_settings? ? :active : :inactive}
%a{:href => '#email', 'data-toggle' => 'tab'}Email
.tab-content