Fix setting query language via widgets (fixes #227)
Change-Id: I616f7573de02ee3e7ec77a5c9db47d3f858acde6
diff --git a/dev/js/spec/pluginSpec.js b/dev/js/spec/pluginSpec.js
index 6dd31b3..e3da71e 100644
--- a/dev/js/spec/pluginSpec.js
+++ b/dev/js/spec/pluginSpec.js
@@ -742,6 +742,44 @@
document.body.removeChild(f);
});
+ it('should send messages', function () {
+ let qel = document.createElement('input');
+ qel.setAttribute('id','q-field');
+
+ let qlel = document.createElement('select');
+ qlel.setAttribute('id','ql-field');
+ qlel.innerHTML = '<option value="poliqarp">Poliqarp</option><option value="cosmas2">Cosmas II</option><option value="annis">Annis QL</option><option value="cqp">CQP (neu)</option><option value="cql">CQL v1.2</option><option value="fcsql">FCSQL</option>';
+
+ document.body.appendChild(qel);
+ document.body.appendChild(qlel);
+
+ var manager = pluginServerClass.create();
+ var id = manager.addService({"name":'Example 1', "src":'about:blank'});
+ expect(id).toMatch(/^id-/);
+
+ let data = {
+ "originID" : id,
+ "action" : "set",
+ "key" : "QueryForm",
+ "value" : {
+ "q" : "test3",
+ "ql" : "cosmas2"
+ }
+ };
+
+ manager._receiveMsg({
+ "data" : data
+ });
+ manager.destroy();
+ expect(qel.value).toEqual("test3");
+ expect(qlel.value).toEqual("cosmas2");
+ // Recreate initial state
+
+ qel.remove();
+ qlel.remove();
+ });
+
+
it('should reply to query information requests (pagination)', function () {
var manager = pluginServerClass.create();
var id = manager.addService({"name":'Service', "src":'about:blank'});
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index b47e75c..76d1a0e 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -555,24 +555,27 @@
break;
case 'set':
-
- // Get Query information from form
+
+ // Get Query information from data
if (d.key == 'QueryForm') {
let v = d["value"];
+
if (v["q"] != undefined && this._q) {
this._q.value = v["q"];
};
// Set query language field
// Identical to tutorial.js
- if (v[ql] != undefined && KorAP.QLmenu) {
- KorAP.QLmenu.selectValue(ql);
- }
+ if (v["ql"] != undefined) {
+ if (KorAP.QLmenu) {
+ KorAP.QLmenu.selectValue(v["ql"]);
+ }
- else if (this._ql) {
- let found = Array.from(this._ql.options).find(o => o.value === ql);
- if (found)
- found.selected = true;
+ else if (this._ql) {
+ let found = Array.from(this._ql.options).find(o => o.value === v["ql"]);
+ if (found)
+ found.selected = true;
+ };
};
window.scrollTo(0, 0);