var objFileReportTranslations = JSON.parse('{"FileReportCancelConfirm":"Are you sure you want to cancel the report on a dangerous file?","FileReportConfirm":"Are you sure you want to report problem on this file?","ReasonPlaceholder":"Enter a description of the problem or violation...","PleaseSelectType":"Please select type of violation.","Type_Copyrights":"Copyrights","Type_PersonalPrivacy":"Personal privacy","Type_Hatred":"Hatred","Type_Malware":"Malware","Type_Spam":"Spam","Type_Pornographic":"Adult content","Type_Other":"Other"}');
function showFileReportModal( domLink, strHash, fnCallback )
{
if ( typeof fnCallback === "undefined" )
{
fnCallback = function () {};
}
if ( $( domLink ).hasClass( 'has_reported' ) )
return showCancelFileReportModal(domLink, strHash, fnCallback);
var strInputs = '';
strInputs += '
';
strInputs += '
';
strInputs += '';
strInputs += '
';
strInputs += '
';
strInputs += '';
fConfirm(
objFileReportTranslations.FileReportConfirm + strInputs,
null,
'OK',
'Cancel',
// Submit
function( bolSubmitted, jqModalWindow )
{
if( bolSubmitted === true )
{
var jqReason = $( '.reason', jqModalWindow );
var jqType = $( '.type', jqModalWindow );
makeFileReportRequest( strHash, jqReason.val(), jqType.val(), function ( strActionResponse ) {
finishFileReport( domLink, strActionResponse );
fnCallback( strActionResponse );
});
}
},
// Validate
function ( jqModalWindow )
{
var jqReason = $( '.reason', jqModalWindow );
var jqType = $( '.type', jqModalWindow );
var bolOk = true;
if ( $.trim( jqReason.val() ).length < 4 )
{
jqReason.css({'border-color': 'red'});
bolOk = false;
}
else
{
jqReason.css({'border-color': 'inherit'});
}
if ( $.trim( jqType.val() ) == '' )
{
jqType.css({'border-color': 'red'});
bolOk = false;
}
else
{
jqType.css({'border-color': 'inherit'});
}
return bolOk;
}
);
}
function showCancelFileReportModal(domLink, strHash, fnCallback)
{
if ( typeof fnCallback === "undefined" )
{
fnCallback = function () {};
}
fConfirm(
objFileReportTranslations.FileReportCancelConfirm,
null,
'OK',
'Cancel',
// Submit
function( bolSubmitted )
{
if( bolSubmitted === true )
{
makeFileReportRequest( strHash, null, null, function ( strActionResponse ) {
finishFileReport( domLink, strActionResponse );
fnCallback( strActionResponse );
});
}
}
);
}
function finishFileReport( domLink, strActionResponse )
{
if ( strActionResponse == 'report' )
{
$( domLink ).addClass( 'has_reported' ).attr( 'my_title', 'Cancel report on a dangerous file' );
fSuccess('Your message about dangerous file content has been successfully submitted. It will be reviewed shortly.');
}
else
{
$( domLink ).removeClass( 'has_reported' ).attr( 'my_title', 'Report problem' );
fSuccess('Your message about dangerous file content has been cancelled.');
}
}
function makeFileReportRequest( strHash, strReason, strType, fncCallback )
{
$.ajax( {
type: "POST",
dataType: "json",
url: "/ajax/report_file.php",
data: {
'report': true,
'h': strHash,
'reason': !!strReason ? strReason : null,
'type': !!strType ? strType : null
},
success: function ( data )
{
if ( data[ 'status' ] == 'ok' )
{
fncCallback( data[ 'action' ] );
}
}
} );
}