437 lines
22 KiB
JavaScript
437 lines
22 KiB
JavaScript
var textlength = 0;
|
|
var index = 0;
|
|
function searchTextResize(element) {
|
|
textlength = (textlength == 0 ? 1 : textlength);
|
|
var width_ = (Number(textlength) + 3);
|
|
$(element).css('width', width_ + 'rem');
|
|
}
|
|
|
|
function inputFocus(element) {
|
|
$(element).find('ul.ul-search').find('.input-text').focus();
|
|
}
|
|
function searchTextMultiple(element, urlPost, hasCode) {
|
|
var text = $(element).val();
|
|
|
|
|
|
textlength = text.length;
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
if (text != "") {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
$(element).parent().parent().parent('.custom-select').children('ul.result').show();
|
|
$.ajax({
|
|
/* contentType: 'charset=utf-8',*/
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: urlPost,//'@Url.Page("/Company/InsuranceJob/Index", "JobListByText")',
|
|
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
|
data: { "textSearch": text },
|
|
success: function (response) {
|
|
//console.log(response);
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
if (response.list.length > 0) {
|
|
var ids = [];
|
|
// $(element).parent('.custom-select').children().children('span.items-selected').each(function(x)
|
|
$('.custom-select').children('ul.ul-search').find('span.items-selected').each(function (x) {
|
|
ids.push(Number($(this).attr('data-value')));
|
|
});
|
|
$.each(response.list, function (i, item) {
|
|
if (jQuery.inArray(item.id, ids) == -1) {
|
|
if (hasCode) {
|
|
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item" onclick="selectItemSearchMultiple(this)" data-code="' + item.jobCode + '" data-name="' + item.Name + '" data-value="' + item.id + '"><span class="name-right">' + item.Name + '</span><span class="line">|</span><span class="code-left">' + item.jobCode + '</span></li>');
|
|
|
|
$('.code-left').each(function () {
|
|
var spanContent = $(this).text();
|
|
if (/\D/.test(spanContent)) { // Check if the content of the span contains non-digits
|
|
$(this).css('color', 'red');
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item" onclick="selectItemSearchMultiple(this)" data-name="' + item.searchResultTitle + '" data-value="' + item.id + '"><span class="name-right">' + item.searchResultTitle + '</span></li>');
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item"><span>هیچ نتیجه ای یافت نشد</span></li>');
|
|
}
|
|
},
|
|
failure: function (response) {
|
|
// console.log(5, response);
|
|
}
|
|
|
|
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function searchText(e,element, urlPost, hasCode) {
|
|
|
|
var code = e.code;
|
|
|
|
if (code != "ArrowDown" && code != "ArrowUp" && code != "Enter") {
|
|
|
|
var text = $(element).val();
|
|
|
|
textlength = text.length;
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
if (text != "") {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
$(element).parent().parent().parent('.custom-select').children('ul.result').show();
|
|
$.ajax({
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: urlPost,//'@Url.Page("/Company/InsuranceJob/Index", "JobListByText")',
|
|
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
|
data: { "textSearch": text },
|
|
success: function (response) {
|
|
index = 0;
|
|
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
if (response.list.length > 0) {
|
|
var ids = [];
|
|
|
|
$(element).parent().parent().parent('.custom-select').children('.result').find("li.select-item:not(.hasinput)").remove();
|
|
|
|
$('.custom-select').children('ul.ul-search').find('span.items-selected').each(function (x) {
|
|
ids.push(Number($(this).attr('data-value')));
|
|
});
|
|
$.each(response.list, function (i, item) {
|
|
if (jQuery.inArray(item.id, ids) == -1) {
|
|
if (hasCode) {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item" onclick="selectItemSearch(this)" data-code="' + item.searchResultCode + '" data-name="' + item.searchResultTitle + '" data-value="' + item.id + '"><span class="name-right">' + item.searchResultTitle + '</span><span class="line">|</span><span class="code-left">' + item.searchResultCode + '</span></li>');
|
|
$('.code-left').each(function () {
|
|
var spanContent = $(this).text();
|
|
if (/\D/.test(spanContent)) { // Check if the content of the span contains non-digits
|
|
$(this).css('color', 'red');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item" onclick="selectItemSearch(this)" data-name="' + item.searchResultTitle + '" data-value="' + item.id + '"><span class="name-right">' + item.searchResultTitle + '</span></li>');
|
|
}
|
|
}
|
|
});
|
|
$(element).parent().parent().parent('.custom-select').children('.result').find("li.select-item:not(.hasinput)").first().focus();
|
|
$(element).parent().parent().parent('.custom-select').children('.result').find("li.select-item:not(.hasinput)").first().addClass('arrowselected');
|
|
}
|
|
else {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
$(element).parent().parent().parent('.custom-select').children('.result').append('<li class="select-item"><span>هیچ نتیجه ای یافت نشد</span></li>');
|
|
}
|
|
},
|
|
failure: function (response) {
|
|
//console.log(5, response);
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$(element).parent().parent().parent('.custom-select').children('.result').find("li.select-item:not(.hasinput)").remove();
|
|
}
|
|
}
|
|
}
|
|
|
|
var selectItemSearch = function (element) {
|
|
let activeTabPane = $('.tab-pane.active');
|
|
var name = activeTabPane.find(element).attr("data-name");
|
|
var code = activeTabPane.find(element).attr("data-code");
|
|
var value = activeTabPane.find(element).attr("data-value");
|
|
//وقنی اسکرول بالا رفت اینطور شود
|
|
//$(element).parent().parent('.custom-select').children('ul.result').removeClass('posistion-static');
|
|
//$(element).parent().parent('.custom-select').children('ul.result').removeClass('posistion-absolute');
|
|
activeTabPane.find(element).parent().parent().children('ul.ul-search').find('input').val('');
|
|
activeTabPane.find(element).parent().parent().children('ul.ul-search').find('input').parent('li').remove();
|
|
activeTabPane.find(element).parent().parent('.custom-select').children('ul.result').hide();
|
|
activeTabPane.find(element).parent().parent().children('ul.ul-search').find('.singleItem').remove();
|
|
|
|
|
|
if (code == 'undefined' || code == null) {
|
|
activeTabPane.find(element).parent().parent().children('ul.ul-search').append('<li onclick="openSearchResult(this)" class="singleItem"><span data-value="' + value + '" >' + name + '</li>');
|
|
}
|
|
else
|
|
activeTabPane.find(element).parent().parent().children('ul.ul-search').append('<li onclick="openSearchResultByCode(this)" class="singleItem"><span class="value" data-value="' + value + '" >' + name + '</span>|<span class="code" data-code="' + code + '" >' + code + '</span></li>');
|
|
|
|
//$(element).parent().parent().children('ul.ul-search').append('<li> <input onkeyup="searchText(this)" onkeypress="searchTextResize(this)" class="text-right input-text" /></li>');
|
|
}
|
|
|
|
var openSearchResult = function (element) {
|
|
// var url = $(element).parent().attr('data-url');
|
|
$(element).parent().parent('.custom-select').children('.result').html('');
|
|
|
|
$(element).parent().parent('.custom-select').children('ul.result').show()
|
|
//وقنی اسکرول شد اینطور شود
|
|
// $(element).parent().parent('.custom-select').children('ul.result').show().addClass('posistion-static'); posistion-absolute
|
|
$(element).parent().parent('.custom-select').children('.result').append('<li class="select-item hasinput"><input onkeyup="searchTextForSingle(event,this,false)" class="text-right input-text-single " /></li>');
|
|
}
|
|
var openSearchResultByCode = function (element) {
|
|
// var url = $(element).parent().attr('data-url');
|
|
$(element).parent().parent('.custom-select').children('.result').html('');
|
|
|
|
$(element).parent().parent('.custom-select').children('ul.result').show()
|
|
//وقنی اسکرول شد اینطور شود
|
|
// $(element).parent().parent('.custom-select').children('ul.result').show().addClass('posistion-static'); posistion-absolute
|
|
$(element).parent().parent('.custom-select').children('.result').append('<li class="select-item hasinput"><input onkeyup="searchTextForSingle(event,this,true)" class="text-right input-text-single " /></li>');
|
|
}
|
|
|
|
function selectItemSearchMultiple(element) {
|
|
var code = $(element).attr("data-code");
|
|
var name = $(element).attr("data-name");
|
|
var value = $(element).attr("data-value");
|
|
$(element).parent().parent().children('ul.ul-search').find('input').val('');
|
|
$(element).parent().parent().children('ul.ul-search').find('input').parent('li').remove();
|
|
$(element).parent().parent().children('ul.ul-search').append('<li><span data-value="' + value + '" class="items-selected">' + name + '<span data-code="' + code + '" data-name="' + name + '" onclick="deleteSelect(this,' + value + ')" class="del-selected"><i class="fa fa-times"></></span>' + '</span></li>');
|
|
$(element).parent().parent().children('ul.ul-search').append('<li> <input onkeyup="searchText(this)" onkeypress="searchTextResize(this)" class="text-right input-text" /></li>');
|
|
}
|
|
|
|
function deleteSelect(element, id) {
|
|
var text = $(element).parent().parent('.custom-select').find('input.input-text').val();
|
|
var code = $(element).attr("data-code");
|
|
var name = $(element).attr("data-name");
|
|
var value = id;
|
|
if (text != '' && name.indexOf(text) != -1) {
|
|
$(element).parent().parent('.custom-select').children('.result').prepend('<li class="job-item" onclick="selectItemSearch(this)" data-code="' + code + '" data-name="' + name + '" data-value="' + id + '"><span class="name-right">' + name + '</span><span class="line">|</span> <span class="code-left">' + code + '</span></li>');
|
|
$('.code-left').each(function () {
|
|
var spanContent = $(this).text();
|
|
if (/\D/.test(spanContent)) { // Check if the content of the span contains non-digits
|
|
$(this).css('color', 'red');
|
|
}
|
|
});
|
|
}
|
|
$(element).parent().remove();
|
|
}
|
|
|
|
$(document).click(
|
|
function (e) {
|
|
// console.log($(e.target).attr('class'));
|
|
var classElement = $(e.target).parent().attr('class');
|
|
if (classElement != "input-text-single" && classElement != "select-item hasinput" && classElement != "del-selected" && classElement != "singleItem" && classElement != "select-item" && classElement !="result options text-right" ) {
|
|
$(".dadmehr-select-search").find('.result').hide();
|
|
}
|
|
});
|
|
|
|
function handleClick(event) {
|
|
const customSelect = $(event.target).closest(".custom-select input");
|
|
const divOffset = customSelect.offset();
|
|
$(".options").css("top", divOffset.top - 5);
|
|
if ($(window).width() < 1550) {
|
|
$(".options").css("top", divOffset.top + 10);
|
|
// console.log(1);
|
|
}
|
|
}
|
|
|
|
function searchTextForSingle(e,element, hasCode) {
|
|
// console.log(2);
|
|
var code = e.code;
|
|
// console.log(code);
|
|
if (code != "ArrowDown" && code != "ArrowUp" && code != "Enter") {
|
|
var urlPost = $(element).parent().parent().parent().find('.ul-search').attr('data-url');
|
|
// searchText(element, urlPost, hasCode);
|
|
|
|
var text = $(element).val();
|
|
textlength = text.length;
|
|
// $(element).parent().parent().parent('.custom-select').children('.result').html('');
|
|
if (text != "") {
|
|
$.ajax({
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: urlPost,
|
|
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
|
data: { "textSearch": text },
|
|
success: function (response) {
|
|
index = 0;
|
|
// console.log(response);
|
|
if (response.list.length > 0) {
|
|
var ids = [];
|
|
$(element).parent().parent('.result').find("li.select-item:not(.hasinput)").remove();
|
|
$.each(response.list, function (i, item) {
|
|
|
|
if (jQuery.inArray(item.id, ids) == -1) {
|
|
if (hasCode) {
|
|
$(element).parent().parent('.result').append('<li class="select-item" onclick="selectItemSearch(this)" data-code="' + item.searchResultCode + '" data-name="' + item.searchResultTitle + '" data-value="' + item.id + '"><span class="name-right">' + item.searchResultTitle + '</span><span class="line">|</span><span class="code-left">' + item.searchResultCode + '</span></li>');
|
|
$('.code-left').each(function () {
|
|
var spanContent = $(this).text();
|
|
if (/\D/.test(spanContent)) { // Check if the content of the span contains non-digits
|
|
$(this).css('color', 'red');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$(element).parent().parent('.result').append('<li class="select-item" onclick="selectItemSearch(this)" data-name="' + item.searchResultTitle + '" data-value="' + item.id + '"><span class="name-right">' + item.searchResultTitle + '</span></li>');
|
|
}
|
|
}
|
|
});
|
|
$(element).parent().parent('.result').find("li.select-item:not(.hasinput)").first().focus();
|
|
$(element).parent().parent('.result').find("li.select-item:not(.hasinput)").first().addClass('arrowselected');
|
|
}
|
|
else {
|
|
$(element).parent().parent('.result').find("li.select-item:not(.hasinput)").remove();
|
|
$(element).parent().parent('.result').append('<li class="select-item"><span>هیچ نتیجه ای یافت نشد</span></li>');
|
|
}
|
|
},
|
|
failure: function (response) {
|
|
console.log(5, response);
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$(element).parent().parent('.result').find("li.select-item:not(.hasinput)").remove();
|
|
}
|
|
}
|
|
}
|
|
|
|
//document.addEventListener('keydown', function (event) {
|
|
|
|
// var ul = $(this).closest('.dadmehr-select-search').find('.result');
|
|
// if (ul.is(":visible")) {
|
|
// liSelected = ul.find(".arrowselected")[0];
|
|
// var len = ul.find("li").length - 1;
|
|
// if (event.which === 40) {
|
|
// console.log(index);
|
|
// //if (index==-1)
|
|
// //ul.find("li.select-item:not(.hasinput)").first().focus();
|
|
// index++;
|
|
// //down
|
|
|
|
// if (liSelected) {
|
|
// removeClass(liSelected, 'arrowselected');
|
|
// next = ul.find('li')[index];
|
|
// if (typeof next !== undefined && index <= len) {
|
|
// liSelected = next;
|
|
|
|
// }
|
|
// else {
|
|
// index = 0;
|
|
// liSelected = ul.find('li')[0];
|
|
// }
|
|
// ul.find("li:eq(" + index + ")")
|
|
// .addClass('arrowselected');
|
|
// //liSelected.addClass('arrowselected');
|
|
// }
|
|
// else {
|
|
// index = 0;
|
|
|
|
// liSelected = ul.find('li')[0];
|
|
// addClass(liSelected, 'arrowselected');
|
|
// }
|
|
// }
|
|
// else if (event.which === 38) {
|
|
|
|
// liSelected.focus();
|
|
// //up
|
|
// if (liSelected) {
|
|
// removeClass(liSelected, 'arrowselected');
|
|
// index--;
|
|
// console.log(index);
|
|
// next = ul.find('li')[index];
|
|
// if (typeof next !== undefined && index >= 0) {
|
|
// liSelected = next;
|
|
// } else {
|
|
// index = len;
|
|
// liSelected = ul.find('li')[len];
|
|
// }
|
|
// addClass(liSelected, 'arrowselected');
|
|
// } else {
|
|
// index = 0;
|
|
// liSelected = ul.find('li')[len];
|
|
// addClass(liSelected, 'arrowselected');
|
|
// }
|
|
// }
|
|
// else if (event.which === 13) {
|
|
// var selectItem = ul.find('li.arrowselected');
|
|
|
|
// selectItemSearch(selectItem);
|
|
// }
|
|
// }
|
|
//}, false);
|
|
|
|
function removeClass(el, className) {
|
|
if (el.classList) {
|
|
el.classList.remove(className);
|
|
} else {
|
|
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
|
}
|
|
};
|
|
|
|
function addClass(el, className) {
|
|
if (el.classList) {
|
|
el.classList.add(className);
|
|
} else {
|
|
el.className += ' ' + className;
|
|
}
|
|
};
|
|
|
|
|
|
//document.addEventListener('keydown', function (e) {
|
|
document.onkeydown = function (e) {
|
|
|
|
var ul = $('.dadmehr-select-search').find('.result');
|
|
|
|
if (ul.is(":visible")) {
|
|
|
|
switch (e.which) {
|
|
case 38: // Up arrow
|
|
e.preventDefault();
|
|
ul.find("li").removeClass('arrowselected');
|
|
if ((index - 1) >= 0) {
|
|
index--;
|
|
ul.find("li.select-item:eq(" + index + ")").addClass('arrowselected');
|
|
ul.scrollTop(index * (ul.find("li.select-item:eq(" + index + ")").outerHeight()+5));
|
|
ul.find("li.arrowselected").focus();
|
|
} else {
|
|
index = -1;
|
|
}
|
|
|
|
break;
|
|
case 40: // Down arrow
|
|
e.preventDefault();
|
|
if ((index + 1) < ul.find("li").length) {
|
|
|
|
|
|
ul.find("li.select-item").removeClass('arrowselected');
|
|
index++;
|
|
//console.log(index);
|
|
console.log(index);
|
|
ul.find("li.select-item:eq(" + index + ")").addClass('arrowselected');
|
|
ul.scrollTop(index * (ul.find("li.select-item:eq(" + index + ")").outerHeight()+5));
|
|
ul.find("li.arrowselected").focus();
|
|
console.log(index * ul.find("li.select-item:eq(" + index + ")").outerHeight());
|
|
console.log(ul.find("li.select-item:eq(" + index + ")").outerHeight());
|
|
|
|
}
|
|
break;
|
|
case 13: // Enter
|
|
if (index > -1) {
|
|
var selectItem = ul.find('li.arrowselected');
|
|
selectItemSearch(selectItem);
|
|
}
|
|
index = -1;
|
|
//proposalList.empty();
|
|
//params.onSubmit(input.val());
|
|
break;
|
|
case 9: // Tab
|
|
if (index > -1) {
|
|
var selectItem = ul.find('li.arrowselected');
|
|
selectItemSearch(selectItem);
|
|
}
|
|
index = -1;
|
|
//proposalList.empty();
|
|
//params.onSubmit(input.val());
|
|
break;
|
|
case 27: // Esc button
|
|
index = -1;
|
|
//proposalList.empty();
|
|
//input.val('');
|
|
break;
|
|
}
|
|
|
|
}
|
|
};
|
|
|