Skip to content

Commit

Permalink
SAK-43061 Add delete column to bulk edit modal in gbng (sakaiproject#…
Browse files Browse the repository at this point in the history
…7926)

Add additional functionality to the bulk edit modal that allows for
multiple items to be deleted. This feature also fixes the toggle all
for release and include columns.

Co-authored-by: kozar <[email protected]>
  • Loading branch information
davidpbauer and jkozar2 authored Apr 16, 2020
1 parent 135f9cb commit 70eb590
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ label.addgradeitem.due.help = Select a date
label.addgradeitem.category = Category
label.addgradeitem.nocategoryassigned = Items not assigned to a category will not count toward the course grade.
label.addgradeitem.toggle.all = Toggle all
label.addgradeitem.delete.toggle.all = Toggle all the items to be deleted.
label.addgradeitem.release = Release item to students?
label.addgradeitem.release.toggle.all = Toggle all the items to be released.
label.addgradeitem.include = Include item in course grade calculations?
Expand Down Expand Up @@ -642,6 +643,7 @@ bulkedit.heading=Bulk Edit Items
bulkedit.column.header.gradebookitem=Gradebook Item
bulkedit.column.header.release=Release to students
bulkedit.column.header.include=Include in course grade calculations
bulkedit.column.header.delete=Delete
bulkedit.update.success = The gradebook items were successfully updated
bulkedit.update.error = Some gradebook items could not be updated. Please try again. If the problem persists, contact your System Administrator.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public GradebookPage() {
this.form.add(this.courseGradeStatisticsWindow);

this.bulkEditItemsWindow = new GbModalWindow("bulkEditItemsWindow");
this.bulkEditItemsWindow.setWidthUnit("%");
this.bulkEditItemsWindow.setInitialWidth(65);
this.bulkEditItemsWindow.setPositionAtTop(true);
this.bulkEditItemsWindow.showUnloadConfirmation(false);
this.form.add(this.bulkEditItemsWindow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
<thead>
<tr>
<th class="col-md-4"><wicket:message key="bulkedit.column.header.gradebookitem" /></th>
<th class="col-md-1"><wicket:message key="bulkedit.column.header.release" /><br/><input type="checkbox" id="releaseToggleAll" onclick="releaseToggleCheckboxes();" wicket:message="aria-label:label.addgradeitem.release.toggle.all"> <span wicket:id="toggleAllLabel">Toggle All</span></th>
<th class="col-md-1"><wicket:message key="bulkedit.column.header.include" /><br/><input type="checkbox" id="includeToggleAll" onclick="includeToggleCheckboxes();" wicket:message="aria-label:label.addgradeitem.include.toggle.all"> <span wicket:id="toggleAllLabel">Toggle All</span></th>
<th class="col-md-1"><wicket:message key="bulkedit.column.header.release" /><br/><input type="checkbox" id="releaseToggleAll" onchange="releaseToggleCheckboxes();" wicket:message="aria-label:label.addgradeitem.release.toggle.all"> <label for="releaseToggleAll" wicket:id="releaseToggleAllLabel">Toggle All</label></th>
<th class="col-md-1"><wicket:message key="bulkedit.column.header.include" /><br/><input type="checkbox" id="includeToggleAll" onchange="includeToggleCheckboxes();" wicket:message="aria-label:label.addgradeitem.include.toggle.all"> <label for="includeToggleAll" wicket:id="includeToggleAllLabel">Toggle All</label></th>
<th class="col-md-1"><wicket:message key="bulkedit.column.header.delete" /><br/><input type="checkbox" id="deleteToggleAll" onchange="deleteToggleCheckboxes();" wicket:message="aria-label:label.addgradeitem.delete.toggle.all"> <label for="deleteToggleAll" wicket:id="deleteToggleAllLabel">Toggle All</label></th>
</tr>
</thead>
<tbody>
<tr wicket:id="listView">
<td><span wicket:id="itemTitle">item title</span></td>
<td><input wicket:id="release" type="checkbox" wicket:message="aria-label:label.addgradeitem.release" /></td>
<td><input wicket:id="include" type="checkbox" wicket:message="aria-label:label.addgradeitem.include" /></td>
<td><span wicket:id="itemTitle" class="itemTitle" >item title</span></td>
<td><input wicket:id="release" type="checkbox" class="release" wicket:message="aria-label:label.addgradeitem.release" /></td>
<td><input wicket:id="include" type="checkbox" class="include" wicket:message="aria-label:label.addgradeitem.include" /></td>
<td><input wicket:id="delete" type="checkbox" class="deleteBox" wicket:message="aria-label:label.addgradeitem.delete" onclick="disableAndStrikeoutOneRow(this);"/></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.sakaiproject.gradebookng.tool.panels;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -28,6 +29,7 @@
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.util.ListModel;
import org.sakaiproject.gradebookng.tool.component.GbAjaxButton;
Expand All @@ -48,6 +50,16 @@ public class BulkEditItemsPanel extends BasePanel {

private final ModalWindow window;

private List<Long> deletableItemsList = new ArrayList<Long>();

public List<Long> getDeletableItemsList () {
return this.deletableItemsList;
}

public void clearDeletableItemsList () {
this.deletableItemsList.clear();
}

public BulkEditItemsPanel(final String id, final IModel<String> model, final ModalWindow window) {
super(id, model);
this.window = window;
Expand All @@ -67,7 +79,9 @@ public void onInitialize() {
form.add(new GradebookItemView("listView", model.getObject()));
form.add(new SubmitButton("submit"));
form.add(new CancelButton("cancel"));
form.add(new Label("toggleAllLabel", getString("label.addgradeitem.toggle.all")));
form.add(new Label("releaseToggleAllLabel", getString("label.addgradeitem.toggle.all")));
form.add(new Label("includeToggleAllLabel", getString("label.addgradeitem.toggle.all")));
form.add(new Label("deleteToggleAllLabel", getString("label.addgradeitem.toggle.all")));
add(form);

}
Expand All @@ -89,16 +103,30 @@ protected void populateItem(final ListItem<Assignment> item) {

final ReleaseCheckbox release = new ReleaseCheckbox("release", new PropertyModel<Boolean>(assignment, "released"));
final IncludeCheckbox include = new IncludeCheckbox("include", new PropertyModel<Boolean>(assignment, "counted"));
final AjaxCheckBox delete = new AjaxCheckBox("delete", Model.of(Boolean.FALSE)){
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateModel();
if (this.getModel().getObject()) { // if the checkbox has just been checked, this will be True.
BulkEditItemsPanel.this.deletableItemsList.add(item.getModelObject().getId());
} else { // this means the checkbox has been unchecked.
BulkEditItemsPanel.this.deletableItemsList.remove(item.getModelObject().getId());
}
}
};

// Are there categories in this Gradebook? If so, and this item is not in a category, disabled grade
// calculation inclusion.
List<CategoryDefinition> categories = businessService.getGradebookCategories();
if (categories != null && categories.size() > 0 && StringUtils.isBlank(assignment.getCategoryName())) {
include.setEnabled(false);
}

if (assignment.isExternallyMaintained()){ //don't allow External items to be deleted.
delete.setEnabled(false);
}
item.add(release);
item.add(include);
item.add(delete);
}

}
Expand All @@ -114,6 +142,7 @@ public CancelButton(final String id) {

@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
BulkEditItemsPanel.this.clearDeletableItemsList();
BulkEditItemsPanel.this.window.close(target);
}

Expand All @@ -139,7 +168,10 @@ public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
log.debug("Bulk edit assignment: {}", a);
result = BulkEditItemsPanel.this.businessService.updateAssignment(a);
}

for (int count=0; count < BulkEditItemsPanel.this.getDeletableItemsList().size(); count++){
BulkEditItemsPanel.this.businessService.removeAssignment(BulkEditItemsPanel.this.getDeletableItemsList().get(count));
}
BulkEditItemsPanel.this.clearDeletableItemsList();
if (result) {
getSession().success(getString("bulkedit.update.success"));
} else {
Expand Down
36 changes: 30 additions & 6 deletions gradebookng/tool/src/webapp/scripts/gradebook-bulk-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Gradebook Bulk Edit Javascript
*************************************************************************************/
function toggleCheckboxes(checkboxFamily) {
if(document.getElementById(checkboxFamily+'ToggleAll').checked) {
if(document.getElementById(checkboxFamily+'ToggleAll').checked) { //selecting all
$(':checkbox').each(function() {
if(this.name.includes(checkboxFamily)) {
this.checked = true;
if(this.name.includes(checkboxFamily) && !this.checked && !this.disabled) {
this.click();
}
});
} else {
} else { //deselecting all
$(':checkbox').each(function() {
if(this.name.includes(checkboxFamily)) {
this.checked = false;
if(this.name.includes(checkboxFamily) && this.checked && !this.disabled) {
this.click();
}
});
}
Expand All @@ -25,3 +25,27 @@ function includeToggleCheckboxes() {
toggleCheckboxes('include');
}

function deleteToggleCheckboxes() {
toggleCheckboxes('delete');
}

function disableAndStrikeoutOneRow(deleteBox) {
var listRow = deleteBox.parentElement.parentElement;
var releaseBox = listRow.getElementsByClassName('release')[0];
var includeBox = listRow.getElementsByClassName('include')[0];
var titleBox = listRow.getElementsByClassName('itemTitle')[0];
if (deleteBox.checked){
if (includeBox.disabled){ //if Include is already disabled, it's supposed to stay disabled; this appears to be the case for Uncategorized items.
includeBox.setAttribute('class', includeBox.getAttribute('class') + ' stayDisabled'); //fake CSS class to denote that this box should always be disabled
}
releaseBox.disabled = true;
includeBox.disabled = true;
titleBox.setAttribute('style', 'text-decoration: line-through;');
} else {
releaseBox.disabled = false;
if (!includeBox.getAttribute('class').includes('stayDisabled')){ //don't enable ones that are marked as stayDisabled.
includeBox.disabled = false;
}
titleBox.removeAttribute('style');
}
}

0 comments on commit 70eb590

Please sign in to comment.