Skip to content

Commit

Permalink
id and only flags used in users query
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmckay committed Dec 8, 2011
1 parent f09df15 commit 135866a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/app/controllers/users_controller.rb
Expand Up @@ -17,9 +17,9 @@ def section_id
'operations'
end

before_filter :setup_options, :only => [:items, :index, :account]
before_filter :find_user, :only => [:index, :edit, :edit_environment, :update_environment,
:update, :update_roles, :clear_helptips, :destroy, :account]
before_filter :setup_options, :only => [:items, :index]
before_filter :find_user, :only => [:items, :index, :edit, :edit_environment, :update_environment,
:update, :update_roles, :clear_helptips, :destroy]
before_filter :authorize
skip_before_filter :require_org

Expand Down Expand Up @@ -51,18 +51,20 @@ def rules
:disable_helptip => user_helptip,
}
end


# Render list of users. Note that if the current user does not have permission
# to view all users, the results are restricted to just themselves.
def items
if User.any_readable?
render_panel_items(User.readable, @panel_options, params[:search], params[:offset])
if params[:only]
users = [@user]
else
users = User.readable
end
else
render_panel_items([current_user], @panel_options, params[:search], params[:offset])
users = [current_user]
end
end

def account
@user = current_user
render_panel_items([current_user], @panel_options, params[:search], params[:offset])
render_panel_items(users, @panel_options, params[:search], params[:offset])
end

def edit
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/layouts/_header.haml
Expand Up @@ -13,7 +13,7 @@
= render :partial => '/layouts/org'
%ul
%li.hello
= link_to users_path do
= link_to users_path(:id => current_user, :only => true) do
%strong
= current_user.username
%li
Expand Down
4 changes: 4 additions & 0 deletions src/app/views/users/index.html.haml
@@ -1,4 +1,8 @@
= javascript :edit, :edit_helpers, :env_select
= javascript do
:javascript
var only = '#{@only}'


.grid_16#main
= two_panel(@users, @panel_options)
Expand Down
29 changes: 27 additions & 2 deletions src/public/javascripts/panel.js
Expand Up @@ -494,6 +494,17 @@ KT.panel = (function ($) {
});
panels_list.push(new_panel);
},
// http://devnull.djolley.net/2010/11/accessing-query-string-parameters-from.html
queryParameters = function () {
var queryString = new Object;
var qstr=window.location.search.substring(1);
var params=qstr.split('&');
for (var i=0; i<params.length; i++) {
var pair=params[i].split('=');
queryString[pair[0]]=pair[1];
}
return queryString;
},
actions = (function(){
var action_list = {};

Expand Down Expand Up @@ -608,6 +619,7 @@ KT.panel = (function ($) {
panelAjax: panelAjax,
control_bbq: control_bbq,
registerPanel: registerPanel,
queryParameters: queryParameters,
actions: actions
};
})(jQuery);
Expand Down Expand Up @@ -784,8 +796,7 @@ KT.panel.list = (function () {
extra_params = options['extra_params'],
data = {},
page_load = page_load || false,
search_cb = search_cb ||
function () {};
search_cb = search_cb || function () {};
e.preventDefault();
button.attr("disabled", "disabled");
element.find('section').empty();
Expand All @@ -794,6 +805,20 @@ KT.panel.list = (function () {
$.bbq.pushState($(this).serialize());
}
url += '?offset=' + offset;

// Pass along all additional parameters
var qp = KT.panel.queryParameters();
if (qp) {
for (var key in qp) {
url += '&' + key + '=' + qp[key];
}
}
//var only = KT.panel.queryParameters()['only'];
//var id = KT.panel.queryParameters()['id'];
//if(only) {
// url += '&id=' + id
// url += '&only=' + only
//}
if (extra_params) {
for (var i = 0; i < extra_params.length; i += 1) {
data[extra_params[i]['hash_id']] = $.bbq.getState(extra_params[i]['hash_id']);
Expand Down

0 comments on commit 135866a

Please sign in to comment.