Commit 68f5b96b by Xavier Antoviaque

Merge pull request #58 from aboudreault/html-tip-fix

Fix html tip display issue and an issue related to publish_event
parents 5a365759 9bbaee77
...@@ -13,6 +13,15 @@ function MentoringBlock(runtime, element) { ...@@ -13,6 +13,15 @@ function MentoringBlock(runtime, element) {
} }
} }
function setContent(dom, content) {
dom.html('');
dom.append(content);
var template = $('#light-child-template', dom).html();
if (template) {
dom.append(template);
}
}
function renderAttempts() { function renderAttempts() {
var data = $('.attempts', element).data(); var data = $('.attempts', element).data();
$('.attempts', element).html(attemptsTemplate(data)); $('.attempts', element).html(attemptsTemplate(data));
...@@ -36,7 +45,7 @@ function MentoringBlock(runtime, element) { ...@@ -36,7 +45,7 @@ function MentoringBlock(runtime, element) {
children_dom.push(child_dom); children_dom.push(child_dom);
children.push(child); children.push(child);
if (typeof child !== 'undefined') { if (typeof child !== 'undefined') {
child = child(runtime, child_dom); child = child(runtime, child_dom, mentoring);
child.name = $(child_dom).attr('name'); child.name = $(child_dom).attr('name');
children[children.length-1] = child; children[children.length-1] = child;
} }
...@@ -75,6 +84,7 @@ function MentoringBlock(runtime, element) { ...@@ -75,6 +84,7 @@ function MentoringBlock(runtime, element) {
var mentoring = { var mentoring = {
callIfExists: callIfExists, callIfExists: callIfExists,
setContent: setContent,
renderAttempts: renderAttempts, renderAttempts: renderAttempts,
renderDependency: renderDependency, renderDependency: renderDependency,
readChildren: readChildren, readChildren: readChildren,
...@@ -83,7 +93,8 @@ function MentoringBlock(runtime, element) { ...@@ -83,7 +93,8 @@ function MentoringBlock(runtime, element) {
displayChild: displayChild, displayChild: displayChild,
displayChildren: displayChildren, displayChildren: displayChildren,
getChildByName: getChildByName, getChildByName: getChildByName,
step: step step: step,
event_url: runtime.handlerUrl(element, 'publish_event')
} }
if (data.mode === 'standard') { if (data.mode === 'standard') {
......
...@@ -22,11 +22,7 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -22,11 +22,7 @@ function MentoringStandardView(runtime, element, mentoring) {
mentoring.renderAttempts(); mentoring.renderAttempts();
// Messages should only be displayed upon hitting 'submit', not on page reload // Messages should only be displayed upon hitting 'submit', not on page reload
messagesDOM.append(results.message); mentoring.setContent(messagesDOM, results.message);
var template = $('#light-child-template', messagesDOM).html();
if (template) {
messagesDOM.append(template);
}
if (messagesDOM.html().trim()) { if (messagesDOM.html().trim()) {
messagesDOM.prepend('<div class="title1">Feedback</div>'); messagesDOM.prepend('<div class="title1">Feedback</div>');
messagesDOM.show(); messagesDOM.show();
......
// TODO: Split in two files // TODO: Split in two files
function MessageView(element) { function MessageView(element, mentoring) {
return { return {
messageDOM: $('.feedback', element), messageDOM: $('.feedback', element),
allPopupsDOM: $('.choice-tips, .feedback', element), allPopupsDOM: $('.choice-tips, .feedback', element),
...@@ -32,7 +32,7 @@ function MessageView(element) { ...@@ -32,7 +32,7 @@ function MessageView(element) {
function publish_event(data) { function publish_event(data) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'publish_event'), url: mentoring.event_url,
data: JSON.stringify(data) data: JSON.stringify(data)
}); });
} }
...@@ -47,7 +47,7 @@ function MessageView(element) { ...@@ -47,7 +47,7 @@ function MessageView(element) {
}, },
showMessage: function(message) { showMessage: function(message) {
if (_.isString(message)) { if (_.isString(message)) {
this.messageDOM.html(message); mentoring.setContent(this.messageDOM, message)
this.showPopup(this.messageDOM); this.showPopup(this.messageDOM);
} }
else { else {
...@@ -63,7 +63,7 @@ function MessageView(element) { ...@@ -63,7 +63,7 @@ function MessageView(element) {
} }
} }
function MCQBlock(runtime, element) { function MCQBlock(runtime, element, mentoring) {
return { return {
mode: null, mode: null,
init: function(options) { init: function(options) {
...@@ -85,7 +85,7 @@ function MCQBlock(runtime, element) { ...@@ -85,7 +85,7 @@ function MCQBlock(runtime, element) {
if (this.mode === 'assessment') if (this.mode === 'assessment')
return; return;
var messageView = MessageView(element); var messageView = MessageView(element, mentoring);
messageView.clearResult(); messageView.clearResult();
var choiceInputs = $('.choice input', element); var choiceInputs = $('.choice input', element);
...@@ -135,7 +135,7 @@ function MCQBlock(runtime, element) { ...@@ -135,7 +135,7 @@ function MCQBlock(runtime, element) {
}, },
clearResult: function() { clearResult: function() {
MessageView(element).clearResult(); MessageView(element, mentoring).clearResult();
}, },
validate: function(){ validate: function(){
...@@ -148,7 +148,7 @@ function MCQBlock(runtime, element) { ...@@ -148,7 +148,7 @@ function MCQBlock(runtime, element) {
}; };
} }
function MRQBlock(runtime, element) { function MRQBlock(runtime, element, mentoring) {
return { return {
mode: null, mode: null,
init: function(options) { init: function(options) {
...@@ -170,7 +170,7 @@ function MRQBlock(runtime, element) { ...@@ -170,7 +170,7 @@ function MRQBlock(runtime, element) {
if (this.mode === 'assessment') if (this.mode === 'assessment')
return; return;
var messageView = MessageView(element); var messageView = MessageView(element, mentoring);
if (result.message) { if (result.message) {
messageView.showMessage('<div class="message-content">' + result.message + '</div>'+ messageView.showMessage('<div class="message-content">' + result.message + '</div>'+
...@@ -209,7 +209,7 @@ function MRQBlock(runtime, element) { ...@@ -209,7 +209,7 @@ function MRQBlock(runtime, element) {
}, },
clearResult: function() { clearResult: function() {
MessageView(element).clearResult(); MessageView(element, mentoring).clearResult();
}, },
validate: function(){ validate: function(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment