blob: 02c6e53b13720ae6cb552e5e56374aae21faf05b [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
40
Akron5cb9b2b2018-07-24 17:01:09 +020041 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 () {
Akron362c11a2018-08-29 20:01:30 +020063 delete this._opened['kq'];
64 }.bind(this);
Akron5cb9b2b2018-07-24 17:01:09 +020065
Akron6112b522018-07-25 13:48:53 +020066 this._opened['kq'] = true;
Akron5cb9b2b2018-07-24 17:01:09 +020067 this.add(this._kq);
68 });
69
70 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020071 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020072 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) {
Akron88d1ccc2018-08-14 17:22:05 +020083 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 };
Akron5cb9b2b2018-07-24 17:01:09 +020099 });
hebasta043e96f2019-11-28 12:33:00 +0100100
101
Akron5cb9b2b2018-07-24 17:01:09 +0200102 }
103 }
104});