Commit 1f160d6e by Arthur Barrett

added a box around the instructions text

parent 7b195eb0
...@@ -12,7 +12,6 @@ from xmodule.contentstore.content import StaticContent ...@@ -12,7 +12,6 @@ from xmodule.contentstore.content import StaticContent
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class AnnotatableModule(XModule): class AnnotatableModule(XModule):
# Note: js and css in common/lib/xmodule/xmodule
js = {'coffee': [resource_string(__name__, 'js/src/javascript_loader.coffee'), js = {'coffee': [resource_string(__name__, 'js/src/javascript_loader.coffee'),
resource_string(__name__, 'js/src/collapsible.coffee'), resource_string(__name__, 'js/src/collapsible.coffee'),
resource_string(__name__, 'js/src/html/display.coffee'), resource_string(__name__, 'js/src/html/display.coffee'),
...@@ -77,22 +76,32 @@ class AnnotatableModule(XModule): ...@@ -77,22 +76,32 @@ class AnnotatableModule(XModule):
attr = {} attr = {}
attr.update(self._get_annotation_class_attr(index, el)) attr.update(self._get_annotation_class_attr(index, el))
attr.update(self._get_annotation_data_attr(index, el)) attr.update(self._get_annotation_data_attr(index, el))
for key in attr.keys(): for key in attr.keys():
el.set(key, attr[key]['value']) el.set(key, attr[key]['value'])
if '_delete' in attr[key]: if '_delete' in attr[key] and attr[key]['_delete'] is not None:
delete_key = attr[key]['_delete'] delete_key = attr[key]['_delete']
del el.attrib[delete_key] del el.attrib[delete_key]
index += 1 index += 1
return etree.tostring(xmltree, encoding='unicode') return etree.tostring(xmltree, encoding='unicode')
def _extract_instructions(self, xmltree):
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
instructions = xmltree.find('instructions')
if instructions is not None:
instructions.tag = 'div'
xmltree.remove(instructions)
return etree.tostring(instructions, encoding='unicode')
return None
def get_html(self): def get_html(self):
""" Renders parameters to template. """ """ Renders parameters to template. """
context = { context = {
'display_name': self.display_name, 'display_name': self.display_name,
'element_id': self.element_id, 'element_id': self.element_id,
'discussion_id': self.discussion_id, 'instructions_html': self.instructions,
'instructions_html': self.instructions_html,
'content_html': self._render_content() 'content_html': self._render_content()
} }
...@@ -103,25 +112,11 @@ class AnnotatableModule(XModule): ...@@ -103,25 +112,11 @@ class AnnotatableModule(XModule):
XModule.__init__(self, system, location, definition, descriptor, XModule.__init__(self, system, location, definition, descriptor,
instance_state, shared_state, **kwargs) instance_state, shared_state, **kwargs)
self.element_id = self.location.html_id()
xmltree = etree.fromstring(self.definition['data']) xmltree = etree.fromstring(self.definition['data'])
# extract discussion id self.instructions = self._extract_instructions(xmltree)
self.discussion_id = xmltree.get('discussion', '')
del xmltree.attrib['discussion']
# extract instructions text (if any)
instructions = xmltree.find('instructions')
instructions_html = None
if instructions is not None:
instructions.tag = 'div'
instructions_html = etree.tostring(instructions, encoding='unicode')
xmltree.remove(instructions)
self.instructions_html = instructions_html
# everything else is annotatable content
self.content = etree.tostring(xmltree, encoding='unicode') self.content = etree.tostring(xmltree, encoding='unicode')
self.element_id = self.location.html_id()
class AnnotatableDescriptor(RawDescriptor): class AnnotatableDescriptor(RawDescriptor):
module_class = AnnotatableModule module_class = AnnotatableModule
......
...@@ -7,19 +7,29 @@ ...@@ -7,19 +7,29 @@
} }
} }
.annotatable-description { .annotatable-section {
position: relative; position: relative;
padding: 2px 4px; padding: .5em 1em;
border: 1px solid $border-color; border: 1px solid $border-color;
border-radius: 3px; border-radius: .5em;
margin-bottom: .5em; margin-bottom: .5em;
.annotatable-toggle {
position: absolute; .annotatable-section-title {}
right: 0; .annotatable-section-body {
margin: 2px 7px 2px 0; border-top: 1px solid $border-color;
margin-top: .5em;
padding-top: .5em;
} }
} }
.annotatable-toggle {
position: absolute;
right: 0;
margin: 2px 1em 2px 0;
&.expanded:after { content: " \2191" }
&.collapsed:after { content: " \2193" }
}
.annotatable-span { .annotatable-span {
display: inline; display: inline;
cursor: pointer; cursor: pointer;
......
...@@ -5,6 +5,7 @@ class @Annotatable ...@@ -5,6 +5,7 @@ class @Annotatable
toggleAnnotationsSelector: '.annotatable-toggle-annotations' toggleAnnotationsSelector: '.annotatable-toggle-annotations'
toggleInstructionsSelector: '.annotatable-toggle-instructions' toggleInstructionsSelector: '.annotatable-toggle-instructions'
instructionsSelector: '.annotatable-instructions' instructionsSelector: '.annotatable-instructions'
sectionSelector: '.annotatable-section'
spanSelector: '.annotatable-span' spanSelector: '.annotatable-span'
replySelector: '.annotatable-reply' replySelector: '.annotatable-reply'
...@@ -109,12 +110,13 @@ class @Annotatable ...@@ -109,12 +110,13 @@ class @Annotatable
toggleInstructions: () -> toggleInstructions: () ->
hide = (@instructionsHidden = not @instructionsHidden) hide = (@instructionsHidden = not @instructionsHidden)
@toggleInstructionsButtonText hide @toggleInstructionsButton hide
@toggleInstructionsText hide @toggleInstructionsText hide
toggleInstructionsButtonText: (hide) -> toggleInstructionsButton: (hide) ->
buttonText = (if hide then 'Show' else 'Hide')+' Instructions' txt = (if hide then 'Expand' else 'Collapse')+' Instructions'
@$(@toggleInstructionsSelector).text(buttonText) cls = (if hide then ['expanded', 'collapsed'] else ['collapsed','expanded'])
@$(@toggleInstructionsSelector).text(txt).removeClass(cls[0]).addClass(cls[1])
toggleInstructionsText: (hide) -> toggleInstructionsText: (hide) ->
@$(@instructionsSelector)[if hide then 'slideUp' else 'slideDown']() @$(@instructionsSelector)[if hide then 'slideUp' else 'slideDown']()
......
"""Module annotatable tests"""
import unittest
from xmodule import annotatable
class AnnotatableModuleTestCase(unittest.TestCase):
<div class="annotatable-wrapper" data-discussion-id="${discussion_id}"> <div class="annotatable-wrapper">
<div class="annotatable-header"> <div class="annotatable-header">
% if display_name is not UNDEFINED and display_name is not None: % if display_name is not UNDEFINED and display_name is not None:
<div class="annotatable-title">${display_name}</div> <div class="annotatable-title">${display_name}</div>
...@@ -6,16 +6,21 @@ ...@@ -6,16 +6,21 @@
</div> </div>
% if instructions_html is not UNDEFINED and instructions_html is not None: % if instructions_html is not UNDEFINED and instructions_html is not None:
<div class="annotatable-description"> <div class="annotatable-section">
Instructions <div class="annotatable-section-title">
<a class="annotatable-toggle annotatable-toggle-instructions" href="javascript:void(0)">Hide Instructions</a> Instructions
<a class="annotatable-toggle annotatable-toggle-instructions expanded" href="javascript:void(0)">Collapse Instructions</a>
</div>
<div class="annotatable-section-body annotatable-instructions">
${instructions_html}
</div>
</div> </div>
<div class="annotatable-instructions">${instructions_html}</div>
% endif % endif
<div class="annotatable-description"> <div class="annotatable-section">
Guided Discussion Guided Discussion
<a class="annotatable-toggle annotatable-toggle-annotations" href="javascript:void(0)">Hide Annotations</a> <a class="annotatable-toggle annotatable-toggle-annotations" href="javascript:void(0)">Hide Annotations</a>
</div> </div>
<div class="annotatable-content">${content_html}</div> <div class="annotatable-content">${content_html}</div>
</div> </div>
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