Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 1 | /** |
| 2 | * The result panel |
| 3 | * |
| 4 | * @author Nils Diewald |
| 5 | */ |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 6 | "use strict"; |
| 7 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 8 | define([ |
| 9 | 'panel', |
| 10 | 'view/result/koralquery' |
| 11 | ], function (panelClass, kqViewClass) { |
| 12 | |
| 13 | const d = document; |
| 14 | |
| 15 | // Localization values |
| 16 | const loc = KorAP.Locale; |
| 17 | loc.TOGGLE_ALIGN = loc.TOGGLE_ALIGN || 'toggle alignment'; |
| 18 | loc.SHOW_KQ = loc.SHOW_KQ || 'show KoralQuery'; |
| 19 | |
| 20 | return { |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 21 | create : function (opened) { |
| 22 | return Object.create(panelClass)._init(['result']).upgradeTo(this)._init(opened); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 23 | }, |
| 24 | |
| 25 | // Initialize panel |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 26 | _init : function (opened) { |
| 27 | this._opened = opened; |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 28 | |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 29 | // If plugins are enabled, add all buttons for the result panel |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 30 | if (KorAP.Plugin) { |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 31 | |
| 32 | // Add all result buttons in order |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 33 | KorAP.Plugin |
| 34 | .buttonGroup("result") |
| 35 | .forEach(i => this.actions.add.apply(this.actions, i)); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 36 | |
| 37 | KorAP.Plugin.clearButtonGroup("result"); |
| 38 | }; |
| 39 | |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 40 | this.prepend = true; |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 41 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 42 | return this; |
| 43 | }, |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Add KoralQuery action to panel |
| 48 | */ |
| 49 | addKqAction : function () { |
| 50 | |
| 51 | // Open KoralQuery view |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 52 | const kqButton = this.actions.add( |
| 53 | loc.SHOW_KQ, |
| 54 | {'cls':['show-kq','button-icon']}, |
| 55 | function () { |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 56 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 57 | const t = this; |
| 58 | |
| 59 | // Show only once - otherwise toggle |
| 60 | if (t._kq && t._kq.shown()) { |
| 61 | t._kq.close(); |
| 62 | return; |
| 63 | }; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 64 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 65 | t._kq = kqViewClass.create(); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 66 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 67 | // On close, remove session info on KQ |
| 68 | t._kq.onClose = function () { |
| 69 | delete this._opened['kq']; |
| 70 | }.bind(t); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 71 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 72 | t._opened['kq'] = true; |
| 73 | t.add(t._kq); |
| 74 | } |
| 75 | ); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 76 | |
| 77 | // Show KoralQuery in case it's meant to be shown |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 78 | if (this._opened['kq']) |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 79 | kqButton.click(); |
| 80 | }, |
| 81 | |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 82 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 83 | /** |
| 84 | * Add align action to panel |
| 85 | */ |
| 86 | addAlignAction : function () { |
| 87 | /** |
| 88 | * Toggle the alignment (left <=> right) |
| 89 | */ |
Akron | 792b1a4 | 2020-09-14 18:56:38 +0200 | [diff] [blame] | 90 | this.actions.add(loc.TOGGLE_ALIGN, {'cls':['align','right','button-icon']}, function (e) { |
Akron | 14f3ee9 | 2020-10-19 11:59:40 +0200 | [diff] [blame^] | 91 | const olCl = d.querySelector('#search > ol').classList; |
Akron | 88d1ccc | 2018-08-14 17:22:05 +0200 | [diff] [blame] | 92 | if (olCl.contains('align-left')) { |
| 93 | olCl.remove('align-left'); |
| 94 | olCl.add('align-right'); |
| 95 | this.button.toggleClass("right", "center"); |
| 96 | } |
| 97 | else if (olCl.contains('align-right')) { |
| 98 | olCl.remove('align-right'); |
| 99 | olCl.add('align-center'); |
| 100 | this.button.toggleClass("center", "left"); |
| 101 | } |
| 102 | else if (olCl.contains('align-center')) { |
| 103 | olCl.remove('align-center'); |
| 104 | olCl.add('align-left'); |
| 105 | this.button.toggleClass("left", "right"); |
| 106 | }; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 107 | }); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | }); |