File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/components/leads/leads_dashboard.js
var utils = require('../utils');
var moment = require('moment');
var LeadCallView = require('../lead-call');
const LEADS_CSV_URL = `//${appConfig.server_url}/leads/csv`;
const LEAD_CALL_DETAILS = `//${appConfig.server_url}/leads/filteroptions`;
const LEAD_PRESIGNED_URL = `//${appConfig.server_url}/presigned_audio_url`;
var leads = {
tableApi: null,
fromDate: null,
ogFromDate: null,
toDate: null,
ogToDate: null,
//frFriendlyNameObject: null,
//nwFriendlyNameObject: null,
frPhonenumberObject: null,
nwPhonenumberObject: null,
//frUniqueCallObject: null,
//nwUniqueCallObject: null,
frLeadSourceObject: null,
nwLeadSourceObject: null,
frCallStatusObject: null,
nwCallStatusObject: null,
frTypeObject: null,
nwTypeObject: null,
frProgressStatusObject: null,
nwProgressStatusObject: null,
frAnsweredByObject: null,
nwAnsweredByObject: null,
frAudioObject: null,
nwAudioObject: null,
frAssignedAgentObject: null,
nwAssignedAgentObject: null,
searchUrl: "",
gloIsPartnerRole: false,
btnReset: false,
init: function () {
console.log(this)
var loThat = this;
// Determine if user is super user and the role they have
if ($('#superUserType').length == 1) {
const roles = ['partner', 'limitsysadmin']
if (roles.includes($('#superUserType').val())) {
loThat.gloIsPartnerRole = true
}
}
//Define start and end date
this.ogFromDate = moment().subtract(1, "month");
this.ogToDate = moment();
this.fromDate = this.ogFromDate;
this.toDate = this.ogToDate;
//Load content and events
loThat.loadTable(loThat.setTableUrl());
loThat.loadDropDownFilterOptions();
loThat.loadDatePickers();
loThat.setEvents();
loThat.setTableUrl();
loThat.loadStyles();
},
getFilter: function (paFilter) {
var loThat = this,
evalObject = null;
if (paFilter === "answered_agent") {
evalObject = loThat.frAnsweredByObject;
} else
if (paFilter === "assigned_agent") {
evalObject = loThat.frAssignedAgentObject;
} else
if (paFilter === "audio") {
evalObject = loThat.frAudioObject;
} else
if (paFilter === "call_source") {
evalObject = loThat.frLeadSourceObject;
} else
if (paFilter === "call_status") {
evalObject = loThat.frCallStatusObject;
} else
/*if (paFilter === "friendly") {
evalObject = loThat.frFriendlyNameObject;
} else*/
if (paFilter === "phone") {
evalObject = loThat.frPhonenumberObject;
} else
if (paFilter === "progress_status") {
evalObject = loThat.frProgressStatusObject;
} else
if (paFilter === "type") {
evalObject = loThat.frTypeObject;
} /*else
if (paFilter === "unique") {
evalObject = loThat.frUniqueCallObject;
}*/
if (evalObject === null || evalObject === undefined || evalObject.id === undefined) {
return "null";
}
else {
return evalObject.id;
}
},
getFromDateFilter: function () {
var loThat = this;
return loThat.fromDate.format("MMDDYYYY");
},
getToDateFilter: function () {
var loThat = this;
return loThat.toDate.format("MMDDYYYY");
},
loadTable: function (paLeadUrl) {
spinnerAdded();
var loThat = this;
var loButtons = [];
if (!loThat.gloIsPartnerRole) {
loButtons = [{
text: "Download csv",
className: "btn-primary btn btn-csv-dl",
action: function (e, dt, node, config) {
var searchOptions = {
search: dt.ajax.params().search,
pn: loThat.getFilter("phone"),
//fn: loThat.getFilter("friendly"),
df: loThat.getFromDateFilter(),
dt: loThat.getToDateFilter(),
aa: loThat.getFilter("assigned_agent"),
ab: loThat.getFilter("answered_agent"),
ad: loThat.getFilter("audio"),
tp: loThat.getFilter("type"),
ps: loThat.getFilter("progress_status"),
so: loThat.getFilter("call_source"),
st: loThat.getFilter("call_status")
},
queryString = $.param(searchOptions),
url = `${LEADS_CSV_URL}?${queryString}`;
window.open(url);
}
}]
} else {
loButtons = [{
text: "Restricted",
className: "btn-primary btn disabled"
}]
}
App.datatables();
loThat.tableApi = $("#leads-datatable").DataTable({
fnDrawCallback: function (oSettings) {
$(".btn-lead-sms").off().on("click", function (e) {
var leadId = this.getAttribute("data-sms-id");
$("#smsModalData").val(leadId);
e.preventDefault();
$("#mySms").modal();
});
spinnerRemoved();
},
buttons: loButtons,
dom: "<'row'<'col-sm-3 col-md-3 col-lg-2'B><'col-sm-2 col-lg-2'l><'col-xs-12 col-sm-7 col-md-7 col-lg-8 datatables-padding text-right'f>>" +
"<'row'<'col-sm-12't>>" +
"<'row'<'col-sm-5'i><'col-sm-7'rp>>",
columns: [
{
data: null,
render: function (data, type, row, meta) {
return loThat.tableApi.page.info().start + meta.row + 1;
},
searchable: false,
orderable: false
},
{
data: 1,
render: function (data, type, row) {
if (row[1].length && row[15].length) {
return row[1] + ' ' + row[15];
} else if (row[1].length && !row[15].length) {
return row[1];
} else {
return '';
}
}
},
null,
{
data: 3,
render: utils.formatNumber
},
{
data: 4,
render: utils.formatNumber
},
{
data: 12,
className: "text-center text-capitalize"
},
{
data: 5,
searchable: false,
render: function (date) {
return `<time datetime='${date}'>${moment(new Date(date)).fromNow()}</time>`;
}
},
{
data: 6,
className: "text-center text-capitalize",
render: function (status) {
var classes = {
"ringing": "label-success",
"in-progress": "label-success",
"retry-pending": "label-warning",
"missed": "label-danger",
"unanswered": "label-warning",
"completed": "label-primary",
"other": "label-default"
};
if (!(status in classes)) {
status = "other";
}
return `<span class="label ${classes[status]}" title="">${status}</span>`;
}
},
{
data: 7,
className: "text-center text-capitalize"
},
{
data: 8,
className: "text-center text-capitalize"
},
{
data: 10,
searchable: true,
orderable: true,
render: function (data, type, row, meta) {
return `<a href="/agents/edit/${row[11]}">${row[10]}</a>`;
}
},
{
data: 9,
className: "",
searchable: false,
orderable: false,
render: function (url) {
if (!url) {
return "";
} else if (url === 'Restricted') {
return "Restricted";
}
////url = url.split("?")[0]
return `<audio class="mediPlayer listen custom-audio" controls controlsList="nodownload">
<source class="mediPlayer" data-url="${url}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>`;
}
},
{
data: "0",
searchable: false,
orderable: false,
className: "text-center",
render: function (id, data, row) {
if (loThat.gloIsPartnerRole) {
return '<a href="#" class="btn btn-secondary" aria-expanded="true" disabled> Restricted </a>';
} else {
return '<div class="dropdown">' +
'<a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="true" > Actions ' +
'<b class="caret"></b>' +
'</a>' +
'<ul class="calls-action-menu dropdown-menu">' +
'<li><a href="/leads/edit/' + id + '" title="Edit details">Edit</a></li>' +
'<li><a href="" class="btn-lead-call" data-lead-id="' + id + '" title="Call" data-toggle="modal" data-target="#myModal">Call</a></li>' +
'<li><a href="" class="btn-lead-sms" data-sms-id="' + row[14] + '" title="SMS">SMS</a></li>' +
'</ul>' +
'</div>';
}
}
}
],
"initComplete": function (settings, json) {
var input = $('.dataTables_filter input').unbind(),
self = this.api(),
$searchButton = $('<a>')
.text('search')
.click(function () {
self.search(input.val()).draw();
spinnerAdded();
}),
$clearButton = $('<a>')
.text('clear')
.click(function () {
input.val('');
$searchButton.click();
});
$(document).keypress(function (event) {
if (event.which == 13) {
$searchButton.click();
}
});
if (!$(".tbl-search-btn").length) {
$('.dataTables_filter').append($searchButton, $clearButton);
$("#leads-datatable_filter a").addClass("btn btn-primary btn-default tbl-search-btn");
$("#leads-datatable_filter span i").remove();
}
if (loThat.objectEmpty(json.graphAnswered) && loThat.objectEmpty(json.graphMissed) && loThat.objectEmpty(json.graphTotal) && loThat.objectEmpty(json.graphPoints)) {
$(".feedback-section").hide();
$("#leadLineChart").html("");
} else {
$(".feedback-section").show();
}
},
"order": [[5, "desc"]],
"language": {
"lengthMenu": 'Display <select class="form-control dataTables-records-length-select">' +
'<option value="30"> 30</option>' +
'<option value="40"> 40</option>' +
'<option value="50"> 50</option>' +
'<option value="100"> 100</option>' +
'</select> records'
},
"pageLength": 50,
"processing": false,
"serverSide": true,
"ajax": {
url: paLeadUrl,
complete: function () {
const style = document.createElement('style');
style.innerHTML = `
audio {
width:145px;
}
audio::-webkit-media-controls-volume-slider-container {
width: 100px;
}
audio::-webkit-media-controls-volume-slider-container {
display:none !important;
}
audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-text-track-list {
display:none;
}
audio::-webkit-media-controls-volume-control-container {
transition: none !important;
animation: none !important;
transform:none !important;
}
audio::-webkit-media-controls-volume-control-hover-background {
transition: none !important;
animation: none !important;
transform:none !important;
}
audio::-webkit-media-controls-volume-slider {
display:none;
transition: none !important;
animation: none !important;
transform:none !important;
}
audio::-webkit-media-controls-timeline {
width:65px;
}
audio::-webkit-media-controls-overflow-button {
display:none;
}
`;
document.head.appendChild(style);
if ($(".mediPlayer").length > 0) {
$(".mediPlayer").each(function () {
var audioClip = $(this);
var url = audioClip.attr('data-url');
if (url && audioClip.attr('data-url') != "") {
audioClip.attr('src', 'pending');
var searchOptions = { url: url };
var queryString = $.param(searchOptions);
var fileDetailsUrl = `${LEAD_PRESIGNED_URL}?${queryString}`;
$.ajax(fileDetailsUrl, {
success: function (data) {
let decodedUrl = data.replace(/&/g, '&');
audioClip.attr('src', decodedUrl);
audioClip.parent('.listen').attr('src', decodedUrl)
audioClip[0].volume = 1.0; // Set volume to 100%
},
error: function (data) {
audioClip.closest('td').attr("title", "Error loading clip...");
}
});
}
});
$(".btn-lead-call").off().on("click", function (e) {
var id = this.getAttribute("data-lead-id");
new LeadCallView({
leadCall: false,
callId: id
}).render();
e.preventDefault();
});
}
}
}
});
loThat.loadStyles();
loThat.tableApi.on("xhr", function (e, settings, json) {
if (json !== undefined && json !== null) {
loThat.refreshGraph(json.graphAnswered, json.graphMissed, json.graphTotal, json.graphPoints);
loThat.loadSideBarTexts(
json.answered_calls,
json.calls,
json.call_duration_min,
json.missed_calls,
json.percentage_answered,
json.percentage_missed,
json.unique_calls,
json.avg_call_duration_min,
json.avg_call_duration_sec
);
}
});
},
loadDropDownFilterOptions: function () {
var loThat = this;
$.ajax({
url: `${LEAD_CALL_DETAILS}`,
type: "GET",
dataType: "json",
success: function (response) {
loThat.populateDropDowns("cbAnsweredBy", response.answered_agent_data, "answered_agent");
loThat.populateDropDowns("cbAssignedAgent", response.assigned_agent_data, "assigned_agent");
//loThat.populateDropDowns("cbFriendlyname", response.tool_name_data, "friendly");
loThat.populateDropDowns("cbPhonenumber", response.phonenumber_data, "phone");
loThat.populateDropDowns("cbProgress", response.progress_data, "progress_status");
loThat.populateDropDowns('cbSource', response.source_data, 'call_source');
loThat.populateDropDowns("cbStatus", response.status_data, "call_status");
//loThat.populateDropDowns('cbType', response.type_data, 'type');
}
});
},
setAudioRecordingDetails: function (paParentElement, paAudioElement) {
if (paAudioElement.length > 0) {
var currentTime = parseInt(paAudioElement[0].currentTime);
var durationTime = parseInt(paAudioElement[0].duration);
var loading = false;
var currentMinutes = Math.floor(currentTime / 60);
var currentSeconds = currentTime - currentMinutes * 60;
var durationMinutes = Math.floor(durationTime / 60);
var durationSeconds = durationTime - durationMinutes * 60;
if (currentMinutes < 10) {
currentMinutes = "0" + currentMinutes;
}
if (currentSeconds < 10) {
currentSeconds = "0" + currentSeconds;
}
if (durationMinutes === undefined || durationMinutes === null || isNaN(durationMinutes)) {
loading = true;
} else
if (durationMinutes < 10) {
durationMinutes = "0" + durationMinutes;
}
if (durationSeconds === undefined || durationSeconds === null || isNaN(durationSeconds)) {
loading = true;
} else
if (durationSeconds < 10) {
durationSeconds = "0" + durationSeconds;
}
if (loading) {
paParentElement.attr("title", "Loading clip details...");
} else {
paParentElement.attr("title", "Current Time: " + currentMinutes + ":" + currentSeconds + " Duration: " + durationMinutes + ":" + durationSeconds);
}
}
},
loadDatePickers: function () {
var loThat = this;
$("#date-from").datetimepicker({
format: "MM/DD/YYYY",
icons: {
time: "fa fa-clock-o",
date: "fa fa-calendar",
up: "fa fa-chevron-up",
down: "fa fa-chevron-down",
previous: "fa fa-chevron-left",
next: "fa fa-chevron-right",
today: "fa fa-screenshot",
clear: "fa fa-trash",
close: "fa fa-remove",
inline: true
},
defaultDate: loThat.fromDate
});
$("#date-to").datetimepicker({
format: "MM/DD/YYYY",
icons: {
time: "fa fa-clock-o",
date: "fa fa-calendar",
up: "fa fa-chevron-up",
down: "fa fa-chevron-down",
previous: "fa fa-chevron-left",
next: "fa fa-chevron-right",
today: "fa fa-screenshot",
clear: "fa fa-trash",
close: "fa fa-remove",
inline: true
},
defaultDate: loThat.toDate
});
},
//General UI events for selecting the filters etc
setEvents: function () {
var loThat = this;
var loCurrentDate = moment();
$("#date-from").on("dp.change", function (ev) {
if (ev.date !== null && ev.date !== undefined) {
loThat.fromDate = ev.date;
if (loThat.btnReset === false) {
loThat.tableApi.destroy();
loThat.loadTable(loThat.setTableUrl());
}
}
});
$("#date-to").on("dp.change", function (ev) {
if (ev.date !== null && ev.date !== undefined) {
loThat.toDate = ev.date;
if (loThat.btnReset === false) {
loThat.tableApi.destroy();
loThat.loadTable(loThat.setTableUrl());
}
}
});
$(".btn-short-today").on("click", function (ev) {
loThat.btnReset = false
$("#date-from").data("DateTimePicker").date(loCurrentDate);
$("#date-to").data("DateTimePicker").date(loCurrentDate);
loThat.btnReset = true
});
$(".btn-short-week").on("click", function (ev) {
loThat.btnReset = false
$("#date-from").data("DateTimePicker").date(moment().subtract(7, "d"));
$("#date-to").data("DateTimePicker").date(loCurrentDate);
loThat.btnReset = true
});
$(".btn-short-month").on("click", function (ev) {
loThat.btnReset = false
$("#date-from").data("DateTimePicker").date(loThat.getFirstDayOfMonth());
$("#date-to").data("DateTimePicker").date(loThat.getLastDayOfMonth());
loThat.btnReset = true
});
$(".btn-short-year").on("click", function (ev) {
loThat.btnReset = false
$("#date-from").data("DateTimePicker").date(loThat.getFirstDayOfYear());
$("#date-to").data("DateTimePicker").date(loThat.getLastDayOfYear());
loThat.btnReset = true
});
$(".btn-additional-filters").on("click", function (ev) {
$("#myLeadFilterModal").modal("show");
});
$("#btnApply").on("click", function (ev) {
//Set new filters
/*if (loThat.nwFriendlyNameObject !== null) {
loThat.frFriendlyNameObject = loThat.nwFriendlyNameObject;
}*/
if (loThat.nwPhonenumberObject !== null) {
loThat.frPhonenumberObject = loThat.nwPhonenumberObject;
}
if (loThat.nwLeadSourceObject !== null) {
loThat.frLeadSourceObject = loThat.nwLeadSourceObject;
}
if (loThat.nwCallStatusObject !== null) {
loThat.frCallStatusObject = loThat.nwCallStatusObject;
}
if (loThat.nwTypeObject !== null) {
loThat.frTypeObject = loThat.nwTypeObject;
}
if (loThat.nwProgressStatusObject !== null) {
loThat.frProgressStatusObject = loThat.nwProgressStatusObject;
}
if (loThat.nwAnsweredByObject !== null) {
loThat.frAnsweredByObject = loThat.nwAnsweredByObject;
}
if (loThat.nwAssignedAgentObject !== null) {
loThat.frAssignedAgentObject = loThat.nwAssignedAgentObject;
}
if (loThat.nwAudioObject !== null) {
loThat.frAudioObject = loThat.nwAudioObject;
}
/*if ($("#chkUniqueCalls").is(":checked")) {
loThat.frUniqueCallObject = {
id: true,
name: "Unique"
};
} else {
loThat.frUniqueCallObject = {
id: false,
name: "Unique"
};
}*/
$("#myLeadFilterModal").modal("hide");
//Apply new filters
loThat.reloadTable();
});
$("#btnCancel").on("click", function (ev) {
if (loThat.nwAnsweredByObject !== undefined && loThat.nwAnsweredByObject !== null) {
if (loThat.frAnsweredByObject !== undefined && loThat.frAnsweredByObject !== null) {
$("#cbAnsweredBy").val(loThat.frAnsweredByObject.name);
} else {
$("#cbAnsweredBy").val("---");
}
}
if (loThat.nwAssignedAgentObject !== undefined && loThat.nwAssignedAgentObject !== null) {
if (loThat.frAssignedAgentObject !== undefined && loThat.frAssignedAgentObject !== null) {
$("#cbAssignedAgent").val(loThat.frAssignedAgentObject.name);
} else {
$("#cbAssignedAgent").val("---");
}
}
if (loThat.nwPhonenumberObject !== undefined && loThat.nwPhonenumberObject !== null) {
if (loThat.frPhonenumberObject !== undefined && loThat.frPhonenumberObject !== null) {
$("#cbPhonenumber").val(loThat.frPhonenumberObject.name);
} else {
$("#cbPhonenumber").val("---");
}
}
/*if (loThat.nwFriendlyNameObject !== undefined && loThat.nwFriendlyNameObject !== null) {
if (loThat.frFriendlyNameObject !== undefined && loThat.frFriendlyNameObject !== null) {
$("#cbFriendlyname").val(loThat.frFriendlyNameObject.name);
} else {
$("#cbFriendlyname").val("---");
}
}*/
if (loThat.nwProgressStatusObject !== undefined && loThat.nwProgressStatusObject !== null) {
if (loThat.frProgressStatusObject !== undefined && loThat.frProgressStatusObject !== null) {
$("#cbProgress").val(loThat.frProgressStatusObject.name);
} else {
$("#cbProgress").val("---");
}
}
if (loThat.nwLeadSourceObject !== undefined && loThat.nwLeadSourceObject !== null) {
if (loThat.frLeadSourceObject !== undefined && loThat.frLeadSourceObject !== null) {
$("#cbSource").val(loThat.frLeadSourceObject.name);
} else {
$("#cbSource").val("---");
}
}
if (loThat.nwCallStatusObject !== undefined && loThat.nwCallStatusObject !== null) {
if (loThat.frCallStatusObject !== undefined && loThat.frCallStatusObject !== null) {
$("#cbStatus").val(loThat.frCallStatusObject.name);
} else {
$("#cbStatus").val("---");
}
}
if (loThat.nwTypeObject !== undefined && loThat.nwTypeObject !== null) {
if (loThat.frTypeObject !== undefined && loThat.frTypeObject !== null) {
$("#cbType").val(loThat.frTypeObject.name);
} else {
$("#cbType").val("---");
}
}
if (loThat.nwAudioObject !== undefined && loThat.nwAudioObject !== null) {
if (loThat.frAudioObject !== undefined && loThat.frAudioObject !== null) {
$("#cbAudio").val(loThat.frAudioObject.name);
} else {
$("#cbAudio").val("---");
}
}
loThat.nwAnsweredByObject = null;
loThat.nwAssignedAgentObject = null;
loThat.nwAssignedAgentObject = null;
loThat.nwAudioObject = null;
loThat.nwPhonenumberObject = null;
//loThat.nwFriendlyNameObject = null;
loThat.nwProgressStatusObject = null;
loThat.nwLeadSourceObject = null;
loThat.nwCallStatusObject = null;
loThat.nwTypeObject = null;
/*if ($("#chkUniqueCalls").is(":checked") && loThat.frUniqueCallObject !== null && loThat.frUniqueCallObject !== undefined && loThat.frUniqueCallObject.id !== true) {
$("#chkUniqueCalls").attr("checked", false);
} else
if (!$("#chkUniqueCalls").is(":checked") && loThat.frUniqueCallObject !== null && loThat.frUniqueCallObject !== undefined && loThat.frUniqueCallObject.id !== false) {
$("#chkUniqueCalls").attr("checked", true);
}*/
});
$("#btnResetFilters").on("click", function (ev) {
loThat.btnReset = true;
// Reset date filters
$("#date-from").data("DateTimePicker").date(loThat.ogFromDate);
$("#date-to").data("DateTimePicker").date(loThat.ogToDate);
$("#chkUniqueCalls").prop("checked", false);
loThat.frAnsweredByObject = null;
loThat.nwAnsweredByObject = null;
loThat.frAssignedAgentObject = null;
loThat.nwAssignedAgentObject = null;
loThat.frPhonenumberObject = null;
loThat.nwPhonenumberObject = null;
//loThat.frFriendlyNameObject = null;
//loThat.nwFriendlyNameObject = null;
loThat.frProgressStatusObject = null;
loThat.nwProgressStatusObject = null;
loThat.frLeadSourceObject = null;
loThat.nwLeadSourceObject = null;
loThat.frCallStatusObject = null;
loThat.nwCallStatusObject = null;
loThat.frTypeObject = null;
loThat.nwTypeObject = null;
loThat.frAudioObject = null;
loThat.nwAudioObject = null;
//loThat.frUniqueCallObject = null;
//loThat.nwUniqueCallObject = null;
$("#cbAnsweredBy, #cbAssignedAgent, #cbPhonenumber, #cbProgress, #cbSource, #cbStatus, #cbType, #cbAudio, #cbAnsweredBy").val("---");
loThat.reloadTable();
});
$("#date-from").on("click", function (ev) {
if (loThat.btnReset === true) {
loThat.btnReset = false;
}
});
$("#date-to").on("click", function (ev) {
if (loThat.btnReset === true) {
loThat.btnReset = false;
}
});
$("#cbType").on("change", function (ev) {
var loItem = $("#cbType option:selected");
loThat.nwTypeObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.text()
};
});
/*$(".sourcie").off().on("click", function(ev) {
loThat.nwLeadSourceObject = {
id: ($(this).attr("id") == -1) ? null : $(this).attr("id"),
name: $(this).html()
};
});*/
$("#cbAudio").off().on("click", function (ev) {
var loItem = $("#cbAudio option:selected");
loThat.nwAudioObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.text()
};
});
},
loadStyles: function () {
$("#leads-datatable_filter label").addClass("form-group");
$("#leads-datatable_length label").addClass("form-group");
$(".dataTables_filter input").attr("placeholder", "Search Records");
},
loadSideBarTexts: function (paAnswered, paCalls, paDuration, paMissed, paPercAnswered, paPercMissed, paUnique, paAverageDurationMin, paAverageDurationSec) {
$(".unique-calls").html(paCalls + "<graph> " + paUnique + " unique calls</graph>");
$(".answered-calls").html(paAnswered + "<graph> " + paPercAnswered + "% of all calls </graph>");
$(".missed-calls").html(paMissed + "<graph> " + paPercMissed + "% of all calls </graph>");
$(".call-duration").html(paDuration + "<graph> min </graph>");
$(".avg-call-duration").html(paAverageDurationMin + "<graph> min </graph>" + paAverageDurationSec + "<graph> sec </graph>");
},
refreshGraph: function (paAnswered, paMissed, paTotal, paLabels) {
var loWidth = window.innerWidth,
loGraphHeight = 400,
loRightBuffer = 40,
loChartOffset = 60,
loLabelOffset = 2,
loXOffset = -10,
loYOffset = 10,
loFullWidth = false;
if (loWidth < 640) {
loRightBuffer = 5;
loChartOffset = 12;
loLabelOffset = 6;
loXOffset = 0;
loYOffset = 0;
$(".graph-section").css("padding-left", 0).css("padding-right", 0);
$(".graph-chart-content").css("padding-left", 0).css("padding-right", 0);
}
if (paLabels.length > 1) {
loFullWidth = true;
}
var loChart = new Chartist.Line("#leadLineChart", {
// Our labels and three data series
labels: paLabels,
series: [
paTotal,
paAnswered,
paMissed
]
}, {
fullWidth: loFullWidth,
chartPadding: {
right: loRightBuffer
},
// We are setting a few options for our chart and override the defaults
// Set hight of the chart
height: loGraphHeight,
// Don't draw the line chart points
showPoint: true,
// Disable line smoothing
lineSmooth: false,
// X-Axis specific configuration
axisX: {
labelOffset: {
x: loXOffset,
y: loYOffset
},
// We can disable the grid for this axis
showGrid: true,
// and also don't show the label
showLabel: true,
labelInterpolationFnc: function skipLabels(value, index, labels) {
if (labels.length > 15) {
return index % loLabelOffset === 0 ? value : null;
} else {
return value;
}
}
},
// Y-Axis specific configuration
axisY: {
// Lets offset the chart a bit from the labels
low: 0,
offset: loChartOffset,
// The label interpolation function enables you to modify the values
// used for the labels on each axis. Here we are converting the
// values into million pound.
labelInterpolationFnc: function (value) {
return value;
},
onlyInteger: true
}
});
},
reloadTable: function () {
var loThat = this;
loThat.tableApi.destroy();
//loThat.tableApi.fnDestroy();
loThat.loadTable(loThat.setTableUrl());
},
populateDropDowns: function (paControl, paDict, paShortName) {
var loThat = this;
var loHtml = "";
loHtml = loHtml + '<option id="' + -1 + '" class="' + paShortName + ' ">---</option>';
for (var lpItem in paDict) {
if (paDict.hasOwnProperty(lpItem)) {
loHtml = loHtml + '<option class="' + paShortName + '" id="' + lpItem + '">' + paDict[lpItem] + '</option>';
}
}
if (paShortName === "answered_agent") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwAnsweredByObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
if (paShortName === "assigned_agent") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwAssignedAgentObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
if (paShortName === "phone") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwPhonenumberObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
/*if (paShortName === "friendly") {
$("#" + paControl).html(loHtml).on("change", function(ev) {
var loItem = $(this).children(":selected");
loThat.nwFriendlyNameObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}*/
if (paShortName === "progress_status") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwProgressStatusObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
if (paShortName === "call_source") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwLeadSourceObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
if (paShortName === "call_status") {
$("#" + paControl).html(loHtml).on("change", function (ev) {
var loItem = $(this).children(":selected");
loThat.nwCallStatusObject = {
id: (loItem.attr("id") == -1) ? null : loItem.attr("id"),
name: loItem.val()
};
});
}
},
setTableUrl: function () {
var loThat = this,
loUrl = "/data",
df = "?df=",
dt = "dt=",
//fn = "fn=",
pn = "pn=",
aa = "aa=",
ab = "ab=",
ad = "ad=",
ps = "ps=",
so = "so=",
st = "st=",
tp = "tp=";
aa += loThat.getFilter("assigned_agent") + "&";
ab += loThat.getFilter("answered_agent") + "&";
ad += loThat.getFilter("audio") + "&";
df += loThat.fromDate.format("MMDDYYYY") + "&";
dt += loThat.toDate.format("MMDDYYYY") + "&";
//fn += loThat.getFilter("friendly") + "&";
pn += loThat.getFilter("phone") + "&";
ps += loThat.getFilter("progress_status") + "&";
so += loThat.getFilter("call_source") + "&";
st += loThat.getFilter("call_status") + "&";
tp += loThat.getFilter("type");
loUrl += df + dt + pn + aa + ab + ad + ps + so + st + tp;
loThat.searchUrl = loUrl;
return loUrl;
},
objectEmpty: function (paObject) {
if (paObject === null || paObject === undefined || paObject.length == 0)
return true;
else
return false;
},
getFirstDayOfMonth: function () {
var loDate = new Date(),
loYear = loDate.getFullYear(),
loMonth = loDate.getMonth();
return moment(new Date(loYear, loMonth, 1));
},
getLastDayOfMonth: function () {
var loDate = new Date(),
loYear = loDate.getFullYear(),
loMonth = loDate.getMonth();
return moment(new Date(loYear, loMonth + 1, 0));
},
getFirstDayOfYear: function () {
var loThisYear = (new Date()).getFullYear();
var loStart = new Date("1/1/" + loThisYear);
return moment(loStart.valueOf());
},
getLastDayOfYear: function () {
var loThisYear = (new Date()).getFullYear();
var loEnd = new Date("12/31/" + loThisYear);
return moment(loEnd.valueOf());
}
};
// function used to add spinner loader
function spinnerAdded() {
document.getElementById("loaderContainer").style.display = "block";
document.getElementById("loader").style.display = "block";
document.getElementById("postLoader").style.display = "none";
}//end add spinner loader function
// function used to remove spinner loader
function spinnerRemoved() {
document.getElementById("loaderContainer").style.display = "none";
document.getElementById("loader").style.display = "none";
document.getElementById("postLoader").style.display = "block";
}//end remove spinner loader function
$(document).ready(function () {
leads.init();
});