Skip to content

Commit

Permalink
MDL-60008 assign: Info messages
Browse files Browse the repository at this point in the history
Better support for information messages from the conversion process.
  • Loading branch information
Damyon Wiese committed Dec 6, 2018
1 parent 86c5770 commit e3511e7
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 90 deletions.
16 changes: 8 additions & 8 deletions mod/assign/feedback/editpdf/classes/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widg

$canvas = html_writer::div($loading, 'drawingcanvas');
$canvas = html_writer::div($canvas, 'drawingregion');
$changesmessage = html_writer::tag('div',
get_string('draftchangessaved', 'assignfeedback_editpdf'),
array(
'class' => 'assignfeedback_editpdf_unsavedchanges warning label label-info'
));

$changesmessage = html_writer::div($changesmessage, 'unsaved-changes');
// Place for messages, but no warnings displayed yet.
$changesmessage = html_writer::div('', 'warningmessages');
$canvas .= $changesmessage;

$infoicon = $this->image_icon('i/info', '');
$infomessage = html_writer::div($infoicon, 'infoicon');
$canvas .= $infomessage;

$body .= $canvas;

$footer = '';
Expand Down Expand Up @@ -269,7 +268,8 @@ public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widg
'stamppicker',
'cannotopenpdf',
'pagenumber',
'partialwarning'
'partialwarning',
'draftchangessaved'
), 'assignfeedback_editpdf');

return $html;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
$string['pagenumber'] = 'Page {$a}';
$string['pagexofy'] = 'Page {$a->page} of {$a->total}';
$string['pen'] = 'Pen';
$string['partialwarning'] = 'Some of the submission files must be downloaded.';
$string['partialwarning'] = 'Some of the files in this submission can only be accessed by direct download.';
$string['pluginname'] = 'Annotate PDF';
$string['privacy:metadata:colourpurpose'] = 'Colour of the comment or annotation';
$string['privacy:metadata:conversionpurpose'] = 'Files are converted to PDFs to allow for annotations.';
Expand Down
22 changes: 11 additions & 11 deletions mod/assign/feedback/editpdf/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
cursor: move;
}

.assignfeedback_editpdf_widget .infoicon {
display: none;
}

.assignfeedback_editpdf_widget .warningmessages {
position: absolute;
margin-left: 20px;
margin-right: 20px;
bottom: 20px;
}

.assignfeedback_editpdf_widget .drawingregion {
border: 1px solid #ccc;
left: 1em;
Expand Down Expand Up @@ -59,17 +70,6 @@
padding: 0;
}

.assignfeedback_editpdf_widget .assignfeedback_editpdf_unsavedchanges.haschanges {
display: inline-block;
}

.assignfeedback_editpdf_widget .assignfeedback_editpdf_unsavedchanges {
display: none;
position: absolute;
left: 20px;
top: 120px;
}

.yui3-colourpicker-hidden,
.yui3-commentsearch-hidden,
.yui3-commentmenu-hidden {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdf/ajax.php',
COMMENTMENU: '.commentdrawable a',
ANNOTATIONCOLOURBUTTON: '.annotationcolourbutton',
DELETEANNOTATIONBUTTON: '.deleteannotationbutton',
UNSAVEDCHANGESDIV: '.assignfeedback_editpdf_unsavedchanges',
WARNINGMESSAGECONTAINER: '.warningmessages',
ICONMESSAGECONTAINER: '.infoicon',
UNSAVEDCHANGESDIV: '.assignfeedback_editpdf_warningmessages',
UNSAVEDCHANGESINPUT: 'input[name="assignfeedback_editpdf_haschanges"]',
STAMPSBUTTON: '.currentstampbutton',
DIALOGUE: '.' + CSS.DIALOGUE
Expand Down Expand Up @@ -3756,7 +3758,7 @@ EDITOR.prototype = {
// The combined document is still waiting for input to be ready.
poll = true;

} else if (data.status === 1) {
} else if (data.status === 1 || data.status === 3) {
// The combine document is ready for conversion into a single PDF.
poll = true;

Expand Down Expand Up @@ -3833,15 +3835,41 @@ EDITOR.prototype = {
* Display an error in a small part of the page (don't block everything).
*
* @param string The error text.
* @param boolean dismissable Not critical messages can be removed after a short display.
* @protected
* @method warning
*/
warning: function(message) {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
warning: function(message, dismissable) {
var icontemplate = this.get_dialogue_element(SELECTOR.ICONMESSAGECONTAINER);
var warningregion = this.get_dialogue_element(SELECTOR.WARNINGMESSAGECONTAINER);
var delay = 15, duration = 1;
var messageclasses = 'assignfeedback_editpdf_warningmessages alert alert-warning';
if (dismissable) {
delay = 4;
messageclasses = 'assignfeedback_editpdf_warningmessages alert alert-info';
}
var warningelement = Y.Node.create('<div class="' + messageclasses + '" role="alert"></div>');

// Copy info icon template.
warningelement.append(icontemplate.one('*').cloneNode());

// Append the message.
warningelement.append(message);

// Add the entire warning to the container.
warningregion.prepend(warningelement);

var warningelement = Y.Node.create('<div class="alert alert-warning" role="alert"></div>');
warningelement.setHTML(message);
drawingregion.prepend(warningelement);
// Remove the message after a short delay.
warningelement.transition(
{
duration: duration,
delay: delay,
opacity: 0
},
function() {
warningelement.remove();
}
);
},

/**
Expand Down Expand Up @@ -3887,7 +3915,7 @@ EDITOR.prototype = {
readonly = this.get('readonly');
if (!readonly && data.partial) {
// Warn about non converted files, but only for teachers.
this.warning(M.util.get_string('partialwarning', 'assignfeedback_editpdf'));
this.warning(M.util.get_string('partialwarning', 'assignfeedback_editpdf'), false);
}

// Update the ui.
Expand Down Expand Up @@ -4476,6 +4504,7 @@ EDITOR.prototype = {
* @method save_current_page
*/
save_current_page: function() {
this.clear_warnings(false);
if (this.get('destroyed')) {
return;
}
Expand Down Expand Up @@ -4503,16 +4532,9 @@ EDITOR.prototype = {
if (jsondata.error) {
return new M.core.ajaxException(jsondata);
}
// Show warning that we have not saved the feedback.
Y.one(SELECTOR.UNSAVEDCHANGESINPUT).set('value', 'true');
Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('opacity', 1);
Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('display', 'inline-block');
Y.one(SELECTOR.UNSAVEDCHANGESDIV).transition({
duration: 1,
delay: 2,
opacity: 0
}, function() {
Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('display', 'none');
});
this.warning(M.util.get_string('draftchangessaved', 'assignfeedback_editpdf'), true);
} catch (e) {
return new M.core.exception(e);
}
Expand Down Expand Up @@ -4587,6 +4609,22 @@ EDITOR.prototype = {
}
},

/**
* Clear all current warning messages from display.
* @protected
* @method clear_warnings
* @param {Boolean} allwarnings If true, all previous warnings are removed.
*/
clear_warnings: function(allwarnings) {
// Remove all warning messages, they may not relate to the current document or page anymore.
var warningregion = this.get_dialogue_element(SELECTOR.WARNINGMESSAGECONTAINER);
if (allwarnings) {
warningregion.empty();
} else {
warningregion.all('.alert-info').remove(true);
}
},

/**
* Load the image for this pdf page and remove the loading icon (if there).
* @protected
Expand Down Expand Up @@ -4653,6 +4691,7 @@ EDITOR.prototype = {
pageselect.removeAttribute('disabled');
pageselect.on('change', function() {
this.currentpage = pageselect.get('value');
this.clear_warnings(false);
this.change_page();
}, this);

Expand All @@ -4676,6 +4715,7 @@ EDITOR.prototype = {
if (this.currentpage < 0) {
this.currentpage = 0;
}
this.clear_warnings(false);
this.change_page();
},

Expand All @@ -4690,6 +4730,7 @@ EDITOR.prototype = {
if (this.currentpage >= this.pages.length) {
this.currentpage = this.pages.length - 1;
}
this.clear_warnings(false);
this.change_page();
},

Expand Down
Loading

0 comments on commit e3511e7

Please sign in to comment.