blob: 7d771ad77a0b4a625302345d6a18a04bcae68d01 [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';
Akronece4bb72020-10-19 12:24:20 +020019
20 const aRoll = ['left', 'right','center'];
Akron5cb9b2b2018-07-24 17:01:09 +020021
22 return {
Akron386f1222022-12-21 16:26:11 +010023 type : 'result',
24
Akron6112b522018-07-25 13:48:53 +020025 create : function (opened) {
26 return Object.create(panelClass)._init(['result']).upgradeTo(this)._init(opened);
Akron5cb9b2b2018-07-24 17:01:09 +020027 },
28
29 // Initialize panel
Akron6112b522018-07-25 13:48:53 +020030 _init : function (opened) {
31 this._opened = opened;
hebasta043e96f2019-11-28 12:33:00 +010032
hebasta043e96f2019-11-28 12:33:00 +010033 // If plugins are enabled, add all buttons for the result panel
Akron14f3ee92020-10-19 11:59:40 +020034 if (KorAP.Plugin) {
hebasta043e96f2019-11-28 12:33:00 +010035
36 // Add all result buttons in order
Akron14f3ee92020-10-19 11:59:40 +020037 KorAP.Plugin
38 .buttonGroup("result")
Akron37ea1192021-07-28 10:40:14 +020039 .forEach(i => this.actions().add.apply(this.actions(), i));
hebasta043e96f2019-11-28 12:33:00 +010040
41 KorAP.Plugin.clearButtonGroup("result");
42 };
43
hebastad025eb92019-12-07 21:04:42 +010044 this.prepend = true;
hebasta043e96f2019-11-28 12:33:00 +010045
Akron5cb9b2b2018-07-24 17:01:09 +020046 return this;
47 },
48
49
50 /**
51 * Add KoralQuery action to panel
52 */
53 addKqAction : function () {
54
55 // Open KoralQuery view
Akron37ea1192021-07-28 10:40:14 +020056 const kqButton = this.actions().add(
Akron14f3ee92020-10-19 11:59:40 +020057 loc.SHOW_KQ,
58 {'cls':['show-kq','button-icon']},
59 function () {
Akron5cb9b2b2018-07-24 17:01:09 +020060
Akron14f3ee92020-10-19 11:59:40 +020061 const t = this;
62
63 // Show only once - otherwise toggle
64 if (t._kq && t._kq.shown()) {
65 t._kq.close();
66 return;
67 };
Akron5cb9b2b2018-07-24 17:01:09 +020068
Akron14f3ee92020-10-19 11:59:40 +020069 t._kq = kqViewClass.create();
Akron5cb9b2b2018-07-24 17:01:09 +020070
Akron14f3ee92020-10-19 11:59:40 +020071 // On close, remove session info on KQ
72 t._kq.onClose = function () {
73 delete this._opened['kq'];
74 }.bind(t);
Akron5cb9b2b2018-07-24 17:01:09 +020075
Akron14f3ee92020-10-19 11:59:40 +020076 t._opened['kq'] = true;
77 t.add(t._kq);
78 }
79 );
Akron5cb9b2b2018-07-24 17:01:09 +020080
81 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020082 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020083 kqButton.click();
84 },
85
Akron14f3ee92020-10-19 11:59:40 +020086
Akron5cb9b2b2018-07-24 17:01:09 +020087 /**
88 * Add align action to panel
89 */
90 addAlignAction : function () {
91 /**
92 * Toggle the alignment (left <=> right)
93 */
Akron37ea1192021-07-28 10:40:14 +020094 this.actions().add(loc.TOGGLE_ALIGN, {'cls':['align','right','button-icon']}, function (e) {
Akronece4bb72020-10-19 12:24:20 +020095 var olCl = d.querySelector('#search > ol').classList;
96
97 aRoll.find(function(align, i) {
98 if (olCl.contains('align-' + align)) {
99 const n = i >= 2 ? 0 : i+1;
100 const nn = n >= 2 ? 0 : n+1;
101 olCl.remove('align-' + align);
102 olCl.add('align-' + aRoll[n]);
103 this.button.toggleClass(aRoll[n], aRoll[nn]);
104 return true;
105 };
106 }, this);
107 });
Akron5cb9b2b2018-07-24 17:01:09 +0200108 }
109 }
110});