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 |
| 33 | for (i in resultButtons) { |
| 34 | this.actions.add.apply(this.actions, resultButtons[i]); |
| 35 | }; |
| 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 |
| 52 | var kqButton = this.actions.add(loc.SHOW_KQ, ['show-kq','button-icon'], function () { |
| 53 | |
| 54 | // Show only once - otherwise toggle |
| 55 | if (this._kq && this._kq.shown()) { |
| 56 | this._kq.close(); |
| 57 | return; |
| 58 | }; |
| 59 | |
| 60 | this._kq = kqViewClass.create(); |
| 61 | |
| 62 | // On close, remove session info on KQ |
| 63 | this._kq.onClose = function () { |
Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 64 | delete this._opened['kq']; |
| 65 | }.bind(this); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 66 | |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 67 | this._opened['kq'] = true; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 68 | this.add(this._kq); |
| 69 | }); |
| 70 | |
| 71 | // Show KoralQuery in case it's meant to be shown |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 72 | if (this._opened['kq']) |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 73 | kqButton.click(); |
| 74 | }, |
| 75 | |
| 76 | /** |
| 77 | * Add align action to panel |
| 78 | */ |
| 79 | addAlignAction : function () { |
| 80 | /** |
| 81 | * Toggle the alignment (left <=> right) |
| 82 | */ |
| 83 | this.actions.add(loc.TOGGLE_ALIGN, ['align','right','button-icon'], function (e) { |
Akron | 88d1ccc | 2018-08-14 17:22:05 +0200 | [diff] [blame] | 84 | var olCl = d.querySelector('#search > ol').classList; |
| 85 | if (olCl.contains('align-left')) { |
| 86 | olCl.remove('align-left'); |
| 87 | olCl.add('align-right'); |
| 88 | this.button.toggleClass("right", "center"); |
| 89 | } |
| 90 | else if (olCl.contains('align-right')) { |
| 91 | olCl.remove('align-right'); |
| 92 | olCl.add('align-center'); |
| 93 | this.button.toggleClass("center", "left"); |
| 94 | } |
| 95 | else if (olCl.contains('align-center')) { |
| 96 | olCl.remove('align-center'); |
| 97 | olCl.add('align-left'); |
| 98 | this.button.toggleClass("left", "right"); |
| 99 | }; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 100 | }); |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 101 | |
| 102 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | }); |