<commit_before>/**
 * This file implements main functionality of call4action module
 */

function init() {
    //console.log(window.sessionStorage);
    var teacher = window.sessionStorage.getItem("teacherId");

    if (teacher == null) {

        //show login dialog
        $('#loginModal').modal({

            backdrop: 'static',
            keyboard: false

        });

        $("#loginModal").on("hidden.bs.modal", function () {

            if (window.sessionStorage.getItem("teacherId") == null) {
                // put your default event here
                $("#warning-message").removeClass("hidden");
            }
            else {
                $("#warning-message").addClass("hidden");
                //show content
                $("#mainContent").removeClass("hidden");
            }

        });
    }
    else {
        //show content
        $("#mainContent").removeClass("hidden");
        $('[data-toggle="popover"]').popover();
        $(".icon_info").tooltip();

        initStudentTable();

        //Dependent Task
        //dynamically generate list of tasks
        $('input[type=radio][name=task-type]').change(function () {
            console.log(this.value);
            if (this.value === '1') {
                document.getElementById("taskDiv").classList.remove("hidden");

                getTasks(function (tasks) {
                    generateTaskTable(tasks["DATA"]);
                });
            }
            else {
                document.getElementById("taskDiv").classList.add("hidden");
            }
        });


    }

    /**
     * SUBMIT TASK
     */
    document.getElementById("submit-btn").addEventListener('click', function () {

        var form = document.getElementById("taskForm");
        if (form.checkValidity()) {


            //check if any students were selected
            if ($('table.table.table-striped :checkbox:checked').length > 0) {
                $("#select-error-message").addClass("hidden");

                var formData = $('#taskForm').serializeArray();
                //check if select all in the data, remove it
                var data = formData.filter(function (el) {
                    return el.name !== "select-all";
                });

                //prepare data to be send on server
                var taskName = formData.find(function (obj) {
                    return obj.name === "title";
                });
                var taskDescription = formData.find(function (obj) {
                    return obj.name === "description";
                });
                var studentIDs = formData.filter(function (obj) {
                    return obj.name === "student";

                }).map(function (students) {
                    return students.value;
                });

                var taskType = formData.find(function (obj) {
                    return obj.name === "task-type";
                });

                var isReflection = 0;
                //check if this task is Reflection task
                if ($('#reflection-checkbox').is(":checked")) {
                    isReflection = 1;
                }
                console.log(isReflection);


                //check if it is dependent task, if task choosen fomr the list

                if (taskType.value === "1") {
                    if ($("#taskList").val() === "0") {
                        //show error message
                        $("#task-error-message").removeClass("hidden");

                    }
                    else {
                        $("#task-error-message").addClass("hidden");
                        var taskId = $("#taskList").val();

                        //autogenerate additional text "Note! This task can be done after Task Name"
                        var subtitle = "Note! This task can be done after <b>" + $("#taskList option:selected").text() + "</b>";

                        var timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
                        var preparedData = { "subtitle": subtitle, "taskId": taskId, "func": "addTask", "type": taskType.value, "taskName": taskName.value, "taskDescription": taskDescription.value, "teacherId": window.sessionStorage.getItem("teacherId"), "pilotsite": window.sessionStorage.getItem("sessionId"), "students": studentIDs, "status": 0, "timestamp": timestamp,"isReflection":isReflection };

                        console.log(preparedData);
                        submitTask(preparedData, function (result) {
                            //clear form data
                            $("#taskForm").find("input[type=text], textarea").val("");
                            emptyCheckboxes();

                            //show success notification
                            if (result["RESULT"] === "SUCCESS") {
                                showMessage("Task was created successfully!", "alert-success");

                            }
                            else {
                                showMessage("Some issue is occurred, please try again later.", "alert-danger");
                            }
                            document.getElementById("taskDiv").classList.add("hidden");
                        });
                    }
                }
                else {




                    var timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
                    var preparedData = { "subtitle": "", "taskId": -1, "func": "addTask", "type": taskType.value, "taskName": taskName.value, "taskDescription": taskDescription.value, "teacherId": window.sessionStorage.getItem("teacherId"), "pilotsite": window.sessionStorage.getItem("sessionId"), "students": studentIDs, "status": 0, "timestamp": timestamp,"isReflection":isReflection };


                    submitTask(preparedData, function (result) {
                        //clear form data
                        $("#taskForm").find("input[type=text], textarea").val("");
                        emptyCheckboxes();
                        //show success notification
                        if (result["RESULT"] === "SUCCESS") {
                            showMessage("Task was created successfully!", "alert-success");
                        }
                        else {
                            showMessage("Some issue is occurred, please try again later.", "alert-danger");
                        }
                    });
                }

            }
            else {
                $("#select-error-message").removeClass("hidden");
            }



        }
        else {

            form.querySelector('button[type="submit"]').click();
        }
    }, false);



}

function generateReflectionLink() {
    var link = "<a href='#' onclick=\"openSmallWindow('./lnu/reflection/index.html','Reflection',event);\"> Do Reflection</a>";
    return link;
}

function initStudentTable() {

    getStudents(function (students) {
        //console.log(students.length);
        //console.log(students);
        if (students == "error") {
            displayErrorMsg();
        } else {
            generateStudentTable(students["DATA"]);
        }
    });
<commit_msg>update call4action modeule: remove generation link<commit_after>/**
 * This file implements main functionality of call4action module
 */

function init() {
    //console.log(window.sessionStorage);
    var teacher = window.sessionStorage.getItem("teacherId");

    if (teacher == null) {

        //show login dialog
        $('#loginModal').modal({

            backdrop: 'static',
            keyboard: false

        });

        $("#loginModal").on("hidden.bs.modal", function () {

            if (window.sessionStorage.getItem("teacherId") == null) {
                // put your default event here
                $("#warning-message").removeClass("hidden");
            }
            else {
                $("#warning-message").addClass("hidden");
                //show content
                $("#mainContent").removeClass("hidden");
            }

        });
    }
    else {
        //show content
        $("#mainContent").removeClass("hidden");
        $('[data-toggle="popover"]').popover();
        $(".icon_info").tooltip();

        initStudentTable();

        //Dependent Task
        //dynamically generate list of tasks
        $('input[type=radio][name=task-type]').change(function () {
            console.log(this.value);
            if (this.value === '1') {
                document.getElementById("taskDiv").classList.remove("hidden");

                getTasks(function (tasks) {
                    generateTaskTable(tasks["DATA"]);
                });
            }
            else {
                document.getElementById("taskDiv").classList.add("hidden");
            }
        });


    }

    /**
     * SUBMIT TASK
     */
    document.getElementById("submit-btn").addEventListener('click', function () {

        var form = document.getElementById("taskForm");
        if (form.checkValidity()) {


            //check if any students were selected
            if ($('table.table.table-striped :checkbox:checked').length > 0) {
                $("#select-error-message").addClass("hidden");

                var formData = $('#taskForm').serializeArray();
                //check if select all in the data, remove it
                var data = formData.filter(function (el) {
                    return el.name !== "select-all";
                });

                //prepare data to be send on server
                var taskName = formData.find(function (obj) {
                    return obj.name === "title";
                });
                var taskDescription = formData.find(function (obj) {
                    return obj.name === "description";
                });
                var studentIDs = formData.filter(function (obj) {
                    return obj.name === "student";

                }).map(function (students) {
                    return students.value;
                });

                var taskType = formData.find(function (obj) {
                    return obj.name === "task-type";
                });

                var isReflection = 0;
                //check if this task is Reflection task
                if ($('#reflection-checkbox').is(":checked")) {
                    isReflection = 1;
                }
                console.log(isReflection);


                //check if it is dependent task, if task choosen fomr the list

                if (taskType.value === "1") {
                    if ($("#taskList").val() === "0") {
                        //show error message
                        $("#task-error-message").removeClass("hidden");

                    }
                    else {
                        $("#task-error-message").addClass("hidden");
                        var taskId = $("#taskList").val();

                        //autogenerate additional text "Note! This task can be done after Task Name"
                        var subtitle = "Note! This task can be done after <b>" + $("#taskList option:selected").text() + "</b>";

                        var timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
                        var preparedData = { "subtitle": subtitle, "taskId": taskId, "func": "addTask", "type": taskType.value, "taskName": taskName.value, "taskDescription": taskDescription.value, "teacherId": window.sessionStorage.getItem("teacherId"), "pilotsite": window.sessionStorage.getItem("sessionId"), "students": studentIDs, "status": 0, "timestamp": timestamp,"isReflection":isReflection };

                        console.log(preparedData);
                        submitTask(preparedData, function (result) {
                            //clear form data
                            $("#taskForm").find("input[type=text], textarea").val("");
                            emptyCheckboxes();

                            //show success notification
                            if (result["RESULT"] === "SUCCESS") {
                                showMessage("Task was created successfully!", "alert-success");

                            }
                            else {
                                showMessage("Some issue is occurred, please try again later.", "alert-danger");
                            }
                            document.getElementById("taskDiv").classList.add("hidden");
                        });
                    }
                }
                else {




                    var timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
                    var preparedData = { "subtitle": "", "taskId": -1, "func": "addTask", "type": taskType.value, "taskName": taskName.value, "taskDescription": taskDescription.value, "teacherId": window.sessionStorage.getItem("teacherId"), "pilotsite": window.sessionStorage.getItem("sessionId"), "students": studentIDs, "status": 0, "timestamp": timestamp,"isReflection":isReflection };


                    submitTask(preparedData, function (result) {
                        //clear form data
                        $("#taskForm").find("input[type=text], textarea").val("");
                        emptyCheckboxes();
                        //show success notification
                        if (result["RESULT"] === "SUCCESS") {
                            showMessage("Task was created successfully!", "alert-success");
                        }
                        else {
                            showMessage("Some issue is occurred, please try again later.", "alert-danger");
                        }
                    });
                }

            }
            else {
                $("#select-error-message").removeClass("hidden");
            }



        }
        else {

            form.querySelector('button[type="submit"]').click();
        }
    }, false);



}



function initStudentTable() {

    getStudents(function (students) {
        //console.log(students.length);
        //console.log(students);
        if (students == "error") {
            displayErrorMsg();
        } else {
            generateStudentTable(students["DATA"]);
        }
    });

{'fraction_non_alphanumeric': 0.1390974805249491, 'fraction_numerical': 0.0023159519966313427, 'mean_word_length': 1.4743879145685015, 'pattern_counts': {'":': 50, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718443', 'n_tokens_mistral': 3443, 'n_tokens_neox': 3237, 'n_words': 714}