Commit c449576f by Alan Boudreault

Removed FeedbackBlock and added width/height in tip child

parent ac8381b0
...@@ -139,10 +139,10 @@ You can set the number of maximum attempts for the unit completion: ...@@ -139,10 +139,10 @@ You can set the number of maximum attempts for the unit completion:
</mentoring> </mentoring>
``` ```
### Custom feedback popup window ### Custom tip popup window size
You can use the `feedback` child to have a custom popup window. Currently, only the *width* and You can specify `width` and `height` attributes to the `tip` child to customize the popup window
*height* can be modified. The value of those attribute should be valid CSS. size. The value of those attribute should be valid CSS.
```xml ```xml
<mentoring url_name="mcq_1" enforce_dependency="false"> <mentoring url_name="mcq_1" enforce_dependency="false">
...@@ -150,7 +150,7 @@ You can use the `feedback` child to have a custom popup window. Currently, only ...@@ -150,7 +150,7 @@ You can use the `feedback` child to have a custom popup window. Currently, only
<question>What do you like in this MRQ?</question> <question>What do you like in this MRQ?</question>
<choice value="elegance">Its elegance</choice> <choice value="elegance">Its elegance</choice>
... ...
<feedback width="100px" height="50px"/> <tip require="elegance" width="50px" height="20px">This is something everyone has to like about this MRQ</tip>
</mrq> </mrq>
</mentoring> </mentoring>
``` ```
......
...@@ -8,4 +8,3 @@ from .mentoring import MentoringBlock ...@@ -8,4 +8,3 @@ 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,7 +35,6 @@ from xblock.fragment import Fragment ...@@ -35,7 +35,6 @@ 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
...@@ -80,7 +79,7 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -80,7 +79,7 @@ class MentoringBlock(XBlockWithLightChildren):
def student_view(self, context): def student_view(self, context):
fragment, named_children = self.get_children_fragment( fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_view', context, view_name='mentoring_view',
not_instance_of=(MentoringMessageBlock, FeedbackBlock) not_instance_of=MentoringMessageBlock
) )
fragment.add_content(render_template('templates/html/mentoring.html', { fragment.add_content(render_template('templates/html/mentoring.html', {
......
...@@ -10,6 +10,22 @@ function MessageView(element) { ...@@ -10,6 +10,22 @@ function MessageView(element) {
showPopup: function(popupDOM) { showPopup: function(popupDOM) {
var self = this; var self = this;
this.clearPopupEvents(); this.clearPopupEvents();
// Set the width/height
var tip = $('.tip', popupDOM)[0];
var data = $(tip).data();
if (data && data.width) {
popupDOM.css('width', data.width)
} else {
popupDOM.css('width', '')
}
if (data && data.height) {
popupDOM.css('height', data.height);
} else {
popupDOM.css('height', '')
}
popupDOM.show(); popupDOM.show();
popupDOM.on('click', function() { popupDOM.on('click', function() {
self.clearPopupEvents(); self.clearPopupEvents();
......
...@@ -30,7 +30,6 @@ from xblock.fragment import Fragment ...@@ -30,7 +30,6 @@ 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,8 +79,7 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -80,8 +79,7 @@ class QuestionnaireAbstractBlock(LightChild):
template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type) template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type)
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)
...@@ -113,22 +111,6 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -113,22 +111,6 @@ 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,7 @@ ...@@ -10,6 +10,7 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
{{feedback.body_html|safe}} <div
<div class="feedback"></div>
</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 %}
{{feedback.body_html|safe}} <div class="feedback"></div>
</div> </div>
</fieldset> </fieldset>
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
{{feedback.body_html|safe}} <div class="feedback"></div>
</div> </div>
</fieldset> </fieldset>
{% if self.content %}<p>{{ self.content }}</p>{% endif %} <div
{% for name, c in named_children %} class="tip"
{{c.body_html|safe}} {% if self.width %}data-width="{{self.width}}"{% endif %}
{% endfor %} {% if self.height %}data-height="{{self.height}}"{% endif %}
>
{% if self.content %}<p>{{ self.content }}</p>{% endif %}
{% for name, c in named_children %}
{{c.body_html|safe}}
{% endfor %}
</div>
...@@ -57,6 +57,8 @@ class TipBlock(LightChild): ...@@ -57,6 +57,8 @@ class TipBlock(LightChild):
display = String(help="List of choices to display the tip for", scope=Scope.content, default=None) display = String(help="List of choices to display the tip for", scope=Scope.content, default=None)
reject = String(help="List of choices to reject", scope=Scope.content, default=None) reject = String(help="List of choices to reject", scope=Scope.content, default=None)
require = String(help="List of choices to require", scope=Scope.content, default=None) require = String(help="List of choices to require", scope=Scope.content, default=None)
width = String(help="Width of the tip popup", scope=Scope.content, default='')
height = String(help="Height of the tip popup", scope=Scope.content, default='')
has_children = True has_children = True
def render(self): def render(self):
......
...@@ -58,8 +58,7 @@ BLOCKS_CHILDREN = [ ...@@ -58,8 +58,7 @@ BLOCKS_CHILDREN = [
'message = mentoring:MentoringMessageBlock', 'message = mentoring:MentoringMessageBlock',
'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