<div class="settings_common_container">
	<div class="settings_common_header">	
		<%= link_to t(:cancel), settings_user_groups_path, class:"href_delete_button", style:"float:left" %>
	<div class="settings_common_header_text"><%= t('.edit_user_group')%></div>
</div>
<div class="settings_common_table_container" style="padding-top:10px">
  <table class="table_body">		
  <tr>
     <td align="right"><%= t('.group_name')%>:</td>
     <td> <%= text_field(:group,:name_rus, :class => "text_field_relative")  %></td>
  </tr>
  <tr>
	 <td align="right"> <%= t('.access')%>:</td>
	 <td><table>
		<% Menu.all.each do |menu|%>
		<tr>
			
		 	<td><%= menu[I18n.locale] %></td>
			<%if menu.user_accesses.where(:user_group_id => @group.id).count > 0; @menu_selected = true;else; @menu_selected = false; end%>
		 	<td><%= check_box_tag "menu_#{menu.id}",menu.id, @menu_selected, :class => "menu_access" %></td>
		</tr>
		<% end %>
	 </table></td>

  </tr >
    <td colspan="2" align="center"><div class="button" onclick="update_group_access()" style="position:relative" ><%= t(:update)%></div></td>
  </tr>
		</table>
	</div>
</div>

<script>


function update_group_access(){
	menu_array=[]
			menus=document.getElementsByClassName('menu_access')
			for (n=0;n<menus.length;n++){
				menu_array.push({'id':menus[n].value,'status':menus[n].checked})
			}
	$.post('<%= update_access_settings_user_group_path(:id => params[:id]) %>',{settings: JSON.stringify(menu_array)}, function(){
		window.open('<%= settings_user_groups_path%>','_self');		
	
	})
}

</script>