const errorModal = $( '#errorModal' );
const askQuestionModal = $( '#askQuestionModal' );
const readMoreModal = $( '#readMoreModal' );
const answerModal = $( '#answerModal' );
const welcomeModal = $('#welcomeModal' );
const welcomeModalText = $('#welcomeModalText');
const welcomeModalClose = $('#welcomeModalClose' );
const answerText = $('#answer' );
const answerModalTitle = $('#answerModalLabel');
readMoreModalText = $('#readMoreModalText' );
const readMoreModalTitle = $('#readMoreModalLabel' );
const errorMsg = $( '#errorMsg' );
const askErrorMsg = $('#askErrorMsg')
const answerErrorMsg = $('#answerErrorMsg' );
const questions = $( '#questions' )
const question = $('#question' );
const askButton = $('#askBtn' );
const nickname = $('#nickname' );
let is_owner = false;
let room_code = '00AA';
let q_interval = '';
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 ( !nickname.val() )
{
askErrorMsg.html( 'Please enter a name first!' );
askButton.prop( 'disabled', false );
return;
}
if( nickname.val().length > 20 || nickname.val().length < 3 )
{
askErrorMsg.html( 'The name should be 3-20 characters long.' );
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(),"nickname":nickname.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!
The nickname should contain at least 3 up to 20 characters!" );
break;
case 910:
askErrorMsg.html( "The Room is locked.
You cannot ask/answer questions anymore!" );
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 )
{
let _answer = '';
if( result.data.answer === null || result.data.answer.length < 5 )
{
_answer = 'So far there is no answer to this question.';
}
else
{
_answer = result.data.answer;
}
readMoreModalTitle.html( 'Question from: ' + result.data.created_by );
readMoreModalText.html( 'Question
' + result.data.question +
'