<%  @calendar_view_disable=1    %>

<div class="settings_common_container">

	<div class="settings_common_header" align="center">
		<div class="settings_common_header_text"><%= t('.ad_settings') %></div>
	</div>
	<div class="settings_common_table_container">
		<table class="table_body">
			<tr><td colspan="2" style="font-size:16px" align="center"><b><%= t('.connection_settings') %></b></td></tr>
			<% LdapParameter.all.each do |parameter| %>
			<tr style="height:50px">
				<td align="right"><%= t(".#{parameter[:parameter]}") %>:</td>
				<td><%= text_field_tag  "ad_parameter_#{parameter[:parameter]}" ,parameter[:value], :class => "text_field_relative" %></td>
			</tr>
			<% end %>
			<tr><td colspan="2" style="font-size:16px" align="center"><b><%= t('.user_group_settings') %></b><br>(<%= t('.user_group_description') %>)</td></tr>
			
			<% LdapUserGroup.joins(:user_group).select(:name_rus,:ldap_group_name,:user_group_id).all.each do |group| %>
			<tr style="height:50px">
				<td align="right"><%= group[:name_rus] %> = </td>
				<td><%= text_field_tag  "group_id_#{group[:user_group_id]}" ,group[:ldap_group_name], :class => "text_field_relative" %></td>
			</tr>
			<% end %>
  		  	<tr id="update_user_confirm_button">
   			 	<td colspan="2" align="center"><a class="href_edit_button" onclick="update_ad_settings()"><%= t(:update)%></a></td>
  		  	</tr>
			<tr id="update_ad_success" style="display:none">
				<td colspan="2" align="center" style=";color:<%= $green %>"><%= t('.updated')%></td>
			</tr> 
		</table>
	</div>
</div>

<script>
$(document).ready(
	function() { 
		$(".settings_common_table_container").niceScroll(scroll_settings);
	}
);
var parameter_list=<%= raw LdapParameter.select(:parameter,:value).to_json %>
var group_list=<%= raw LdapUserGroup.select(:user_group_id,:ldap_group_name).to_json %>
function update_ad_settings(){
	for(i=0;i<parameter_list.length;i++){
		parameter_list[i].value=document.getElementById('ad_parameter_'+parameter_list[i].parameter).value
	}
	for(i=0;i<group_list.length;i++){
		group_list[i].ldap_group_name=document.getElementById('group_id_'+group_list[i].user_group_id).value
	}
	$.post('update_ad_settings',{parameters:JSON.stringify(parameter_list),groups:JSON.stringify(group_list)},function(){
		document.getElementById('update_ad_success').style.display=''
		setTimeout(function(){document.getElementById('update_ad_success').style.display='none'},5000)
	}).fail(function(error) {
		show_loading(0)
		console.log(error)
		error_show(error)
  	})
}
</script>