Skip to content

Commit

Permalink
SAK-43108 Moved rubrics utils into top window (sakaiproject#7988)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored and ern committed Mar 12, 2020
1 parent 1405a48 commit 2ed8429
Show file tree
Hide file tree
Showing 43 changed files with 193 additions and 191 deletions.
4 changes: 4 additions & 0 deletions assignment/tool/src/webapp/vm/assignment/assignment_macros.vm
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,8 @@
</div>
#end
#end
#macro( rubricsRequirements )
#javascript("/rubrics-service/webcomponents/sakai-rubrics-utils.js")
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#end
<!-- end: assignment_macros.vm -->
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- start: chef_assignments_instructor_grading_submission.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#rubricsRequirements
#set( $H = '-' )
#javascript("/library/js/lang-datepicker/lang-datepicker.js")

<script type="text/javascript">
<script>
focus_path = ['$fField'];
$(document).ready(function () {
//click anywhere to close the peer assessment information box
Expand Down Expand Up @@ -706,7 +706,7 @@
<span id="allowResubmitTime">
<label for="allowResubmitDate">$tlang.getString("gen.acesubunt")</label>
<input type="text" id="allowResubmitDate" name="allowResubmitDate" class="datepicker" value=""/>
<script type="text/javascript">
<script>
localDatePicker({
input: '#allowResubmitDate',
useTime: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- start: chef_assignments_instructor_list_submissions.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#rubricsRequirements
#set( $H = '-' )
<script>includeLatestJQuery('assignments');</script>
#javascript("/library/js/lang-datepicker/lang-datepicker.js")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- start: chef_assignments_instructor_new_edit_assignment.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#set( $H = '-' )
#rubricsRequirements
<!-- Initialize the Bootstrap-multiselect plugin: -->
<script type="text/javascript">
<script>
$(document).ready(function() {
$('#selectedGroups').multiselect({
selectAllText: '$tlang.getString("asn.edit.selectall")',
Expand All @@ -19,7 +19,7 @@
});
});
</script>
<script type="text/javascript">
<script>
#if($turnitin_forceSingleAttachment)
function forceSingleAttachment(checked) {
if(checked){
Expand Down Expand Up @@ -236,7 +236,7 @@
</p>
</div>

<script type="text/javascript">
<script>
localDatePicker({
input:'#visibledate',
useTime:1,
Expand Down Expand Up @@ -266,7 +266,7 @@
</p>
</div>

<script type="text/javascript">
<script>
localDatePicker({
input:'#opendate',
useTime:1,
Expand All @@ -292,7 +292,7 @@
<input type="text" id="duedate" name="duedate" class="form-control datepicker" value="">
</div>

<script type="text/javascript">
<script>
localDatePicker({
input:'#duedate',
useTime:1,
Expand Down Expand Up @@ -321,7 +321,7 @@
</p>
</div>

<script type="text/javascript">
<script>
localDatePicker({
input:'#closedate',
useTime:1,
Expand Down Expand Up @@ -524,7 +524,7 @@
<input type="text" id="resubmit" name="resubmit" class="datepicker" value="">
</div>

<script type="text/javascript">
<script>
localDatePicker({
input:'#resubmit',
useTime:1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- start: chef_assignments_list_assignments.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#rubricsRequirements
<script>
focus_path = ["search"];
var linkFlag = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- start: chef_assignments_student_view_grade.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#rubricsRequirements
<script>
$(document).ready(function () {
$("#accordion").accordion({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- start: chef_assignments_student_view_submission.vm -->
#module("/rubrics-service/webcomponents/rubric-association-requirements.js")
#rubricsRequirements
<script>
$(document).ready(function(){
$('#submissionFileCount').val(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ protected void onUpdate(final AjaxRequestTarget target) {
public void renderHead(final IHeaderResponse response) {

final String version = PortalUtils.getCDNQuery();
response.render(StringHeaderItem.forString(
"<script src=\"/rubrics-service/webcomponents/sakai-rubrics-utils.js" + version + "\"></script>"));
response.render(StringHeaderItem.forString(
"<script type=\"module\" src=\"/rubrics-service/webcomponents/rubric-association-requirements.js" + version + "\"></script>"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ private DropInfoPair getDropInfo(final String categoryName, final Map<String, Ca
public void renderHead(final IHeaderResponse response) {

final String version = PortalUtils.getCDNQuery();
response.render(StringHeaderItem.forString(
"<script src=\"/rubrics-service/webcomponents/sakai-rubrics-utils.js" + version + "\"></script>"));
response.render(StringHeaderItem.forString(
"<script type=\"module\" src=\"/rubrics-service/webcomponents/rubric-association-requirements.js" + version + "\"></script>"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
public void renderHead(final IHeaderResponse response) {

final String version = PortalUtils.getCDNQuery();
response.render(StringHeaderItem.forString(
"<script src=\"/rubrics-service/webcomponents/sakai-rubrics-utils.js" + version + "\"></script>"));
response.render(StringHeaderItem.forString(
"<script type=\"module\" src=\"/rubrics-service/webcomponents/rubric-association-requirements.js" + version + "\"></script>"));
}
Expand Down
3 changes: 3 additions & 0 deletions lessonbuilder/tool/src/webapp/templates/ShowItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
top: 12px !important;
}
</style>

<script type="module" src="/rubrics-service/webcomponents/sakai-rubric-student.js"></script>
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js"></script>
<script type="text/javascript">

// need a delay to allow dynamic things like inserting the html editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="/messageforums-tool/js/permissions_header.js"></script>
<script src="/messageforums-tool/js/datetimepicker.js"></script>
<script src="/library/js/lang-datepicker/lang-datepicker.js"></script>
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/rubrics-service/webcomponents/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<link href="/library/webjars/jquery-ui/1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src="/messageforums-tool/js/messages.js"></script>
<script src="/messageforums-tool/js/datetimepicker.js"></script>
<script src="/library/js/lang-datepicker/lang-datepicker.js"></script>
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/rubrics-service/webcomponents/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<link href="/library/webjars/jquery-ui/1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>includeLatestJQuery("msgcntr");</script>
<script src="/messageforums-tool/js/sak-10625.js"></script>
<script src="/messageforums-tool/js/forum.js"></script>
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/rubrics-service/webcomponents/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<!--jsp/discussionForum/forum/dfForumDetail.jsp-->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!--jsp/discussionForum/area/dfAreaInclude.jsp-->
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/rubrics-service/webcomponents/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<h:panelGrid columns="1" cellpadding="3" rendered="#{empty ForumTool.forums}">
<h:panelGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script src="/messageforums-tool/js/forum_movethread.js"></script>

<script src="/messageforums-tool/js/sak-10625.js"></script>
<script src="/rubrics-service/webcomponents/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/rubrics-service/webcomponents/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>

<!--jsp/discussionForum/message/dfAllMessages.jsp-->
Expand Down
45 changes: 43 additions & 2 deletions rubrics/tool/src/main/frontend/webcomponents/rubrics-element.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
import {SakaiElement} from "/webcomponents/sakai-element.js";
import {rubricsUtils} from "./sakai-rubrics-utils.js";

class RubricsElement extends SakaiElement {

constructor() {

super();

this.rubricsUtils = rubricsUtils;
this.locale = window.portal ? window.portal.locale : window.top.portal.locale;
}

isUtilsAvailable() {

let available = window.top.rubrics && window.top.rubrics.utils;
if (!available) {
console.error("Rubrics Utils has not been loaded (sakai-rubrics-utils.js). THINGS WILL BREAK!");
}
return available;
}

initLightbox(token, i18n) {

if (this.isUtilsAvailable()) {
window.top.rubrics.utils.initLightbox(token, i18n);
}
}

showRubricLightbox(id, attributes) {

if (this.isUtilsAvailable()) {
window.top.rubrics.utils.showRubric(id, attributes);
}
}

// get high low values from objects in array
getHighLow(myArray, property) {

var lowest = Number.POSITIVE_INFINITY;
var highest = Number.NEGATIVE_INFINITY;
var tmp;

for (var i=myArray.length-1; i>=0; i--) {
tmp = myArray[i][property];
if (tmp < lowest) lowest = tmp;
if (tmp > highest) highest = tmp;
}

return {
high: highest,
low: lowest
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,15 @@ export class SakaiItemDelete extends RubricsElement {
if (!this.classList.contains("show-tooltip")) {
this.closeOpen();
this.popoverOpen = "true";
var triggerPosition = this.rubricsUtils.altOffset(e.target);

this.classList.add("show-tooltip");

var popover = $(`#delete_${this.type}_${this.item.id}`);

var target = this.querySelector(".fa-times");

this.rubricsUtils.css(popover[0], {
'left': target.offsetLeft - 280 + "px",
'top': (target.offsetTop - this.offsetHeight*2 - 10) + "px",
});
popover[0].style.left = target.offsetLeft - 280 + "px";
popover[0].style.top = (target.offsetTop - this.offsetHeight*2 - 10) + "px";

$('.btn-danger').focus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SakaiRubricAssociation extends RubricsElement {

set token(newValue) {

this.i18nPromise.then(r => this.rubricsUtils.initLightbox(newValue, r));
this.i18nPromise.then(r => this.initLightbox(newValue, r));
this._token = "Bearer " + newValue;
}

Expand Down Expand Up @@ -182,7 +182,7 @@ class SakaiRubricAssociation extends RubricsElement {

e.preventDefault();
if (this.isAssociated) {
this.rubricsUtils.showRubric(this.selectedRubric);
this.showRubricLightbox(this.selectedRubric);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
if (!c.selectedvalue) {
c.selectedvalue = 0;
}
c.pointrange = this.rubricsUtils.getHighLow(c.ratings, "points");
c.pointrange = this.getHighLow(c.ratings, "points");
});

if (this.evaluationDetails) this.decorateCriteria();
Expand Down Expand Up @@ -85,7 +85,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
<div class="rating-item ${this.selectedRatings.includes(r.id) ? "selected" : ""}" data-rating-id="${r.id}" id="rating-item-${r.id}" data-criterion-id="${c.id}" @click="${this.toggleRating}">
<h5 class="criterion-item-title">${r.title}</h5>
<p>${r.description}</p>
<span class="points" data-points="${r.points}">${r.points.toLocaleString(portal.locale)} <sr-lang key="points">Points</sr-lang></span>
<span class="points" data-points="${r.points}">${r.points.toLocaleString(this.locale)} <sr-lang key="points">Points</sr-lang></span>
</div>
`)}
</div>
Expand Down Expand Up @@ -119,7 +119,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
<div class="rubric-totals" style="margin: 10px 0px 10px 0px;">
<input type="hidden" aria-labelledby="${tr("total")}" id="rbcs-${this.evaluatedItemId}-${this.entityId}-totalpoints" name="rbcs-${this.evaluatedItemId}-${this.entityId}-totalpoints" .value="${this.totalPoints}">
<div class="total-points">
<sr-lang key="total">Total</sr-lang>: <strong id="sakai-rubrics-total-points">${this.totalPoints.toLocaleString(portal.locale)}</strong>
<sr-lang key="total">Total</sr-lang>: <strong id="sakai-rubrics-total-points">${this.totalPoints.toLocaleString(this.locale)}</strong>
</div>
</div>
Expand Down Expand Up @@ -335,7 +335,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
updateTotalPoints() {

this.calculateTotalPointsFromCriteria();
var detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, value: this.totalPoints.toLocaleString(portal.locale) };
var detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, value: this.totalPoints.toLocaleString(this.locale) };
this.dispatchEvent(new CustomEvent('total-points-updated', {detail: detail, bubbles: true, composed: true}));

this.updateStateDetails();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export class SakaiRubricCriteriaReadonly extends RubricsElement {
<div class="cr-table">
<div class="cr-table-row">
${c.ratings.map(r => html`
<div tabindex="0" title="${tr("rating_title")}: ${r.title}. ${tr("rating_description")}: ${r.description}. ${tr("point_value")}: ${r.points.toLocaleString(portal.locale)}" class="rating-item" id="rating_item_${r.id}" on-save-ratings="saveRatings" @on-delete-rating="${this.deleteCriterionRating}">
<div tabindex="0" title="${tr("rating_title")}: ${r.title}. ${tr("rating_description")}: ${r.description}. ${tr("point_value")}: ${r.points.toLocaleString(this.locale)}" class="rating-item" id="rating_item_${r.id}" on-save-ratings="saveRatings" @on-delete-rating="${this.deleteCriterionRating}">
<h5 class="criterion-item-title">${r.title}</h5>
<p>${r.description}</p>
<span class="points">${r.points.toLocaleString(portal.locale)} ${tr("points")}</span>
<span class="points">${r.points.toLocaleString(this.locale)} ${tr("points")}</span>
</div>
`)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RubricsElement} from "./rubrics-element.js";
import {css,html} from "/webcomponents/assets/lit-element/lit-element.js";
import {html} from "/webcomponents/assets/lit-element/lit-element.js";
import {repeat} from "/webcomponents/assets/lit-html/directives/repeat.js";
import {SakaiRubricEdit} from "./sakai-rubric-edit.js";
import {SakaiItemDelete} from "./sakai-item-delete.js";
Expand Down Expand Up @@ -76,7 +76,7 @@ export class SakaiRubricCriteria extends RubricsElement {
</p>
</div>
<span class="points">
${r.points.toLocaleString(portal.locale)} <sr-lang key="points">Points</sr-lang>
${r.points.toLocaleString(this.locale)} <sr-lang key="points">Points</sr-lang>
</span>
<div class="add-criterion-item">
Expand Down Expand Up @@ -201,7 +201,7 @@ export class SakaiRubricCriteria extends RubricsElement {

$.ajax({
url: "/rubrics-service/rest/ratings",
headers: {"Content-Type": "application/json" , "x-copy-source": "default", "authorization": this.token, "lang": portal.locale},
headers: {"Content-Type": "application/json" , "x-copy-source": "default", "authorization": this.token, "lang": this.locale},
method: "POST",
data: "{}"
})
Expand Down Expand Up @@ -258,7 +258,7 @@ export class SakaiRubricCriteria extends RubricsElement {

$.ajax({
url: "/rubrics-service/rest/criterions/",
headers: {"x-copy-source": e.target.dataset.criterionId, "authorization": this.token, "lang": portal.locale},
headers: {"x-copy-source": e.target.dataset.criterionId, "authorization": this.token, "lang": this.locale},
contentType: "application/json",
method: "POST",
data: "{}"
Expand Down Expand Up @@ -310,7 +310,7 @@ export class SakaiRubricCriteria extends RubricsElement {

$.ajax({
url: "/rubrics-service/rest/criterions/",
headers: {"Content-Type": "application/json", "x-copy-source": "default", "authorization": this.token, "lang": portal.locale},
headers: {"Content-Type": "application/json", "x-copy-source": "default", "authorization": this.token, "lang": this.locale},
method: "POST",
data: "{}"
})
Expand Down
Loading

0 comments on commit 2ed8429

Please sign in to comment.