@oat-sa/tao-test-runner-qti
Version:
TAO Test Runner QTI implementation
111 lines (97 loc) • 3.54 kB
JavaScript
/**
* This program 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; under version 2
* of the License (non-upgradable).
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016 (original work) Open Assessment Technologies SA ;
*/
/**
* Test Runner Content Plugin : Feedback
*
* @author Bertrand Chevrier <bertrand@taotesting.com>
*/
import __ from 'i18n';
import pluginFactory from 'taoTests/runner/plugin';
import feedback from 'ui/feedback';
/**
* Returns the configured plugin
*/
export default pluginFactory({
name: 'feedback',
/**
* Initialize the plugin (called during runner's init)
*/
init: function init() {
var self = this;
//keep a ref of the feedbacks
var currentFeedback;
var testRunner = this.getTestRunner();
/**
* Close the current feedback
*/
var closeCurrent = function closeCurrent() {
if (currentFeedback) {
currentFeedback.close();
}
};
this.setState('enabled', true);
//change plugin state
testRunner
.on('error', function(err) {
var message = err;
var type = 'error';
if (self.getState('enabled')) {
if ('object' === typeof err) {
message = err.message;
type = err.type;
}
if (!message) {
switch (type) {
case 'TestState':
message = __('The test has been closed/suspended!');
break;
case 'FileNotFound':
message = __('File not found!');
break;
default:
message = __('An error occurred!');
}
}
currentFeedback = feedback().error(message);
}
})
.on('danger', function(message) {
if (self.getState('enabled')) {
currentFeedback = feedback().danger(message);
}
})
.on('warning', function(message) {
if (self.getState('enabled')) {
currentFeedback = feedback().warning(message);
}
})
.on('info', function(message) {
if (self.getState('enabled')) {
currentFeedback = feedback().info(message);
}
})
.on('alert.* confirm.* unloaditem', closeCurrent)
.on('disablefeedbackalerts', function() {
closeCurrent();
self.setState('enabled', false);
})
.on('enablefeedbackalerts', function() {
self.setState('enabled', true);
});
}
});