javascriptalertify

Javascript Alertify


I have an htm table, the positions, and questions for them, for user answer

<table id="position_holder">
    <tbody>
        <tr>
            <td>СБ</td>
            <td>
            <a id="6" href="/position-holder/#">Руководитель службы СБ</a>
                <div class="question">Имеете ли вы высшее образование?</div>
                <div class="question">Ваш стаж работы по специальности не менее 5 лет в правоохранительных органах ?</div>
                <div class="question">Ваш возраст от 25 до 50 лет?</div>
            </td>
        </tr>
        <tr>
            <td>Отдел безопасности объектов СБ</td>
            <td>
            <a id="7" href="/position-holder/#">Начальник отдела</a>
            </td>
        </tr>
        <tr>
            <td>ДБиОТ, ООС и ОЗ</td>
            <td>
            <a id="8" href="/position-holder/#">Директор ДБиОТ, ООС и ОЗ</a>
            <div class="question">Ваш возраст от 25 до 50 лет?</div>
                <div class="question">Ваш стаж работы по специальности не менее 5 лет (в нефтяной промышленности на руководящих должностях)?</div>
                <div class="question">Ваш стаж работы в текущей должности не менее 2 лет?</div>
                <div class="question">Есть ли у Вас в наличии высшее профессиональное (техническое)образование?</div>
                <div class="question">Ваша текущая должность в АО "КБМ", согласно оргструктуре, находится на одну ступень ниже либо является аналогичной в другом подразделении?</div>
            </td>
        </tr>
        <tr>
            <td>ДБиОТ, ООС и ОЗ</td>
            <td>
            <a id="9" href="/position-holder/#">Ведущий специалист гражданской обороны</a>
            </td>
        </tr>
    </tbody>
</table>

i have a javascript. If user click on position he have to test pass with questions in there.

$('#position_holder td a').on('click', function(){
    if($(this).next().text() == ''){
        alertify.alert('Tests are not set!');
    }
    $(this).parents("td").find(".question").each(function (index) {
       if(!confirm($(this).text())){
           alertify.alert('Test faild!');
           return false;
        }else if($(this).next().text() == ''){
           console.log('Test success! Ajax request started!');
           alertify.alert('Test passed!');
        }
    });
    return false;
});

It works well. I need to have some buity to confirm and alert messages.

I use a http://fabien-d.github.io/alertify.js/ library to it.

Alerts looks well, but i cant figure how to implement it it confirm.

I cant set if(!alerify.confirm($(this).text())){ it not working, and even to do it throw loop, please help!


Solution

  • At the end i do it myself

            $('#position_holder td a').on('click', function(){
                if($(this).next().text() == ''){
                    alertify.alert('No test here yet!');
                    return false;
                }
                var questions = $(this).parents("td").find(".question").toArray();
                var posId = $(this).attr('id');
                answerTheQuestion(questions, questions.length, 0, posId);
                return false;
            });
    
            function answerTheQuestion(questions, num, pos, posId){
                if(num == 0){
                    alertify.alert('Test done!');
                    return false;
                }
                console.log(questions, num, pos, posId);
                var currentQuestion = questions[pos];
                alertify.confirm($(currentQuestion).text(), function (e) {
                    if (e) {
                        // user clicked "ok"
                        answerTheQuestion(questions, num - 1, pos + 1, posId);
                    } else {
                        // user clicked "cancel"
                        alertify.alert('Test failed!');
                    }
                });
            }