Commit 1a76c1b0 by Alan Boudreault

Added FeedbackBlock to get a more flexible control of the popup window.

parent 5da686d1
......@@ -8,3 +8,4 @@ from .mentoring import MentoringBlock
from .message import MentoringMessageBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock, MentoringTableColumnHeaderBlock
from .tip import TipBlock
from .feedback import FeedbackBlock
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Harvard
#
# Authors:
# Alan Boudreault <alan@alanb.ca>
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
# Imports ###########################################################
import logging
from .light_children import LightChild, Scope, String
from .utils import render_template
# Globals ###########################################################
log = logging.getLogger(__name__)
# Classes ###########################################################
class FeedbackBlock(LightChild):
"""
Represent a feedback block. Currently only used to set the width/heigth style but could be
useful to set a static header/body etc.
"""
width = String(help="Width of the feedback popup", scope=Scope.content, default='')
height = String(help="Height of the feedback popup", scope=Scope.content, default='')
def render(self):
"""
Returns a fragment containing the formatted feedback
"""
fragment, named_children = self.get_children_fragment({})
fragment.add_content(render_template('templates/html/feedback.html', {
'self': self,
'named_children': named_children,
}))
return self.xblock_container.fragment_text_rewriting(fragment)
......@@ -35,6 +35,7 @@ from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren
from .message import MentoringMessageBlock
from .feedback import FeedbackBlock
from .utils import get_scenarios_from_path, load_resource, render_template
......@@ -77,8 +78,10 @@ class MentoringBlock(XBlockWithLightChildren):
has_score = True
def student_view(self, context):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view',
not_instance_of=MentoringMessageBlock)
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_view',
not_instance_of=(MentoringMessageBlock, FeedbackBlock)
)
fragment.add_content(render_template('templates/html/mentoring.html', {
'self': self,
......
......@@ -32,7 +32,7 @@
}
.mentoring .questionnaire .choice-tips,
.mentoring .questionnaire .choice-message {
.mentoring .questionnaire .feedback {
display: none;
color: #fff;
position: absolute;
......@@ -54,13 +54,13 @@
}
.mentoring .questionnaire .choice-tips .tip-choice-group,
.mentoring .questionnaire .choice-message .tip-choice-group,
.mentoring .questionnaire .choice-message .message-content {
.mentoring .questionnaire .feedback .tip-choice-group,
.mentoring .questionnaire .feedback .message-content {
position: relative;
}
.mentoring .questionnaire .choice-tips .close,
.mentoring .questionnaire .choice-message .close {
.mentoring .questionnaire .feedback .close {
background-image: url({{ close_icon_url }});
cursor: pointer;
position: absolute;
......@@ -71,7 +71,7 @@
}
.mentoring .questionnaire .choice-tips p,
.mentoring .questionnaire .choice-message p {
.mentoring .questionnaire .feedback p {
color: #fff;
}
......
// TODO: Split in two files
function MessageView(element) {
return {
messageDOM: $('.choice-message', element),
allPopupsDOM: $('.choice-tips, .choice-message', element),
messageDOM: $('.feedback', element),
allPopupsDOM: $('.choice-tips, .feedback', element),
clearPopupEvents: function() {
this.allPopupsDOM.hide();
$('.close', this.allPopupsDOM).off('click');
......
......@@ -30,6 +30,7 @@ from xblock.fragment import Fragment
from .choice import ChoiceBlock
from .light_children import LightChild, Scope, String
from .tip import TipBlock
from .feedback import FeedbackBlock
from .utils import render_template
......@@ -80,6 +81,7 @@ class QuestionnaireAbstractBlock(LightChild):
html = render_template(template_path, {
'self': self,
'custom_choices': self.custom_choices,
'feedback': self.get_feedback().render()
})
fragment = Fragment(html)
......@@ -111,6 +113,22 @@ class QuestionnaireAbstractBlock(LightChild):
tips.append(child)
return tips
def get_feedback(self):
"""
Returns the feedback child in this block. If there is no feedback block, provide a default one.
"""
feedback = None
for child in self.get_children_objects():
if isinstance(child, FeedbackBlock):
feedback = child
break
if feedback is None:
feedback = FeedbackBlock(self)
feedback.init_block_from_node(feedback,[],{})
return feedback
def get_submission_display(self, submission):
"""
Get the human-readable version of a submission value
......
<div
class="feedback"
style="{% if self.width %}width:{{self.width}};{% endif %}{% if self.height %}height:{{self.height}};{% endif %}"
>
</div>
......@@ -10,6 +10,6 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
<div class="choice-message"></div>
{{feedback.body_html|safe}}
</div>
</fieldset>
......@@ -35,6 +35,6 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
<div class="choice-message"></div>
{{feedback.body_html|safe}}
</div>
</fieldset>
......@@ -18,7 +18,7 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
<div class="choice-message"></div>
{{feedback.body_html|safe}}
</div>
</fieldset>
<div class="show-answer">
......
......@@ -59,6 +59,7 @@ BLOCKS_CHILDREN = [
'tip = mentoring:TipBlock',
'choice = mentoring:ChoiceBlock',
'html = mentoring:HTMLBlock',
'feedback = mentoring:FeedbackBlock'
]
setup(
......
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