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) { |
Akron | 88d1ccc | 2018-08-14 17:22:05 +0200 | [diff] [blame] | 68 | var olCl = d.querySelector('#search > ol').classList; |
| 69 | if (olCl.contains('align-left')) { |
| 70 | olCl.remove('align-left'); |
| 71 | olCl.add('align-right'); |
| 72 | this.button.toggleClass("right", "center"); |
| 73 | } |
| 74 | else if (olCl.contains('align-right')) { |
| 75 | olCl.remove('align-right'); |
| 76 | olCl.add('align-center'); |
| 77 | this.button.toggleClass("center", "left"); |
| 78 | } |
| 79 | else if (olCl.contains('align-center')) { |
| 80 | olCl.remove('align-center'); |
| 81 | olCl.add('align-left'); |
| 82 | this.button.toggleClass("left", "right"); |
| 83 | }; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 84 | }); |
| 85 | } |
| 86 | } |
| 87 | }); |