blob: 3c5dc31f6df7041d9ea67b6c88b44417a4f6ad3f [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
Akron678c26f2020-10-09 08:52:50 +020033 resultButtons.forEach(i => this.actions.add.apply(this.actions, i));
hebasta043e96f2019-11-28 12:33:00 +010034
35 KorAP.Plugin.clearButtonGroup("result");
36 };
37
hebastad025eb92019-12-07 21:04:42 +010038 this.prepend = true;
hebasta043e96f2019-11-28 12:33:00 +010039
Akron5cb9b2b2018-07-24 17:01:09 +020040 return this;
41 },
42
43
44 /**
45 * Add KoralQuery action to panel
46 */
47 addKqAction : function () {
48
49 // Open KoralQuery view
Akron792b1a42020-09-14 18:56:38 +020050 var kqButton = this.actions.add(loc.SHOW_KQ, {'cls':['show-kq','button-icon']}, function () {
Akron5cb9b2b2018-07-24 17:01:09 +020051
52 // Show only once - otherwise toggle
53 if (this._kq && this._kq.shown()) {
54 this._kq.close();
55 return;
56 };
57
58 this._kq = kqViewClass.create();
59
60 // On close, remove session info on KQ
61 this._kq.onClose = function () {
Akron362c11a2018-08-29 20:01:30 +020062 delete this._opened['kq'];
63 }.bind(this);
Akron5cb9b2b2018-07-24 17:01:09 +020064
Akron6112b522018-07-25 13:48:53 +020065 this._opened['kq'] = true;
Akron5cb9b2b2018-07-24 17:01:09 +020066 this.add(this._kq);
67 });
68
69 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020070 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020071 kqButton.click();
72 },
73
74 /**
75 * Add align action to panel
76 */
77 addAlignAction : function () {
78 /**
79 * Toggle the alignment (left <=> right)
80 */
Akron792b1a42020-09-14 18:56:38 +020081 this.actions.add(loc.TOGGLE_ALIGN, {'cls':['align','right','button-icon']}, function (e) {
Akron88d1ccc2018-08-14 17:22:05 +020082 var olCl = d.querySelector('#search > ol').classList;
83 if (olCl.contains('align-left')) {
84 olCl.remove('align-left');
85 olCl.add('align-right');
86 this.button.toggleClass("right", "center");
87 }
88 else if (olCl.contains('align-right')) {
89 olCl.remove('align-right');
90 olCl.add('align-center');
91 this.button.toggleClass("center", "left");
92 }
93 else if (olCl.contains('align-center')) {
94 olCl.remove('align-center');
95 olCl.add('align-left');
96 this.button.toggleClass("left", "right");
97 };
Akron5cb9b2b2018-07-24 17:01:09 +020098 });
hebasta043e96f2019-11-28 12:33:00 +010099
100
Akron5cb9b2b2018-07-24 17:01:09 +0200101 }
102 }
103});