blob: 978a1b6021aefefea97dd19cc4dc7d2e8c22d286 [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;
Akron5cb9b2b2018-07-24 17:01:09 +020026 return this;
27 },
28
29
30 /**
31 * Add KoralQuery action to panel
32 */
33 addKqAction : function () {
34
35 // Open KoralQuery view
36 var kqButton = this.actions.add(loc.SHOW_KQ, ['show-kq','button-icon'], function () {
37
38 // Show only once - otherwise toggle
39 if (this._kq && this._kq.shown()) {
40 this._kq.close();
41 return;
42 };
43
44 this._kq = kqViewClass.create();
45
46 // On close, remove session info on KQ
47 this._kq.onClose = function () {
Akron362c11a2018-08-29 20:01:30 +020048 delete this._opened['kq'];
49 }.bind(this);
Akron5cb9b2b2018-07-24 17:01:09 +020050
Akron6112b522018-07-25 13:48:53 +020051 this._opened['kq'] = true;
Akron5cb9b2b2018-07-24 17:01:09 +020052 this.add(this._kq);
53 });
54
55 // Show KoralQuery in case it's meant to be shown
Akron6112b522018-07-25 13:48:53 +020056 if (this._opened['kq'])
Akron5cb9b2b2018-07-24 17:01:09 +020057 kqButton.click();
58 },
59
60 /**
61 * Add align action to panel
62 */
63 addAlignAction : function () {
64 /**
65 * Toggle the alignment (left <=> right)
66 */
67 this.actions.add(loc.TOGGLE_ALIGN, ['align','right','button-icon'], function (e) {
Akron88d1ccc2018-08-14 17:22:05 +020068 var olCl = d.querySelector('#search > ol').classList;
69 if (olCl.contains('align-left')) {
70 olCl.remove('align-left');
71 olCl.add('align-right');
72 this.button.toggleClass("right", "center");
73 }
74 else if (olCl.contains('align-right')) {
75 olCl.remove('align-right');
76 olCl.add('align-center');
77 this.button.toggleClass("center", "left");
78 }
79 else if (olCl.contains('align-center')) {
80 olCl.remove('align-center');
81 olCl.add('align-left');
82 this.button.toggleClass("left", "right");
83 };
Akron5cb9b2b2018-07-24 17:01:09 +020084 });
85 }
86 }
87});