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' : { |
Akron | ba09ed2 | 2020-10-01 16:01:45 +0200 | [diff] [blame] | 34 | 'action' : 'setWidget', |
Akron | db570fd | 2020-11-19 14:39:10 +0100 | [diff] [blame^] | 35 | 'template' : 'http://localhost:7777/export', |
| 36 | 'permissions': ['scripts', 'forms', 'downloads'] |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame] | 37 | } |
| 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 |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 48 | 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); |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | // There is a koralQuery |
| 55 | if (KorAP.koralQuery !== undefined) { |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 56 | |
| 57 | if (KorAP.koralQuery["errors"]) { |
| 58 | var errors = KorAP.koralQuery["errors"]; |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame] | 59 | for ( var i in errors) { |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 60 | |
| 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(); |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame] | 71 | obj.hint.alert(0, errors[i][1]); |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 72 | } |
hebasta | 40a85cf | 2020-07-15 18:10:08 +0200 | [diff] [blame] | 73 | } |
| 74 | }; |
| 75 | }; |
hebasta | 393829f | 2020-03-09 12:37:29 +0100 | [diff] [blame] | 76 | }); |