starting on infinite scrolling of select2 inside members form. member itself might be working, roles are definitely not
Conflicts: app/controllers/members_controller.rb app/models/principal.rb Conflicts: app/controllers/members_controller.rb removes deprecated test for autocompletion Conflicts: Gemfile app/views/members/_new_member_form.rhtml public/javascripts/members_select_boxes.js Conflicts: Gemfile Conflicts: Gemfile test/functional/members_controller_test.rbpull/82/head
parent
b8aaa2bd64
commit
26bff02cc7
@ -0,0 +1,32 @@ |
||||
<%= javascript_include_tag "members_select_boxes.js" %> |
||||
|
||||
<% remote_form_for(:member, :url => {:controller => 'members', :action => 'new', :id => project}, :method => :post, :html => {:id => "members_add_form"}) do |f| %> |
||||
<fieldset> |
||||
<legend><%= l(:label_member_new) %></legend> |
||||
<p> |
||||
<label> |
||||
<% options = principals.collect { |obj| [obj.name, obj.id] } %> |
||||
<%= select_tag "member[user_ids][]", options_for_select(options), |
||||
:title => l(:label_principal_search), |
||||
:multiple => true, |
||||
:'data-placeholder' => l(:label_principal_search), |
||||
:'data-ajaxURL' => url_for(:controller => "members", :action => "autocomplete_for_member"), |
||||
:'data-projectId' => project.id, |
||||
:class => "select2-select" %> |
||||
</label> |
||||
</p> |
||||
<p> |
||||
<label> |
||||
<% options = roles.collect { |obj| [obj.name, obj.id] } %> |
||||
<%= select_tag 'member[role_ids][]', options_for_select(options), |
||||
:title => l(:label_role_plural), |
||||
:multiple => true, |
||||
:'data-placeholder' => l(:label_role_plural), |
||||
:'data-ajaxURL' => url_for(:controller => "members", :action => "autocomplete_for_roles"), |
||||
:'data-projectId' => project.id, |
||||
:class => "select2-select" %> |
||||
</label> |
||||
</p> |
||||
<p><%= submit_tag l(:button_add), :id => 'member-add-submit' %></p> |
||||
</fieldset> |
||||
<% end %> |
@ -0,0 +1,68 @@ |
||||
jQuery(document).ready(function($) { |
||||
var load_cb, memberstab, update_cb; |
||||
init_members_cb = function () { |
||||
$("#members_add_form select.select2-select").each(function (ix, elem){ |
||||
if (!$.isEmptyObject(elem.siblings('div.select2-select.select2-container'))) { |
||||
setTimeout (function () { |
||||
var attributes, allowed, currentName, fakeInput; |
||||
attributes = {} |
||||
allowed = ["title", "placeholder"]; |
||||
|
||||
for(var i = 0; i < $(elem).get(0).attributes.length; i++) { |
||||
currentName = $(elem).get(0).attributes[i].name; |
||||
if(currentName.indexOf("data-") == 0 || $.inArray(currentName, allowed)); //only ones starting with data-
|
||||
attributes[currentName] = $(elem).attr(currentName); |
||||
} |
||||
fakeInput = $(elem).after("<input type='hidden'></input>").siblings(":input:first"); |
||||
fakeInput.attr(attributes); |
||||
$(fakeInput).select2({ |
||||
minimumInputLength: 1, |
||||
ajax: { |
||||
url: $(fakeInput).attr("data-ajaxURL"), |
||||
dataType: 'json', |
||||
quietMillis: 100, |
||||
contentType: "application/json", |
||||
data: function (term, page) { |
||||
return { |
||||
q: term, //search term
|
||||
page_limit: 10, // page size
|
||||
page: page, // page number
|
||||
id: fakeInput.attr("data-projectId") // current project id
|
||||
}; |
||||
}, |
||||
results: function (data, page) { |
||||
|
||||
// notice we return the value of more so Select2 knows if more results can be loaded
|
||||
active_principals = [] |
||||
data.results.principals.each(function (e) { |
||||
if (e.active === true) { |
||||
active_principals.push(e); |
||||
} |
||||
}); |
||||
return {'results': active_principals, 'more': data.results.more}; |
||||
} |
||||
}, |
||||
formatResult: formatPrincipal, // omitted for brevity, see the source of this page
|
||||
formatSelection: formatPrincipalSelection |
||||
}); |
||||
// $(elem).hide();
|
||||
}, 0); |
||||
} |
||||
}); |
||||
} |
||||
memberstab = $('#tab-members').first(); |
||||
if ((memberstab != null) && (memberstab.hasClass("selected"))) { |
||||
init_members_cb(); |
||||
} else { |
||||
memberstab.click(init_members_cb); |
||||
} |
||||
|
||||
formatPrincipal = function (principal) { |
||||
var markup = "<span class='select2-match' data-value='" + principal.id + "'>" + principal.name + "</span>"; |
||||
return markup; |
||||
} |
||||
formatPrincipalSelection = function (principal) { |
||||
return principal.name; |
||||
} |
||||
|
||||
}); |
Loading…
Reference in new issue