From: Julien Lancelot Date: Wed, 26 Jun 2013 15:14:09 +0000 (+0200) Subject: SONAR-4421 Improve assign box X-Git-Tag: 3.7~360 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f74c99ea6c3fd2f4290950062e5ed0a4563fa8d2;p=sonarqube.git SONAR-4421 Improve assign box --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index f75d10eb544..f34e77b5cb7 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -9,6 +9,7 @@ activation=Activation active=Active add_verb=Add age=Age +assign_to_me=Assign to me alerts=Alerts all=All and=And @@ -83,6 +84,7 @@ more_actions=More actions name=Name name_too_long_x=Name is too long (maximum is {0} characters) none=None +unassign=Unassign off=Off on=On open=Open diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 98886673a8a..b27a0d7e6be 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -586,14 +586,6 @@ module ApplicationHelper html_class=options[:html_class]||'' min_length=options[:min_length] - ajax_options={ - 'quietMillis' => 300, - 'url' => "'#{ws_url}'", - 'data' => 'function (term, page) {return {s:term, p:page}}', - 'results' => 'function (data, page) {return {more: data.more, results: data.results}}' - } - ajax_options.merge!(options[:select2_ajax_options]) if options[:select2_ajax_options] - js_options={ 'minimumInputLength' => min_length, 'allowClear' => options[:allow_clear]||false, @@ -603,7 +595,34 @@ module ApplicationHelper } js_options['placeholder']= "'#{options[:placeholder]}'" if options.has_key?(:placeholder) js_options['width']= "'#{width}'" if width - js_options['ajax']='{' + ajax_options.map { |k, v| "#{k}:#{v}" }.join(',') + '}' + + choices = options[:include_choices] + if choices && !choices.empty? + js_options['minimumInputLength']=0 + js_options['query']=" + function(query) { + if (query.term.length == 0) { + query.callback({results: [{#{ choices.map { |id, text| "id:'#{id}',text:'#{text}'" }.join('}, {')}}]}); + } else if (query.term.length >= #{min_length}) { + $j.ajax('#{ws_url}', { + data: {s: query.term}, + dataType: 'jsonp' + }).done(function(data) { + query.callback(data); + }); + } + }" + else + ajax_options={ + 'quietMillis' => 300, + 'url' => "'#{ws_url}'", + 'data' => 'function (term, page) {return {s:term, p:page}}', + 'results' => 'function (data, page) {return {more: data.more, results: data.results}}' + } + ajax_options.merge!(options[:select2_ajax_options]) if options[:select2_ajax_options] + js_options['ajax']='{' + ajax_options.map { |k, v| "#{k}:#{v}" }.join(',') + '}' + end + js_options.merge!(options[:select2_options]) if options[:select2_options] html = "" @@ -702,6 +721,7 @@ module ApplicationHelper # * :selected_user - the user that is selected by default. # * :placeholder - the label to display when nothing is selected # * :open - true if the select-box must be open. Default is false. + # * :include_choices - choices that will be display when selecting the box # * :select2_options - hash of select2 options # def user_select_tag(name, options={}) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb index 1399397f159..245534ee64f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb @@ -5,15 +5,16 @@ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb index e4076fe0a68..391a08bb4fa 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb @@ -5,7 +5,7 @@ %> - +
<% if project && !project.blank? @@ -35,7 +36,7 @@ [label, plan.key] }, first_plan.key) end - %> + %>
\ No newline at end of file
- <%= user_select_tag('assignee', :html_id => user_select_box_id, :open => true) -%> + <% + choices = {} + choices[current_user.login] = escape_javascript(message('assign_to_me')) if !@issue.assignee || @issue.assignee != current_user.login + choices[''] = escape_javascript(message('unassign')) if @issue.assignee + %> + <%= + user_select_tag('assignee', :html_id => user_select_box_id, :open => true, :include_choices => choices) + -%>   - <% if @issue.assignee %> - <%= image_tag 'sep12.png' -%> -   - -   - <% end %> <%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>