Commit fdbfc077 by Xavier Antoviaque

Merge pull request #21 from aboudreault/mrq-tip-width-height

Removed FeedbackBlock and added width/height in tip child
parents ac8381b0 c449576f
......@@ -139,10 +139,10 @@ You can set the number of maximum attempts for the unit completion:
</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
*height* can be modified. The value of those attribute should be valid CSS.
You can specify `width` and `height` attributes to the `tip` child to customize the popup window
size. The value of those attribute should be valid CSS.
```xml
<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
<question>What do you like in this MRQ?</question>
<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>
</mentoring>
```
......
......@@ -8,4 +8,3 @@ 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,7 +35,6 @@ 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
......@@ -80,7 +79,7 @@ class MentoringBlock(XBlockWithLightChildren):
def student_view(self, context):
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_view',
not_instance_of=(MentoringMessageBlock, FeedbackBlock)
not_instance_of=MentoringMessageBlock
)
fragment.add_content(render_template('templates/html/mentoring.html', {
......
......@@ -10,6 +10,22 @@ function MessageView(element) {
showPopup: function(popupDOM) {
var self = this;
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.on('click', function() {
self.clearPopupEvents();
......
......@@ -30,7 +30,6 @@ 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,8 +79,7 @@ class QuestionnaireAbstractBlock(LightChild):
template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type)
html = render_template(template_path, {
'self': self,
'custom_choices': self.custom_choices,
'feedback': self.get_feedback().render()
'custom_choices': self.custom_choices
})
fragment = Fragment(html)
......@@ -113,22 +111,6 @@ 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,7 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
{{feedback.body_html|safe}}
<div
<div class="feedback"></div>
</div>
</fieldset>
......@@ -35,6 +35,6 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
{{feedback.body_html|safe}}
<div class="feedback"></div>
</div>
</fieldset>
......@@ -17,6 +17,6 @@
<div class="choice-tips"></div>
</div>
{% endfor %}
{{feedback.body_html|safe}}
<div class="feedback"></div>
</div>
</fieldset>
{% if self.content %}<p>{{ self.content }}</p>{% endif %}
{% for name, c in named_children %}
{{c.body_html|safe}}
{% endfor %}
<div
class="tip"
{% if self.width %}data-width="{{self.width}}"{% endif %}
{% 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):
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)
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
def render(self):
......
......@@ -58,8 +58,7 @@ BLOCKS_CHILDREN = [
'message = mentoring:MentoringMessageBlock',
'tip = mentoring:TipBlock',
'choice = mentoring:ChoiceBlock',
'html = mentoring:HTMLBlock',
'feedback = mentoring:FeedbackBlock'
'html = mentoring:HTMLBlock'
]
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