registered-sites/app/views/admin/registered_sites/_site_selection_box.html.erb

99 lines
3.2 KiB
Plaintext

<% content_for :page_specific_javascript do -%>
<%= javascript_include_tag "select2/select2.min" %>
<%= javascript_include_tag "lib/jquery.nanoscroller" %>
<% end -%>
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "member_select" %>
<% end %>
<div id="selected_email_users" class="selected_users">
<% recieve_sites.each do |recieve_site| %>
<span class="alert alert-info selected_user" id="<%= recieve_site.id %>">
<span class='close remove_user' onclick='removeUser($(this))'>x</span>
<%= recieve_site.title.nil? ? recieve_site.site_domain : recieve_site.title %>
<%= hidden_field_tag field, recieve_site.id %>
</span>
<% end %>
</div>
<a class="btn btn-primary btn-small" onclick="delete_all_sites()">delete all</a>
<a class="btn btn-primary btn-small select_user_modal"><%= t(:add) %></a>
<script type="text/javascript">
var mail_users = Array();
function delete_all_sites(){
$('.alert.alert-info.selected_user').remove()
}
$(function(){
$.each($(".selected_user"),function(){
mail_users.push($(this).attr("id"));
});
$(".select_user_modal").click(function(){
if($("#select_user").length==0) {
$("#main-wrap").after("<span id='select_user'></span>");
}
$.get("<%= get_select_box_admin_registered_sites_path %>",function(modal){
$("#select_user").html(modal);
$('#member-filter').ready(function(){
updateModal();
$("#member-filter").modal();
$('#member-filter').on('shown', function() {
$(".nano").nanoScroller();
});
})
});
});
});
var addByRole = function(role){
$.each($("#r_"+role+" .check-item"), function(){
mail_users.push($(this).find("input[type='checkbox']").val());
});
}
var removeUser = function(user){
mail_users = $.grep(mail_users, function(value) {return value != $(user).parent().attr('id');});
$(user).parent().remove();
}
var updateUsers = function(){
$.each($(".role_field input:checked"), function(){
addByRole($(this).val());
});
$("#selected_email_users").html("");
mail_users = $.unique(mail_users);
$.each(mail_users, function(i, user_id){
var username = $("input[value='"+user_id+"']").parent().find(".user-name").html();
$("#selected_email_users").append(
" <span class='alert alert-info selected_user' id='"+user_id+"'>"+
"<span class='close remove_user' onclick='removeUser($(this))'>x</span>"+
username+
"<input type='hidden' name='<%= field %>' value='"+user_id+"' >"+
"</span>"
);
});
}
var updateModal = function(){
$.each($("#selected_email_users .selected_user"),function(){
var user_id = $(this).attr('id');
$("input[value='"+user_id+"']").parent("li").hide();
});
$('.check-item').click(function(e){
var user_id = $(e.target).find("input[type='checkbox']").val();
if (user_id==undefined){
user_id = $(e.target).val()
}
$(e.target).toggleClass("active");
if($(e.target).hasClass("active")){
mail_users.push(user_id);
}else{
mail_users = $.grep(mail_users, function(value) {return value != user_id;});
}
});
}
</script>