33
vendor/js/faq.js
vendored
33
vendor/js/faq.js
vendored
@ -13,6 +13,7 @@ answerErrorMsg = $('#answerErrorMsg' );
|
||||
questions = $( '#questions' )
|
||||
question = $('#question' );
|
||||
askButton = $('#askBtn' );
|
||||
nickname = $('#nickname' );
|
||||
|
||||
function request( a_uri, a_data, a_successhandler, a_errorhandler )
|
||||
{
|
||||
@ -56,6 +57,19 @@ function askQuestion()
|
||||
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 )
|
||||
{
|
||||
@ -64,7 +78,7 @@ function askQuestion()
|
||||
return;
|
||||
}
|
||||
|
||||
request( 'addQuestion', {"question":question.val()},
|
||||
request( 'addQuestion', {"question":question.val(),"nickname":nickname.val()},
|
||||
function( result ){
|
||||
askErrorMsg.html( '' );
|
||||
askButton.prop( 'disabled', false );
|
||||
@ -79,7 +93,7 @@ function askQuestion()
|
||||
askErrorMsg.html( "Something wrong happened. We don't know why...<br>Try again later please!" );
|
||||
break;
|
||||
case 903:
|
||||
askErrorMsg.html( "The question should contain at least 10 up to 500 characters!<br>Just not romans, but also not just 'help'." );
|
||||
askErrorMsg.html( "The question should contain at least 10 up to 500 characters!<br>The nickname should contain at least 3 up to 20 characters!" );
|
||||
break;
|
||||
default:
|
||||
$('.modal').modal('hide');
|
||||
@ -122,13 +136,13 @@ function openReadMoreModal( id )
|
||||
let answer_id = 0;
|
||||
function openAnswerModal( id )
|
||||
{
|
||||
answerModalTitle.html( 'Answer ' + 'Anonymous' + " question" );
|
||||
answerModalTitle.html( 'Answer ' + 'XXX' + " question" );
|
||||
answerErrorMsg.html( '' );
|
||||
answerModal.modal( 'show' );
|
||||
|
||||
request( 'getQuestion', {"question_id":id}, function( result )
|
||||
{
|
||||
readMoreModalTitle.html( 'Answer ' + result.data.created_by + " question" );
|
||||
answerModalTitle.html( 'Answer ' + result.data.created_by + "'s question" );
|
||||
if( result.data.answer !== null && result.data.answer.length > 5 )
|
||||
{
|
||||
answerText.val( result.data.answer );
|
||||
@ -147,9 +161,9 @@ function answer()
|
||||
return;
|
||||
}
|
||||
|
||||
if( answerText.val().length < 5 || answerText.val().length > 500 )
|
||||
if( answerText.val().length < 5 || answerText.val().length > 1000 )
|
||||
{
|
||||
answerErrorMsg.html( 'The answer should contain 10-500 characters!' );
|
||||
answerErrorMsg.html( 'The answer should contain 10-1000 characters!' );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,7 +197,7 @@ function getQuestions()
|
||||
{
|
||||
questions.append( '<div class="col-sm-6 col-lg-4 col-md-5"><div class="card" id="q_' + result.data.questions[i].id + '" style=" margin-bottom: 10px;">' +
|
||||
' <div class="card-body">' +
|
||||
' <h5 class="card-title">Question</h5>' +
|
||||
' <h5 class="card-title text-warning">Question</h5>' +
|
||||
' <h6 class="card-subtitle mb-2 text-muted">From ' + result.data.questions[i].created_by + '</h6>' +
|
||||
' <p class="card-text">'+ result.data.questions[i].question + '</p>' +
|
||||
' <a href="#" onclick="openReadMoreModal(\''+ result.data.questions[i].id + '\');" class="card-link">Read more</a>' +
|
||||
@ -193,6 +207,11 @@ function getQuestions()
|
||||
'</div> ' )
|
||||
}
|
||||
else if ( $( '#qa_' + result.data.questions[i].id ).length < 1 && result.data.questions[i].answer !== null && result.data.questions[i].answer.length > 5 )
|
||||
{
|
||||
$('#q_' + result.data.questions[i].id + ' p' ).html( result.data.questions[i].question + '<hr><span id="qa_' + result.data.questions[i].id + '">' + result.data.questions[i].answer + '</span>' );
|
||||
$('#q_' + result.data.questions[i].id + ' h5').addClass( 'text-info' ).removeClass( 'text-warning' );
|
||||
}
|
||||
else if ( result.data.questions[i].answer !== $('#qa_' + result.data.questions[i].id ).html() )
|
||||
{
|
||||
$('#q_' + result.data.questions[i].id + ' p' ).html( result.data.questions[i].question + '<hr><span id="qa_' + result.data.questions[i].id + '">' + result.data.questions[i].answer + '</span>' );
|
||||
}
|
||||
|
Reference in New Issue
Block a user