Skip to content

Commit

Permalink
#1367 Add validation to the course grade options so that the instruct…
Browse files Browse the repository at this point in the history
…or must select at least one option
  • Loading branch information
steveswinsburg committed Feb 16, 2016
1 parent 3015b84 commit 11824bd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ settingspage.displaycoursegrade.preview-percentage-first = 88%
settingspage.displaycoursegrade.preview-percentage-second = (88%)
settingspage.displaycoursegrade.preview-points-first = 176/200
settingspage.displaycoursegrade.preview-points-second = [176/200]
settingspage.displaycoursegrade.instructions = Choose the options for formatting the course grade. You must choose at least one option.
settingspage.displaycoursegrade.notenough = Display course grade is selected but you didn't select any formatting options.

settingspage.categories.none = No categories
settingspage.categories.categoriesonly = Categories only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ public void onValidate() {
}
}

// validate the course grade display settings
if (model.getGradebookInformation().isCourseGradeDisplayed()) {
int displayOptions = 0;

if (model.getGradebookInformation().isCourseLetterGradeDisplayed()) {
displayOptions++;
}

if (model.getGradebookInformation().isCourseAverageDisplayed()) {
displayOptions++;
}

if (model.getGradebookInformation().isCoursePointsDisplayed()) {
displayOptions++;
}

if (displayOptions == 0) {
error(getString("settingspage.displaycoursegrade.notenough"));
}
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ <h3 class="panel-title">
</div>

<div class="form-group" wicket:id="courseGradeType">
<div class="col-sm-offset-2 col-sm-10">

<p class="instruction"><wicket:message key="settingspage.displaycoursegrade.instructions" /></p>
<p class="messageError" wicket:id="minimumOptions">minimum options message</p>

<div class="col-sm-offset-1 col-sm-20">

<div class="checkbox">
<label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.gradebookng.business.GradebookNgBusinessService;
import org.sakaiproject.gradebookng.tool.model.GbSettings;
Expand All @@ -30,6 +31,7 @@ public class SettingsGradeReleasePanel extends Panel {
IModel<GbSettings> model;

Label preview;
Label minimumOptions;

public SettingsGradeReleasePanel(final String id, final IModel<GbSettings> model) {
super(id, model);
Expand Down Expand Up @@ -103,8 +105,9 @@ public boolean isVisible() {

@Override
protected void onUpdate(final AjaxRequestTarget target) {
// update preview
// update preview and validation
target.add(SettingsGradeReleasePanel.this.preview);
target.add(SettingsGradeReleasePanel.this.minimumOptions);
}
};
letterGrade.setOutputMarkupId(true);
Expand All @@ -117,8 +120,9 @@ protected void onUpdate(final AjaxRequestTarget target) {

@Override
protected void onUpdate(final AjaxRequestTarget target) {
// update preview
// update preview and validation
target.add(SettingsGradeReleasePanel.this.preview);
target.add(SettingsGradeReleasePanel.this.minimumOptions);
}
};
percentage.setOutputMarkupId(true);
Expand All @@ -131,13 +135,46 @@ protected void onUpdate(final AjaxRequestTarget target) {

@Override
protected void onUpdate(final AjaxRequestTarget target) {
// update preview
// update preview and validation
target.add(SettingsGradeReleasePanel.this.preview);
target.add(SettingsGradeReleasePanel.this.minimumOptions);
}
};
points.setOutputMarkupId(true);
courseGradeType.add(points);

// minimum options label. only shows if we have too few selected
this.minimumOptions = new Label("minimumOptions", new ResourceModel("settingspage.displaycoursegrade.notenough")) {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
final GradebookInformation settings = SettingsGradeReleasePanel.this.model.getObject().getGradebookInformation();

// validation label
if (settings.isCourseGradeDisplayed()) {
int displayOptions = 0;
if (settings.isCourseLetterGradeDisplayed()) {
displayOptions++;
}
if (settings.isCourseAverageDisplayed()) {
displayOptions++;
}
if (settings.isCoursePointsDisplayed()) {
displayOptions++;
}
if (displayOptions == 0) {
System.out.println("visible");
return true;
}
}
return false;
}

};
this.minimumOptions.setOutputMarkupPlaceholderTag(true);
courseGradeType.add(this.minimumOptions);

// preview model, uses settings to determine out what to display
final Model<String> previewModel = new Model<String>() {
private static final long serialVersionUID = 1L;
Expand Down

0 comments on commit 11824bd

Please sign in to comment.