Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
f68f023e
Commit
f68f023e
authored
Jan 08, 2013
by
Carlos Andrés Rocha
Committed by
Victor Shnayder
Feb 05, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP integration of edit-a-molecule
parent
c5b86f3e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
71 deletions
+72
-71
common/lib/capa/capa/inputtypes.py
+7
-2
common/lib/capa/capa/responsetypes.py
+1
-1
common/lib/capa/capa/templates/chemicalequationinput.html
+2
-1
common/lib/capa/capa/templates/editamolecule.html
+22
-18
common/static/applets/capa/edit-a-molecule.jar
+0
-0
common/static/js/capa/edit-a-molecule.js
+40
-49
No files found.
common/lib/capa/capa/inputtypes.py
View file @
f68f023e
...
...
@@ -850,11 +850,16 @@ class EditAMoleculeInput(InputTypeBase):
"""
Can set size of text field.
"""
return
[
Attribute
(
'file'
),]
return
[
Attribute
(
'file'
),
Attribute
(
'missing'
,
None
)]
def
_extra_context
(
self
):
"""
"""
return
{
'applet_loader'
:
'/static/js/capa/edit_a_molecule.js'
,}
context
=
{
'applet_loader'
:
'/static/js/capa/edit-a-molecule.js'
,
}
return
context
registry
.
register
(
EditAMoleculeInput
)
common/lib/capa/capa/responsetypes.py
View file @
f68f023e
...
...
@@ -875,7 +875,7 @@ def sympy_check2():
allowed_inputfields
=
[
'textline'
,
'textbox'
,
'crystallography'
,
'chemicalequationinput'
,
'vsepr_input'
,
'drag_and_drop_input'
]
'drag_and_drop_input'
,
'editamoleculeinput'
]
def
setup_response
(
self
):
xml
=
self
.
xml
...
...
common/lib/capa/capa/templates/chemicalequationinput.html
View file @
f68f023e
...
...
@@ -31,10 +31,11 @@
<div
id=
"input_${id}_preview"
class=
"equation"
>
</div>
<p
id=
"answer_${id}"
class=
"answer"
></p>
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
</div>
% endif
</section>
2
common/lib/capa/capa/templates/editamolecule.html
View file @
f68f023e
<section
id=
"editamoleculeinput_${id}"
class=
"editamoleculeinput"
>
<div
class=
"script_placeholder"
data-src=
"/static/js/capa/jsmolcalc/jsmolcalc.nocache.js"
/>
<div
class=
"script_placeholder"
data-src=
"${applet_loader}"
/>
% if status == 'unsubmitted':
...
...
@@ -11,26 +12,29 @@
<div
class=
"incorrect"
id=
"status_${id}"
>
% endif
<input
type=
"text"
name=
"input_${id}"
id=
"input_${id}"
value=
"${value|h}"
/>
<!-- <object type="application/x-java-applet" id="applet_${id}" class="applet" height="400" width="500"> -->
<!-- <param name="archive" value="/static/applets/capa/edit-a-molecule.jar" /> -->
<!-- <param name="code" value="JME.class" /> -->
<!-- <param name="file" value="${file}" /> -->
<!-- Applet failed to run. No Java plug-in was found. -->
<!-- </object> -->
<p
class=
"status"
>
% if status == 'unsubmitted':
unanswered
% elif status == 'correct':
correct
% elif status == 'incorrect':
incorrect
% elif status == 'incomplete':
incomplete
% endif
</p>
<input
type=
"hidden"
name=
"input_${id}"
id=
"input_${id}"
value=
"${value|h}"
/>
<div
id=
"input_${id}_preview"
class=
"equation"
>
</div>
<p
id=
"answer_${id}"
class=
"answer"
></p>
<p
class=
"status"
>
% if status == 'unsubmitted':
unanswered
% elif status == 'correct':
correct
% elif status == 'incorrect':
incorrect
% elif status == 'incomplete':
incomplete
% endif
</p>
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
</div>
<p
id=
"answer_${id}"
class=
"answer"
></p>
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
</div>
% endif
</section>
common/static/applets/
JME
.jar
→
common/static/applets/
capa/edit-a-molecule
.jar
View file @
f68f023e
File moved
common/static/js/capa/edit-a-molecule.js
View file @
f68f023e
$
(
document
).
ready
(
function
(){
var
applet
=
$
(
"#JME"
)[
0
];
var
template
=
_
.
template
(
$
(
"#task-template"
).
text
());
(
function
()
{
var
timeout
=
1000
;
function
waitForApplet
()
{
function
initializeApplet
(
applet
)
{
console
.
log
(
"Initializing "
+
applet
);
waitForApplet
(
applet
);
}
function
waitForApplet
(
applet
)
{
if
(
applet
.
isActive
&&
applet
.
isActive
())
{
console
.
log
(
"Applet is ready."
);
loadInitialData
(
);
requestAppletData
(
applet
);
}
else
if
(
timeout
>
30
*
1000
)
{
console
.
error
(
"Applet did not load on time."
);
}
else
{
console
.
log
(
"Waiting for applet..."
);
setTimeout
(
waitForApplet
,
timeout
);
setTimeout
(
function
()
{
waitForApplet
(
applet
);
}
,
timeout
);
}
}
function
loadInitialData
()
{
function
requestAppletData
(
applet
)
{
var
file
=
$
(
applet
).
find
(
'param[name=file]'
).
attr
(
'value'
);
console
.
log
(
"Getting file url..."
);
console
.
log
(
file
);
console
.
log
(
"Loading mol data..."
);
jQuery
.
ajax
({
url
:
"dopamine.mol"
,
url
:
file
,
dataType
:
"text"
,
success
:
function
(
data
)
{
console
.
log
(
"Done."
);
setup
(
data
);
loadAppletData
(
applet
,
data
);
},
error
:
function
()
{
console
.
error
(
"Cannot load mol data."
);
...
...
@@ -30,44 +38,18 @@ $(document).ready(function(){
});
}
function
setup
(
data
)
{
function
loadAppletData
(
applet
,
data
)
{
applet
.
readMolFile
(
data
);
setupTasks
();
$
(
"#update"
).
click
(
updateInfo
);
updateInfo
();
}
function
setupTasks
()
{
console
.
log
(
"Getting initial tasks..."
);
var
tasks
=
getTasks
();
jQuery
.
each
(
tasks
,
function
(
index
,
task
)
{
var
value
=
task
.
toString
();
var
fragment
=
$
(
template
({
task
:
value
}));
$
(
"#tasks"
).
append
(
fragment
);
fragment
.
find
(
"button"
).
click
(
function
()
{
checkTask
(
task
,
index
);
});
});
console
.
log
(
"Done."
);
updateAppletInfo
(
applet
);
}
function
update
Info
(
)
{
var
info
=
get
Info
(
);
$
(
"#properties"
).
html
(
info
.
toString
());
function
update
AppletInfo
(
applet
)
{
var
info
=
get
AppletInfo
(
applet
);
console
.
log
(
info
.
toString
());
return
info
;
}
function
checkTask
(
task
,
index
)
{
var
info
=
updateInfo
();
var
value
=
task
.
check
(
info
);
$
(
"#tasks li span.result"
).
eq
(
index
).
html
(
value
);
}
function
getInfo
()
{
function
getAppletInfo
(
applet
)
{
var
mol
=
applet
.
molFile
();
var
smiles
=
applet
.
smiles
();
var
jme
=
applet
.
jmeFile
();
...
...
@@ -75,13 +57,22 @@ $(document).ready(function(){
return
jsmol
.
API
.
getInfo
(
mol
,
smiles
,
jme
);
}
function
getTasks
()
{
var
mol
=
applet
.
molFile
();
var
smiles
=
applet
.
smiles
();
var
jme
=
applet
.
jmeFile
();
console
.
log
(
'EDIT A MOLECULE'
);
return
jsmol
.
API
.
getTasks
(
mol
,
smiles
,
jme
);
}
// FIXME: [rocha] This should be called automatically by the GWT
// script loader, but for some reason it is not.
jsmolcalc
.
onInjectionDone
(
'jsmolcalc'
);
// FIXME: [rocha] This is a hack to capture the click on the check
// button and update the hidden field with the applet values
var
check
=
$
(
'.editamoleculeinput'
).
parents
(
'.problem'
).
find
(
'input.check'
);
check
.
on
(
'click'
,
function
()
{
console
.
log
(
"CLICK"
);});
// TODO: [rocha] add function to update hidden field
// TODO: [rocha] load state from hidden field if available
// initialize applet
var
applets
=
$
(
'.editamoleculeinput object'
);
applets
.
each
(
function
(
i
,
el
)
{
initializeApplet
(
el
);
});
waitForApplet
();
});
}).
call
(
this
);
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