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