Commit ba55cf4e by Piotr Mitros

Add event tracking

parent 3ac421ac
"""TO-DO: Show a toggle which lets students mark things as done.""" """ Show a toggle which lets students mark things as done."""
import pkg_resources import pkg_resources
import uuid import uuid
...@@ -7,6 +7,24 @@ from xblock.core import XBlock ...@@ -7,6 +7,24 @@ from xblock.core import XBlock
from xblock.fields import Scope, String, Boolean, DateTime, Float from xblock.fields import Scope, String, Boolean, DateTime, Float
from xblock.fragment import Fragment from xblock.fragment import Fragment
try:
from eventtracking import tracker
except ImportError:
class tracker(object): # pylint: disable=invalid-name
"""
Define tracker if eventtracking cannot be imported. This is a workaround
so that the code works in both edx-platform and XBlock workbench (the latter
of which does not support event emission). This should be replaced with XBlock's
emit(), but at present, emit() is broken.
"""
def __init__(self):
""" Do nothing """
pass
@staticmethod
def emit(param1, param2):
""" In workbench, do nothing for event emission """
pass
class DoneXBlock(XBlock): class DoneXBlock(XBlock):
""" """
...@@ -46,6 +64,9 @@ class DoneXBlock(XBlock): ...@@ -46,6 +64,9 @@ class DoneXBlock(XBlock):
grade = 0 grade = 0
self.runtime.publish(self, 'grade', {'value': grade, 'max_value': 1}) self.runtime.publish(self, 'grade', {'value': grade, 'max_value': 1})
# Above should emit a similar event. Once it does, we should be
# able to eliminate this
tracker.emit("edx.done.toggle", {'done': self.done})
return {} return {}
def student_view(self, context=None): def student_view(self, context=None):
......
/* Dummy code to make sure events work in Workbench as well as
* edx-platform*/
if (typeof Logger === 'undefined') {
var Logger = {
log: function(a, b) { return; }
}
}
function update_knob(element, data) { function update_knob(element, data) {
if($('.done_onoffswitch-checkbox', element).prop("checked")) { if($('.done_onoffswitch-checkbox', element).prop("checked")) {
$(".done_onoffswitch-switch", element).css("background-image", "url("+data['checked']+")"); $(".done_onoffswitch-switch", element).css("background-image", "url("+data['checked']+")");
...@@ -30,11 +38,13 @@ function DoneXBlock(runtime, element, data) { ...@@ -30,11 +38,13 @@ function DoneXBlock(runtime, element, data) {
$(function ($) { $(function ($) {
$('.done_onoffswitch', element).addClass("done_animated"); $('.done_onoffswitch', element).addClass("done_animated");
$('.done_onoffswitch-checkbox', element).change(function(){ $('.done_onoffswitch-checkbox', element).change(function(){
var checked = $('.done_onoffswitch-checkbox', element).prop("checked");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: handlerUrl, url: handlerUrl,
data: JSON.stringify({"done":$('.done_onoffswitch-checkbox', element).prop("checked")}), data: JSON.stringify({'done':checked}),
}); });
Logger.log("edx.done.toggle", {'done': checked});
update_knob(element, data); update_knob(element, data);
}); });
}); });
......
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