mirror of
https://github.com/moodle/moodle.git
synced 2025-04-06 00:42:44 +02:00
MDL-77323 question: Prevent drag item sent into two drop zone
This commit is contained in:
parent
3312a6814a
commit
d07d010288
2
question/type/ddwtos/amd/build/ddwtos.min.js
vendored
2
question/type/ddwtos/amd/build/ddwtos.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -305,7 +305,7 @@ define([
|
||||
*/
|
||||
DragDropToTextQuestion.prototype.dragMove = function(pageX, pageY, drag) {
|
||||
var thisQ = this;
|
||||
this.getRoot().find('span.drop.group' + this.getGroup(drag)).each(function(i, dropNode) {
|
||||
this.getRoot().find('span.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, dropNode) {
|
||||
var drop = $(dropNode);
|
||||
if (thisQ.isPointInDrop(pageX, pageY, drop)) {
|
||||
drop.addClass('valid-drag-over-drop');
|
||||
@ -313,14 +313,6 @@ define([
|
||||
drop.removeClass('valid-drag-over-drop');
|
||||
}
|
||||
});
|
||||
this.getRoot().find('span.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, dropNode) {
|
||||
var drop = $(dropNode);
|
||||
if (thisQ.isPointInDrop(pageX, pageY, drop) && !thisQ.isDragSameAsDrop(drag, drop)) {
|
||||
drop.addClass('valid-drag-over-drop');
|
||||
} else {
|
||||
drop.removeClass('valid-drag-over-drop');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -334,36 +326,31 @@ define([
|
||||
var thisQ = this,
|
||||
root = this.getRoot(),
|
||||
placed = false;
|
||||
root.find('span.drop.group' + this.getGroup(drag)).each(function(i, dropNode) {
|
||||
var drop = $(dropNode);
|
||||
if (!thisQ.isPointInDrop(pageX, pageY, drop)) {
|
||||
// Not this drop.
|
||||
root.find('span.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, dropNode) {
|
||||
if (placed) {
|
||||
return false;
|
||||
}
|
||||
const dropZone = $(dropNode);
|
||||
if (!thisQ.isPointInDrop(pageX, pageY, dropZone)) {
|
||||
// Not this drop zone.
|
||||
return true;
|
||||
}
|
||||
|
||||
let drop = null;
|
||||
if (dropZone.hasClass('placed')) {
|
||||
// This is an placed drag item in a drop.
|
||||
dropZone.removeClass('valid-drag-over-drop');
|
||||
// Get the correct drop.
|
||||
drop = thisQ.getDrop(drag, thisQ.getClassnameNumericSuffix(dropZone, 'inplace'));
|
||||
} else {
|
||||
// Empty drop.
|
||||
drop = dropZone;
|
||||
}
|
||||
// Now put this drag into the drop.
|
||||
drop.removeClass('valid-drag-over-drop');
|
||||
thisQ.sendDragToDrop(drag, drop);
|
||||
placed = true;
|
||||
return false; // Stop the each() here.
|
||||
});
|
||||
|
||||
root.find('span.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, placedNode) {
|
||||
var placedDrag = $(placedNode);
|
||||
if (!thisQ.isPointInDrop(pageX, pageY, placedDrag) || thisQ.isDragSameAsDrop(drag, placedDrag)) {
|
||||
// Not this placed drag.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now put this drag into the drop.
|
||||
placedDrag.removeClass('valid-drag-over-drop');
|
||||
var currentPlace = thisQ.getClassnameNumericSuffix(placedDrag, 'inplace');
|
||||
var drop = thisQ.getDrop(drag, currentPlace);
|
||||
thisQ.sendDragToDrop(drag, drop);
|
||||
placed = true;
|
||||
return false; // Stop the each() here.
|
||||
});
|
||||
|
||||
if (!placed) {
|
||||
this.sendDragHome(drag);
|
||||
}
|
||||
@ -769,17 +756,6 @@ define([
|
||||
return this.getRoot().find('.drop.group' + this.getGroup(drag) + '.place' + currentPlace);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check that the drag is drop to it's clone.
|
||||
*
|
||||
* @param {jQuery} drag The drag.
|
||||
* @param {jQuery} drop The drop.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
DragDropToTextQuestion.prototype.isDragSameAsDrop = function(drag, drop) {
|
||||
return this.getChoice(drag) === this.getChoice(drop) && this.getGroup(drag) === this.getGroup(drop);
|
||||
};
|
||||
|
||||
/**
|
||||
* Singleton that tracks all the DragDropToTextQuestions on this page, and deals
|
||||
* with event dispatching.
|
||||
|
@ -47,13 +47,22 @@ class behat_qtype_ddwtos extends behat_base {
|
||||
|
||||
/**
|
||||
* Get the xpath for a given drop box.
|
||||
* @param string $dragitem the number of the drop box.
|
||||
* @param string $spacenumber the number of the drop box.
|
||||
* @return string the xpath expression.
|
||||
*/
|
||||
protected function drop_xpath($spacenumber) {
|
||||
return '//span[contains(@class, " drop ") and contains(@class, "place' . $spacenumber . ' ")]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the xpath for a given drop box contain a placed drag.
|
||||
* @param string $placeddragnumber the number of the placed drag.
|
||||
* @return string the xpath expression.
|
||||
*/
|
||||
protected function inplace_xpath(string $placeddragnumber): string {
|
||||
return '//span[contains(@class, "inplace' . $placeddragnumber . '")]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag the drag item with the given text to the given space.
|
||||
*
|
||||
@ -68,6 +77,21 @@ class behat_qtype_ddwtos extends behat_base {
|
||||
'xpath_element', $this->drop_xpath($spacenumber), 'xpath_element');
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag the drag item with the given text to the given placed drag number.
|
||||
*
|
||||
* @param string $dragitem the text of the item to drag.
|
||||
* @param int $placeddragnumber the number of the placed drag to drop into.
|
||||
*
|
||||
* @Given /^I drag "(?P<drag_item>[^"]*)" to placed drag "(?P<number>\d+)" in the drag and drop into text question$/
|
||||
*/
|
||||
public function i_drag_to_placed_drag_number_in_the_drag_and_drop_into_text_question(string $dragitem,
|
||||
int $placeddragnumber): void {
|
||||
$generalcontext = behat_context_helper::get('behat_general');
|
||||
$generalcontext->i_drag_and_i_drop_it_in($this->drag_xpath($dragitem),
|
||||
'xpath_element', $this->inplace_xpath($placeddragnumber), 'xpath_element');
|
||||
}
|
||||
|
||||
/**
|
||||
* Type some characters while focussed on a given space.
|
||||
*
|
||||
|
@ -25,9 +25,15 @@ Feature: Preview a drag-drop into text question
|
||||
@javascript @_bug_phantomjs
|
||||
Scenario: Preview a question using the mouse.
|
||||
When I am on the "Drag to text" "core_question > preview" page logged in as teacher
|
||||
And I should see "quick" in the home area of drag and drop into text question
|
||||
And I should see "slow" in the home area of drag and drop into text question
|
||||
And I drag "quick" to space "1" in the drag and drop into text question
|
||||
And I drag "fox" to space "2" in the drag and drop into text question
|
||||
And I drag "assiduous" to space "3" in the drag and drop into text question
|
||||
And I drag "slow" to placed drag "1" in the drag and drop into text question
|
||||
And I should see "quick" in the home area of drag and drop into text question
|
||||
And I drag "quick" to placed drag "1" in the drag and drop into text question
|
||||
And I should see "slow" in the home area of drag and drop into text question
|
||||
And I press "Submit and finish"
|
||||
Then the state of "The" question is shown as "Partially correct"
|
||||
And I should see "Mark 0.67 out of 1.00"
|
||||
|
Loading…
x
Reference in New Issue
Block a user