Commit dcf0840b by Tim Krones

Address review comments.

parent 9e6e0011
...@@ -135,6 +135,10 @@ class TestVectorDraw(StudioEditableBaseTest): ...@@ -135,6 +135,10 @@ class TestVectorDraw(StudioEditableBaseTest):
# Slope # Slope
vector_slope = vector_properties.find_element_by_css_selector(".vector-prop-slope") vector_slope = vector_properties.find_element_by_css_selector(".vector-prop-slope")
self.assertFalse(vector_slope.is_displayed()) self.assertFalse(vector_slope.is_displayed())
# "Update" button
update_button = vector_properties.find_element_by_css_selector('button.update')
update_button_disabled = update_button.get_attribute('disabled')
self.assertEquals(bool(update_button_disabled), input_fields_disabled)
else: else:
self.assert_not_present( self.assert_not_present(
menu, menu,
......
...@@ -127,6 +127,16 @@ ...@@ -127,6 +127,16 @@
color: #ff0000; color: #ff0000;
} }
.vectordraw_block .menu .vector-properties .disabled {
border: 1px solid #707070;
background-color: #ececec;
color: #868686;
}
.vectordraw_block .menu .vector-properties .disabled:hover {
background: none;
}
.vectordraw_block .action button { .vectordraw_block .action button {
height: 40px; height: 40px;
margin-right: 10px; margin-right: 10px;
......
...@@ -34,6 +34,16 @@ ...@@ -34,6 +34,16 @@
float: right; float: right;
} }
.vectordraw_edit_block .menu .controls .disabled {
border: 1px solid #707070;
background-color: #ececec;
color: #868686;
}
.vectordraw_edit_block .menu .controls .disabled:hover {
background: none;
}
.vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-name, .vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-name,
.vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-tail, .vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-tail,
.vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-angle { .vectordraw_edit_block .menu .vector-properties .vector-prop-list .row .vector-prop-angle {
......
...@@ -369,17 +369,19 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -369,17 +369,19 @@ function VectorDrawXBlock(runtime, element, init_args) {
} }
// Enable input fields // Enable input fields
$('.vector-properties input').prop('disabled', false); $('.vector-properties input').prop('disabled', false);
// Enable buttons
$('.vector-properties button').removeClass('disabled').prop('disabled', false);
// Hide error message // Hide error message
$('.vector-prop-update .update-error', element).hide(); $('.vector-prop-update .update-error', element).hide();
}; };
VectorDraw.prototype.resetVectorProperties = function(vector) { VectorDraw.prototype.resetVectorProperties = function(vector) {
// Clear current selection // Reset dropdown for selecting vector to default value
this.element.find('.menu .element-list-edit option').attr('selected', false);
// Select default value
$('.menu .element-list-edit option[value="-"]', element).attr('selected', true); $('.menu .element-list-edit option[value="-"]', element).attr('selected', true);
// Reset input fields to default values and disable them // Reset input fields to default values and disable them
$('.menu .vector-prop-list input', element).prop('disabled', true).val(''); $('.menu .vector-prop-list input', element).prop('disabled', true).val('');
// Disable "Update" button
$('.vector-properties button').addClass('disabled').prop('disabled', true);
}; };
VectorDraw.prototype.isVectorTailDraggable = function(vector) { VectorDraw.prototype.isVectorTailDraggable = function(vector) {
......
...@@ -10,6 +10,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -10,6 +10,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
this.resultMode = false; this.resultMode = false;
this.settings = settings; this.settings = settings;
this.numberOfVectors = this.settings.vectors.length; this.numberOfVectors = this.settings.vectors.length;
this.editableProperties = ['name', 'label', 'tail', 'length', 'angle'];
this.checks = [ this.checks = [
'tail', 'tail_x', 'tail_y', 'tip', 'tip_x', 'tip_y', 'coords', 'length', 'angle' 'tail', 'tail_x', 'tail_y', 'tip', 'tip_x', 'tip_y', 'coords', 'length', 'angle'
]; ];
...@@ -212,18 +213,18 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -212,18 +213,18 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
}; };
VectorDraw.prototype.addEditMenuOption = function(vectorName, idx) { VectorDraw.prototype.addEditMenuOption = function(vectorName, idx) {
// 1. Find dropdown for selecting vector to edit // Find dropdown for selecting vector to edit
var editMenu = this.element.find('.menu .element-list-edit'); var editMenu = this.element.find('.menu .element-list-edit');
// 2. Remove current selection(s) // Remove current selection(s)
editMenu.find('option').attr('selected', false); editMenu.find('option').attr('selected', false);
// 3. Create option for newly added vector // Create option for newly added vector
var newOption = $('<option>') var newOption = $('<option>')
.attr('value', 'vector-' + idx) .attr('value', 'vector-' + idx)
.attr('data-vector-name', vectorName) .attr('data-vector-name', vectorName)
.text(vectorName); .text(vectorName);
// 4. Append option to dropdown // Append option to dropdown
editMenu.append(newOption); editMenu.append(newOption);
// 5. Select newly added option // Select newly added option
newOption.attr('selected', true); newOption.attr('selected', true);
}; };
...@@ -231,26 +232,26 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -231,26 +232,26 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
if (!this.wasUsed) { if (!this.wasUsed) {
this.wasUsed = true; this.wasUsed = true;
} }
// 1. Remove selected vector from board // Remove selected vector from board
var vectorName = $('.element-list-edit', element).find('option:selected').data('vector-name'); var vectorName = $('.element-list-edit', element).find('option:selected').data('vector-name');
var boardObject = this.board.elementsByName[vectorName]; var boardObject = this.board.elementsByName[vectorName];
this.board.removeAncestors(boardObject); this.board.removeAncestors(boardObject);
// 2. Mark vector as "deleted" so it will be removed from "vectors" field on save // Mark vector as "deleted" so it will be removed from "vectors" field on save
var vectorSettings = this.getVectorSettingsByName(String(vectorName)); var vectorSettings = this.getVectorSettingsByName(String(vectorName));
vectorSettings.deleted = true; vectorSettings.deleted = true;
// 3. Remove entry that corresponds to selected vector from menu for selecting vector to edit // Remove entry that corresponds to selected vector from menu for selecting vector to edit
var idx = _.indexOf(this.settings.vectors, vectorSettings), var idx = _.indexOf(this.settings.vectors, vectorSettings),
editOption = this.getEditMenuOption("vector", idx); editOption = this.getEditMenuOption("vector", idx);
editOption.remove(); editOption.remove();
// 4. Discard information about expected position (if any) // Discard information about expected position (if any)
delete this.settings.expected_result_positions[vectorName]; delete this.settings.expected_result_positions[vectorName];
// 5. Discard information about expected result (if any) // Discard information about expected result (if any)
delete this.settings.expected_result[vectorName]; delete this.settings.expected_result[vectorName];
// 6. Reset input fields for vector properties to default values // Reset input fields for vector properties to default values
this.resetVectorProperties(); this.resetVectorProperties();
// 7. Reset selected vector // Reset selected vector
this.selectedVector = null; this.selectedVector = null;
// 8. Hide message about pending changes // Hide message about pending changes
$('.vector-prop-update .update-pending', element).hide(); $('.vector-prop-update .update-pending', element).hide();
}; };
...@@ -265,7 +266,6 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -265,7 +266,6 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
// Update vector positions using positions from expected result // Update vector positions using positions from expected result
var expectedResultPositions = this.settings.expected_result_positions; var expectedResultPositions = this.settings.expected_result_positions;
if (!_.isEmpty(expectedResultPositions)) { if (!_.isEmpty(expectedResultPositions)) {
// Loop over vectors and update their positions based on expected result positions
_.each(this.settings.vectors, function(vec) { _.each(this.settings.vectors, function(vec) {
var vectorName = vec.name, var vectorName = vec.name,
resultPosition = expectedResultPositions[vectorName]; resultPosition = expectedResultPositions[vectorName];
...@@ -279,27 +279,26 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -279,27 +279,26 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
}, this); }, this);
this.board.update(); this.board.update();
} }
// Hide or disable operations that are specific to defining initial state // Hide or disable buttons for operations that are specific to defining initial state
$(evt.currentTarget).prop('disabled', true); $(evt.currentTarget).addClass('disabled').prop('disabled', true);
$('.add-vector', element).css('visibility', 'hidden'); $('.add-vector', element).css('visibility', 'hidden');
$('.vector-prop-name input', element).prop('disabled', true);
$('.vector-prop-label input', element).prop('disabled', true);
$('.vector-remove button').hide(); $('.vector-remove button').hide();
// Reset vector properties to ensure a clean slate // Reset vector properties to ensure a clean slate
this.resetVectorProperties(); this.resetVectorProperties();
// Show controls for opting in and out of checks // Show controls for opting in and out of checks
$('.checks', element).show(); $('.checks', element).show();
// Disable input fields that users should not be able to interact with unless a vector is selected
_.each(['tail', 'length', 'angle'], function(propName) {
$('.vector-prop-' + propName + ' input', element).prop('disabled', true);
});
}; };
VectorDraw.prototype.resetVectorProperties = function(vector) { VectorDraw.prototype.resetVectorProperties = function(vector) {
// Select default value // Reset dropdown for selecting vector to default value
$('.menu .element-list-edit option[value="-"]', element).attr('selected', true); $('.element-list-edit option[value="-"]', element).attr('selected', true);
// Reset input fields to default values // Reset input fields and disable them
$('.menu .vector-prop-list input', element).val(''); // (users should not be able to interact with them unless a vector is selected)
_.each(this.editableProperties, function(propName) {
$('.vector-prop-' + propName + ' input', element).prop('disabled', true).val('');
});
// Disable buttons
$('.vector-properties button').addClass('disabled').prop('disabled', true);
}; };
VectorDraw.prototype.getMouseCoords = function(evt) { VectorDraw.prototype.getMouseCoords = function(evt) {
...@@ -372,6 +371,8 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -372,6 +371,8 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
} }
// Enable input fields // Enable input fields
$('.vector-properties input').prop('disabled', false); $('.vector-properties input').prop('disabled', false);
// Enable buttons
$('.vector-properties button').removeClass('disabled').prop('disabled', false);
}; };
VectorDraw.prototype.updateChecks = function(vector) { VectorDraw.prototype.updateChecks = function(vector) {
...@@ -565,10 +566,9 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -565,10 +566,9 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
$('.vector-prop-update .update-pending', element).hide(); $('.vector-prop-update .update-pending', element).hide();
// Get name of vector that is currently "selected" // Get name of vector that is currently "selected"
var vectorName = String($('.element-list-edit', element).find('option:selected').data('vector-name')), var vectorName = String($('.element-list-edit', element).find('option:selected').data('vector-name')),
editableProperties = ['name', 'label', 'tail', 'length', 'angle'],
newValues = {}; newValues = {};
// Get values from input fields // Get values from input fields
_.each(editableProperties, function(prop) { _.each(this.editableProperties, function(prop) {
newValues[prop] = $.trim($('.vector-prop-' + prop + ' input', element).val()); newValues[prop] = $.trim($('.vector-prop-' + prop + ' input', element).val());
}); });
// Process values // Process values
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="vector-prop vector-prop-update"> <div class="vector-prop vector-prop-update">
<button class="update"> <button class="update disabled" disabled="disabled">
<span class="update-label" aria-hidden="true">{% trans "Update" %}</span> <span class="update-label" aria-hidden="true">{% trans "Update" %}</span>
<span class="sr">{% trans "Update properties of selected element" %}</span> <span class="sr">{% trans "Update properties of selected element" %}</span>
</button> </button>
......
...@@ -200,17 +200,17 @@ ...@@ -200,17 +200,17 @@
</div> </div>
<div class="row"> <div class="row">
<div class="vector-prop vector-prop-update"> <div class="vector-prop vector-prop-update">
<button class="update"> <button class="update disabled" disabled="disabled">
<span class="update-label" aria-hidden="true">{% trans "Update" %}</span> <span class="update-label" aria-hidden="true">{% trans "Update" %}</span>
<span class="sr">{% trans "Update properties of selected element" %}</span> <span class="sr">{% trans "Update properties of selected element" %}</span>
</button> </button>
<span class="update-pending"> <span class="update-pending">
{% trans "Pending changes." %} {% trans "Unsaved changes." %}
</span> </span>
<span class="update-error">{% trans "Invalid input." %}</span> <span class="update-error">{% trans "Invalid input." %}</span>
</div> </div>
<div class="vector-prop vector-remove"> <div class="vector-prop vector-remove">
<button class="remove"> <button class="remove disabled" disabled="disabled">
<span class="remove-label" aria-hidden="true">{% trans "Remove" %}</span> <span class="remove-label" aria-hidden="true">{% trans "Remove" %}</span>
<span class="sr">{% trans "Remove selected element" %}</span> <span class="sr">{% trans "Remove selected element" %}</span>
</button> </button>
......
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