Improved response view
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index d6493cb..87073d6 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -10,6 +10,9 @@
KorAP.API = KorAP.API || {};
+ /**
+ * Retrieve information about a match
+ */
KorAP.API.getMatchInfo = function (match, param, cb) {
// match is a KorAP.Match object
@@ -38,6 +41,16 @@
KorAP.API.getJSON(url, cb);
};
+ /**
+ * Retrieve information about collections
+ */
+ KorAP.API.getCollections = function (cb) {
+ KorAP.API.getJSON(KorAP.URL + '/collection', cb);
+ };
+
+ /**
+ * General method to retrieve JSON information
+ */
KorAP.API.getJSON = function (url, onload) {
var req = new XMLHttpRequest();
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index c960ec2..0f6c1e8 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -153,16 +153,19 @@
// Initialize documentation links
obj.tutorial.initDocLinks(document);
-/*
+ // There is a currentQuery
if (KorAP.currentQuery !== undefined) {
- var sb = document.getElementById('searchbar');
var kq = document.createElement('div');
kq.setAttribute('id', 'koralquery');
- sb.parentNode.insertBefore(kq, sb.nextSibling);
- kq.innerHTML = JSON.stringify(KorAP.currentQuery, null, ' ');
- hljs.highlightBlock(kq);
+
+ var kqInner = document.createElement('div');
+ kq.appendChild(kqInner);
+ kqInner.innerHTML = JSON.stringify(KorAP.currentQuery, null, ' ');
+ hljs.highlightBlock(kqInner);
+
+ var sb = document.getElementById('search');
+ sb.insertBefore(kq, sb.firstChild);
};
-*/
/**
* Add VC creation on submission.
@@ -192,12 +195,14 @@
});
// Render Virtual collection
+// TODO:: Use currentQuery!!!
function _getCurrentVC (vcClass) {
var vc = vcClass.create([
['title', 'string'],
['subTitle', 'string'],
['pubDate', 'date'],
- ['author', 'string']
+ ['author', 'string'],
+ ['corpusID', 'string']
]);
if (KorAP.currentVC !== undefined)
vc.fromJson(KorAP.currentVC);
diff --git a/dev/js/src/vc/chooseitem.js b/dev/js/src/vc/chooseitem.js
new file mode 100644
index 0000000..81ee4ca
--- /dev/null
+++ b/dev/js/src/vc/chooseitem.js
@@ -0,0 +1,89 @@
+define(['menu/item', 'util'], function (itemClass) {
+
+ var loc = KorAP.Locale;
+
+ return {
+
+ /**
+ * Create new menu item.
+ * Pass two parameters: value and type.
+ * the value may be localized by a name in
+ * KorAP.Locale with the prefix 'VC_',
+ * e.g. 'VC_subTitle'.
+ */
+ create : function (params) {
+ return Object.create(itemClass)
+ .upgradeTo(this)
+ ._init(params);
+ },
+
+ // Initialize item object
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ this._id = params[0];
+ this._name = params[1];
+ this._desc = params[2];
+
+ this._lcField = ' ' + this._name.toLowerCase();
+ this._lcField += ' ' + this._desc.toLowerCase();
+
+ return this;
+ },
+
+ /**
+ * Override click event by passing all clicks
+ * to the menu object.
+ */
+ onclick : function (e) {
+ this.menu().release(
+ this._id,
+ this._name
+ );
+ e.halt();
+ },
+
+ /**
+ * Get the name of the item.
+ */
+ name : function () {
+ return this._name;
+ },
+
+ /**
+ * Get the identifier of the item.
+ */
+ id : function () {
+ return this._id;
+ },
+
+ /**
+ * Get the description of the item.
+ */
+ desc : function () {
+ return this._desc;
+ },
+
+ /**
+ * Get the HTML element associated with the item.
+ */
+ element : function () {
+
+ // already defined
+ if (this._element !== undefined)
+ return this._element;
+
+ // Create list item
+ var li = document.createElement("li");
+ li.setAttribute("data-type", this._type);
+ li.setAttribute("data-key", this._key);
+
+ // Connect action
+ li["onclick"] = this.onclick.bind(this);
+
+ li.ap pendChild(document.createTextNode(this._name));
+ return this._element = li;
+ }
+ }
+});
diff --git a/dev/js/src/vc/choosemenu.js b/dev/js/src/vc/choosemenu.js
new file mode 100644
index 0000000..7e00d44
--- /dev/null
+++ b/dev/js/src/vc/choosemenu.js
@@ -0,0 +1,21 @@
+/**
+ * Menu showing all predefined virtual collections.
+ * THIS IS EXPERIMENTAL AND MAY BE REMOVED!
+ */
+define(['vc/menu', 'api'], function (menuClass, itemClass) {
+ return {
+ create : function (params) {
+ return Object.create(menuClass)
+ .upgradeTo(this)
+ ._init(itemClass, undefined, params);
+ },
+
+ /**
+ * A click event was released
+ */
+ release : function (id, name) {
+ if (this._cb !== undefined)
+ this._cb(id, name);
+ }
+ };
+});