@@ -106,7 +106,7 @@ public class GradebookPage extends BasePage {
106
106
GbModalWindow courseGradeStatisticsWindow ;
107
107
108
108
Label liveGradingFeedback ;
109
- boolean hasAssignmentsAndGrades ;
109
+ boolean hasGradebookItems , hasStudents ;
110
110
private static final AttributeModifier DISPLAY_NONE = new AttributeModifier ("style" , "display: none" );
111
111
112
112
Form <Void > form ;
@@ -115,6 +115,8 @@ public class GradebookPage extends BasePage {
115
115
boolean showGroupFilter = true ;
116
116
private GbGradeTable gradeTable ;
117
117
118
+ private final WebMarkupContainer tableArea ;
119
+
118
120
@ SuppressWarnings ({ "rawtypes" , "unchecked" , "serial" })
119
121
public GradebookPage () {
120
122
disableLink (this .gradebookPageLink );
@@ -195,25 +197,6 @@ public GradebookPage() {
195
197
this .courseGradeStatisticsWindow .setPositionAtTop (true );
196
198
this .form .add (this .courseGradeStatisticsWindow );
197
199
198
- final GbAjaxButton addGradeItem = new GbAjaxButton ("addGradeItem" ) {
199
- @ Override
200
- public void onSubmit (final AjaxRequestTarget target , final Form form ) {
201
- final GbModalWindow window = getAddOrEditGradeItemWindow ();
202
- window .setTitle (getString ("heading.addgradeitem" ));
203
- window .setComponentToReturnFocusTo (this );
204
- window .setContent (new AddOrEditGradeItemPanel (window .getContentId (), window , null ));
205
- window .show (target );
206
- }
207
-
208
- @ Override
209
- public boolean isVisible () {
210
- return (businessService .isUserAbleToEditAssessments ());
211
- }
212
- };
213
- addGradeItem .setDefaultFormProcessing (false );
214
- addGradeItem .setOutputMarkupId (true );
215
- this .form .add (addGradeItem );
216
-
217
200
// first get any settings data from the session
218
201
final GradebookUiSettings settings = getUiSettings ();
219
202
@@ -227,28 +210,52 @@ public boolean isVisible() {
227
210
final List <Assignment > assignments = this .businessService .getGradebookAssignments (sortBy );
228
211
final List <String > students = this .businessService .getGradeableUsers ();
229
212
230
- this . hasAssignmentsAndGrades = !assignments . isEmpty () && ! students .isEmpty ();
231
-
213
+ hasGradebookItems = !assignments .isEmpty ();
214
+ hasStudents = ! students . isEmpty ();
232
215
// categories enabled?
233
216
final boolean categoriesEnabled = this .businessService .categoriesAreEnabled ();
234
217
235
218
// grading type?
236
219
final GradingType gradingType = GradingType .valueOf (gradebook .getGrade_type ());
237
220
221
+ tableArea = new WebMarkupContainer ("gradeTableArea" );
222
+ if (!hasGradebookItems ) {
223
+ tableArea .add (AttributeAppender .append ("class" , "gradeTableArea" ));
224
+ }
225
+ form .add (tableArea );
226
+
227
+ final GbAddButton addGradeItem = new GbAddButton ("addGradeItem" );
228
+ addGradeItem .setDefaultFormProcessing (false );
229
+ addGradeItem .setOutputMarkupId (true );
230
+ tableArea .add (addGradeItem );
231
+
238
232
final WebMarkupContainer noAssignments = new WebMarkupContainer ("noAssignments" );
239
233
noAssignments .setVisible (assignments .isEmpty ());
240
- this .form .add (noAssignments );
234
+ tableArea .add (noAssignments );
235
+ final GbAddButton addGradeItem2 = new GbAddButton ("addGradeItem2" ) {
236
+ @ Override
237
+ public boolean isVisible () {
238
+ return GradebookPage .this .role == GbRole .INSTRUCTOR ;
239
+ }
240
+ };
241
+ addGradeItem2 .setDefaultFormProcessing (false );
242
+ addGradeItem2 .setOutputMarkupId (true );
243
+ noAssignments .add (addGradeItem2 );
241
244
242
245
final WebMarkupContainer noStudents = new WebMarkupContainer ("noStudents" );
243
246
noStudents .setVisible (students .isEmpty ());
244
- this . form .add (noStudents );
247
+ tableArea .add (noStudents );
245
248
246
249
// Populate the toolbar
247
250
final WebMarkupContainer toolbar = new WebMarkupContainer ("toolbar" );
248
- this .form .add (toolbar );
251
+ tableArea .add (toolbar );
252
+
253
+ final WebMarkupContainer toolbarColumnTools = new WebMarkupContainer ("gbToolbarColumnTools" );
254
+ toolbarColumnTools .setVisible (hasGradebookItems );
255
+ toolbar .add (toolbarColumnTools );
249
256
250
257
final WebMarkupContainer toggleGradeItemsToolbarItem = new WebMarkupContainer ("toggleGradeItemsToolbarItem" );
251
- toolbar .add (toggleGradeItemsToolbarItem );
258
+ toolbarColumnTools .add (toggleGradeItemsToolbarItem );
252
259
253
260
this .gradeTable = new GbGradeTable ("gradeTable" ,
254
261
new LoadableDetachableModel () {
@@ -276,7 +283,7 @@ public GbGradeTableData load() {
276
283
this .gradeTable .addEventListener ("viewCourseGradeStatistics" , new ViewCourseGradeStatisticsAction ());
277
284
278
285
279
- this . form .add (this .gradeTable );
286
+ tableArea .add (this .gradeTable );
280
287
281
288
final Button toggleCategoriesToolbarItem = new Button ("toggleCategoriesToolbarItem" ) {
282
289
@ Override
@@ -302,7 +309,7 @@ public boolean isVisible() {
302
309
return categoriesEnabled ;
303
310
}
304
311
};
305
- toolbar .add (toggleCategoriesToolbarItem );
312
+ toolbarColumnTools .add (toggleCategoriesToolbarItem );
306
313
307
314
final GbAjaxLink sortGradeItemsToolbarItem = new GbAjaxLink ("sortGradeItemsToolbarItem" ) {
308
315
@ Override
@@ -324,7 +331,7 @@ public boolean isVisible() {
324
331
return (businessService .isUserAbleToEditAssessments ());
325
332
}
326
333
};
327
- toolbar .add (sortGradeItemsToolbarItem );
334
+ toolbarColumnTools .add (sortGradeItemsToolbarItem );
328
335
329
336
// section and group dropdown
330
337
final List <GbGroup > groups = this .businessService .getSiteSectionsAndGroups ();
@@ -405,15 +412,13 @@ protected void onUpdate(final AjaxRequestTarget target) {
405
412
groupFilter .setNullValid (false );
406
413
407
414
// if only one item, hide the dropdown
408
- if (groups .size () == 1 || !this .hasAssignmentsAndGrades ) {
409
- groupFilter .setVisible (false );
410
- }
415
+ groupFilter .setVisible (groups .size () > 1 && hasStudents );
411
416
412
417
final WebMarkupContainer studentFilter = new WebMarkupContainer ("studentFilter" );
413
- studentFilter .setVisible (this . hasAssignmentsAndGrades );
418
+ studentFilter .setVisible (hasStudents );
414
419
toolbar .add (studentFilter );
415
420
416
- this . form .add (groupFilter );
421
+ tableArea .add (groupFilter );
417
422
418
423
final Map <String , Object > togglePanelModel = new HashMap <>();
419
424
togglePanelModel .put ("assignments" , this .businessService .getGradebookAssignments (sortBy ));
@@ -424,17 +429,9 @@ protected void onUpdate(final AjaxRequestTarget target) {
424
429
new ToggleGradeItemsToolbarPanel ("gradeItemsTogglePanel" , Model .ofMap (togglePanelModel ));
425
430
add (gradeItemsTogglePanel );
426
431
427
- this .form .add (new WebMarkupContainer ("captionToggle" ).setVisible (this .hasAssignmentsAndGrades ));
428
-
429
- //
430
- // hide/show components
431
- //
432
+ tableArea .add (new WebMarkupContainer ("captionToggle" ).setVisible (hasStudents ));
432
433
433
- // Only show the toolbar if there are students and grade items
434
- toolbar .setVisible (!assignments .isEmpty ());
435
-
436
- // Show the table if there are grade items
437
- this .gradeTable .setVisible (!assignments .isEmpty ());
434
+ toolbar .setVisible (hasStudents || hasGradebookItems );
438
435
439
436
stopwatch .time ("Gradebook page done" , stopwatch .getTime ());
440
437
}
@@ -560,15 +557,15 @@ public void onBeforeRender() {
560
557
// add simple feedback nofication to sit above the table
561
558
// which is reset every time the page renders
562
559
this .liveGradingFeedback = new Label ("liveGradingFeedback" , getString ("feedback.saved" ));
563
- this .liveGradingFeedback .setVisible (this . hasAssignmentsAndGrades );
560
+ this .liveGradingFeedback .setVisible (hasGradebookItems && hasStudents );
564
561
this .liveGradingFeedback .setOutputMarkupId (true );
565
562
this .liveGradingFeedback .add (DISPLAY_NONE );
566
563
567
564
// add the 'saving...' message to the DOM as the JavaScript will
568
565
// need to be the one that displays this message (Wicket will handle
569
566
// the 'saved' and 'error' messages when a grade is changed
570
567
this .liveGradingFeedback .add (new AttributeModifier ("data-saving-message" , getString ("feedback.saving" )));
571
- this . form .addOrReplace (this .liveGradingFeedback );
568
+ tableArea .addOrReplace (this .liveGradingFeedback );
572
569
}
573
570
574
571
public Component updateLiveGradingMessage (final String message ) {
@@ -578,4 +575,29 @@ public Component updateLiveGradingMessage(final String message) {
578
575
}
579
576
return this .liveGradingFeedback ;
580
577
}
578
+
579
+ private class GbAddButton extends GbAjaxButton {
580
+
581
+ public GbAddButton (String id ) {
582
+ super (id );
583
+ }
584
+
585
+ public GbAddButton (String id , Form <?> form ) {
586
+ super (id , form );
587
+ }
588
+
589
+ @ Override
590
+ public void onSubmit (final AjaxRequestTarget target , final Form form ) {
591
+ final GbModalWindow window = getAddOrEditGradeItemWindow ();
592
+ window .setTitle (getString ("heading.addgradeitem" ));
593
+ window .setComponentToReturnFocusTo (this );
594
+ window .setContent (new AddOrEditGradeItemPanel (window .getContentId (), window , null ));
595
+ window .show (target );
596
+ }
597
+
598
+ @ Override
599
+ public boolean isVisible () {
600
+ return GradebookPage .this .role == GbRole .INSTRUCTOR && hasGradebookItems ;
601
+ }
602
+ }
581
603
}
0 commit comments