:only => [:assign, :comment_form, :flag_as_false_positive,
:violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment],
:redirect_to => {:action => :error_not_post}
- helper SourceHelper
+ helper SourceHelper, UsersHelper
def index
init_params()
def init_params
@user_names = [["Any", ""]] + options_for_users
- default_user = (current_user ? [current_user.id.to_s] : [''])
- @authors = filter_any(params[:authors]) || ['']
- @assignees = filter_any(params[:assignees]) || default_user
+ default_user = (current_user ? current_user.id : '')
+ @assignee_id = params[:assignee_id] || default_user
+ @author_id = params[:author_id] || ''
@severities = filter_any(params[:severities]) || ['']
@statuses = filter_any(params[:statuses]) || [Review::STATUS_OPEN]
@projects = filter_any(params[:projects]) || ['']
unless @severities == ['']
options['severities']=@severities.join(',')
end
- unless @authors == ['']
- options['authors']=@authors.map{|s| s.to_i}.join(',')
+ if @author_id
+ options['authors']=@author_id.to_s
end
- unless @assignees == ['']
- options['assignees']=@assignees.map{|s| s.to_i}.join(',')
+ if @assignee_id
+ options['assignees']=@assignee_id.to_s
end
unless @id == ''
if is_number? @id
class UsersController < ApplicationController
SECTION=Navigation::SECTION_CONFIGURATION
- before_filter :admin_required, :except => ['new', 'signup']
- skip_before_filter :check_authentication, :only => ['new', 'signup']
+ before_filter :admin_required, :except => ['new', 'signup', 'autocomplete']
+ skip_before_filter :check_authentication, :only => ['new', 'signup', 'autocomplete']
def create
return unless request.post?
user.groups<<default_group if default_group
user
end
+
+ def autocomplete
+ @users = User.find(:all, :conditions => ["UPPER(name) like UPPER(?)", params[:user_name_start]+"%"])
+ @char_count = params[:user_name_start].size
+ render :partial => 'autocomplete'
+ end
+
end
link_to_login_with_IP content_text, options
end
end
+
+ #
+ # Generates a text input field that knows how to contact the server to retrieve
+ # and suggest a list of user names & IDs based on the first letters typed by
+ # the user.
+ # The text input displays a string (the name of the user) but the real input
+ # field that is submitted is a hidden one that contains the user ID that corresponds
+ # to the typed name (if the user exists, of course).
+ #
+ # Example:
+ # <%= user_autocomplete_field "assignee_id", @assignee_id -%>
+ # # => generates an input field for the parameter 'assignee_id'
+ #
+ def user_autocomplete_field(param_id, param_value)
+ param_id_name = param_id
+ param_id_value = param_value
+
+ unless param_id_value.blank?
+ user = User.find(param_id_value)
+ param_displayed_value = user.name if user
+ param_displayed_value += " (me)" if user && current_user && current_user.id == param_id_value.to_i
+ end
+
+ server_url = url_for :controller => 'users', :action => 'autocomplete'
+
+ render :partial => 'autocomplete/text_field', :locals => {:param_id_name => param_id_name, :param_id_value => param_id_value,
+ :param_displayed_value => param_displayed_value, :server_url => server_url }
+ end
end
--- /dev/null
+ <input type="text" id="autocompleteText-<%= param_id_name -%>" value="<%= param_displayed_value -%>" onkeyup="if (this.value=='') $('<%= param_id_name -%>').value='';"/>
+ <input type="hidden" id="<%= param_id_name -%>" name="<%= param_id_name -%>" value="<%= param_id_value -%>"/>
+ <span id="load-<%= param_id_name -%>" style="display: none">
+ <%= image_tag("loading.gif") -%>
+ </span>
+ <div id="autocomplete-<%= param_id_name -%>" class="autocomplete"></div>
+ <script>
+ new Ajax.Autocompleter("autocompleteText-<%= param_id_name -%>", "autocomplete-<%= param_id_name -%>", "<%= server_url -%>", {
+ paramName: "user_name_start",
+ minChars: 2,
+ indicator: 'load-<%= param_id_name -%>',
+ afterUpdateElement : getSelection<%= param_id_name -%>
+ });
+ function getSelection<%= param_id_name -%>(text, li) {
+ $('<%= param_id_name -%>').value = li.id
+ }
+ </script>
\ No newline at end of file
$('statuses').value = ''
$('severities').value = ''
$('projects').value = ''
- $('authors').value = ''
- $('assignees').value = ''
+ $('author_id').value = ''
+ $('autocompleteText-author_id').value = ''
+ $('assignee_id').value = ''
+ $('autocompleteText-assignee_id').value = ''
}
}
function launchSearch(columnName, link) {
<option value="<%= Severity::INFO -%>" class="sev_INFO" <%= 'selected' if @severities.include?(Severity::INFO) -%>>Info</option>
</select>
</td>
-
<td width="1%" nowrap>
<span class="note">Project</span><br/>
<select size="6" name="projects[]" multiple="multiple" id="projects">
<% end %>
</select>
</td>
-
<td width="1%" nowrap>
<span class="note">Created by</span><br/>
- <%= select_tag "authors", options_for_select(@user_names, @authors), :multiple => true, :size => 6 %>
- </td>
- <td width="1%" nowrap>
+ <%= user_autocomplete_field "author_id", @author_id -%>
+ <br/>
<span class="note">Assigned to</span><br/>
- <%= select_tag "assignees", options_for_select(@user_names, @assignees), :multiple => true, :size => 6 %>
+ <%= user_autocomplete_field "assignee_id", @assignee_id -%>
+ <br/>
</td>
<td width="1%" nowrap>
<span class="note">Id</span><br/>
--- /dev/null
+<% current_user_id = current_user.id if current_user %>
+<ul>
+ <%
+ @users.each do |user|
+ user_name = user.name
+ %>
+ <li id="<%= h(user.id) -%>"><strong><%= h(user_name)[0..@char_count-1] -%></strong><%= h(user_name)[@char_count..user_name.size-1] -%> <i><%= "(me)" if current_user_id == user.id -%></i></li>
+ <% end %>
+</ul>
-
+/* REVIEWS */
div#review .actions{
visibility: hidden;
}
}
-
+/* AUTOCOMPLETE FIELDS */
+div.autocomplete {
+ position:absolute;
+ width:250px;
+ background-color:#fff;
+ border:1px solid #ccc;
+ margin:0;
+ padding:0;
+ color: #111;
+ line-height: 1em;
+}
+div.autocomplete ul {
+ list-style-type:none;
+ margin:0;
+ padding:0;
+}
+div.autocomplete ul li.selected {
+ background-color: #4b9fd5;
+ color: #fff;
+ margin: 0;
+}
+div.autocomplete ul li {
+ list-style-type:none;
+ display:block;
+ margin:0;
+ padding: 5px 10px;
+ cursor:pointer;
+ color: #333;
+ line-height: 1em;
+}
+div.autocomplete strong {
+ font-weight: bold;
+}