errorModal = $( '#errorModal' );
askQuestionModal = $( '#askQuestionModal' );
readMoreModal = $( '#readMoreModal' );
answerModal = $( '#answerModal' );
answerText = $('#answer' );
answerModalTitle = $('#answerModalLabel');
readMoreModalText = $('#readMoreModalText' );
readMoreModalTitle = $('#readMoreModalLabel' );
errorMsg = $( '#errorMsg' );
askErrorMsg = $('#askErrorMsg')
answerErrorMsg = $('#answerErrorMsg' );
questions = $( '#questions' )
question = $('#question' );
askButton = $('#askBtn' );
function request( a_uri, a_data, a_successhandler, a_errorhandler )
{
$.ajax(
{
url: "?c=Faq&a=" + a_uri,
type: 'POST',
data: JSON.stringify( a_data ),
dataType: 'json',
success: function (result)
{
a_successhandler(result);
},
error: function ( result, errorcode )
{
if( errorcode === "parseerror" )
{
$('.modal').modal( 'hide' );
setTimeout( function(){
$('.modal').modal('hide');
errorMsg.html( 'The action was not successfully.
Our server sent a weird response. Cannot parse this shit lmao' );
errorModal.modal( 'show' );
askButton.prop( 'disabled', false );
}, 500 );
}
a_errorhandler( result, errorcode );
},
});
}
function askQuestion()
{
askButton.prop( 'disabled', true );
if ( !question.val() )
{
askErrorMsg.html( 'Please enter a question first!' );
askButton.prop( 'disabled', false );
return;
}
if( question.val().length > 500 || question.val().length < 10 )
{
askErrorMsg.html( 'The question should be 15-50 characters long.' );
askButton.prop( 'disabled', false );
return;
}
request( 'addQuestion', {"question":question.val()},
function( result ){
askErrorMsg.html( '' );
askButton.prop( 'disabled', false );
question.val('');
askQuestionModal.modal( 'hide' );
}, function( result ) {
askButton.prop( 'disabled', false );
switch( result.status )
{
case 901:
case 902:
askErrorMsg.html( "Something wrong happened. We don't know why...
Try again later please!" );
break;
case 903:
askErrorMsg.html( "The question should contain at least 10 up to 500 characters!
Just not romans, but also not just 'help'." );
break;
default:
$('.modal').modal('hide');
setTimeout( function( result ){
errorMsg.html( "The action was not successfully.
Maybe the room doesn't exist anymore.
Also may check your internet connection." );
errorModal.modal( 'show' );
}, 500 );
}
}
);
}
function openReadMoreModal( id )
{
readMoreModal.modal( 'show' );
readMoreModalText.html( 'Loading...' );
readMoreModalTitle.html( 'Question from: Anonymous' );
request( 'getQuestion', {"question_id":id}, function( result )
{
readMoreModalTitle.html( 'Question from: ' + result.data.created_by );
readMoreModalText.html( 'Question
' + result.data.question +
'