Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DoneXBlock
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
DoneXBlock
Commits
c12cf3d3
Commit
c12cf3d3
authored
Sep 11, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4 from pmitros/event-tracking
Add event tracking
parents
3ac421ac
ba55cf4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
done/done.py
+22
-1
done/static/js/src/done.js
+11
-1
No files found.
done/done.py
View file @
c12cf3d3
"""
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
):
...
...
done/static/js/src/done.js
View file @
c12cf3d3
/* 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
);
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment