Merge branch 'MDL-42028-master-4' of git://github.com/mouneyrac/moodle

This commit is contained in:
Marina Glancy 2013-10-28 16:56:45 +11:00
commit 5ea6d66e9f
12 changed files with 496 additions and 45 deletions

View File

@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Process concurrent ajax request.
* ALL RETURNED INFO IS PUBLIC.
*
* @package assignfeedback_editpdf
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
// To be able to process concurrent ajax request with the generate pdf ajax request we can not use cookie.
define('NO_MOODLE_COOKIES', true);
use \assignfeedback_editpdf\document_services;
require_once('../../../../config.php');
try {
$assignmentid = required_param('assignmentid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$attemptnumber = required_param('attemptnumber', PARAM_INT);
// Retrieve the assignments.
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
$assignment = new assign($context, null, null);
// Get the generated images from file API call.
$grade = $assignment->get_user_grade($userid, false, $attemptnumber);
// Check we found a grade.
if (empty($grade)) {
throw new coding_exception('grade not found');
}
$component = 'assignfeedback_editpdf';
$filearea = document_services::PAGE_IMAGE_FILEAREA;
$filepath = '/';
$fs = get_file_storage();
$files = $fs->get_directory_files($context->id, $component, $filearea, $grade->id, $filepath);
// The important security part: we ONLY RETURN the total NUMBER of generated images.
echo $OUTPUT->header();
echo json_encode(count($files));
echo $OUTPUT->footer();
} catch (Exception $e) {
// This should never happened!
// Return a 500 HTTP header so Y.io gets it as a failure.
if (substr(php_sapi_name(), 0, 3) == 'cgi') {
header("Status: 500 Internal Server Error");
} else {
header('HTTP/1.0 500 Internal Server Error');
}
throw new moodle_exception('An exception was caught but can not be returned for security purpose.
To easily debug, comment the try catch.');
}

View File

@ -242,6 +242,47 @@ class document_services {
return $file;
}
/**
* This function will return the number of pages of a pdf.
* @param int|\assign $assignment
* @param int $userid
* @param int $attemptnumber (-1 means latest attempt)
* @return int number of pages
*/
public static function page_number_for_attempt($assignment, $userid, $attemptnumber) {
global $CFG;
require_once($CFG->libdir . '/pdflib.php');
$assignment = self::get_assignment_from_param($assignment);
if (!$assignment->can_view_submission($userid)) {
\print_error('nopermission');
}
// Get a combined pdf file from all submitted pdf files.
$file = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
if (!$file) {
\print_error('Could not generate combined pdf.');
}
// Store the combined pdf file somewhere to be opened by tcpdf.
$tmpdir = \make_temp_directory('assignfeedback_editpdf/pagetotal/'
. self::hash($assignment, $userid, $attemptnumber));
$combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME;
$file->copy_content_to($combined); // Copy the file.
// Get the total number of pages.
$pdf = new pdf();
$pagecount = $pdf->set_pdf($combined);
// Delete temporary folders and files.
@unlink($combined);
@rmdir($tmpdir);
return $pagecount;
}
/**
* This function will generate and return a list of the page images from a pdf.
* @param int|\assign $assignment
@ -263,7 +304,7 @@ class document_services {
// Need to generate the page images - first get a combined pdf.
$file = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
if (!$file) {
throw \moodle_exception('Could not generate combined pdf.');
throw new \moodle_exception('Could not generate combined pdf.');
}
$tmpdir = \make_temp_directory('assignfeedback_editpdf/pageimages/' . self::hash($assignment, $userid, $attemptnumber));
@ -275,14 +316,8 @@ class document_services {
$pdf->set_image_folder($tmpdir);
$pagecount = $pdf->set_pdf($combined);
$i = 0;
$images = array();
for ($i = 0; $i < $pagecount; $i++) {
$images[$i] = $pdf->get_image($i);
}
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
$files = array();
$record = new \stdClass();
$record->contextid = $assignment->get_context()->id;
$record->component = 'assignfeedback_editpdf';
@ -291,11 +326,14 @@ class document_services {
$record->filepath = '/';
$fs = \get_file_storage();
foreach ($images as $index => $image) {
$files = array();
for ($i = 0; $i < $pagecount; $i++) {
$image = $pdf->get_image($i);
$record->filename = basename($image);
$files[$index] = $fs->create_file_from_pathname($record, $tmpdir . '/' . $image);
$files[$i] = $fs->create_file_from_pathname($record, $tmpdir . '/' . $image);
@unlink($tmpdir . '/' . $image);
}
@unlink($combined);
@rmdir($tmpdir);
@ -407,7 +445,7 @@ class document_services {
// Need to generate the page images - first get a combined pdf.
$file = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
if (!$file) {
throw \moodle_exception('Could not generate combined pdf.');
throw new \moodle_exception('Could not generate combined pdf.');
}
$tmpdir = \make_temp_directory('assignfeedback_editpdf/final/' . self::hash($assignment, $userid, $attemptnumber));

View File

@ -198,7 +198,16 @@ class assignfeedback_editpdf_renderer extends plugin_renderer_base {
'pageheader');
$body = $pageheader;
$loading = $this->pix_icon('i/loading', get_string('loadingeditor', 'assignfeedback_editpdf'), 'moodle', array('class'=>'loading'));
// Loading progress bar.
$progressbar = html_writer::div('', 'bar', array('style' => 'width: 0%'));
$progressbar = html_writer::div($progressbar, 'progress progress-info progress-striped active',
array('title' => get_string('loadingeditor', 'assignfeedback_editpdf'),
'role'=> 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0,
'aria-valuemax' => 100));
$progressbarlabel = html_writer::div(get_string('generatingpdf', 'assignfeedback_editpdf'),
'progressbarlabel');
$loading = html_writer::div($progressbar . $progressbarlabel, 'loading');
$canvas = html_writer::div($loading, 'drawingcanvas');
$body .= html_writer::div($canvas, 'drawingregion');
@ -214,7 +223,8 @@ class assignfeedback_editpdf_renderer extends plugin_renderer_base {
'userid'=>$widget->userid,
'attemptnumber'=>$widget->attemptnumber,
'stampfiles'=>$widget->stampfiles,
'readonly'=>$widget->readonly));
'readonly'=>$widget->readonly,
'pagetotal'=>$widget->pagetotal));
$this->page->requires->yui_module('moodle-assignfeedback_editpdf-editor',
'M.assignfeedback_editpdf.editor.init',

View File

@ -47,6 +47,8 @@ class assignfeedback_editpdf_widget implements renderable {
public $stampfiles = array();
/** @var bool $readonly */
public $readonly = true;
/** @var integer $pagetotal */
public $pagetotal = 0;
/**
* Constructor
@ -57,8 +59,10 @@ class assignfeedback_editpdf_widget implements renderable {
* @param string $downloadfilename - Name of the generated pdf.
* @param string[] $stampfiles - The file names of the stamps.
* @param bool $readonly - Show the readonly interface (no tools).
* @param integer $pagetotal - The total number of pages.
*/
public function __construct($assignment, $userid, $attemptnumber, $downloadurl, $downloadfilename, $stampfiles, $readonly) {
public function __construct($assignment, $userid, $attemptnumber, $downloadurl,
$downloadfilename, $stampfiles, $readonly, $pagetotal) {
$this->assignment = $assignment;
$this->userid = $userid;
$this->attemptnumber = $attemptnumber;
@ -66,5 +70,6 @@ class assignfeedback_editpdf_widget implements renderable {
$this->downloadfilename = $downloadfilename;
$this->stampfiles = $stampfiles;
$this->readonly = $readonly;
$this->pagetotal = $pagetotal;
}
}

View File

@ -66,6 +66,7 @@ $string['pagenumber'] = 'Page {$a}';
$string['pagexofy'] = 'Page {$a->page} of {$a->total}';
$string['pen'] = 'Pen';
$string['pluginname'] = 'Annotate PDF';
$string['generatingpdf'] = 'Generating the PDF...';
$string['rectangle'] = 'Rectangle';
$string['red'] = 'Red';
$string['result'] = 'Result:';

View File

@ -131,6 +131,10 @@ class assign_feedback_editpdf extends assign_feedback_plugin {
$filename = $feedbackfile->get_filename();
}
// Retrieve total number of pages.
$pagetotal = document_services::page_number_for_attempt($this->assignment->get_instance()->id,
$userid,
$attempt);
$widget = new assignfeedback_editpdf_widget($this->assignment->get_instance()->id,
$userid,
@ -138,7 +142,8 @@ class assign_feedback_editpdf extends assign_feedback_plugin {
$url,
$filename,
$stampfiles,
$readonly);
$readonly,
$pagetotal);
return $widget;
}

View File

@ -240,3 +240,131 @@ ul.assignfeedback_editpdf_menu {
padding-left: 20px;
padding-right: 4px;
}
.assignfeedback_editpdf_widget .drawingcanvas .loading .progressbarlabel {
text-align: center;
}
/**
* Bootstrap 2.3.2 progress bar css.
* Required for none bootstrap theme.
*/
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 40px 0;
}
to {
background-position: 0 0;
}
}
@-moz-keyframes progress-bar-stripes {
from {
background-position: 40px 0;
}
to {
background-position: 0 0;
}
}
@-ms-keyframes progress-bar-stripes {
from {
background-position: 40px 0;
}
to {
background-position: 0 0;
}
}
@-o-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
@keyframes progress-bar-stripes {
from {
background-position: 40px 0;
}
to {
background-position: 0 0;
}
}
.progress {
height: 20px;
margin-bottom: 20px;
overflow: hidden;
background-color: #f7f7f7;
background-image: -moz-linear-gradient(top, #f5f5f5, #f9f9f9);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#f5f5f5), to(#f9f9f9));
background-image: -webkit-linear-gradient(top, #f5f5f5, #f9f9f9);
background-image: -o-linear-gradient(top, #f5f5f5, #f9f9f9);
background-image: linear-gradient(to bottom, #f5f5f5, #f9f9f9);
background-repeat: repeat-x;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#fff9f9f9', GradientType=0);
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
.progress .bar {
float: left;
width: 0;
height: 100%;
font-size: 12px;
color: #ffffff;
text-align: center;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background-color: #0e90d2;
background-image: -moz-linear-gradient(top, #149bdf, #0480be);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#149bdf), to(#0480be));
background-image: -webkit-linear-gradient(top, #149bdf, #0480be);
background-image: -o-linear-gradient(top, #149bdf, #0480be);
background-image: linear-gradient(to bottom, #149bdf, #0480be);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf', endColorstr='#ff0480be', GradientType=0);
-webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
-moz-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: width 0.6s ease;
-moz-transition: width 0.6s ease;
-o-transition: width 0.6s ease;
transition: width 0.6s ease;
}
.progress .bar + .bar {
-webkit-box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.15);
-moz-box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.15);
box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.15);
}
.progress-striped .bar {
background-color: #149bdf;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
-webkit-background-size: 40px 40px;
-moz-background-size: 40px 40px;
-o-background-size: 40px 40px;
background-size: 40px 40px;
}
.progress.active .bar {
-webkit-animation: progress-bar-stripes 2s linear infinite;
-moz-animation: progress-bar-stripes 2s linear infinite;
-ms-animation: progress-bar-stripes 2s linear infinite;
-o-animation: progress-bar-stripes 2s linear infinite;
animation: progress-bar-stripes 2s linear infinite;
}

View File

@ -21,6 +21,7 @@ YUI.add('moodle-assignfeedback_editpdf-editor', function (Y, NAME) {
* @module moodle-assignfeedback_editpdf-editor
*/
var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
AJAXBASEPROGRESS = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax_progress.php',
CSS = {
DIALOGUE : 'assignfeedback_editpdf_widget'
},
@ -32,6 +33,7 @@ var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
SEARCHCOMMENTSLIST : '.assignfeedback_editpdf_commentsearch ul',
PAGESELECT : '.' + CSS.DIALOGUE + ' .navigate-page-select',
LOADINGICON : '.' + CSS.DIALOGUE + ' .loading',
PROGRESSBARCONTAINER : '.' + CSS.DIALOGUE + ' .progress-info.progress-striped',
DRAWINGREGION : '.' + CSS.DIALOGUE + ' .drawingregion',
DRAWINGCANVAS : '.' + CSS.DIALOGUE + ' .drawingcanvas',
SAVE : '.' + CSS.DIALOGUE + ' .savebutton',
@ -3122,30 +3124,88 @@ EDITOR.prototype = {
*/
load_all_pages : function() {
var ajaxurl = AJAXBASE,
config;
config,
checkconversionstatus,
ajax_error_total;
config = {
method: 'get',
context: this,
sync: false,
data : {
'sesskey' : M.cfg.sesskey,
'action' : 'loadallpages',
'userid' : this.get('userid'),
'attemptnumber' : this.get('attemptnumber'),
'assignmentid' : this.get('assignmentid')
sesskey : M.cfg.sesskey,
action : 'loadallpages',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
this.all_pages_loaded(response.responseText);
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
// If pages are not loaded, check PDF conversion status for the progress bar.
if (this.pagecount <= 0) {
checkconversionstatus = {
method: 'get',
context: this,
sync: false,
data : {
sesskey : M.cfg.sesskey,
action : 'conversionstatus',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
ajax_error_total = 0;
if (this.pagecount === 0) {
var pagetotal = this.get('pagetotal');
// Update the progress bar.
var progressbarcontainer = Y.one(SELECTOR.PROGRESSBARCONTAINER);
var progressbar = progressbarcontainer.one('.bar');
if (progressbar) {
// Calculate progress.
var progress = (response.response / pagetotal) * 100;
progressbar.setStyle('width', progress + '%');
progressbarcontainer.setAttribute('aria-valuenow', progress);
}
// New ajax request delayed of a second.
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
failure: function(tid, response) {
ajax_error_total = ajax_error_total + 1;
// We only continue on error if the all pages were not generated,
// and if the ajax call did not produce 5 errors in the row.
if (this.pagecount === 0 && ajax_error_total < 5) {
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
return new M.core.exception(response.responseText);
}
}
};
// We start the AJAX "generated page total number" call a second later to give a chance to
// the AJAX "combined pdf generation" call to clean the previous submission images.
Y.later(1000, this, function () {
ajax_error_total = 0;
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
/**
@ -3612,7 +3672,7 @@ EDITOR.prototype = {
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
@ -3807,6 +3867,10 @@ Y.extend(EDITOR, Y.Base, EDITOR.prototype, {
stampfiles : {
validator : Y.Lang.isArray,
value : ''
},
pagetotal : {
validator : Y.Lang.isInteger,
value : 0
}
}
});

View File

@ -21,6 +21,7 @@ YUI.add('moodle-assignfeedback_editpdf-editor', function (Y, NAME) {
* @module moodle-assignfeedback_editpdf-editor
*/
var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
AJAXBASEPROGRESS = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax_progress.php',
CSS = {
DIALOGUE : 'assignfeedback_editpdf_widget'
},
@ -32,6 +33,7 @@ var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
SEARCHCOMMENTSLIST : '.assignfeedback_editpdf_commentsearch ul',
PAGESELECT : '.' + CSS.DIALOGUE + ' .navigate-page-select',
LOADINGICON : '.' + CSS.DIALOGUE + ' .loading',
PROGRESSBARCONTAINER : '.' + CSS.DIALOGUE + ' .progress-info.progress-striped',
DRAWINGREGION : '.' + CSS.DIALOGUE + ' .drawingregion',
DRAWINGCANVAS : '.' + CSS.DIALOGUE + ' .drawingcanvas',
SAVE : '.' + CSS.DIALOGUE + ' .savebutton',
@ -3122,30 +3124,88 @@ EDITOR.prototype = {
*/
load_all_pages : function() {
var ajaxurl = AJAXBASE,
config;
config,
checkconversionstatus,
ajax_error_total;
config = {
method: 'get',
context: this,
sync: false,
data : {
'sesskey' : M.cfg.sesskey,
'action' : 'loadallpages',
'userid' : this.get('userid'),
'attemptnumber' : this.get('attemptnumber'),
'assignmentid' : this.get('assignmentid')
sesskey : M.cfg.sesskey,
action : 'loadallpages',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
this.all_pages_loaded(response.responseText);
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
// If pages are not loaded, check PDF conversion status for the progress bar.
if (this.pagecount <= 0) {
checkconversionstatus = {
method: 'get',
context: this,
sync: false,
data : {
sesskey : M.cfg.sesskey,
action : 'conversionstatus',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
ajax_error_total = 0;
if (this.pagecount === 0) {
var pagetotal = this.get('pagetotal');
// Update the progress bar.
var progressbarcontainer = Y.one(SELECTOR.PROGRESSBARCONTAINER);
var progressbar = progressbarcontainer.one('.bar');
if (progressbar) {
// Calculate progress.
var progress = (response.response / pagetotal) * 100;
progressbar.setStyle('width', progress + '%');
progressbarcontainer.setAttribute('aria-valuenow', progress);
}
// New ajax request delayed of a second.
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
failure: function(tid, response) {
ajax_error_total = ajax_error_total + 1;
// We only continue on error if the all pages were not generated,
// and if the ajax call did not produce 5 errors in the row.
if (this.pagecount === 0 && ajax_error_total < 5) {
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
return new M.core.exception(response.responseText);
}
}
};
// We start the AJAX "generated page total number" call a second later to give a chance to
// the AJAX "combined pdf generation" call to clean the previous submission images.
Y.later(1000, this, function () {
ajax_error_total = 0;
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
/**
@ -3612,7 +3672,7 @@ EDITOR.prototype = {
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
@ -3807,6 +3867,10 @@ Y.extend(EDITOR, Y.Base, EDITOR.prototype, {
stampfiles : {
validator : Y.Lang.isArray,
value : ''
},
pagetotal : {
validator : Y.Lang.isInteger,
value : 0
}
}
});

View File

@ -311,30 +311,88 @@ EDITOR.prototype = {
*/
load_all_pages : function() {
var ajaxurl = AJAXBASE,
config;
config,
checkconversionstatus,
ajax_error_total;
config = {
method: 'get',
context: this,
sync: false,
data : {
'sesskey' : M.cfg.sesskey,
'action' : 'loadallpages',
'userid' : this.get('userid'),
'attemptnumber' : this.get('attemptnumber'),
'assignmentid' : this.get('assignmentid')
sesskey : M.cfg.sesskey,
action : 'loadallpages',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
this.all_pages_loaded(response.responseText);
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
// If pages are not loaded, check PDF conversion status for the progress bar.
if (this.pagecount <= 0) {
checkconversionstatus = {
method: 'get',
context: this,
sync: false,
data : {
sesskey : M.cfg.sesskey,
action : 'conversionstatus',
userid : this.get('userid'),
attemptnumber : this.get('attemptnumber'),
assignmentid : this.get('assignmentid')
},
on: {
success: function(tid, response) {
ajax_error_total = 0;
if (this.pagecount === 0) {
var pagetotal = this.get('pagetotal');
// Update the progress bar.
var progressbarcontainer = Y.one(SELECTOR.PROGRESSBARCONTAINER);
var progressbar = progressbarcontainer.one('.bar');
if (progressbar) {
// Calculate progress.
var progress = (response.response / pagetotal) * 100;
progressbar.setStyle('width', progress + '%');
progressbarcontainer.setAttribute('aria-valuenow', progress);
}
// New ajax request delayed of a second.
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
failure: function(tid, response) {
ajax_error_total = ajax_error_total + 1;
// We only continue on error if the all pages were not generated,
// and if the ajax call did not produce 5 errors in the row.
if (this.pagecount === 0 && ajax_error_total < 5) {
Y.later(1000, this, function () {
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
return new M.core.exception(response.responseText);
}
}
};
// We start the AJAX "generated page total number" call a second later to give a chance to
// the AJAX "combined pdf generation" call to clean the previous submission images.
Y.later(1000, this, function () {
ajax_error_total = 0;
Y.io(AJAXBASEPROGRESS, checkconversionstatus);
});
}
},
/**
@ -801,7 +859,7 @@ EDITOR.prototype = {
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
return new M.core.exception(response.responseText);
}
}
};
@ -996,6 +1054,10 @@ Y.extend(EDITOR, Y.Base, EDITOR.prototype, {
stampfiles : {
validator : Y.Lang.isArray,
value : ''
},
pagetotal : {
validator : Y.Lang.isInteger,
value : 0
}
}
});

View File

@ -19,6 +19,7 @@
* @module moodle-assignfeedback_editpdf-editor
*/
var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
AJAXBASEPROGRESS = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax_progress.php',
CSS = {
DIALOGUE : 'assignfeedback_editpdf_widget'
},
@ -30,6 +31,7 @@ var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
SEARCHCOMMENTSLIST : '.assignfeedback_editpdf_commentsearch ul',
PAGESELECT : '.' + CSS.DIALOGUE + ' .navigate-page-select',
LOADINGICON : '.' + CSS.DIALOGUE + ' .loading',
PROGRESSBARCONTAINER : '.' + CSS.DIALOGUE + ' .progress-info.progress-striped',
DRAWINGREGION : '.' + CSS.DIALOGUE + ' .drawingregion',
DRAWINGCANVAS : '.' + CSS.DIALOGUE + ' .drawingcanvas',
SAVE : '.' + CSS.DIALOGUE + ' .savebutton',