Skip to content

Commit

Permalink
SAK-42766 Changing grade schema deletes categories in Gradebook (saka…
Browse files Browse the repository at this point in the history
  • Loading branch information
josecebe authored Mar 18, 2020
1 parent 34829ec commit 3c23dd1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h3 class="panel-title">
<div><wicket:message key="settingspage.categories.instructions.applydropkeep" /></div>
</div>

<table class="table table-striped table-bordered table-hover">
<table class="table table-striped table-bordered table-hover" id="table-categories">
<thead>
<tr>
<th class="gb-category-sort-column"></th>
Expand Down Expand Up @@ -76,12 +76,12 @@ <h3 class="panel-title">
<td class="gb-category-droplowest"><input wicket:id="categoryDropLowest" type="text" size="5" class="form-control" /></td>
<td class="gb-category-keephighest"><input wicket:id="categoryKeepHighest" type="text" size="5" class="form-control" /></td>
<td class="gb-category-equalweight"><input wicket:id="equalWeight" type="checkbox" class="form-control" /></td>
<td><button wicket:id="remove" class="btn btn-default btn-table"><wicket:message key="button.remove" /></button></td>
<td><button wicket:id="remove" type="button" class="btn btn-default btn-table"><wicket:message key="button.remove" /></button></td>
</tr>
</tbody>
</table>
<div>
<button wicket:id="addCategory" type="submit" class="btn-add-category btn btn-default btn-sm"><wicket:message key="settingspage.categories.add" /></button>
<button wicket:id="addCategory" type="button" class="btn-add-category btn btn-default btn-sm"><wicket:message key="settingspage.categories.add" /></button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h3 class="panel-title">

<!-- schema table -->
<div wicket:id="schemaWrap">
<table class="table table-striped table-bordered table-hover" style="width: auto;">
<table class="table table-striped table-bordered table-hover" style="width: auto;" id="table-grading-schema">
<thead>
<tr>
<th class="col-md-1"><wicket:message key="settingspage.gradingschema.grade" /></th>
Expand All @@ -41,16 +41,16 @@ <h3 class="panel-title">
</tr>
</thead>
<tbody>
<tr wicket:id="schemaView">
<tr wicket:id="schemaView" class="gb-schema-row">
<td><input wicket:id="grade" type="text" size="10" class="form-control" /></td>
<td><input wicket:id="minPercent" type="text" size="10" class="form-control" /></td>
<td><button wicket:id="remove" class="btn btn-default btn-table"><wicket:message key="button.remove" /></button></td>
<td><button wicket:id="remove" type="button" class="btn btn-default btn-table"><wicket:message key="button.remove" /></button></td>
</tr>
</tbody>
</table>

<div>
<button wicket:id="addMapping" type="submit" class="btn-add-category btn btn-default btn-sm"><wicket:message key="settingspage.gradingschema.add" /></button>
<button wicket:id="addMapping" type="button" class="btn-add-mapping btn btn-default btn-sm"><wicket:message key="settingspage.gradingschema.add" /></button>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ protected void onSubmit(final AjaxRequestTarget target, final Form<?> f) {
// repaint table
target.add(SettingsGradingSchemaPanel.this.schemaWrap);

// reinitialize any custom behaviour
target.appendJavaScript("sakai.gradebookng.settings.gradingschemas = new GradebookGradingSchemaSettings($('#settingsGradingSchema'));");
// focus the new grading schema input
target.appendJavaScript("sakai.gradebookng.settings.gradingschemas.focusLastRow();");
// Note that we don't need to worry about showing warnings about modifications here as the change notifications will handle
// that once a value has been added to the schema
}
Expand Down
63 changes: 49 additions & 14 deletions gradebookng/tool/src/webapp/scripts/gradebook-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@
* Gradebook Settings Javascript
*************************************************************************************/

/**************************************************************************************
* A GradebookSettings to encapsulate all the settings page features
*/
function GradebookSettings($container) {
this.$container = $container;

this.categories = new GradebookCategorySettings($container.find("#settingsCategories"));
};


/**************************************************************************************
* A GradebookCategorySettings to encapsulate all the category settings features
*/
function GradebookCategorySettings($container) {
this.$container = $container;
this.$table = this.$container.find("table");
this.$table = this.$container.find("#table-categories");

// only if categories are enabled
if (this.$table.length > 0) {
Expand All @@ -44,7 +34,6 @@ GradebookCategorySettings.prototype.setupSortableCategories = function() {
});
};


GradebookCategorySettings.prototype.setupKeyboardSupport = function() {
var self = this;

Expand Down Expand Up @@ -77,12 +66,58 @@ GradebookCategorySettings.prototype.updateCategoryOrders = function() {
});
};


/**************************************************************************************
* A GradebookGradingSchemaSettings to encapsulate all the grading schema settings features
*/
function GradebookGradingSchemaSettings($container) {
this.$container = $container;
this.$table = this.$container.find("#table-grading-schema");

// only if categories are enabled
if (this.$table.length > 0) {
this.setupKeyboardSupport();
}
}

GradebookGradingSchemaSettings.prototype.setupKeyboardSupport = function() {
var self = this;

self.$table.on("keydown", ":text", function(event) {
// add new row upon return
if (event.keyCode == 13) {
event.preventDefault();
event.stopPropagation();

self.$container.find(".btn-add-mapping").trigger("click");
}
});
}

GradebookGradingSchemaSettings.prototype.focusLastRow = function() {
// get the first input#text in the last row of the table
var $input = this.$table.find(".gb-schema-row:last :text:first");
// attempt to set focus
$input.focus();
// Wicket may try to set focus on the input last focused before form submission
// so set this manually to our desired input
Wicket.Focus.setFocusOnId($input.attr("id"));
}

/**************************************************************************************
* A GradebookSettings to encapsulate all the settings page features
*/
function GradebookSettings($container) {
this.$container = $container;
this.categories = new GradebookCategorySettings($container.find("#settingsCategories"));
this.categories = new GradebookGradingSchemaSettings($container.find("#settingsGradingSchema"));
};

/**************************************************************************************
* Initialise
*/
$(function() {
sakai.gradebookng = {
settings: new GradebookSettings($("#gradebookSettings"))
};

});
});

0 comments on commit 3c23dd1

Please sign in to comment.