Commit 1ce056f7 by Tim Krones

Fix: Make sure clicking buttons causes corresponding child to be added

after deleting child that can only be added once.

This is a follow-up to the previous commit. It is now possible to add
and remove children ad infinitum, irrespective of whether the parent
block allows single or multiple copies of them.
parent 6ae2e891
function MentoringWithStepsEdit(runtime, element) { function MentoringWithStepsEdit(runtime, element) {
"use strict"; "use strict";
var $buttons = $('.add-xblock-component-button[data-category=sb-review-step]', element);
var blockIsPresent = function(klass) { var blockIsPresent = function(klass) {
return $('.xblock ' + klass).length > 0; return $('.xblock ' + klass).length > 0;
}; };
...@@ -18,21 +20,26 @@ function MentoringWithStepsEdit(runtime, element) { ...@@ -18,21 +20,26 @@ function MentoringWithStepsEdit(runtime, element) {
} }
}; };
var initButtons = function(dataCategory) { var updateButtons = function(buttons) {
var $buttons = $('.add-xblock-component-button[data-category='+dataCategory+']', element); buttons.each(function() {
$buttons.each(function() { var button = $(this);
updateButton($(this), blockIsPresent('.xblock-header-sb-review-step')); updateButton(button, blockIsPresent('.xblock-header-sb-review-step'));
}); });
};
var initButtons = function() {
updateButtons($buttons);
$buttons.on('click', disableButton); $buttons.on('click', disableButton);
}; };
var updateButtons = function() { var resetButtons = function() {
initButtons('sb-review-step'); var $disabledButtons = $buttons.filter('.disabled');
updateButtons($disabledButtons);
}; };
ProblemBuilderUtil.transformClarifications(element); ProblemBuilderUtil.transformClarifications(element);
updateButtons(); initButtons();
runtime.listenTo('deleted-child', updateButtons); runtime.listenTo('deleted-child', resetButtons);
} }
function ReviewStepEdit(runtime, element) { function ReviewStepEdit(runtime, element) {
"use strict"; "use strict";
var $buttons = $('.add-xblock-component-button[data-category=pb-message]', element);
var blockIsPresent = function(klass) { var blockIsPresent = function(klass) {
return $('.xblock ' + klass).length > 0; return $('.xblock ' + klass).length > 0;
}; };
...@@ -18,22 +20,27 @@ function ReviewStepEdit(runtime, element) { ...@@ -18,22 +20,27 @@ function ReviewStepEdit(runtime, element) {
} }
}; };
var initButtons = function(dataCategory) { var updateButtons = function(buttons) {
var $buttons = $('.add-xblock-component-button[data-category='+dataCategory+']', element); buttons.each(function() {
$buttons.each(function() { var button = $(this);
var msg_type = $(this).data('boilerplate'); var msgType = button.data('boilerplate');
updateButton($(this), blockIsPresent('.submission-message.'+msg_type)); updateButton(button, blockIsPresent('.submission-message.'+msgType));
}); });
};
var initButtons = function() {
updateButtons($buttons);
$buttons.on('click', disableButton); $buttons.on('click', disableButton);
}; };
var updateButtons = function() { var resetButtons = function() {
initButtons('pb-message'); var $disabledButtons = $buttons.filter('.disabled');
updateButtons($disabledButtons);
}; };
ProblemBuilderUtil.transformClarifications(element); ProblemBuilderUtil.transformClarifications(element);
updateButtons(); initButtons();
runtime.listenTo('deleted-child', updateButtons); runtime.listenTo('deleted-child', resetButtons);
} }
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