Skip to content

Commit

Permalink
Merge pull request sakaiproject#1712 from payten/1596-popover-links
Browse files Browse the repository at this point in the history
1596 introduce links to header flag popovers
  • Loading branch information
steveswinsburg committed Feb 13, 2016
2 parents 28e6b03 + 9901cc5 commit 1287d4a
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ label.noduedate=-
label.coursegrade.released=Course grade has been released to students.
label.coursegrade.notreleased=Course grade has not been released to students.
label.coursegrade.nopermission=-
label.coursegrade.editsettings=Edit Release Settings

label.gradeitem.externalapplabel=Gradebook Item coming from {0}
label.gradeitem.released=Gradebook Item has been released and is visible to students.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public WebMarkupContainer buildFlagWithPopover(final String componentId, final S
flagWithPopover.add(new AttributeModifier("data-trigger", "focus"));
flagWithPopover.add(new AttributeModifier("data-placement", "bottom"));
flagWithPopover.add(new AttributeModifier("data-html", "true"));
flagWithPopover.add(new AttributeModifier("data-container", "#gradebookGrades"));
flagWithPopover.add(new AttributeModifier("data-template", "'<div class=\"gb-popover popover\" role=\"tooltip\"><div class=\"arrow\"></div><div class=\"popover-content\"></div></div>'"));
flagWithPopover.add(new AttributeModifier("data-content", generatePopoverContent(message)));
flagWithPopover.add(new AttributeModifier("tabindex", "0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<span class="caret"></span>
</a>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><a wicket:id="editAssignmentDetails" href="#" role="menuitem"><wicket:message key="assignment.option.edit" /></a></li>
<li><a wicket:id="editAssignmentDetails" href="#" class="edit-assignment-details" role="menuitem"><wicket:message key="assignment.option.edit" /></a></li>
<li><a wicket:id="viewAssignmentGradeStatistics" href="#" role="menuitem"><wicket:message key="assignment.option.viewgradestatistics" /></a></li>
<li><a wicket:id="moveAssignmentLeft" href="#" class="move-assignment-left" role="menuitem"><wicket:message key="assignment.option.moveleft" /></a></li>
<li><a wicket:id="moveAssignmentRight" href="#" class="move-assignment-right" role="menuitem"><wicket:message key="assignment.option.moveright" /></a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.core.util.string.ComponentRenderer;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
Expand Down Expand Up @@ -127,14 +128,14 @@ public void onClick() {
}
add(externalAppFlag);

add(gradebookPage.buildFlagWithPopover("extraCreditFlag", getString("label.gradeitem.extracredit"))
add(gradebookPage.buildFlagWithPopover("extraCreditFlag", generateFlagPopover(HeaderFlagPopoverPanel.Flag.GRADE_ITEM_EXTRA_CREDIT))
.setVisible(assignment.isExtraCredit()));
add(gradebookPage.buildFlagWithPopover("isCountedFlag", getString("label.gradeitem.counted")).setVisible(assignment.isCounted()));
add(gradebookPage.buildFlagWithPopover("notCountedFlag", getString("label.gradeitem.notcounted"))
add(gradebookPage.buildFlagWithPopover("isCountedFlag", generateFlagPopover(HeaderFlagPopoverPanel.Flag.GRADE_ITEM_COUNTED)).setVisible(assignment.isCounted()));
add(gradebookPage.buildFlagWithPopover("notCountedFlag", generateFlagPopover(HeaderFlagPopoverPanel.Flag.GRADE_ITEM_NOT_COUNTED))
.setVisible(!assignment.isCounted()));
add(gradebookPage.buildFlagWithPopover("isReleasedFlag", getString("label.gradeitem.released"))
add(gradebookPage.buildFlagWithPopover("isReleasedFlag", generateFlagPopover(HeaderFlagPopoverPanel.Flag.GRADE_ITEM_RELEASED))
.setVisible(assignment.isReleased()));
add(gradebookPage.buildFlagWithPopover("notReleasedFlag", getString("label.gradeitem.notreleased"))
add(gradebookPage.buildFlagWithPopover("notReleasedFlag", generateFlagPopover(HeaderFlagPopoverPanel.Flag.GRADE_ITEM_NOT_RELEASED))
.setVisible(!assignment.isReleased()));

add(new AttributeModifier("data-assignmentId", assignment.getId()));
Expand Down Expand Up @@ -331,4 +332,9 @@ private Component getParentCellFor(final Component component) {
return getParentCellFor(component.getParent());
}
}


private String generateFlagPopover(HeaderFlagPopoverPanel.Flag flag) {
return new HeaderFlagPopoverPanel("popover", flag, this.modelData.getObject().getId()).toPopoverString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public void onInitialize() {
final Gradebook gradebook = this.businessService.getGradebook();
final GradebookPage gradebookPage = (GradebookPage) getPage();

add(gradebookPage.buildFlagWithPopover("isReleasedFlag", getString("label.coursegrade.released"))
.setVisible(gradebook.isCourseGradeDisplayed()));
add(gradebookPage.buildFlagWithPopover("notReleasedFlag", getString("label.coursegrade.notreleased"))
.setVisible(!gradebook.isCourseGradeDisplayed()));
add(gradebookPage.buildFlagWithPopover("isReleasedFlag",
new HeaderFlagPopoverPanel("popover", HeaderFlagPopoverPanel.Flag.COURSE_GRADE_RELEASED).toPopoverString())
.setVisible(gradebook.isCourseGradeDisplayed()));
add(gradebookPage.buildFlagWithPopover("notReleasedFlag",
new HeaderFlagPopoverPanel("popover", HeaderFlagPopoverPanel.Flag.COURSE_GRADE_NOT_RELEASED).toPopoverString())
.setVisible(!gradebook.isCourseGradeDisplayed()));

// menu
final WebMarkupContainer menu = new WebMarkupContainer("menu");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<blockquote>
<p><span wicket:id="snippet"></span></p>
</blockquote>
<p wicket:id="editCommentContainer"><a href="javascript:void(0);" class="gb-popover-edit-comments" aria-haspopup="true"><wicket:message key="comment.option.edit" /></a></p>
<p wicket:id="editCommentContainer"><a href="javascript:void(0);" class="gb-popover-link" aria-haspopup="true"><wicket:message key="comment.option.edit" /></a></p>
<p wicket:id="externalComment">Editable in [Tool Name] Tool</p>
</li>
<li wicket:id="isExternalNotification" class="gb-popover-notification-is-external text-info"><span wicket:id="message"></span></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >

<body>
<wicket:panel>

<ul class="gb-popover-notifications">
<li class="text-info">
<p class="gb-popover-message">
<wicket:container wicket:id="message" />
</p>
<a wicket:id="link" class="gb-popover-link">
<wicket:container wicket:id="linkText" />
</a>
</li>
</ul>

</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.sakaiproject.gradebookng.tool.panels;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.core.util.string.ComponentRenderer;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.gradebookng.business.GbRole;
import org.sakaiproject.gradebookng.business.GradebookNgBusinessService;
import org.sakaiproject.gradebookng.tool.pages.SettingsPage;
import org.sakaiproject.user.api.User;

public class HeaderFlagPopoverPanel extends Panel {

private static final long serialVersionUID = 1L;

@SpringBean(name = "org.sakaiproject.gradebookng.business.GradebookNgBusinessService")
private GradebookNgBusinessService businessService;

public enum Flag {
GRADE_ITEM_EXTRA_CREDIT("label.gradeitem.extracredit"),
GRADE_ITEM_RELEASED("label.gradeitem.released"),
GRADE_ITEM_NOT_RELEASED("label.gradeitem.released"),
GRADE_ITEM_COUNTED("label.gradeitem.counted"),
GRADE_ITEM_NOT_COUNTED("label.gradeitem.notcounted"),
COURSE_GRADE_RELEASED("label.coursegrade.released"),
COURSE_GRADE_NOT_RELEASED("label.coursegrade.notreleased");

private String messageKey;

Flag(final String messageKey) {
this.messageKey = messageKey;
}

public String getMessageKey() {
return this.messageKey;
}
}


Flag flag;
Long assignmentId;


public HeaderFlagPopoverPanel(final String id, final Flag flag, final Long assignmentId) {
super(id);

this.flag = flag;
this.assignmentId = assignmentId;
}


public HeaderFlagPopoverPanel(final String id, final Flag flag) {
super(id);

this.flag = flag;
}

@Override
public void onInitialize() {
super.onInitialize();

add(new Label("message", getString(flag.getMessageKey())));

GbRole role = businessService.getUserRole();
boolean isInstructor = GbRole.INSTRUCTOR == role;

if (isInstructor) {
if (flag == Flag.COURSE_GRADE_NOT_RELEASED || flag == Flag.COURSE_GRADE_RELEASED) {
Link link = new Link("link") {
@Override
public void onClick() {
setResponsePage(new SettingsPage());
}
};
link.add(new Label("linkText", getString("label.coursegrade.editsettings")));
add(link);
} else if (assignmentId != null) {
AjaxLink link = new AjaxLink("link") {
@Override
public void onClick(AjaxRequestTarget target) {
// do nothing
}
};
String javascript = String.format("sakai.gradebookng.spreadsheet.editAssignmentFromFlag('%s');",
String.valueOf(assignmentId));
link.add(new AttributeAppender("onclick", javascript));
link.add(new Label("linkText", getString("assignment.option.edit")));
add(link);
} else {
add(new WebMarkupContainer("link").setVisible(false));
}
} else {
add(new WebMarkupContainer("link").setVisible(false));
}
}

public String toPopoverString() {
return ComponentRenderer.renderComponent(this).toString();
}
}
30 changes: 26 additions & 4 deletions gradebookng/tool/src/webapp/scripts/gradebook-grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,13 @@ GradebookSpreadsheet.prototype.getCategoriesMap = function() {
};


GradebookSpreadsheet.prototype.getHeaderModelForAssignment = function(assignmentId) {
return this.$table.find("thead .gb-grade-item-column-cell [data-assignmentid='" + assignmentId + "']").closest(".gb-grade-item-column-cell").data("model");
};


GradebookSpreadsheet.prototype.showGradeItemColumn = function(assignmentId) {
var headerModel = this.$table.find("thead .gb-grade-item-column-cell [data-assignmentid='" + assignmentId + "']").closest(".gb-grade-item-column-cell").data("model");
var headerModel = this.getHeaderModelForAssignment(assignmentId);
headerModel.show();
$.each(this._GRADE_CELLS, function(studentId, assignmentsMap) {
assignmentsMap[assignmentId].show();
Expand All @@ -1045,7 +1050,7 @@ GradebookSpreadsheet.prototype.showGradeItemColumn = function(assignmentId) {


GradebookSpreadsheet.prototype.hideGradeItemColumn = function(assignmentId) {
var headerModel = this.$table.find("thead .gb-grade-item-column-cell [data-assignmentid='" + assignmentId + "']").closest(".gb-grade-item-column-cell").data("model");
var headerModel = this.getHeaderModelForAssignment(assignmentId);
headerModel.hide();
$.each(this._GRADE_CELLS, function(studentId, assignmentsMap) {
assignmentsMap[assignmentId].hide();
Expand Down Expand Up @@ -1309,9 +1314,17 @@ GradebookSpreadsheet.prototype.setupMenusAndPopovers = function() {
self.$spreadsheet.find('[data-toggle="popover"]').popover("hide");
}).on("click", ".popover .gb-popover-close", function(event) {
var $link = $(this);
var cell = self.getCellModelForStudentAndAssignment($link.data("studentuuid"), $link.data("assignmentid"));
var $cellToFocus;

if ($link.data("studentuuid") && $link.data("assignmentid")) {
var cell = self.getCellModelForStudentAndAssignment($link.data("studentuuid"), $link.data("assignmentid"));
$cellToFocus = cell.$cell;
} else {
$cellToFocus = $link.closest("td,th");
}

self.$spreadsheet.find('[data-toggle="popover"]').popover("hide");
cell.$cell.focus();
$cellToFocus.focus();
});

// close the dropdown if the user navigates away from it
Expand Down Expand Up @@ -1471,6 +1484,15 @@ GradebookSpreadsheet.prototype.refreshStudentSummary = function() {
};


GradebookSpreadsheet.prototype.editAssignmentFromFlag = function(assignmentId) {
var $cell = this.getHeaderModelForAssignment(assignmentId).$cell;
var $editLink = $cell.find(".edit-assignment-details");

$editLink.trigger("click");
this.$table.find('[data-toggle="popover"]').popover("hide");
};


/*************************************************************************************
* AbstractCell - behaviour inherited by all cells
*/
Expand Down
5 changes: 3 additions & 2 deletions gradebookng/tool/src/webapp/styles/gradebook-grades.css
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,13 @@
font-family: "gradebook-icons";
content: '\f040';
}
.gb-popover-notifications .gb-popover-edit-comments {
.gb-popover-notifications .gb-popover-link {
float: right;
font-size: 0.8em;
margin: 0 0 1em;
}
.gb-popover-notifications .gb-popover-notification-has-comment blockquote {
margin: 0.5em 0;
margin: 1em 0;
padding: 5px 10px;
font-size: 0.9em;
}
Expand Down

0 comments on commit 1287d4a

Please sign in to comment.