@oat-sa/tao-test-runner-qti
Version:
TAO Test Runner QTI implementation
97 lines (88 loc) • 3.52 kB
JavaScript
define(['i18n', 'taoTests/runner/plugin', 'ui/feedback'], function (__, pluginFactory, feedback$1) { 'use strict';
__ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
pluginFactory = pluginFactory && Object.prototype.hasOwnProperty.call(pluginFactory, 'default') ? pluginFactory['default'] : pluginFactory;
feedback$1 = feedback$1 && Object.prototype.hasOwnProperty.call(feedback$1, 'default') ? feedback$1['default'] : feedback$1;
/**
* 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 ;
*/
/**
* Returns the configured plugin
*/
var feedback = 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$1().error(message);
}
}).on('danger', function (message) {
if (self.getState('enabled')) {
currentFeedback = feedback$1().danger(message);
}
}).on('warning', function (message) {
if (self.getState('enabled')) {
currentFeedback = feedback$1().warning(message);
}
}).on('info', function (message) {
if (self.getState('enabled')) {
currentFeedback = feedback$1().info(message);
}
}).on('alert.* confirm.* unloaditem', closeCurrent).on('disablefeedbackalerts', function () {
closeCurrent();
self.setState('enabled', false);
}).on('enablefeedbackalerts', function () {
self.setState('enabled', true);
});
}
});
return feedback;
});