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) {
"use strict";
var $buttons = $('.add-xblock-component-button[data-category=sb-review-step]', element);
var blockIsPresent = function(klass) {
return $('.xblock ' + klass).length > 0;
};
......@@ -18,21 +20,26 @@ function MentoringWithStepsEdit(runtime, element) {
}
};
var initButtons = function(dataCategory) {
var $buttons = $('.add-xblock-component-button[data-category='+dataCategory+']', element);
$buttons.each(function() {
updateButton($(this), blockIsPresent('.xblock-header-sb-review-step'));
var updateButtons = function(buttons) {
buttons.each(function() {
var button = $(this);
updateButton(button, blockIsPresent('.xblock-header-sb-review-step'));
});
};
var initButtons = function() {
updateButtons($buttons);
$buttons.on('click', disableButton);
};
var updateButtons = function() {
initButtons('sb-review-step');
var resetButtons = function() {
var $disabledButtons = $buttons.filter('.disabled');
updateButtons($disabledButtons);
};
ProblemBuilderUtil.transformClarifications(element);
updateButtons();
runtime.listenTo('deleted-child', updateButtons);
initButtons();
runtime.listenTo('deleted-child', resetButtons);
}
function ReviewStepEdit(runtime, element) {
"use strict";
var $buttons = $('.add-xblock-component-button[data-category=pb-message]', element);
var blockIsPresent = function(klass) {
return $('.xblock ' + klass).length > 0;
};
......@@ -18,22 +20,27 @@ function ReviewStepEdit(runtime, element) {
}
};
var initButtons = function(dataCategory) {
var $buttons = $('.add-xblock-component-button[data-category='+dataCategory+']', element);
$buttons.each(function() {
var msg_type = $(this).data('boilerplate');
updateButton($(this), blockIsPresent('.submission-message.'+msg_type));
var updateButtons = function(buttons) {
buttons.each(function() {
var button = $(this);
var msgType = button.data('boilerplate');
updateButton(button, blockIsPresent('.submission-message.'+msgType));
});
};
var initButtons = function() {
updateButtons($buttons);
$buttons.on('click', disableButton);
};
var updateButtons = function() {
initButtons('pb-message');
var resetButtons = function() {
var $disabledButtons = $buttons.filter('.disabled');
updateButtons($disabledButtons);
};
ProblemBuilderUtil.transformClarifications(element);
updateButtons();
runtime.listenTo('deleted-child', updateButtons);
initButtons();
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