blob: 15eb4793f56e0c762623e22ae1435218256a021f [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;
hebasta043e96f2019-11-28 12:33:00 +010026
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
hebastad025eb92019-12-07 21:04:42 +010040 this.prepend = true;
hebasta043e96f2019-11-28 12:33:00 +010041
Akron5cb9b2b2018-07-24 17:01:09 +020042 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 () {
Akron362c11a2018-08-29 20:01:30 +020064 delete this._opened['kq'];
65 }.bind(this);
Akron5cb9b2b2018-07-24 17:01:09 +020066
Akron6112b522018-07-25 13:48:53 +020067 this._opened['kq'] = true;
Akron5cb9b2b2018-07-24 17:01:09 +020068 this.add(this._kq);
69 });
70
71 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020072 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020073 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) {
Akron88d1ccc2018-08-14 17:22:05 +020084 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 };
Akron5cb9b2b2018-07-24 17:01:09 +0200100 });
hebasta043e96f2019-11-28 12:33:00 +0100101
102
Akron5cb9b2b2018-07-24 17:01:09 +0200103 }
104 }
105});