Commit 3f47c54b by Xavier Antoviaque

Show missing dependency warning through JS to avoid refresh flickering

parent ea944a50
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
background-color: #FEEFB3; background-color: #FEEFB3;
} }
.mentoring .missing-dependency.warning {
display: none;
}
.mentoring .bold { .mentoring .bold {
font-weight: bold; font-weight: bold;
} }
......
...@@ -6,6 +6,15 @@ function MentoringBlock(runtime, element) { ...@@ -6,6 +6,15 @@ function MentoringBlock(runtime, element) {
$('.indicator', element).html(progressTemplate(data)); $('.indicator', element).html(progressTemplate(data));
} }
function renderDependency() {
var warning_dom = $('.missing-dependency', element),
data = warning_dom.data();
if (data.missing === 'True') {
warning_dom.show();
}
}
function callIfExists(obj, fn) { function callIfExists(obj, fn) {
if (typeof obj !== 'undefined' && typeof obj[fn] == 'function') { if (typeof obj !== 'undefined' && typeof obj[fn] == 'function') {
return obj[fn].apply(obj, Array.prototype.slice.call(arguments, 2)); return obj[fn].apply(obj, Array.prototype.slice.call(arguments, 2));
...@@ -59,7 +68,9 @@ function MentoringBlock(runtime, element) { ...@@ -59,7 +68,9 @@ function MentoringBlock(runtime, element) {
} }
function initXBlock() { function initXBlock() {
$(element).find('.submit').bind('click', function() { var submit_dom = $(element).find('.submit');
submit_dom.bind('click', function() {
var data = {}; var data = {};
var children = getChildren(element); var children = getChildren(element);
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
...@@ -72,7 +83,11 @@ function MentoringBlock(runtime, element) { ...@@ -72,7 +83,11 @@ function MentoringBlock(runtime, element) {
$.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults); $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults);
}); });
renderProgress(); if (submit_dom.length) {
renderProgress();
}
renderDependency();
} }
function handleRefreshResults(results) { function handleRefreshResults(results) {
......
<div class="mentoring"> <div class="mentoring">
{% if missing_dependency_url %} <div class="missing-dependency warning" data-missing="{{ self.has_missing_dependency }}">
<div class="warning">
You need to complete <a href="{{ missing_dependency_url }}">the following step</a> before You need to complete <a href="{{ missing_dependency_url }}">the following step</a> before
attempting this step. attempting this step.
</div> </div>
{% endif %}
{% for name, c in named_children %} {% for name, c in named_children %}
{{c.body_html|safe}} {{c.body_html|safe}}
{% endfor %} {% endfor %}
......
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