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B,C","sources":["webpack://WebComponents/./runestone/poll/js/poll.js"],"sourcesContent":["/*\n__author__ = Kirby Olson\n__date__ = 6/12/2015  */\n\"use strict\";\n\nimport RunestoneBase from \"../../common/js/runestonebase\";\nimport \"../css/poll.css\";\n\n\nexport default class Poll extends RunestoneBase {\n    constructor(opts) {\n        super(opts);\n        var orig = opts.orig; //entire <p> element\n        this.origElem = orig;\n        this.divid = orig.id;\n        this.children = this.origElem.childNodes;\n        this.optionList = [];\n        this.optsArray = [];\n        this.comment = false;\n        if ($(this.origElem).is(\"[data-comment]\")) {\n            this.comment = true;\n        }\n        this.resultsViewer = $(orig).data(\"results\");\n        this.getQuestionText();\n        this.getOptionText(); //populates optionList\n        this.renderPoll(); //generates HTML\n        // Checks localStorage to see if this poll has already been completed by this user.\n        this.checkPollStorage();\n        this.caption = \"Poll\";\n        this.addCaption(\"runestone\");\n    }\n    getQuestionText() {\n        //finds the text inside the parent tag, but before the first <li> tag and sets it as the question\n        var _this = this;\n        var firstAnswer;\n        for (var i = 0; i < this.children.length; i++) {\n            if (this.children[i].tagName == \"LI\") {\n                firstAnswer = _this.children[i];\n                break;\n            }\n        }\n        var delimiter = firstAnswer.outerHTML;\n        var fulltext = $(this.origElem).html();\n        var temp = fulltext.split(delimiter);\n        this.question = temp[0];\n    }\n    getOptionText() {\n        //Gets the text from each <li> tag and places it in this.optionList\n        var _this = this;\n        for (var i = 0; i < this.children.length; i++) {\n            if (_this.children[i].tagName == \"LI\") {\n                _this.optionList.push($(_this.children[i]).html());\n            }\n        }\n    }\n    renderPoll() {\n        //generates the HTML that the user interacts with\n        var _this = this;\n        this.containerDiv = document.createElement(\"div\");\n        this.pollForm = document.createElement(\"form\");\n        this.resultsDiv = document.createElement(\"div\");\n        $(this.resultsDiv).addClass(\"poll-results\");\n        this.containerDiv.id = this.divid;\n        $(this.containerDiv).addClass(this.origElem.getAttribute(\"class\"));\n        $(this.pollForm).html(\n            `<span style='font-size: Large'>${this.question}</span>`\n        );\n        $(this.pollForm).attr({\n            id: this.divid + \"_form\",\n            method: \"get\",\n            action: \"\",\n            onsubmit: \"return false;\",\n        });\n        this.pollForm.appendChild(document.createElement(\"br\"));\n        for (var i = 0; i < this.optionList.length; i++) {\n            var radio = document.createElement(\"input\");\n            var tmpid = _this.divid + \"_opt_\" + i;\n            $(radio).attr({\n                id: tmpid,\n                name: this.divid + \"_group1\",\n                type: \"radio\",\n                value: i,\n            });\n            $(radio).click(this.submitPoll.bind(this));\n            var label = document.createElement(\"div\");\n            //$(label).attr(\"for\", tmpid);\n            $(label).html(this.optionList[i]);\n            $(label).addClass(\"poll-option\");\n            this.pollForm.appendChild(radio);\n            this.optsArray.push(radio);\n            this.pollForm.appendChild(label);\n            this.pollForm.appendChild(document.createElement(\"br\"));\n        }\n\n        if (this.comment) {\n            this.renderTextField();\n        }\n        this.resultsDiv.id = this.divid + \"_results\";\n        this.containerDiv.appendChild(this.pollForm);\n        this.containerDiv.appendChild(this.resultsDiv);\n        $(this.origElem).replaceWith(this.containerDiv);\n        this.queueMathJax(this.containerDiv);\n    }\n    renderTextField() {\n        this.textfield = document.createElement(\"input\");\n        this.textfield.type = \"text\";\n        $(this.textfield).addClass(\"form-control\");\n        this.textfield.style.width = \"300px\";\n        this.textfield.name = this.divid + \"_comment\";\n        this.textfield.placeholder = \"Any comments?\";\n        this.pollForm.appendChild(this.textfield);\n        this.pollForm.appendChild(document.createElement(\"br\"));\n    }\n    submitPoll() {\n        //checks the poll, sets localstorage and submits to the server\n        var poll_val = null;\n        for (var i = 0; i < this.optsArray.length; i++) {\n            if (this.optsArray[i].checked) {\n                poll_val = this.optsArray[i].value;\n                break;\n            }\n        }\n        if (poll_val === null) return;\n        var comment_val = \"\";\n        if (this.comment) {\n            comment_val = this.textfield.value;\n        }\n        var act = \"\";\n        if (comment_val !== \"\") {\n            act = poll_val + \":\" + comment_val;\n        } else {\n            act = poll_val;\n        }\n        var eventInfo = { event: \"poll\", act: act, div_id: this.divid };\n        // log the response to the database\n        this.logBookEvent(eventInfo); // in bookfuncs.js\n        // log the fact that the user has answered the poll to local storage\n        let onlineResponse = \"Thanks, your response has been recorded\";\n        let offlineResponse = \"Thanks, your answers are not recorded\";\n        let onlineUpdate = \"Only Your last reponse is recorded\";\n        let offlineUpdate = \"Thanks, your answers are not recorded\";\n        localStorage.setItem(this.divid, \"true\");\n        if (!document.getElementById(`${this.divid}_sent`)) {\n            $(this.pollForm).append(\n                `<span id=${this.divid}_sent><strong>\n                ${eBookConfig.useRunestoneServices ? onlineResponse : offlineResponse}</strong></span>`\n            );\n        } else {\n            $(`#${this.divid}_sent`).html(\n                `<strong>\n                ${eBookConfig.useRunestoneServices ? onlineUpdate : offlineUpdate}\n                </strong>`\n            );\n        }\n        // show the results of the poll\n        if (this.resultsViewer === \"all\") {\n            var data = {};\n            data.div_id = this.divid;\n            data.course = eBookConfig.course;\n            jQuery.get(\n                `${eBookConfig.new_server_prefix}/assessment/getpollresults`,\n                data,\n                this.showPollResults\n            );\n        }\n    }\n    showPollResults(results) {\n        //displays the results returned by the server\n        results = results.detail;\n        var total = results[\"total\"];\n        var optCounts = results[\"opt_counts\"];\n        var div_id = results[\"div_id\"];\n        var my_vote = results[\"my_vote\"];\n        // restore current users vote\n        if (my_vote > -1) {\n            this.optsArray[my_vote].checked = \"checked\";\n        }\n        // show results summary if appropriate\n        if (\n            (this.resultsViewer === \"all\" &&\n                localStorage.getItem(this.divid === \"true\")) ||\n            eBookConfig.isInstructor\n        ) {\n            $(this.resultsDiv).html(\n                `<b>Results:</b> ${total} responses <br><br>`\n            );\n            var list = $(document.createElement(\"div\"));\n            $(list).addClass(\"results-container\");\n            for (var i = 0; i < this.optionList.length; i++) {\n                var count;\n                var percent;\n                if (optCounts[i] > 0) {\n                    count = optCounts[i];\n                    percent = (count / total) * 100;\n                } else {\n                    count = 0;\n                    percent = 0;\n                }\n                var text = count + \" (\" + Math.round(10 * percent) / 10 + \"%)\"; // round percent to 10ths\n                var html;\n                if (percent > 10) {\n                    html =\n                        `<div class=\"progresscounter\">${i + 1}. </div>` +\n                        \"<div class='progress'>\" +\n                        \"<div class='progress-bar progress-bar-success'\" +\n                        `style=\"width: ${percent}%; min-width: 2em;\">` +\n                        \"<span class='poll-text'>\" +\n                        text +\n                        \"</span></div></div>\";\n                } else {\n                    html =\n                        `<div class=\"progresscounter\">${i + 1}. </div>` +\n                        \"<div class='progress'>\" +\n                        \"<div class='progress-bar progress-bar-success'\" +\n                        `style=\"width: ${percent}%; min-width: 2em;\"></div>` +\n                        \"<span class='poll-text' style='margin: 0 0 0 10px;'>\" +\n                        text +\n                        \"</span></div>\";\n                }\n                var el = $(html);\n                list.append(el);\n            }\n            $(this.resultsDiv).append(list);\n        }\n        this.indicate_component_ready();\n    }\n    disableOptions() { }\n    checkPollStorage() {\n        //checks the localstorage to see if the poll has been completed already\n        var _this = this;\n        var len = localStorage.length;\n        if (len > 0) {\n            //If the poll has already been completed, show the results\n            var data = {};\n            data.div_id = this.divid;\n            data.course = eBookConfig.course;\n            jQuery\n                .get(\n                    `${eBookConfig.new_server_prefix}/assessment/getpollresults`,\n                    data,\n                    this.showPollResults.bind(this)\n                )\n                .fail(this.indicate_component_ready.bind(this));\n        } else {\n            this.indicate_component_ready();\n        }\n    }\n}\n\n// Do not render poll data until login-complete event so we know instructor status\n$(document).on(\"runestone:login-complete\", function () {\n    $(\"[data-component=poll]\").each(function (index) {\n        try {\n            window.componentMap[this.id] = new Poll({ orig: this });\n        } catch (err) {\n            console.log(`Error rendering Poll Problem ${this.id}\n                         Details: ${err}`);\n            console.log(err.stack);\n        }\n    });\n});\n\nif (typeof window.component_factory === \"undefined\") {\n    window.component_factory = {};\n}\nwindow.component_factory.poll = function (opts) {\n    return new Poll(opts);\n};\n"],"names":["Poll","constructor","opts","super","orig","this","origElem","divid","id","children","childNodes","optionList","optsArray","comment","$","is","resultsViewer","data","getQuestionText","getOptionText","renderPoll","checkPollStorage","caption","addCaption","firstAnswer","i","length","tagName","delimiter","outerHTML","temp","html","split","question","_this","push","containerDiv","document","createElement","pollForm","resultsDiv","addClass","getAttribute","attr","method","action","onsubmit","appendChild","radio","tmpid","name","type","value","click","submitPoll","bind","label","renderTextField","replaceWith","queueMathJax","textfield","style","width","placeholder","poll_val","checked","comment_val","eventInfo","event","act","div_id","logBookEvent","localStorage","setItem","getElementById","eBookConfig","useRunestoneServices","append","course","jQuery","get","new_server_prefix","showPollResults","results","total","detail","optCounts","my_vote","getItem","isInstructor","list","count","percent","text","Math","round","el","indicate_component_ready","disableOptions","fail","on","each","index","window","componentMap","err","console","log","stack","component_factory","poll"],"sourceRoot":""}