hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Export Demo |
| 3 | * |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 4 | * @author Helge |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 5 | * |
| 6 | */ |
| 7 | |
| 8 | requirejs.config({ |
| 9 | baseUrl: '../js/src', |
| 10 | paths : { |
| 11 | 'lib': '../lib' |
| 12 | } |
| 13 | }); |
| 14 | |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 15 | require([ 'plugin/server', 'panel/result', 'init' ], function(pluginClass, resultPanelClass) { |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 16 | |
| 17 | KorAP.Plugin = pluginClass.create(); |
| 18 | |
| 19 | // Add services container to head |
| 20 | document.head.appendChild(KorAP.Plugin.element()); |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 21 | |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 22 | // 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' : { |
| 34 | 'action' : 'addWidget', |
| 35 | 'template' : 'http://localhost:7777/res/export.html' |
| 36 | } |
| 37 | } ] |
| 38 | }); |
| 39 | |
| 40 | //Add result panel |
| 41 | var show = {}; |
| 42 | var resultPanel = resultPanelClass.create(show); |
| 43 | |
| 44 | var resultInfo = document.getElementById('resultinfo'); |
| 45 | if (resultInfo != null) { |
| 46 | // Move buttons to resultinfo |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 47 | resultInfo.appendChild(resultPanel.actions.element()); |
| 48 | // The views are at the top of the search results |
| 49 | var sb = document.getElementById('search'); |
| 50 | sb.insertBefore(resultPanel.element(), sb.firstChild); |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 51 | }; |
| 52 | |
| 53 | // There is a koralQuery |
| 54 | if (KorAP.koralQuery !== undefined) { |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 55 | |
| 56 | if (KorAP.koralQuery["errors"]) { |
| 57 | var errors = KorAP.koralQuery["errors"]; |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 58 | for ( var i in errors) { |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 59 | |
| 60 | // Malformed query |
| 61 | if (errors[i][0] === 302 && errors[i][2]) { |
| 62 | obj.hint = hintClass.create(); |
| 63 | obj.hint.alert(errors[i][2], errors[i][1]); |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | // no query |
| 68 | else if (errors[i][0] === 301) { |
| 69 | obj.hint = hintClass.create(); |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 70 | obj.hint.alert(0, errors[i][1]); |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 71 | } |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame^] | 72 | } |
| 73 | }; |
| 74 | }; |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 75 | }); |