Fixed KQ view to correctly update session
Change-Id: I045455ec2a03f35e58a2de5d32e69d6fa6ea3919
diff --git a/dev/js/spec/panelSpec.js b/dev/js/spec/panelSpec.js
index 4881c0c..bc065fd 100644
--- a/dev/js/spec/panelSpec.js
+++ b/dev/js/spec/panelSpec.js
@@ -1,4 +1,4 @@
-define(['panel','view','util'], function (panelClass,viewClass) {
+define(['panel','view','panel/result','util'], function (panelClass,viewClass, resultClass) {
var controlStr = "";
@@ -127,4 +127,39 @@
expect(viewE.firstChild.firstChild.data).toEqual("Hello World!");
});
});
+
+ describe('KorAP.Panel.Result', function () {
+
+ it('should be initializable', function () {
+ var show = {};
+ var result = resultClass.create(show);
+ expect(result.element().children.length).toEqual(2);
+ expect(result.element().firstChild.children.length).toEqual(0);
+ });
+
+ it('should open KQAction', function () {
+ var show = {};
+ var result = resultClass.create(show);
+
+ result.addKqAction();
+
+ expect(result.element().lastChild.firstChild.textContent).toEqual("show KoralQuery");
+ expect(show["kq"]).toBeFalsy();
+
+ // Open KQ view
+ result.element().lastChild.firstChild.click();
+
+ expect(result.element().querySelector('#koralquery').textContent).toEqual("{}");
+ expect(show["kq"]).toBeTruthy();
+
+ var close = result.element().firstChild.firstChild.lastChild.firstChild;
+ expect(close.textContent).toEqual("Close");
+
+ // Close view
+ close.click();
+
+ expect(result.element().querySelector('#koralquery')).toBeFalsy();
+ expect(show["kq"]).toBeFalsy();
+ });
+ });
});
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 8e42b4e..4f8c41f 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -271,31 +271,7 @@
view.appendChild(vc.element());
vc.open();
- }
-
- /*
- // The vc is visible
- if (vcname.classList.contains('active')) {
-
- // view.removeChild(vc.element());
- vc.minimize();
- vcname.classList.remove('active');
- delete show['collection'];
- }
-
- // The vc is not visible yet
- else {
-
- // Spawn the element for the first time
- var view = d.getElementById('vc-view');
- if (!view.firstChild)
- view.appendChild(vc.element());
-
- vc.open();
- vcname.classList.add('active');
- show['collection'] = true;
};
- */
};
vcname.onclick = vcclick;
diff --git a/dev/js/src/panel/result.js b/dev/js/src/panel/result.js
index a572180..978a1b6 100644
--- a/dev/js/src/panel/result.js
+++ b/dev/js/src/panel/result.js
@@ -45,8 +45,8 @@
// On close, remove session info on KQ
this._kq.onClose = function () {
- this._opened['kq'] = undefined;
- };
+ delete this._opened['kq'];
+ }.bind(this);
this._opened['kq'] = true;
this.add(this._kq);
diff --git a/dev/js/src/view.js b/dev/js/src/view.js
index 2f35c9e..4885afa 100644
--- a/dev/js/src/view.js
+++ b/dev/js/src/view.js
@@ -6,8 +6,7 @@
define(['buttongroup', 'util'], function (buttonGroupClass) {
const loc = KorAP.Locale;
- loc.CLOSE = loc.CLOSE || 'Close';
-
+ loc.CLOSE = loc.CLOSE || 'Close';
return {
create : function (classes) {
diff --git a/dev/js/src/view/result/koralquery.js b/dev/js/src/view/result/koralquery.js
index 583b196..6060bb8 100644
--- a/dev/js/src/view/result/koralquery.js
+++ b/dev/js/src/view/result/koralquery.js
@@ -18,7 +18,7 @@
kq.setAttribute('id', 'koralquery');
var kqInner = kq.addE('div');
- kqInner.innerHTML = JSON.stringify(KorAP.koralQuery, null, ' ');
+ kqInner.innerHTML = JSON.stringify(KorAP.koralQuery || {}, null, ' ');
// Highlight the view
hljs.highlightBlock(kqInner);