Improved response view
diff --git a/dev/demo/alldemo.js b/dev/demo/alldemo.js
index d7e8525..25aade7 100644
--- a/dev/demo/alldemo.js
+++ b/dev/demo/alldemo.js
@@ -532,7 +532,7 @@
}
});
-// KorAP.currentQuery = queryExample;
+KorAP.currentQuery = queryExample;
require(['app/en', 'init'], function (lang, init) {
KorAP.hintArray = hintArray;
diff --git a/dev/demo/vcdemo.js b/dev/demo/vcdemo.js
index 53ab75e..73cb805 100644
--- a/dev/demo/vcdemo.js
+++ b/dev/demo/vcdemo.js
@@ -64,6 +64,35 @@
]
};
+var collections = [
+ {
+ "statistics":{
+ "paragraphs":2034752,
+ "documents":196510,
+ "tokens":51545081,
+ "sentences":4116282
+ },
+ "query":[
+ {
+ "@value":{
+ "@field":"korap:field#corpusID",
+ "@value":"WPD",
+ "@type":"korap:term"
+ },
+ "@type":"korap:meta-filter"
+ }
+ ],
+ "name":"Wikipedia",
+ "path":"Wikipedia",
+ "description":"Die freie Enzyklopädie",
+ "shared":false,
+ "managed":true,
+ "created":"2015-04-01T23:04:32.000+02:00",
+ "foundries":"",
+ "id":"ZGU0ZTllNTFkYzc3M2VhZmViYzdkYWE2ODI5NDc3NTk4NGQ1YThhOTMwOTNhOWYxNWMwN2M3Y2YyZmE3N2RlNQ=="
+ }
+];
+
require(['vc','lib/domReady', 'lib/highlight/highlight.pack'], function (vcClass, domReady) {
var loc = KorAP.Locale;
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);
+ }
+ };
+});
diff --git a/dev/scss/header/searchbar.scss b/dev/scss/header/searchbar.scss
index e0f241e..d383e73 100644
--- a/dev/scss/header/searchbar.scss
+++ b/dev/scss/header/searchbar.scss
@@ -74,21 +74,6 @@
}
}
-#koralquery {
- margin-top: 10px;
- margin-right: 40px;
- border: {
- radius: $standard-border-radius;
- color: $dark-green;
- style: solid;
- width: $border-size;
- }
- white-space: pre;
- background-color: $nearly-white;
- color: $dark-grey;
-}
-
-
/**
* Checkbox styling
* http://stackoverflow.com/questions/4148499/how-to-style-checkbox-using-css
diff --git a/dev/scss/main/koralquery.scss b/dev/scss/main/koralquery.scss
new file mode 100644
index 0000000..d569d77
--- /dev/null
+++ b/dev/scss/main/koralquery.scss
@@ -0,0 +1,19 @@
+@charset "utf-8";
+@import "../util";
+
+$border-size: 2px;
+
+#koralquery {
+ border: 1px solid $kwic-border;
+ white-space: pre;
+ background-color: $dark-orange;
+ > div {
+ background-color: $nearly-white;
+ margin: {
+ top: 2pt;
+ right: $right-match-distance; // 3em;
+ bottom: 2pt;
+ left: 2pt;
+ }
+ }
+}
diff --git a/dev/scss/main/main.scss b/dev/scss/main/main.scss
index f0ff84b..2bd308d 100644
--- a/dev/scss/main/main.scss
+++ b/dev/scss/main/main.scss
@@ -7,6 +7,7 @@
@import "resultinfo"; // Information on results
@import "sidebar"; // Navigation on the left side
@import "tutorial"; // Embedded and non-embedded tutorial
+@import "koralquery"; // KoralQuery
@import "alertify";
div.intro {