{% extends 'layout2.html' %}
{% load i18n %}
{% load static %}
{% block css_include %}
{% endblock %}
{% block js_include %}
{% endblock %}
{% block content %}
{% translate "CTI Lookup" %}
{% endblock %}
{% block jquery_code %}
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
var datatableCanRedraw = true;
var aoColumns = [
{
sTitle: "ID",
name: "id",
aTargets: [0],
defaultContent: "",
mData: "id",
bVisible: false,
},
{
sTitle: '{% translate "Name" %}',
name: "name",
aTargets: [1],
defaultContent: "",
mData: "name"
},
{
sTitle: '{% translate "Tags" %}',
name: "tags",
aTargets: [2],
defaultContent: "",
mData: "tags"
},
{
sTitle: '{% translate "DB Type" %}',
name: "db_type",
aTargets: [3],
defaultContent: "",
mData: "db_type"
},
{
sTitle: '{% translate "URL" %}',
name: "uri",
aTargets: [4],
defaultContent: "",
mData: "uri"
},
{
sTitle: '{% translate "Action" %}',
mData:"id",
aTargets: [5],
defaultContent: "",
mRender: function(data, type, row) {
//result = ' ';
result = ' ';
if( !row.internal ) {
result += '';
}
return result;
}
}
];
var reputation_ctx_table = $("#reputation_ctx_list").dataTable({
bServerSide : true,
order : [[1, 'desc']],
iDisplayLength: 10,
bProcessing : true,
bSort : true,
sAjaxSource : '',
sServerMethod : 'POST',
aoColumnDefs: aoColumns,
language: language_datatable,
fnServerData : function(sSource, aoData, fnCallback){
var columns = [];
for (var i in aoColumns){
if( aoColumns[i].bSearchable !== false && aoColumns[i].mData !== null )
columns.push(aoColumns[i].mData);
}
aoData.push({
name: 'columns',
value: JSON.stringify(columns)
});
$.ajax({
type : "POST",
url : sSource,
data : aoData,
success: function(data, callback){
if (!data.status){
notify('error', "{% translate 'Error' %}", data.error);
} else {
fnCallback(data);
}
}
}) // /$.ajax
.fail( function( jqXHR, textStatus ) {
notify('error', "{% translate 'Error' %}", jqXHR.responseText);
}) // /$.fail
.done( function( data ) {
if (!data.status){
notify('error', "{% translate 'Error' %}", data.error);
} else {
fnCallback(data);
}
}); // /$.done
}, // /fnServerData
fnCreatedRow: function(nRow, aData, iDataIndex){
/* Events binding to start a reputation_ctx */
$(nRow).on('click', '.download-btn', function(e) {
/* Request download of the selected reputation_context */
/* First, retrieve the action to do */
var action = ($(this).hasClass('download') ? "download" : "");
$.ajax({
type : "GET",
url : "/api/v1/apps/reputation_ctx/"+action+"/"+aData.id,
}) // /$.ajax
.fail( function( jqXHR, textStatus ) {
new PNotify({
title: 'Unknown error occurred',
text: ''+jqXHR.responseText
+'',
type: 'error',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
}) // /$.fail
.done( function( msg ) {
if( msg.status ) {
new PNotify({
title: "Success",
text: ''+msg.message+'',
type: 'success',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
} else {
new PNotify({
title: msg.error.split(':').join(''), // Replace : by return for better view,
text: ''+msg.error_details+'',
type: 'error',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
}
}); // /$.done
e.stopPropagation();
}); // /$(nRow).on('click', '.action'
/* Events binding to edit a reputation context */
$(nRow).on('click', 'td', function(e) {
if (e.target.tagName !== "TD") return;
const url = "{% url 'applications.reputation_ctx.edit' %}" + aData.id
/* Open a reputation context edition in a new tab with ctrl click */
if (e.ctrlKey || e.metaKey) {
window.open(url, '_blank');
} else {
window.location.href = url;
}
}); // /$(nRow).on('click', 'td'
/* Open a reputation context edition in a new tab with middle click */
$(nRow).on('mousedown', 'td', function(e){
if (e.target.tagName === "TD" && e.button === 1) {
window.open("{% url 'applications.reputation_ctx.edit' %}" + aData.id, '_blank');
}
}); // /$(nRow).on('mousedown', 'td'
}, // fnCreatedRow: function
fnDrawCallback: function(settings){
datatableCanRedraw = true;
}, // fnDrawCallback: function
}); // var reputation_ctx_table = $("#backend_list").dataTable
/* Reload table data every 5 seconds if previous one answered */
setInterval(function(){
if(datatableCanRedraw == true) {
datatableCanRedraw = false;
reputation_ctx_table.fnDraw(false);
}
}, 5000);
{% endblock %}