blob: 2bb647a15ae6a3e331904dd3fe2dd66ebf3a7724 [file] [log] [blame]
Akron5cb9b2b2018-07-24 17:01:09 +02001/**
2 * The result panel
3 *
4 * @author Nils Diewald
5 */
Akron14f3ee92020-10-19 11:59:40 +02006"use strict";
7
Akron5cb9b2b2018-07-24 17:01:09 +02008define([
9 'panel',
10 'view/result/koralquery'
11], function (panelClass, kqViewClass) {
12
13 const d = document;
14
15 // Localization values
16 const loc = KorAP.Locale;
17 loc.TOGGLE_ALIGN = loc.TOGGLE_ALIGN || 'toggle alignment';
18 loc.SHOW_KQ = loc.SHOW_KQ || 'show KoralQuery';
19
20 return {
Akron6112b522018-07-25 13:48:53 +020021 create : function (opened) {
22 return Object.create(panelClass)._init(['result']).upgradeTo(this)._init(opened);
Akron5cb9b2b2018-07-24 17:01:09 +020023 },
24
25 // Initialize panel
Akron6112b522018-07-25 13:48:53 +020026 _init : function (opened) {
27 this._opened = opened;
hebasta043e96f2019-11-28 12:33:00 +010028
hebasta043e96f2019-11-28 12:33:00 +010029 // If plugins are enabled, add all buttons for the result panel
Akron14f3ee92020-10-19 11:59:40 +020030 if (KorAP.Plugin) {
hebasta043e96f2019-11-28 12:33:00 +010031
32 // Add all result buttons in order
Akron14f3ee92020-10-19 11:59:40 +020033 KorAP.Plugin
34 .buttonGroup("result")
35 .forEach(i => this.actions.add.apply(this.actions, i));
hebasta043e96f2019-11-28 12:33:00 +010036
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
Akron14f3ee92020-10-19 11:59:40 +020052 const kqButton = this.actions.add(
53 loc.SHOW_KQ,
54 {'cls':['show-kq','button-icon']},
55 function () {
Akron5cb9b2b2018-07-24 17:01:09 +020056
Akron14f3ee92020-10-19 11:59:40 +020057 const t = this;
58
59 // Show only once - otherwise toggle
60 if (t._kq && t._kq.shown()) {
61 t._kq.close();
62 return;
63 };
Akron5cb9b2b2018-07-24 17:01:09 +020064
Akron14f3ee92020-10-19 11:59:40 +020065 t._kq = kqViewClass.create();
Akron5cb9b2b2018-07-24 17:01:09 +020066
Akron14f3ee92020-10-19 11:59:40 +020067 // On close, remove session info on KQ
68 t._kq.onClose = function () {
69 delete this._opened['kq'];
70 }.bind(t);
Akron5cb9b2b2018-07-24 17:01:09 +020071
Akron14f3ee92020-10-19 11:59:40 +020072 t._opened['kq'] = true;
73 t.add(t._kq);
74 }
75 );
Akron5cb9b2b2018-07-24 17:01:09 +020076
77 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020078 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020079 kqButton.click();
80 },
81
Akron14f3ee92020-10-19 11:59:40 +020082
Akron5cb9b2b2018-07-24 17:01:09 +020083 /**
84 * Add align action to panel
85 */
86 addAlignAction : function () {
87 /**
88 * Toggle the alignment (left <=> right)
89 */
Akron792b1a42020-09-14 18:56:38 +020090 this.actions.add(loc.TOGGLE_ALIGN, {'cls':['align','right','button-icon']}, function (e) {
Akron14f3ee92020-10-19 11:59:40 +020091 const olCl = d.querySelector('#search > ol').classList;
Akron88d1ccc2018-08-14 17:22:05 +020092 if (olCl.contains('align-left')) {
93 olCl.remove('align-left');
94 olCl.add('align-right');
95 this.button.toggleClass("right", "center");
96 }
97 else if (olCl.contains('align-right')) {
98 olCl.remove('align-right');
99 olCl.add('align-center');
100 this.button.toggleClass("center", "left");
101 }
102 else if (olCl.contains('align-center')) {
103 olCl.remove('align-center');
104 olCl.add('align-left');
105 this.button.toggleClass("left", "right");
106 };
Akron5cb9b2b2018-07-24 17:01:09 +0200107 });
Akron5cb9b2b2018-07-24 17:01:09 +0200108 }
109 }
110});