blob: bee0409ce8e62e369235ecb1bf8f9dbca9bb273c [file] [log] [blame]
Akron5cb9b2b2018-07-24 17:01:09 +02001/**
2 * The result panel
3 *
4 * @author Nils Diewald
5 */
6define([
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 {
Akron6112b522018-07-25 13:48:53 +020019 create : function (opened) {
20 return Object.create(panelClass)._init(['result']).upgradeTo(this)._init(opened);
Akron5cb9b2b2018-07-24 17:01:09 +020021 },
22
23 // Initialize panel
Akron6112b522018-07-25 13:48:53 +020024 _init : function (opened) {
25 this._opened = opened;
Akron5cb9b2b2018-07-24 17:01:09 +020026 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 () {
Akron6112b522018-07-25 13:48:53 +020048 this._opened['kq'] = undefined;
Akron5cb9b2b2018-07-24 17:01:09 +020049 };
50
Akron6112b522018-07-25 13:48:53 +020051 this._opened['kq'] = true;
Akron5cb9b2b2018-07-24 17:01:09 +020052 this.add(this._kq);
53 });
54
55 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020056 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020057 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});