UNPKG

@oat-sa/tao-test-runner-qti

Version:
87 lines (79 loc) 3.54 kB
define(['jquery', 'i18n', 'taoTests/runner/plugin', 'handlebars', 'lib/handlebars/helpers'], function ($$1, __, pluginFactory, Handlebars, Helpers0) { 'use strict'; $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1; __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __; pluginFactory = pluginFactory && Object.prototype.hasOwnProperty.call(pluginFactory, 'default') ? pluginFactory['default'] : pluginFactory; Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars; Helpers0 = Helpers0 && Object.prototype.hasOwnProperty.call(Helpers0, 'default') ? Helpers0['default'] : Helpers0; if (!Helpers0.__initialized) { Helpers0(Handlebars); Helpers0.__initialized = true; } var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { this.compilerInfo = [4,'>= 1.0.0']; helpers = this.merge(helpers, Handlebars.helpers); return "<span data-control=\"qti-test-item-title\"></span>\n<span data-control=\"qti-test-item-state\"></span>\n"; }); function headerTpl(data, options, asString) { var html = Template(data, options); return (asString || true) ? html : $(html); } /** * 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) 2020 (original work) Open Assessment Technologies SA ; */ function getState(item) { let state = __('Unseen'); if (item.flagged) { state = __('Flagged'); } else if (item.answered) { state = __('Answered'); } else if (item.viewed) { state = __('Viewed'); } return state; } var header = pluginFactory({ name: 'mainLandmark', init() { const testRunner = this.getTestRunner(); const updateTitle = item => { this.$title.text(`${item.label}`).show(); }; const updateState = item => { this.$state.text(`${getState(item)}`).show(); }; testRunner.after('renderitem', () => { const item = testRunner.getCurrentItem(); updateTitle(item); updateState(item); }).on('tool-flagitem', () => { let item = testRunner.getCurrentItem(); item = Object.assign({}, item, { flagged: !item.flagged }); updateState(item); }); }, render() { const $container = this.getAreaBroker().getArea('mainLandmark'); this.$element = $$1(headerTpl()); $container.append(this.$element); this.$title = $container.find(`[data-control="qti-test-item-title"]`); this.$state = $container.find(`[data-control="qti-test-item-state"]`); } }); return header; });