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 ...@@ -8,3 +8,4 @@ from .mentoring import MentoringBlock
from .message import MentoringMessageBlock from .message import MentoringMessageBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock, MentoringTableColumnHeaderBlock from .table import MentoringTableBlock, MentoringTableColumnBlock, MentoringTableColumnHeaderBlock
from .tip import TipBlock 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 ...@@ -35,6 +35,7 @@ from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren from .light_children import XBlockWithLightChildren
from .message import MentoringMessageBlock from .message import MentoringMessageBlock
from .feedback import FeedbackBlock
from .utils import get_scenarios_from_path, load_resource, render_template from .utils import get_scenarios_from_path, load_resource, render_template
...@@ -77,8 +78,10 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -77,8 +78,10 @@ class MentoringBlock(XBlockWithLightChildren):
has_score = True has_score = True
def student_view(self, context): def student_view(self, context):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view', fragment, named_children = self.get_children_fragment(
not_instance_of=MentoringMessageBlock) context, view_name='mentoring_view',
not_instance_of=(MentoringMessageBlock, FeedbackBlock)
)
fragment.add_content(render_template('templates/html/mentoring.html', { fragment.add_content(render_template('templates/html/mentoring.html', {
'self': self, 'self': self,
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
} }
.mentoring .questionnaire .choice-tips, .mentoring .questionnaire .choice-tips,
.mentoring .questionnaire .choice-message { .mentoring .questionnaire .feedback {
display: none; display: none;
color: #fff; color: #fff;
position: absolute; position: absolute;
...@@ -54,13 +54,13 @@ ...@@ -54,13 +54,13 @@
} }
.mentoring .questionnaire .choice-tips .tip-choice-group, .mentoring .questionnaire .choice-tips .tip-choice-group,
.mentoring .questionnaire .choice-message .tip-choice-group, .mentoring .questionnaire .feedback .tip-choice-group,
.mentoring .questionnaire .choice-message .message-content { .mentoring .questionnaire .feedback .message-content {
position: relative; position: relative;
} }
.mentoring .questionnaire .choice-tips .close, .mentoring .questionnaire .choice-tips .close,
.mentoring .questionnaire .choice-message .close { .mentoring .questionnaire .feedback .close {
background-image: url({{ close_icon_url }}); background-image: url({{ close_icon_url }});
cursor: pointer; cursor: pointer;
position: absolute; position: absolute;
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
} }
.mentoring .questionnaire .choice-tips p, .mentoring .questionnaire .choice-tips p,
.mentoring .questionnaire .choice-message p { .mentoring .questionnaire .feedback p {
color: #fff; color: #fff;
} }
......
// TODO: Split in two files // TODO: Split in two files
function MessageView(element) { function MessageView(element) {
return { return {
messageDOM: $('.choice-message', element), messageDOM: $('.feedback', element),
allPopupsDOM: $('.choice-tips, .choice-message', element), allPopupsDOM: $('.choice-tips, .feedback', element),
clearPopupEvents: function() { clearPopupEvents: function() {
this.allPopupsDOM.hide(); this.allPopupsDOM.hide();
$('.close', this.allPopupsDOM).off('click'); $('.close', this.allPopupsDOM).off('click');
......
...@@ -30,6 +30,7 @@ from xblock.fragment import Fragment ...@@ -30,6 +30,7 @@ from xblock.fragment import Fragment
from .choice import ChoiceBlock from .choice import ChoiceBlock
from .light_children import LightChild, Scope, String from .light_children import LightChild, Scope, String
from .tip import TipBlock from .tip import TipBlock
from .feedback import FeedbackBlock
from .utils import render_template from .utils import render_template
...@@ -80,6 +81,7 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -80,6 +81,7 @@ class QuestionnaireAbstractBlock(LightChild):
html = render_template(template_path, { html = render_template(template_path, {
'self': self, 'self': self,
'custom_choices': self.custom_choices, 'custom_choices': self.custom_choices,
'feedback': self.get_feedback().render()
}) })
fragment = Fragment(html) fragment = Fragment(html)
...@@ -111,6 +113,22 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -111,6 +113,22 @@ class QuestionnaireAbstractBlock(LightChild):
tips.append(child) tips.append(child)
return tips 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): def get_submission_display(self, submission):
""" """
Get the human-readable version of a submission value 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 @@ ...@@ -10,6 +10,6 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
<div class="choice-message"></div> {{feedback.body_html|safe}}
</div> </div>
</fieldset> </fieldset>
...@@ -35,6 +35,6 @@ ...@@ -35,6 +35,6 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
<div class="choice-message"></div> {{feedback.body_html|safe}}
</div> </div>
</fieldset> </fieldset>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
<div class="choice-message"></div> {{feedback.body_html|safe}}
</div> </div>
</fieldset> </fieldset>
<div class="show-answer"> <div class="show-answer">
......
...@@ -59,6 +59,7 @@ BLOCKS_CHILDREN = [ ...@@ -59,6 +59,7 @@ BLOCKS_CHILDREN = [
'tip = mentoring:TipBlock', 'tip = mentoring:TipBlock',
'choice = mentoring:ChoiceBlock', 'choice = mentoring:ChoiceBlock',
'html = mentoring:HTMLBlock', 'html = mentoring:HTMLBlock',
'feedback = mentoring:FeedbackBlock'
] ]
setup( 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