	
	<div class="settings_common_table_container" style="padding-top:0px;width:calc(100% + 15px)">
		<table class="table_body" style="width:calc(100% - 15px)">
			<tr>
				<td align="right" style="line-height:50px;font-size:18px"><%= t(:filter_name)%>:</td>
				<td><input id="settings_filters_new_filter_name" class="text_field" style="width:250px;position:relative;cursor:pointer;font-size:16px;color:<%= $blue %>" placeholder='' ></td>
			</tr>
			<!---- ------------------------------------- Фильтр по операциям -------------------------------------------->
			<tr>
				<td colspan="2" align="center"><div class="text_header_red_line" style="width:400px;height:30px;top:0px;left:10px;position:relative" align="center"><%= t(:oper_filter)%></div>
			</tr>
			<tr>
				<td style="border-right:1px solid <%= $gray %>">
					<div style="width:100%;position:relative;height:200px">
						<table style="width:100%">
							<tr >
								<td align="right" style="width:120px;height:30px"><%= t(:filter_by_oper)%>:</td>
								<td style="position:relative;z-index:3;height:30px">
									<div style="width:calc(100% + 15px);height:30px;position:relative;left:calc(-15px / 2)">
									<%=
									render partial: "shared/search_list", locals: {
												select_id:'oper',
												select_name:t(:oper_search),
												search_command:'operation_sort',
												drop_direction:'down',
												input_style: 'text-align:left',
												delete_function:0 }
									%>
									</div>
								</td>
							</tr>
							<tr>
								<td align="right" style="width:120px;height:30px"><%= t(:filter_by_type)%>:</td>
								<td style="position:relative">
									<select id="settings_filters_type_id" size="1" style="width:100%;font-size:14px" >
												<option value="0"><%= t(:filter_none)%></option>
										<% 	OperationType.all.each do |item| %>
												<option value="<%= item[:id] %>"><%= item[:name] %></option>
										<% 	end %>
									</select>
								</td>
							</tr>
							<tr>
								<td align="right" style="width:120px;height:30px"><%= t(:filter_by_system)%>:</td>
								<td style="position:relative">
									<select id="settings_filters_source_id" size="1" style="width:100%;font-size:14px" >
												<option value="0"><%= t(:filter_none)%></option>
										<% 	OperationSource.all.each do |item| %>
												<option value="<%= item[:id] %>"><%= item[:name] %></option>
										<% 	end %>
									</select>
								</td>
							</tr>
							<tr >
								<td colspan="2" align="right" style="width:120px;height:30px">
									<div onclick="settings_filters_add_operations()" style="width:150px;position:relative" class="button"><%= t(:filter_add)%></div>
								</td>
							</tr>
							<tr >
								<td colspan="2" align="right" style="width:120px;height:30px">
									<div onclick="settings_filters_remove_operations(0)" style="width:150px;position:relative" class="red_button"><%= t(:filter_remove)%></div>
								</td>
							</tr>
						</table>
					</div>
				</td>
				<td style="padding:0px;border-top:1px solid <%= $gray %>;border-bottom:1px solid <%= $gray %>;position:relative">
					<div class="settings_filter_scroll_container" style="width:100%;height:300px;position:relative;overflow:scroll;overflow-x:hidden">
						<table class="table_body" id="settings_filters_operation_table" style="width:100%">
						</table>
					</div>
					
				</td>
			</tr>
			<!---- ------------------------------------- Фильтр по пользователям -------------------------------------------->
			<tr>
				<td colspan="2" align="center"><div class="text_header_red_line" style="width:400px;height:30px;top:0px;left:10px;position:relative" align="center"><%= t(:login_filter)%></div>
			</tr>
			<tr>
				<td style="border-right:1px solid <%= $gray %>">
					<div style="width:100%;position:relative;height:200px">
						<table style="width:100%">
							<tr >
								<td align="right" style="width:120px;height:30px"><%= t(:filter_by_login)%>:</td>
								<td style="position:relative;z-index:2;position:relative">
									<div style="width:calc(100% + 15px);height:30px;position:relative;left:calc(-15px / 2)">
									<%=
									render partial: "shared/search_list", locals: {
												select_id:'login',
												select_name:t(:login_search),
												search_command:'login_sort',
												drop_direction:'down',
												input_style: 'text-align:left',
												delete_function:0 }
									%>
									</div>
								</td>
							</tr>
							<tr>
								<td align="right" style="width:120px;height:30px"><%= t(:filter_by_office)%>:</td>
								<td style="position:relative">
									<select id="settings_filters_office_id" size="1" style="width:100%;font-size:14px" >
												<option value="0"><%= t(:filter_none)%></option>
										<% 	Office.all.each do |item| %>
												<option value="<%= item[:id] %>"><%= item[:name] %></option>
										<% 	end %>
									</select>
								</td>
							</tr>
								<td colspan="2" align="right" style="width:120px;height:30px">
									<div onclick="settings_filters_add_logins()" style="width:150px;position:relative" class="button"><%= t(:filter_add)%></div>
								</td>
							</tr>
							<tr >
								<td colspan="2" align="right" style="width:120px;height:30px">
									<div onclick="settings_filters_remove_logins(0)" style="width:150px;position:relative" class="red_button"><%= t(:filter_remove)%></div>
								</td>
							</tr>
						</table>
					</div>
				</td>
				<td style="padding:0px;border-top:1px solid <%= $gray %>;border-bottom:1px solid <%= $gray %>;position:relative">
					<div class="settings_filter_scroll_container" style="width:100%;height:300px;position:relative;overflow:scroll;overflow-x:hidden">
						<table class="table_body" id="settings_filters_login_table" style="width:100%">
						</table>
					</div>
					
				</td>
			</tr>
			
			<script>
			var settings_filters_selected_operation_id = 0
			function oper_select_search(foid){
					settings_filters_selected_operation_id=foid
			}
			var settings_filters_selected_login_id = 0
			function login_select_search(foid){
					settings_filters_selected_login_id=foid
		
			}
			var settings_filters_operation_array=[]
			var settings_filters_login_array=[]

			function settings_filters_create_new_filter(path){
				show_loading(1)
				filter_name=document.getElementById('settings_filters_new_filter_name').value
				filter_operations=[]
				filter_logins=[]
				for (n=0;n<settings_filters_operation_array.length;n++){
					filter_operations.push(settings_filters_operation_array[n].id)
				}
				for (n=0;n<settings_filters_login_array.length;n++){
					filter_logins.push(settings_filters_login_array[n].id)
				}
				$.post(path,{name: filter_name, operations: JSON.stringify(filter_operations), logins: JSON.stringify(filter_logins)},function(){
					show_loading(0)
				})
			}




			///////////////////////////////////////////// Operations /////////////////////////////////
			function settings_filters_add_operations(){
				show_loading(1)
				operation_id=settings_filters_selected_operation_id
				operation_type_id=document.getElementById('settings_filters_type_id').value
				operation_source_id=document.getElementById('settings_filters_source_id').value
				$.getJSON('get_operations_to_filter',{operation_id:operation_id, operation_type_id:operation_type_id, operation_source_id:operation_source_id}, function(data){
					for (i=0;i<data.length;i++){
						check=0
						for (n=0;n<settings_filters_operation_array.length;n++){if (settings_filters_operation_array[n].id == data[i].id){check=1}}
						if (check==0){settings_filters_operation_array.push(data[i])}
					}
					settings_filters_build_operations()
					show_loading(0)
				})	
			}
			function settings_filters_build_operations(){
				
				$('.settings_filters_operation_row').remove()
				for (n=0;n<settings_filters_operation_array.length;n++){
					if(n % 2 == 0){color="<%= $white %>"}else{color="<%= $l_gray %>"}
					console.log(n)
					$('<tr class="settings_filters_operation_row" style="background:'+color+'">'+
							'<td style="width:60px">'+oper_system_source(settings_filters_operation_array[n])+'</td>'+
							'<td>'+settings_filters_operation_array[n].name+' ('+settings_filters_operation_array[n].type_name+')</td>'+
							'<td style="width:40px"><img src="/assets/no_access.png" width="20" height="20" style="cursor:pointer" onclick="settings_filters_remove_operations('+settings_filters_operation_array[n].id+')"></td>'+
						'</tr>').appendTo('#settings_filters_operation_table')
				}
			}
			function settings_filters_remove_operations(id){
				if (id == 0){
					settings_filters_operation_array.length=0
				}else{
					for (n=0;n<settings_filters_operation_array.length;n++){
						if (settings_filters_operation_array[n].id == id){settings_filters_operation_array.splice(n,1)}
					}
				}
				settings_filters_build_operations()
			}

			/////////////////////////// Logins ////////////////////////////////////////

			function settings_filters_add_logins(){
				show_loading(1)
				login_id=settings_filters_selected_login_id
				office_id=document.getElementById('settings_filters_office_id').value
				$.getJSON('get_logins_to_filter',{login_id:login_id, office_id:office_id}, function(data){
					for (i=0;i<data.length;i++){
						check=0
						for (n=0;n<settings_filters_login_array.length;n++){if (settings_filters_login_array[n].id == data[i].id){check=1}}
						if (check==0){settings_filters_login_array.push(data[i])}
					}
					settings_filters_build_logins()
					show_loading(0)
				})	
			}
			function settings_filters_build_logins(){
				$('.settings_filters_login_row').remove()
				for (n=0;n<settings_filters_login_array.length;n++){
					if(n % 2 == 0){color="<%= $white %>"}else{color="<%= $l_gray %>"}
					$('<tr class="settings_filters_login_row" style="background:'+color+'">'+
							'<td>'+settings_filters_login_array[n].name+'</td>'+
							'<td style="width:40px"><img src="/assets/no_access.png" width="20" height="20" style="cursor:pointer" onclick="settings_filters_remove_logins('+settings_filters_login_array[n].id+')"></td>'+
						'</tr>').appendTo('#settings_filters_login_table')
				}
			}
			function settings_filters_remove_logins(id){
				if (id == 0){
					settings_filters_login_array.length=0
				}else{
					for (n=0;n<settings_filters_login_array.length;n++){
						if (settings_filters_login_array[n].id == id){settings_filters_login_array.splice(n,1)}
					}
				}
				settings_filters_build_logins()
			}
			
			$(document).ready(
				function() { 
					$(".settings_common_table_container").niceScroll(scroll_settings);
					$(".settings_filter_scroll_container").niceScroll(scroll_settings);
				}
			);
			
		
			</script>