blob: 94ab856f4107f6f5ea2756ca8ad5a3a5fbad22d7 [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 {
Akron6112b522018-07-25 13:48:53 +020023 create : function (opened) {
24 return Object.create(panelClass)._init(['result']).upgradeTo(this)._init(opened);
Akron5cb9b2b2018-07-24 17:01:09 +020025 },
26
27 // Initialize panel
Akron6112b522018-07-25 13:48:53 +020028 _init : function (opened) {
29 this._opened = opened;
hebasta043e96f2019-11-28 12:33:00 +010030
hebasta043e96f2019-11-28 12:33:00 +010031 // If plugins are enabled, add all buttons for the result panel
Akron14f3ee92020-10-19 11:59:40 +020032 if (KorAP.Plugin) {
hebasta043e96f2019-11-28 12:33:00 +010033
34 // Add all result buttons in order
Akron14f3ee92020-10-19 11:59:40 +020035 KorAP.Plugin
36 .buttonGroup("result")
Akron37ea1192021-07-28 10:40:14 +020037 .forEach(i => this.actions().add.apply(this.actions(), i));
hebasta043e96f2019-11-28 12:33:00 +010038
39 KorAP.Plugin.clearButtonGroup("result");
40 };
41
hebastad025eb92019-12-07 21:04:42 +010042 this.prepend = true;
hebasta043e96f2019-11-28 12:33:00 +010043
Akron5cb9b2b2018-07-24 17:01:09 +020044 return this;
45 },
46
47
48 /**
49 * Add KoralQuery action to panel
50 */
51 addKqAction : function () {
52
53 // Open KoralQuery view
Akron37ea1192021-07-28 10:40:14 +020054 const kqButton = this.actions().add(
Akron14f3ee92020-10-19 11:59:40 +020055 loc.SHOW_KQ,
56 {'cls':['show-kq','button-icon']},
57 function () {
Akron5cb9b2b2018-07-24 17:01:09 +020058
Akron14f3ee92020-10-19 11:59:40 +020059 const t = this;
60
61 // Show only once - otherwise toggle
62 if (t._kq && t._kq.shown()) {
63 t._kq.close();
64 return;
65 };
Akron5cb9b2b2018-07-24 17:01:09 +020066
Akron14f3ee92020-10-19 11:59:40 +020067 t._kq = kqViewClass.create();
Akron5cb9b2b2018-07-24 17:01:09 +020068
Akron14f3ee92020-10-19 11:59:40 +020069 // On close, remove session info on KQ
70 t._kq.onClose = function () {
71 delete this._opened['kq'];
72 }.bind(t);
Akron5cb9b2b2018-07-24 17:01:09 +020073
Akron14f3ee92020-10-19 11:59:40 +020074 t._opened['kq'] = true;
75 t.add(t._kq);
76 }
77 );
Akron5cb9b2b2018-07-24 17:01:09 +020078
79 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020080 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020081 kqButton.click();
82 },
83
Akron14f3ee92020-10-19 11:59:40 +020084
Akron5cb9b2b2018-07-24 17:01:09 +020085 /**
86 * Add align action to panel
87 */
88 addAlignAction : function () {
89 /**
90 * Toggle the alignment (left <=> right)
91 */
Akron37ea1192021-07-28 10:40:14 +020092 this.actions().add(loc.TOGGLE_ALIGN, {'cls':['align','right','button-icon']}, function (e) {
Akronece4bb72020-10-19 12:24:20 +020093 var olCl = d.querySelector('#search > ol').classList;
94
95 aRoll.find(function(align, i) {
96 if (olCl.contains('align-' + align)) {
97 const n = i >= 2 ? 0 : i+1;
98 const nn = n >= 2 ? 0 : n+1;
99 olCl.remove('align-' + align);
100 olCl.add('align-' + aRoll[n]);
101 this.button.toggleClass(aRoll[n], aRoll[nn]);
102 return true;
103 };
104 }, this);
105 });
Akron5cb9b2b2018-07-24 17:01:09 +0200106 }
107 }
108});