Skip to content

Commit

Permalink
Merge pull request #111 from turnitin/fix_dv_launchers
Browse files Browse the repository at this point in the history
Release 2016011102
  • Loading branch information
jmcgettrick committed Jan 26, 2016
2 parents a64c106 + 024e8f3 commit 57446fb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 77 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Date: 2016-January-25
### Release: v2016011102

- Fixes:
- Reworked DV launchers to remove cross domain iframe problem preventing opening in Safari.

---

### Date: 2016-January-12
### Release: v2016011101

Expand Down
9 changes: 8 additions & 1 deletion ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
break;

case "downloadoriginal":
case "default":
case "origreport":
case "grademark":
$assignmentid = required_param('assignment', PARAM_INT);
Expand All @@ -151,7 +152,13 @@

$user = new turnitintooltwo_user($USER->id, $userrole);

echo turnitintooltwo_view::output_dv_launch_form($action, $submissionid, $user->tii_user_id, $userrole);
$launch_form = turnitintooltwo_view::output_dv_launch_form($action, $submissionid, $user->tii_user_id, $userrole, '');
if ($action == 'downloadoriginal') {
echo $launch_form;
} else {
$launch_form = html_writer::tag("div", $launch_form, array('style' => 'display: none'));
echo json_encode($launch_form);
}
}
break;

Expand Down
122 changes: 60 additions & 62 deletions jquery/turnitintooltwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,16 @@ jQuery(document).ready(function($) {

// When the refresh submissions link is clicked, the data in each datatable needs to be reloaded
$(".refresh_link").click(function () {

$(".refresh_link").hide();
$(".refreshing_link").show();

$('table.submissionsDataTable').each(function() {
refreshRequested[$(this).attr("id")] = 1;
partTables[$(this).attr("id")].fnReloadAjax();
partTables[$(this).attr("id")].fnStandingRedraw();
});
if ($(this).is(":visible")) {
$(".refresh_link").hide();
$(".refreshing_link").show();

$('table.submissionsDataTable').each(function() {
refreshRequested[$(this).attr("id")] = 1;
partTables[$(this).attr("id")].fnReloadAjax();
partTables[$(this).attr("id")].fnStandingRedraw();
});
}
return false;
});

Expand Down Expand Up @@ -559,6 +560,11 @@ jQuery(document).ready(function($) {
var due_date = $('#date_due_'+idStr[2]).html();
var due_date_unix = moment(due_date).unix();

var dvtype = idStr[0];
var submission_id = idStr[1];
var part_id = idStr[2];
var user_id = idStr[3];

// Show resubmission grade warning if the due date has not passed.
if (due_date_unix > moment().unix()) {
if ($(this).hasClass('graded_warning')) {
Expand All @@ -569,25 +575,27 @@ jQuery(document).ready(function($) {
}

if (proceed) {
var url = $('#'+idStr[0]+'_url_'+idStr[1]).html()+'&viewcontext=box&do='+idStr[0]+'&submissionid='+idStr[1]+'&sesskey='+M.cfg.sesskey;
var dvWindow = window.open('about:blank', 'dv_'+idStr[1]);
var width = $(window).width();
var height = $(window).height();
dvWindow.document.write('<title>Document Viewer</title>');
dvWindow.document.write('<style>html, body { margin: 0; padding: 0; border: 0; }</style>');
dvWindow.document.write('<frameset><frame id="dvWindow" name="dvWindow"></frame></frameset>');
dvWindow.document.getElementById('dvWindow').src = url;
dvWindow.document.close();
if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
// beforeunload event does not work in Safari.
$(dvWindow).bind('unload', function() {
$("#refresh_"+idStr[2]).click();
});
} else {
$(dvWindow).bind('beforeunload', function() {
$("#refresh_"+idStr[2]).click();
});
}
dvWindow = window.open('', '_blank');
var loading = '<div style="text-align:center;">';
loading += '<img src="'+M.cfg.wwwroot+'/mod/turnitintooltwo/pix/tiiIcon.svg" style="width:100px; height: 100px">';
loading += '<p style="font-family: Arial, Helvetica, sans-serif;">'+M.str.turnitintooltwo.loadingdv+'</p>';
loading += '</div>';
$(dvWindow.document.body).html(loading);

// Get html to launch DV
$.ajax({
type: "POST",
url: M.cfg.wwwroot+"/mod/turnitintooltwo/ajax.php",
dataType: "json",
data: {action: dvtype, submission: submission_id, assignment: $('#assignment_id').html()},
success: function(data) {
$(dvWindow.document.body).html(loading+data);
dvWindow.document.forms[0].submit();
dvWindow.document.close();

checkDVClosed(part_id);
}
});
}
});

Expand Down Expand Up @@ -1117,7 +1125,7 @@ jQuery(document).ready(function($) {
var idStr = $(this).attr("id").split("_");
// Don't open OR DV if score is pending.
if (!$(this).children('.score_colour').hasClass('score_colour_')) {
openDV(idStr[0], idStr[1], idStr[2], idStr[3]);
downloadOriginalFile(idStr[0], idStr[1], idStr[2], idStr[3]);
}
});
}
Expand Down Expand Up @@ -1146,41 +1154,31 @@ jQuery(document).ready(function($) {
});
}

// Open the document viewer within a frame in a new tab
function openDV(dvtype, submission_id, part_id, user_id) {
var proceed = true;

// Show resubmission grade warning.
if ($('#grademark_'+submission_id+'_'+part_id+'_'+user_id).hasClass('graded_warning') && dvtype != 'downloadoriginal') {
if (!confirm(M.str.turnitintooltwo.resubmissiongradewarn)) {
proceed = false;
// Put the form in to the submissions table row and submit it.
// This will download the relevant original file
function downloadOriginalFile(dvtype, submission_id, part_id, user_id) {
// Get html to launch DV
$.ajax({
type: "POST",
url: M.cfg.wwwroot+"/mod/turnitintooltwo/ajax.php",
dataType: "html",
data: {action: dvtype, submission: submission_id, assignment: $('#assignment_id').html()},
success: function(data) {
$("#"+dvtype+"_form_"+submission_id).html(data);
$("#"+dvtype+"_form_"+submission_id).children("form").submit();
$("#"+dvtype+"_form_"+submission_id).html("");
}
}
});
}

if (proceed) {
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "html",
data: {action: dvtype, assignment: $('#assignment_id').html(), submission: submission_id},
success: function(data) {
$("#"+dvtype+"_form_"+submission_id).html(data);
if (dvtype == "downloadoriginal") {
$("#"+dvtype+"_form_"+submission_id).children("form").submit();
} else {
$("#"+dvtype+"_form_"+submission_id).children("form").on("submit", function(event) {
dvWindow = window.open('', 'dv_'+submission_id);
dvWindow.document.write('<frameset><frame id="dvWindow" name="dvWindow"></frame></frameset>');
dvWindow.document.close();
$(dvWindow).bind('beforeunload', function() {
refreshInboxRow(dvtype, submission_id, part_id, user_id);
});
});
$("#"+dvtype+"_form_"+submission_id).children("form").submit();
}
$("#"+dvtype+"_form_"+submission_id).html("");
}
});
// Check whether the DV is still open, refresh the opening window when it closes.
function checkDVClosed(part_id) {
if (window.dvWindow.closed) {
$("#refresh_"+part_id).click();
} else {
setTimeout( function(){
checkDVClosed(part_id);
}, 500);
}
}

Expand Down
2 changes: 1 addition & 1 deletion jquery/turnitintooltwo.min.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions lang/en/turnitintooltwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
$string['turnitininboxlayout_desc'] = 'Choose whether the Turnitin Assignment page should show navigation or be displayed full width.';
$string['layoutoptions_0'] = 'Full width';
$string['layoutoptions_1'] = 'Moodle default - with navigation';
$string['emailnonsubmitters'] = 'Email Non-Submitters';
$string['messagenonsubmitters'] = 'Notify Non-Submitters';
$string['nonsubmittersformdesc'] = 'Please enter a message below to send to students who have not yet submitted to this assignment.';
$string['nonsubmitterssubject'] = 'Subject';
$string['nonsubmittersmessage'] = 'Message';
Expand All @@ -538,10 +538,10 @@
$string['messageprovider:nonsubmitters'] = 'Turnitin Assignment Non Submitter notifications';
$string['checkagainstnote'] = 'Note: If you do not select "Yes" for at least one of the "Check against..." options below then an Originality report will NOT be generated.';
$string['anonblindmarkingnote'] = 'Note: The separate Turnitin anonymous marking setting has been removed. Turnitin will use Moodle\'s blind marking setting to determine the anonymous marking setting.';
$string['displaygradesas'] = 'Grade Display';
$string['displaygradesas_help'] = 'This option sets the display mode for grades the options are display as a percentage or display as a fraction ie 45/60.';
$string['displaygradesasfraction'] = 'Show grades as Fraction (e.g. 89/100)';
$string['displaygradesaspercent'] = 'Show grades as Percentage (e.g. 89&#37;)';
$string['displaygradesas'] = 'Grade Display';
$string['displaygradesas_help'] = 'This option sets the display mode for grades the options are display as a percentage or display as a fraction ie 45/60.';
$string['displaygradesasfraction'] = 'Show grades as Fraction (e.g. 89/100)';
$string['displaygradesaspercent'] = 'Show grades as Percentage (e.g. 89&#37;)';
$string['genspeednote'] = 'Note: Originality Report generation for resubmissions is subject to a twenty-four hour delay.';
$string['cronsubmittedsuccessfully'] = 'Submission: {$a->title} (TII ID: {$a->submissionid}) for the assignment {$a->assignmentname} on the course {$a->coursename} was successfully submitted to Turnitin.';
$string['ppassignmentediterror'] = 'Module {$a->title} (TII ID: {$a->assignmentid}) could not be edited on Turnitin, please consult your API logs for further information';
Expand All @@ -556,3 +556,6 @@
$string['receipt_instructor_copy_subject'] = 'Submission made to assignment';
$string['instructorreceipt'] = 'Notify Instructor upon Submission';
$string['instructorreceipt_desc'] = 'Choose whether to send a notification to each instructor on a course when a submission is made to an assignment.';
$string['errorcode8'] = 'This file has not been submitted to Turnitin because there is a problem creating the temp file. The most likely cause is an invalid file name. Please rename the file and re-upload using Edit Submission.';
$string['errorcode9'] = 'The file cannot be submitted as there is no accessible content in the file pool to submit.';
$string['loadingdv'] = 'Loading Turnitin Document Viewer...';
16 changes: 16 additions & 0 deletions pix/tiiIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions turnitintooltwo_view.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function load_page_components($hidebg = false) {
$PAGE->requires->string_for_js('maxmarkserror', 'turnitintooltwo');
$PAGE->requires->string_for_js('disableanonconfirm', 'turnitintooltwo');
$PAGE->requires->string_for_js('closebutton', 'turnitintooltwo');
$PAGE->requires->string_for_js('loadingdv', 'turnitintooltwo');
}

/**
Expand Down Expand Up @@ -539,7 +540,7 @@ public function init_submission_inbox($cm, $turnitintooltwoassignment, $partdeta
if ($tab_position) {
$output .= html_writer::tag('div', $tab_position, array('id' => 'tab_position', 'class' => 'hidden_class'));
}

foreach ($partdetails as $partid => $partobject) {
if (!empty($partid)) {
$i++;
Expand Down Expand Up @@ -651,7 +652,7 @@ public function init_submission_inbox($cm, $turnitintooltwoassignment, $partdeta
if ($turnitintooltwouser->get_user_role() == 'Instructor') {
$emailnonsubmitters = html_writer::link($CFG->wwwroot.'/mod/turnitintooltwo/view.php?id='.$cm->id.
'&part='.$partid.'&do=emailnonsubmittersform&view_context=box_solid',
html_writer::tag('i', '', array('class' => 'fa fa-reply-all fa-lg')).' '.get_string('emailnonsubmitters', 'turnitintooltwo'),
html_writer::tag('i', '', array('class' => 'fa fa-reply-all fa-lg')).' '.get_string('messagenonsubmitters', 'turnitintooltwo'),
array("class" => "nonsubmitters_link", "id" => "nonsubmitters_".$partid));
}

Expand Down Expand Up @@ -1246,7 +1247,7 @@ public function get_submission_inbox_row($cm, $turnitintooltwoassignment, $parts
$grade .= $OUTPUT->box(html_writer::tag('span', $submissiongrade, array("class" => "grade"))
, 'grademark_grade');
}

// Put in div placeholder for DV launch form.
$grade .= $OUTPUT->box('', 'launch_form', 'grademark_form_'.$submission->submission_objectid);
// URL for DV launcher
Expand Down Expand Up @@ -1524,10 +1525,10 @@ public static function output_dv_launch_form($type, $submissionid, $userid, $use
$lti->setUserId($userid);
$lti->setRole($userrole);
$lti->setButtonText($buttonstring);
$lti->setFormTarget('');

switch ($type) {
case "useragreement":
$lti->setFormTarget('');
$ltifunction = "outputUserAgreementForm";
break;

Expand All @@ -1536,17 +1537,14 @@ public static function output_dv_launch_form($type, $submissionid, $userid, $use
break;

case "default":
$lti->setFormTarget("dvWindow");
$ltifunction = "outputDVDefaultForm";
break;

case "origreport":
$lti->setFormTarget("dvWindow");
$ltifunction = "outputDVReportForm";
break;

case "grademark":
$lti->setFormTarget("dvWindow");
$ltifunction = "outputDVGradeMarkForm";
break;
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$plugin = new StdClass();
}

$plugin->version = 2016011101;
$plugin->version = 2016011102;
$plugin->release = "2.6+";
$plugin->requires = 2013111800;
$plugin->component = 'mod_turnitintooltwo';
Expand Down

0 comments on commit 57446fb

Please sign in to comment.