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,
}
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}'/>"
# * <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={})
<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)">
- <% if @issue.assignee %>
- <%= image_tag 'sep12.png' -%>
-
- <input type="button" value="<%= message('issue.unassign.submit') -%>" onclick="$j('#<%= user_select_box_id -%>').val('');submitIssueForm(this)">
-
- <% end %>
<%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>
<span class="loading hidden"></span>
</td>
%>
<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">
<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?
[label, plan.key]
}, first_plan.key)
end
- %>
+ %>
<div class="modal-field">
<label for="plan">
<input id="plan-action" name="actions[]" type="checkbox" value="plan"/>
</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