summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-07-04 01:33:09 -0700
committerelijah <elijah@riseup.net>2013-07-04 04:12:59 -0700
commit89ad6bd802f9e57c687e8cdb8593c3984e2fbd1b (patch)
tree3079996a475e947deece071fc6b1caea3edb1f80
parent33f55eed348769e1d14b283ec36b8f1bfc2d3c98 (diff)
fix user typeahead
-rw-r--r--users/app/assets/javascripts/users.js4
-rw-r--r--users/app/controllers/v1/users_controller.rb12
-rw-r--r--users/app/views/users/index.html.haml13
-rw-r--r--users/config/routes.rb2
4 files changed, 20 insertions, 11 deletions
diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js
index eed1961..1d05692 100644
--- a/users/app/assets/javascripts/users.js
+++ b/users/app/assets/javascripts/users.js
@@ -10,7 +10,7 @@
};
poll_users = function(query, process) {
- return $.get("/users.json", {
+ return $.get("/1/users.json", {
query: query
}).done(process);
};
@@ -66,7 +66,7 @@
$('#new_session').submit(srp.login);
$('#update_login_and_password').submit(prevent_default);
$('#update_login_and_password').submit(srp.update);
- return $('.user.typeahead').typeahead({
+ return $('#user-typeahead').typeahead({
source: poll_users
});
});
diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb
index e7516bc..e117fc7 100644
--- a/users/app/controllers/v1/users_controller.rb
+++ b/users/app/controllers/v1/users_controller.rb
@@ -2,11 +2,21 @@ module V1
class UsersController < UsersBaseController
skip_before_filter :verify_authenticity_token
- before_filter :authorize, :only => [:update]
before_filter :fetch_user, :only => [:update]
+ before_filter :authorize, :only => [:update]
+ before_filter :authorize_admin, :only => [:index]
respond_to :json
+ def index
+ if params[:query]
+ @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ)
+ respond_with @users.map(&:login).sort
+ else
+ render :json => {'error' => 'query required', 'status' => :unprocessable_entity}
+ end
+ end
+
def create
@user = User.create(params[:user])
respond_with @user # return ID instead?
diff --git a/users/app/views/users/index.html.haml b/users/app/views/users/index.html.haml
index 254e177..fc1001e 100644
--- a/users/app/views/users/index.html.haml
+++ b/users/app/views/users/index.html.haml
@@ -2,13 +2,12 @@
= form_tag users_path, :method => :get, :class => "form-search" do
.input-append
- = text_field_tag :query, "", :class => "user typeahead span2 search-query", :autocomplete => :off
- %button.btn{:type => :submit} Search
+ = text_field_tag :query, params[:query], :id => 'user-typeahead', :class => "search-query", :autocomplete => :off
+ %button.btn{:type => :submit}= t(:search)
-%table.table.table-hover
+%table.table.table-striped
%tr
- %th Login
- %th Created
- %th Action
+ %th= t(:username)
+ %th= t(:created)
+ %th= t(:updated)
= render @users.all
-
diff --git a/users/config/routes.rb b/users/config/routes.rb
index 9eff2a1..693ae7a 100644
--- a/users/config/routes.rb
+++ b/users/config/routes.rb
@@ -5,7 +5,7 @@ Rails.application.routes.draw do
defaults: {format: 'json'} } do
resources :sessions, :only => [:new, :create, :update]
delete "logout" => "sessions#destroy", :as => "logout"
- resources :users, :only => [:create, :update, :destroy]
+ resources :users, :only => [:create, :update, :destroy, :index]
end
get "login" => "sessions#new", :as => "login"