Commit 44832e42 by Xavier Antoviaque

Merge pull request #63 from dragonfi/close-feedback-popup

Close feedback popup on click to anywhere else
parents 57cee667 cdef641a
...@@ -5,6 +5,37 @@ function MentoringBlock(runtime, element) { ...@@ -5,6 +5,37 @@ function MentoringBlock(runtime, element) {
var children = []; var children = [];
var step = data.step; var step = data.step;
function publish_event(data) {
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'publish_event'),
data: JSON.stringify(data)
});
}
$(document).on("click", function(event, ui) {
target = $(event.target);
feedback_box = ".mentoring .feedback";
if (target.is(feedback_box)) {
return;
};
if (target.parents(feedback_box).length>0) {
return;
};
$(feedback_box).each(function(i, el) {
el = $(el);
if (el.is(":hidden")) {
return;
}
el.hide();
publish_event({
event_type:'xblock.mentoring.feedback.closed',
content: el.text()
});
});
});
function callIfExists(obj, fn) { function callIfExists(obj, fn) {
if (typeof obj !== 'undefined' && typeof obj[fn] == 'function') { if (typeof obj !== 'undefined' && typeof obj[fn] == 'function') {
return obj[fn].apply(obj, Array.prototype.slice.call(arguments, 2)); return obj[fn].apply(obj, Array.prototype.slice.call(arguments, 2));
...@@ -94,7 +125,7 @@ function MentoringBlock(runtime, element) { ...@@ -94,7 +125,7 @@ function MentoringBlock(runtime, element) {
displayChildren: displayChildren, displayChildren: displayChildren,
getChildByName: getChildByName, getChildByName: getChildByName,
step: step, step: step,
event_url: runtime.handlerUrl(element, 'publish_event') publish_event: publish_event
} }
if (data.mode === 'standard') { if (data.mode === 'standard') {
...@@ -104,9 +135,5 @@ function MentoringBlock(runtime, element) { ...@@ -104,9 +135,5 @@ function MentoringBlock(runtime, element) {
MentoringAssessmentView(runtime, element, mentoring); MentoringAssessmentView(runtime, element, mentoring);
} }
$.ajax({ publish_event({event_type:"xblock.mentoring.loaded"});
type: "POST",
url: runtime.handlerUrl(element, 'publish_event'),
data: JSON.stringify({event_type:"xblock.mentoring.loaded"})
});
} }
// TODO: Split in two files // TODO: Split in two files
function MessageView(element, mentoring) { function MessageView(element, mentoring) {
return { return {
messageDOM: $('.feedback', element), messageDOM: $('.feedback', element),
...@@ -29,20 +30,17 @@ function MessageView(element, mentoring) { ...@@ -29,20 +30,17 @@ function MessageView(element, mentoring) {
popupDOM.show(); popupDOM.show();
function publish_event(data) { mentoring.publish_event({
$.ajax({ event_type:'xblock.mentoring.feedback.opened',
type: "POST", content: $(popupDOM).text()
url: mentoring.event_url,
data: JSON.stringify(data)
}); });
}
publish_event({event_type:'xblock.mentoring.feedback.opened'});
$('.close', popupDOM).on('click', function() { $('.close', popupDOM).on('click', function() {
self.clearPopupEvents(); self.clearPopupEvents();
console.log(popupDOM); mentoring.publish_event({
publish_event({event_type:'xblock.mentoring.feedback.closed'}); event_type:'xblock.mentoring.feedback.closed',
content: $(popupDOM).text()
});
}); });
}, },
showMessage: function(message) { showMessage: function(message) {
......
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