blob: 1eadf8d9ddd01a3148dedba219c9e3c448821065 [file] [log] [blame]
hebasta393829f2020-03-09 12:37:29 +01001/**
2 * Export Demo
3 *
hebasta40a85cf2020-07-15 18:10:08 +02004 * @author Helge
hebasta393829f2020-03-09 12:37:29 +01005 *
6 */
7
8requirejs.config({
9 baseUrl: '../js/src',
10 paths : {
11 'lib': '../lib'
12 }
13});
14
hebasta40a85cf2020-07-15 18:10:08 +020015require([ 'plugin/server', 'panel/result', 'init' ], function(pluginClass, resultPanelClass) {
hebasta393829f2020-03-09 12:37:29 +010016
17 KorAP.Plugin = pluginClass.create();
18
19 // Add services container to head
20 document.head.appendChild(KorAP.Plugin.element());
hebasta393829f2020-03-09 12:37:29 +010021
hebasta40a85cf2020-07-15 18:10:08 +020022 // Register result plugin
23 KorAP.Plugin.register({
24 'name' : 'Export',
25 'desc' : 'Exports Kalamar results',
26 // 'about' : 'https://localhost:5678/',
27 'embed' : [ {
28 'panel' : 'result',
29 'title' : 'exports KWICs and snippets',
30 //Unicode-Code of the plugins button-icon, Font: Font Awesome
31 'icon' : "\uf019",
32 'classes' : [ 'button-icon', 'plugin' ],
33 'onClick' : {
Akronba09ed22020-10-01 16:01:45 +020034 'action' : 'setWidget',
Akrondb570fd2020-11-19 14:39:10 +010035 'template' : 'http://localhost:7777/export',
36 'permissions': ['scripts', 'forms', 'downloads']
hebasta40a85cf2020-07-15 18:10:08 +020037 }
38 } ]
39 });
40
41 //Add result panel
42 var show = {};
43 var resultPanel = resultPanelClass.create(show);
44
45 var resultInfo = document.getElementById('resultinfo');
46 if (resultInfo != null) {
47 // Move buttons to resultinfo
hebasta393829f2020-03-09 12:37:29 +010048 resultInfo.appendChild(resultPanel.actions.element());
49 // The views are at the top of the search results
50 var sb = document.getElementById('search');
51 sb.insertBefore(resultPanel.element(), sb.firstChild);
hebasta40a85cf2020-07-15 18:10:08 +020052 };
53
54 // There is a koralQuery
55 if (KorAP.koralQuery !== undefined) {
hebasta393829f2020-03-09 12:37:29 +010056
57 if (KorAP.koralQuery["errors"]) {
58 var errors = KorAP.koralQuery["errors"];
hebasta40a85cf2020-07-15 18:10:08 +020059 for ( var i in errors) {
hebasta393829f2020-03-09 12:37:29 +010060
61 // Malformed query
62 if (errors[i][0] === 302 && errors[i][2]) {
63 obj.hint = hintClass.create();
64 obj.hint.alert(errors[i][2], errors[i][1]);
65 break;
66 }
67
68 // no query
69 else if (errors[i][0] === 301) {
70 obj.hint = hintClass.create();
hebasta40a85cf2020-07-15 18:10:08 +020071 obj.hint.alert(0, errors[i][1]);
hebasta393829f2020-03-09 12:37:29 +010072 }
hebasta40a85cf2020-07-15 18:10:08 +020073 }
74 };
75 };
hebasta393829f2020-03-09 12:37:29 +010076});