640 lines
28 KiB
JavaScript
640 lines
28 KiB
JavaScript
|
|
if (typeof isVelocityOrRTG == 'undefined') {
|
|
var isVelocityOrRTG = false;
|
|
}
|
|
|
|
if (typeof isEpicVelocity == 'undefined') {
|
|
var isEpicVelocity = false;
|
|
}
|
|
function generateAffiliateClientList(elem){
|
|
var value = $(elem).val();
|
|
$('#affiliate_client_type_id').val(value);
|
|
var data = {'crmuser_id':value,'action':'AFFILIATE_CLIENT_LIST'};
|
|
$('#epic-affiliate-loader').show()
|
|
$('#affiliate-loader').show()
|
|
$(elem).next('img').show()
|
|
$.ajax({
|
|
type: "POST",
|
|
data: data,
|
|
url: AFFILIATE_URL,
|
|
success: function (response) {
|
|
$(elem).next('img').hide()
|
|
$('#epic-affiliate-loader').hide();
|
|
$('#affiliate-loader').hide();
|
|
response = JSON.parse(response);
|
|
|
|
var s = $('select[name=client_id]');
|
|
var isRTG = false;
|
|
if(s.length == 0){
|
|
s = $('#client-contact-id');
|
|
isRTG = true;
|
|
}
|
|
|
|
s.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(s);
|
|
var clientList = {};
|
|
if(response.is_employee){
|
|
$.each(response.affiliate_list, function (key, value) {
|
|
clientList[value.id] = value.first_name+" "+value.last_name+" ("+value.email+")";
|
|
});
|
|
}else{
|
|
clientList = response
|
|
}
|
|
// if(isRTG){
|
|
// $.each(clientList, function (key, value) {
|
|
// clientList[value.id] = value.first_name+" "+value.last_name+" ("+value.email+")";
|
|
// });
|
|
// }
|
|
|
|
|
|
|
|
console.log(clientList)
|
|
var temp = [];
|
|
$.each(clientList, function (key, value) {
|
|
temp.push({v: value, k: key});
|
|
});
|
|
if(isVelocityOrRTG || isEpicVelocity){
|
|
var temp_client_list = [];
|
|
$.each(clientList, function (key, value) {
|
|
var currentObj = {
|
|
v: value.first_name+" "+ value.last_name+" ("+value.email+")",
|
|
k: value.id,
|
|
contact_id:value.contact_id,
|
|
email:value.email
|
|
}
|
|
temp_client_list.push(currentObj);
|
|
});
|
|
temp = temp_client_list;
|
|
}
|
|
temp.sort(function (a, b) {
|
|
if (a.v > b.v) {
|
|
return 1
|
|
}
|
|
if (a.v < b.v) {
|
|
return -1
|
|
}
|
|
return 0;
|
|
});
|
|
if(isVelocityOrRTG){
|
|
var clientDropdownHtml = "";
|
|
var current_obj = {};
|
|
var attributes = {};
|
|
$.each(temp, function (key, obj) {
|
|
current_obj = {
|
|
value: obj.contact_id,
|
|
text: obj.v
|
|
};
|
|
attributes = {
|
|
'data-id':obj.k,
|
|
'data-email':obj.email
|
|
}
|
|
$('<option />', current_obj).attr(attributes).appendTo(s);
|
|
|
|
})
|
|
}else{
|
|
$.each(temp, function (key, obj) {
|
|
var current_obj = {
|
|
value: obj.k,
|
|
text: obj.v
|
|
};
|
|
$('<option />', current_obj).appendTo(s);
|
|
});
|
|
}
|
|
|
|
},error: function () {
|
|
$(elem).next('img').hide();
|
|
alert("Failed. Try again later.111");
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function generateEmployeeClientList(elem){
|
|
|
|
var value = $(elem).val();
|
|
if(value){
|
|
var client_id = $('#client-contact-id').attr('data-cid');
|
|
|
|
$('#affiliate_client_type_id').val(value);
|
|
var data = {'employee_id':value,'action':'EMPLOYEE_CLIENT_LIST'};
|
|
$('#epic-employee-loader').show()
|
|
$('#employee-loader').show()
|
|
$.ajax({
|
|
type: "POST",
|
|
data: data,
|
|
url: AFFILIATE_URL,
|
|
success: function (response) {
|
|
$('#epic-employee-loader').hide();
|
|
$('#employee-loader').hide()
|
|
var show_client_checkbox = $('input[name=show_client_checkbox]');
|
|
response = JSON.parse(response);
|
|
console.log('hhhh',response);
|
|
if($('button[name=checkConsole]').length){
|
|
$('button[name=checkConsole]').prop('disabled',true);
|
|
}
|
|
|
|
var s = $('select[name=client_id]');
|
|
if(s.length == 0){
|
|
s = $('#client-contact-id')
|
|
}
|
|
s.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(s);
|
|
|
|
var temp = [];
|
|
$.each(response, function (key, value) {
|
|
if(key > 0){
|
|
temp.push({v: value, k: key});
|
|
}
|
|
});
|
|
|
|
if(isVelocityOrRTG || isEpicVelocity){
|
|
|
|
var temp_client_list = [];
|
|
$.each(response, function (key, value) {
|
|
var currentObj = {
|
|
v: value.name+" ("+value.email+")",
|
|
k: key,
|
|
contact_id:value.contact_id,
|
|
email:value.email
|
|
}
|
|
temp_client_list.push(currentObj);
|
|
});
|
|
temp = temp_client_list;
|
|
}
|
|
temp.sort(function (a, b) {
|
|
if (a.v > b.v) {
|
|
return 1
|
|
}
|
|
if (a.v < b.v) {
|
|
return -1
|
|
}
|
|
return 0;
|
|
});
|
|
if(isVelocityOrRTG){
|
|
|
|
var current_obj = {};
|
|
var attributes = {};
|
|
$.each(temp, function (key, obj) {
|
|
current_obj = {
|
|
value: obj.contact_id,
|
|
text: obj.v
|
|
};
|
|
attributes = {
|
|
'data-id':obj.k,
|
|
'data-email':obj.email
|
|
}
|
|
if(client_id > 0){
|
|
attributes['selected'] = "selected";
|
|
}
|
|
$('<option />', current_obj).attr(attributes).appendTo(s);
|
|
|
|
})
|
|
}else{
|
|
|
|
$.each(temp, function (key, obj) {
|
|
$('<option />', {value: obj.k, text: obj.v}).appendTo(s);
|
|
});
|
|
}
|
|
if(!isEpicVelocity)
|
|
if(response.employee_affiliste_list && show_client_checkbox.prop('checked')){
|
|
$('select[name=affiliate_client_id]').html(response.employee_affiliste_list);
|
|
}
|
|
|
|
},error: function () {
|
|
$(elem).next('img').hide();
|
|
alert("Failed. Try again later.111");
|
|
}
|
|
});
|
|
}else{
|
|
if(isVelocityOrRTG){
|
|
|
|
var clientDropdown = $('#client-contact-id');
|
|
if(typeof CLIENT_DEFAULT_LIST != 'undefined'){
|
|
response = CLIENT_DEFAULT_LIST;
|
|
}else{
|
|
response = DEFAULT_CLENT_LIST;
|
|
}
|
|
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
var attributes = {};
|
|
var per_values = {};
|
|
console.log('response',response,client_id);
|
|
for(var val in response) {
|
|
var row = response[val];
|
|
attributes = {
|
|
'data-id':row.contact_id,
|
|
'data-email':row.email
|
|
}
|
|
|
|
var name = row.name;
|
|
if(row.first_name){
|
|
name = row.first_name;
|
|
}
|
|
if(row.last_name){
|
|
if(name){
|
|
name += " "+row.last_name;
|
|
}else{
|
|
name = row.last_name;
|
|
}
|
|
}
|
|
per_values = {value: row.id, text: name+" ("+row.email+")"};
|
|
$('<option />', per_values).attr(attributes).appendTo(clientDropdown);
|
|
}
|
|
}else{
|
|
|
|
var isAffiliatechecked = $('input[name=show_client_checkbox]').prop('checked');
|
|
var affiliate_client_id = $('select[name=affiliate_client_id]').val();
|
|
response = JSON.parse(DEFAULT_CLENT_LIST);
|
|
console.log('DEFAULT_CLENT_LIST',response);
|
|
var clientDropdown = $('select[name=client_id]');
|
|
clientDropdown.empty()
|
|
if(isAffiliatechecked){
|
|
$('input[name=show_client_checkbox]').prop('checked',false);
|
|
$('input[name=show_client_checkbox]').click();
|
|
isAffiliatechecked = true;
|
|
}
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
if(isAffiliatechecked && affiliate_client_id > 0){
|
|
for(var val in response) {
|
|
if(isAffiliatechecked && affiliate_client_id == response[val].crmuser_id){
|
|
$('<option />', {value: response[val].id, text: response[val].name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
}else {
|
|
for(var val in response) {
|
|
$('<option />', {value: response[val].id, text: response[val].name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
function affiliateShow(elem){
|
|
var employee_checkbox = $('input[name=employee_client_type]');
|
|
if($('.affiliate-list').hasClass('isCms')){
|
|
$('.affiliate-list').removeClass('affiliate-show').removeClass('affiliate-hide').removeClass('affiliate-common-hide').addClass('affiliate-hide-op')
|
|
}else{
|
|
|
|
$('.affiliate-list').hide();
|
|
|
|
}
|
|
$('#client_type_id').val(1);
|
|
$('#affiliate_client_type_id').val('');
|
|
$('select[name=affiliate_client_id]').attr('disabled',true);
|
|
if($(elem).prop('checked') && $(elem).val() == 2){
|
|
if(employee_checkbox.prop('checked')){
|
|
employee_checkbox.click();
|
|
$('.employee-list').hide();
|
|
}
|
|
$('#client_type_id').val($(elem).val());
|
|
$('#affiliate_client_type_id').val(-1);
|
|
$('#affiliate-loader').show();
|
|
var formData = {'action':'AFFILIATE_LIST','employee_id':$('select[name=employee_id]').val()};
|
|
$.ajax({
|
|
type: "POST",
|
|
data: formData,
|
|
url: AFFILIATE_URL,
|
|
success: function (response) {
|
|
$('#affiliate-loader').hide();
|
|
var show_client_checkbox = $('input[name=show_client_checkbox]');
|
|
response = JSON.parse(response);
|
|
console.log(response);
|
|
var s = $('select[name=affiliate_client_id]');
|
|
s.empty()
|
|
//$('<option />', {value: -1, text: "All"}).appendTo(s);
|
|
if(response.iscmsuser){
|
|
s.html(response.affilistHTML)
|
|
|
|
}else{
|
|
$('<option />', {value: -1, text: "All"}).appendTo(s);
|
|
|
|
for(var val in response.affiliateList) {
|
|
$('<option />', {value: val, text: response.affiliateList[val]}).appendTo(s);
|
|
}
|
|
}
|
|
|
|
var clientDropdown = $('select[name=client_id]');
|
|
if(clientDropdown.length == 0){
|
|
clientDropdown = $('#client-contact-id');
|
|
}
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
var temp_affiliate_list = {};
|
|
if(!response.iscmsuser){
|
|
$.each(response.affiliate_client_list, function (key, value) {
|
|
temp_affiliate_list[value.id] = value.first_name+" "+value.last_name+" ("+value.email+")";
|
|
});
|
|
}else{
|
|
temp_affiliate_list = response.affiliate_client_list
|
|
}
|
|
var temp = [];
|
|
$.each(temp_affiliate_list, function (key, value) {
|
|
temp.push({v: value, k: key});
|
|
});
|
|
temp.sort(function (a, b) {
|
|
if (a.v > b.v) {
|
|
return 1
|
|
}
|
|
if (a.v < b.v) {
|
|
return -1
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
$.each(temp, function (key, obj) {
|
|
$('<option />', {value: obj.k, text: obj.v}).appendTo(clientDropdown);
|
|
});
|
|
|
|
if(response.iscmsuser){
|
|
$('.affiliate-list').addClass('affiliate-show').show();
|
|
}else{
|
|
$('.affiliate-list').removeClass('affiliate-hide-op').removeClass('affiliate-hide').removeClass('affiliate-common-hide').show();
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
for (var val in response.affiliate_client_list) {
|
|
var clientInfo = response.affiliate_client_list[val];
|
|
$('<option />', {
|
|
'data-email': clientInfo.email,
|
|
'data-id': clientInfo.id,
|
|
value: clientInfo.contact_id,
|
|
text: clientInfo.first_name + " " + clientInfo.last_name + " (" + clientInfo.email + ")"
|
|
}).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
|
|
$('select[name=affiliate_client_id]').attr('disabled',false);
|
|
if(response.employee_affiliste_list && show_client_checkbox.prop('checked')){
|
|
$('select[name=affiliate_client_id]').html(response.employee_affiliste_list);
|
|
}
|
|
},error: function () {
|
|
$(elem).next('img').hide();
|
|
alert("Failed. Try again later.111");
|
|
}
|
|
});
|
|
|
|
}else if(!$(elem).prop('checked')){
|
|
var clientDropdown = $('select[name=client_id]');
|
|
if(isVelocityOrRTG){
|
|
clientDropdown = $('#client-contact-id');
|
|
if(typeof CLIENT_DEFAULT_LIST != 'undefined'){
|
|
response = CLIENT_DEFAULT_LIST;
|
|
}else{
|
|
response = DEFAULT_CLENT_LIST;
|
|
}
|
|
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
var attributes = {};
|
|
var per_values = {};
|
|
for(var val in response) {
|
|
var row = response[val];
|
|
attributes = {
|
|
'data-id':row.id,
|
|
'data-email':row.email
|
|
}
|
|
var name = row.name;
|
|
if(row.first_name){
|
|
name = row.first_name;
|
|
}
|
|
if(row.last_name){
|
|
if(name){
|
|
name += " "+row.last_name;
|
|
}else{
|
|
name = row.last_name;
|
|
}
|
|
}
|
|
per_values = {value: row.contact_id, text: name+" ("+row.email+")"};
|
|
$('<option />', per_values).attr(attributes).appendTo(clientDropdown);
|
|
}
|
|
}else{
|
|
response = JSON.parse(DEFAULT_CLENT_LIST);
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
for(var val in response) {
|
|
if(isEpicVelocity){
|
|
var full_name = response[val].first_name+" "+response[val].last_name;
|
|
$('<option />', {value: response[val].id, text: full_name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}else{
|
|
$('<option />', {value: response[val].id, text: response[val].name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
} }
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function employeeShow(elem, crmuser_id = 0,client_id =0) {
|
|
$('.employee-list').hide();
|
|
if(client_id > 0){
|
|
$('#client-contact-id').attr('data-cid',client_id)
|
|
}
|
|
var affiliate_checkbox = $('input[name=client_type]');
|
|
$('select[name=affiliate_client_id]').attr('disabled', true);
|
|
if ($(elem).prop('checked') && $(elem).val() == 2) {
|
|
if(affiliate_checkbox.prop('checked')){
|
|
affiliate_checkbox.click();
|
|
$('.affiliate-list').hide();
|
|
}
|
|
$('#employee-loader').show();
|
|
var formData = {
|
|
'action': 'EMPLOYEE_LIST'
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
data: formData,
|
|
url: AFFILIATE_URL,
|
|
success: function (response) {
|
|
$('#employee-loader').hide();
|
|
response = JSON.parse(response);
|
|
|
|
var s = $('select[name=dropdown_employee_id]');
|
|
s.empty()
|
|
$('<option />', {
|
|
value: -1,
|
|
text: "All"
|
|
}).appendTo(s);
|
|
for (var val in response.affiliateList) {
|
|
var attr = {
|
|
value: val,
|
|
text: response.affiliateList[val]
|
|
}
|
|
var selected = "";
|
|
if (crmuser_id == val) {
|
|
attr['selected'] = "selected";
|
|
}
|
|
$('<option />', attr).appendTo(s);
|
|
}
|
|
|
|
if (crmuser_id == 0) {
|
|
|
|
var clientDropdown = $('#client-contact-id');
|
|
if(isEpicVelocity){
|
|
clientDropdown = $('select[name=client_id]');
|
|
}
|
|
clientDropdown.empty()
|
|
$('<option />', {
|
|
value: "0",
|
|
text: "Please select client"
|
|
}).appendTo(clientDropdown);
|
|
for (var val in response.affiliate_client_list) {
|
|
var clientInfo = response.affiliate_client_list[val];
|
|
var attributes= {
|
|
'data-email': clientInfo.email,
|
|
'data-id': clientInfo.id,
|
|
value: clientInfo.contact_id,
|
|
text: clientInfo.first_name + " " + clientInfo.last_name + " (" + clientInfo.email + ")"
|
|
}
|
|
if(client_id == clientInfo.id){
|
|
attributes['selected'] = "selected";
|
|
}
|
|
$('<option />', attributes).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
$('.employee-list').show();
|
|
$('select[name=affiliate_client_id]').attr('disabled', false);
|
|
if (crmuser_id > 0) {
|
|
// s.val(crmuser_id).trigger('change');
|
|
}
|
|
|
|
|
|
},
|
|
error: function () {
|
|
$(elem).next('img').hide();
|
|
alert("Failed. Try again later.111");
|
|
}
|
|
});
|
|
|
|
} else if(!$(elem).prop('checked')){
|
|
var clientDropdown = $('select[name=client_id]');
|
|
if(isVelocityOrRTG){
|
|
clientDropdown = $('#client-contact-id');
|
|
|
|
if(typeof CLIENT_DEFAULT_LIST != 'undefined'){
|
|
response = CLIENT_DEFAULT_LIST;
|
|
}else{
|
|
response = DEFAULT_CLENT_LIST;
|
|
}
|
|
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
var attributes = {};
|
|
var per_values = {};
|
|
|
|
for(var val in response) {
|
|
var row = response[val];
|
|
attributes = {
|
|
'data-id':row.id,
|
|
'data-email':row.email
|
|
}
|
|
|
|
var name = row.name;
|
|
if(row.first_name){
|
|
name = row.first_name;
|
|
}
|
|
if(row.last_name){
|
|
if(name){
|
|
name += " "+row.last_name;
|
|
}else{
|
|
name = row.last_name;
|
|
}
|
|
}
|
|
per_values = {value: row.contact_id, text: name+" ("+row.email+")"};
|
|
$('<option />', per_values).attr(attributes).appendTo(clientDropdown);
|
|
}
|
|
}else{
|
|
response = JSON.parse(DEFAULT_CLENT_LIST);
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
for(var val in response) {
|
|
if(isEpicVelocity){
|
|
var full_name = response[val].first_name+" "+response[val].last_name;
|
|
$('<option />', {value: response[val].id, text: full_name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}else{
|
|
$('<option />', {value: response[val].id, text: response[val].name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
function employeeFormShow(elem, crmuser_id = 0,client_id =0) {
|
|
$('.form-employee-list').hide();
|
|
if(client_id > 0){
|
|
$('#client-contact-id').attr('data-cid',client_id)
|
|
}
|
|
var affiliate_checkbox = $('input[name=client_type]');
|
|
$('select[name=affiliate_client_id]').attr('disabled', true);
|
|
if ($(elem).prop('checked') && $(elem).val() == 1) {
|
|
|
|
|
|
} else if(!$(elem).prop('checked')){
|
|
var clientDropdown = $('select[name=client_id]');
|
|
if(isVelocityOrRTG){
|
|
clientDropdown = $('#client-contact-id');
|
|
if(typeof CLIENT_DEFAULT_LIST != 'undefined'){
|
|
response = CLIENT_DEFAULT_LIST;
|
|
}else{
|
|
response = DEFAULT_CLENT_LIST;
|
|
}
|
|
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
var attributes = {};
|
|
var per_values = {};
|
|
|
|
for(var val in response) {
|
|
var row = response[val];
|
|
attributes = {
|
|
'data-id':row.id,
|
|
'data-email':row.email
|
|
}
|
|
|
|
var name = row.name;
|
|
if(row.first_name){
|
|
name = row.first_name;
|
|
}
|
|
if(row.last_name){
|
|
if(name){
|
|
name += " "+row.last_name;
|
|
}else{
|
|
name = row.last_name;
|
|
}
|
|
}
|
|
per_values = {value: row.contact_id, text: name+" ("+row.email+")"};
|
|
$('<option />', per_values).attr(attributes).appendTo(clientDropdown);
|
|
}
|
|
}else{
|
|
response = JSON.parse(DEFAULT_CLENT_LIST);
|
|
clientDropdown.empty()
|
|
$('<option />', {value: "", text: "Please select client"}).appendTo(clientDropdown);
|
|
for(var val in response) {
|
|
$('<option />', {value: response[val].id, text: response[val].name+" ("+response[val].email+")"}).appendTo(clientDropdown);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|