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