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; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 26 | return this; |
| 27 | }, |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Add KoralQuery action to panel |
| 32 | */ |
| 33 | addKqAction : function () { |
| 34 | |
| 35 | // Open KoralQuery view |
| 36 | var kqButton = this.actions.add(loc.SHOW_KQ, ['show-kq','button-icon'], function () { |
| 37 | |
| 38 | // Show only once - otherwise toggle |
| 39 | if (this._kq && this._kq.shown()) { |
| 40 | this._kq.close(); |
| 41 | return; |
| 42 | }; |
| 43 | |
| 44 | this._kq = kqViewClass.create(); |
| 45 | |
| 46 | // On close, remove session info on KQ |
| 47 | this._kq.onClose = function () { |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame^] | 48 | this._opened['kq'] = undefined; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame^] | 51 | this._opened['kq'] = true; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 52 | this.add(this._kq); |
| 53 | }); |
| 54 | |
| 55 | // Show KoralQuery in case it's meant to be shown |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame^] | 56 | if (this._opened['kq']) |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 57 | kqButton.click(); |
| 58 | }, |
| 59 | |
| 60 | /** |
| 61 | * Add align action to panel |
| 62 | */ |
| 63 | addAlignAction : function () { |
| 64 | /** |
| 65 | * Toggle the alignment (left <=> right) |
| 66 | */ |
| 67 | this.actions.add(loc.TOGGLE_ALIGN, ['align','right','button-icon'], function (e) { |
| 68 | var ol = d.querySelector('#search > ol'); |
| 69 | ol.toggleClass("align-left", "align-right"); |
| 70 | this.button.toggleClass("left", "right"); |
| 71 | }); |
| 72 | } |
| 73 | } |
| 74 | }); |