]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4421 Improve assign box
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 15:14:09 +0000 (17:14 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 15:14:09 +0000 (17:14 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb

index f75d10eb5440a5da9e21455c0360e0f1fbeb728f..f34e77b5cb7fe24a38ce4b5d1b2db1071d90a2fc 100644 (file)
@@ -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
index 98886673a8a95ea57ce1a8dbc5f98d121406bdd6..b27a0d7e6bee5b3f6f2271038999b278b8e4fb47 100644 (file)
@@ -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 = "<input type='hidden' id='#{html_id}' class='#{html_class}' name='#{name}'/>"
@@ -702,6 +721,7 @@ module ApplicationHelper
   # * <tt>:selected_user</tt> - the user that is selected by default.
   # * <tt>:placeholder</tt> - the label to display when nothing is selected
   # * <tt>:open</tt> - true if the select-box must be open. Default is false.
+  # * <tt>:include_choices</tt> - choices that will be display when selecting the box
   # * <tt>:select2_options</tt> - hash of select2 options
   #
   def user_select_tag(name, options={})
index 1399397f159661881528c8b9c3773df9fc9e3d21..245534ee64f6bfd9b5d75c77c32374f126d33dc3 100644 (file)
@@ -5,15 +5,16 @@
   <table class="width100">
     <tr>
       <td style="vertical-align:top">
-        <%= 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)
+        -%>
         <input type="button" value="<%= message('issue.assign.submit') -%>" onclick="submitIssueForm(this)">
         &nbsp;
-        <% if @issue.assignee %>
-          <%= image_tag 'sep12.png' -%>
-          &nbsp;
-          <input type="button" value="<%= message('issue.unassign.submit') -%>" onclick="$j('#<%= user_select_box_id -%>').val('');submitIssueForm(this)">
-          &nbsp;
-        <% end %>
         <%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>&nbsp;
         <span class="loading hidden"></span>
       </td>
index e4076fe0a6821964f2a40f906f550b7269428c81..391a08bb4fa12dca7b92699148d1dd4c57a0efbd 100644 (file)
@@ -5,7 +5,7 @@
 %>
 <form id="bulk-change-form" method="post" action="<%= ApplicationController.root_context -%>/issues/bulk_change">
   <input type="hidden" name="issues" value="<%= params[:issues] || @issues.join(',') -%>">
-  <input type="hidden" name="criteria_params" value="<%= params[:criteria_params] ||  @criteria_params.to_query -%>">
+  <input type="hidden" name="criteria_params" value="<%= params[:criteria_params] || @criteria_params.to_query -%>">
   <input type="hidden" name="project" value="<%= project -%>">
   <fieldset>
     <div class="modal-head">
@@ -18,7 +18,8 @@
           <input id="assign-action" name="actions[]" type="checkbox" value="assign"/>
           <%= message('issue.assign.formlink') -%>
         </label>
-        <%= user_select_tag('assign.assignee', :html_id => 'assignee', :open => false) -%>
+        <%= user_select_tag('assign.assignee', :html_id => 'assignee', :open => false,
+          :include_choices => {'' => escape_javascript(message('unassign')), current_user.login => escape_javascript(message('assign_to_me'))}) -%>
       </div>
       <%
          if project && !project.blank?
@@ -35,7 +36,7 @@
                [label, plan.key]
              }, first_plan.key)
            end
-        %>
+      %>
         <div class="modal-field">
           <label for="plan">
             <input id="plan-action" name="actions[]" type="checkbox" value="plan"/>
@@ -63,7 +64,7 @@
   </fieldset>
 </form>
 <script>
-  $j("#bulk-change-form").modalForm({success:function (data) {
+  $j("#bulk-change-form").modalForm({success: function (data) {
     window.location = baseUrl + '/issues/search?' + data;
   }});
 </script>
\ No newline at end of file