orbit4-5/app/views/admin/groups/edit.html.erb

95 lines
3.1 KiB
Plaintext
Raw Normal View History

2015-05-22 19:48:07 +00:00
<%= form_for @group, :url => admin_group_path(@group.id), :html => { :multipart => true , :class=>"form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render :partial => "group_form", locals: {f: f} %>
</fieldset>
<% end %>
<div class="modal fade" id="existing_members_dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Modify members</h4>
</div>
<div class="modal-body">
<table>
<% @existing_members.each do |em| %>
<tr>
<td><img src="<%= em["avatar"] %>" style="width:75px;height:75px;" /></td>
<td width="70%" <%= em["id"] != current_user.id.to_s ? "" : "colspan='3'" %>><h5><%= em["name"][I18n.locale.to_s] %></h5></td>
<% if em["id"] != current_user.id.to_s %>
<td><input type="checkbox" class="make-admin-checkbox" value="<%= em["id"] %>" <%= em["admin"] ? "checked='checked'" : ""%> /> Admin</td>
<td><a href="#" style="font-size:25px;" class="member-delete-btn" data-member="<%= em.to_json %>"><i class="icon-trash"></i></a></td>
<% end %>
</tr>
<% end %>
</table>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<script type="text/javascript">
var members_to_add = [],
existing_members_count = <%= @existing_members.count.to_s %>;
$("#existing_members_dialog").on("shown",function(){
members_to_add = [];
})
$("#existing_members_dialog").on("hidden",function(){
if(members_to_add.length > 0){
var options = "";
$.each(members_to_add,function(i,member){
$(".existing-phone-avatar[data-member-id="+member["id"]+"]").remove();
options+= "<option value='" + member["id"] + "' data-member='" + JSON.stringify(member) + "'>" + member["name"][locale] + "</option>";
})
$(".member_selection").select2("destroy").append(options);
$.ajax({
url : "/admin/groups/existing_member_template",
data : {"group_id" : "<%= @group.id.to_s %>"},
dataType : "html"
}).done(function(template){
$("#group_existing_member_holder").html(template);
})
bindSelect();
}
})
$(".member-delete-btn").on("click",function(){
if(confirm("Are you sure?")){
var el = $(this),
tr = el.parent().parent();
members_to_add.push(el.data("member"));
$.ajax({
url : "/admin/groups/<%= @group.id.to_s %>/remove_user",
data : {"user_id" : el.data("member")["id"]},
dataType : "json",
type : "post"
}).done(function(){
tr.slideUp(function(){
tr.remove();
})
})
}
})
$(".make-admin-checkbox").on("click",function(){
var el = $(this),
admin = el.is(":checked");
$.ajax({
url : "/admin/groups/<%= @group.id.to_s %>/toggle_admin",
data : {"user_id" : el.val(), "admin" : admin},
dataType : "json",
type : "post"
})
})
</script>