Index: lams_learning/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r88f3c4e68acd7c0ad6bcab7c6a3f36197d009468 -recd3b320baed53ab184cc7c5d1a67def50651fe2 --- lams_learning/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 88f3c4e68acd7c0ad6bcab7c6a3f36197d009468) +++ lams_learning/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision ecd3b320baed53ab184cc7c5d1a67def50651fe2) @@ -169,5 +169,6 @@ label.kumalive.poll.answer.no =No label.kumalive.poll.answer.custom =Custom... label.kumalive.poll.answer.custom.tip ={Put} {each} {answer} {in} {curly} {brackets} +label.kumalive.poll.answer.custom.error.syntax =Custom answer syntax is incorrect. Example: {firs answer} {second answer} button.kumalive.poll.start =Ask now! #======= End labels: Exported 151 labels for en AU ===== Index: lams_learning/web/css/kumalive.scss =================================================================== diff -u -r88f3c4e68acd7c0ad6bcab7c6a3f36197d009468 -recd3b320baed53ab184cc7c5d1a67def50651fe2 --- lams_learning/web/css/kumalive.scss (.../kumalive.scss) (revision 88f3c4e68acd7c0ad6bcab7c6a3f36197d009468) +++ lams_learning/web/css/kumalive.scss (.../kumalive.scss) (revision ecd3b320baed53ab184cc7c5d1a67def50651fe2) @@ -51,7 +51,7 @@ width: initial; } -#pollSetupAnswerCustom { +#pollSetupAnswerCustom, #pollSetupAnswerCustomParseError { display: none; } Index: lams_learning/web/includes/javascript/kumalive.js =================================================================== diff -u -r9109f09180cd4d5e01db5fbacf59962b21cb09cd -recd3b320baed53ab184cc7c5d1a67def50651fe2 --- lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision 9109f09180cd4d5e01db5fbacf59962b21cb09cd) +++ lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision ecd3b320baed53ab184cc7c5d1a67def50651fe2) @@ -170,15 +170,16 @@ if (roleTeacher) { $('#raiseHandPromptButton').click(raiseHandPrompt); $('#downHandPromptButton').click(downHandPrompt); - $('#pollButton').click(pollSetup).show(); + $('#pollButton').click(setupPoll).show(); $('#pollSetupAnswer').change(function(){ if ($('#pollSetupAnswer option:selected').val() === 'custom') { $('#pollSetupAnswerCustom').show(); } else { $('#pollSetupAnswerCustom').hide(); } }); - $('#pollSetupCancelButton').click(pollSetupCancel); + $('#pollSetupCancelButton').click(setupPollCancel); + $('#pollSetupStartButton').click(startPoll); $('#score i').click(score); $('#finishButton').click(finish).show(); } else { @@ -613,18 +614,89 @@ } } -function pollSetup() { +function setupPoll() { $('#pollButton').prop('disabled', true); $('#pollCell').show(); + $('#pollSetupQuestion').focus(); } -function pollSetupCancel() { +function setupPollCancel() { $('#pollCell').hide(); $('#pollCell input').val(null); $('#pollCell select option:first-child').prop('selected', true); $('#pollButton').prop('disabled', false); } +function startPoll(){ + var question = $('#pollSetupQuestion').val(), + poll = {}; + // validation + if (question) { + $('#pollSetupQuestionGroup').removeClass('has-error'); + poll.question = question; + } else { + $('#pollSetupQuestionGroup').addClass('has-error'); + } + + if ($('#pollSetupAnswer option:selected').val() === 'custom'){ + $('#pollSetupAnswerCustomParseError').hide(); + var answerString = $('#pollSetupAnswerCustom').val(); + // check if brackets are closed and there is nothing between them, for example "{aaa} {bb" or "{aaa} bb {ccc}" + if (answerString) { + var index = -1, + indexEnd = -1, + answers = []; + do { + // find opening bracket + index = answerString.indexOf('{', index + 1); + if (index >= 0) { + // is there anything other than whitespace between } and { + if (answerString.substring(indexEnd + 1, index).trim()) { + answers = []; + break; + } + // is there a matching } + indexEnd = answerString.indexOf('}', index + 1); + if (indexEnd < 0) { + answers = []; + break; + } + var answer = answerString.substring(index + 1, indexEnd); + // is the answer not empty, i.e. { } + if (answer.trim()) { + answers.push(answer); + } else { + answers = []; + break; + } + } else if (indexEnd && answerString.substring(indexEnd + 1).trim()) { + // is there anything after last } + answers = []; + break; + } + } while (index >= 0); + if (answers.length === 0) { + $('#pollSetupAnswerCustomGroup').addClass('has-error'); + $('#pollSetupAnswerCustomParseError').show(); + } else { + $('#pollSetupAnswerCustomGroup').removeClass('has-error'); + poll.answers = answers; + } + } else { + $('#pollSetupAnswerCustomGroup').addClass('has-error'); + } + } + + if (!poll.question || !poll.answers) { + return; + } + + kumaliveWebsocket.send(JSON.stringify({ + 'type' : 'startPoll', + 'poll' : poll + })); +} + /** * Create a new Kumalive */ Index: lams_learning/web/kumalive/kumalive.jsp =================================================================== diff -u -r9109f09180cd4d5e01db5fbacf59962b21cb09cd -recd3b320baed53ab184cc7c5d1a67def50651fe2 --- lams_learning/web/kumalive/kumalive.jsp (.../kumalive.jsp) (revision 9109f09180cd4d5e01db5fbacf59962b21cb09cd) +++ lams_learning/web/kumalive/kumalive.jsp (.../kumalive.jsp) (revision ecd3b320baed53ab184cc7c5d1a67def50651fe2) @@ -93,12 +93,13 @@
-
- - +
+ +
- +
- +
+
+ + + + +