Add new criterions using menus
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 700f410..436f9ef 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -2,20 +2,10 @@
* Document criterion
*/
-/**
- * Criterion in a KorAP.Doc
- */
-function _changeKey () {
- var doc = this.parentNode.refTo;
- var key = doc.element().firstChild;
- key.appendChild(fieldMenu.element());
- fieldMenu.show();
- fieldMenu.focus();
- // key, matchop, type, value
-};
-
define([
- 'vc/jsonld', 'vc/menu', 'vc/rewritelist'], function (jsonldClass, menuClass, rewriteListClass) {
+ 'vc/jsonld', 'vc/rewritelist'], function (jsonldClass, rewriteListClass) {
+
+/*
var fieldMenu = menuClass.create([
['Titel', 'title', 'string'],
['Untertitel', 'subTitle', 'string'],
@@ -24,9 +14,22 @@
]);
fieldMenu.limit(5);
+*/
_validRegexMatchRE = new RegExp("^(?:eq|ne)$");
+ /**
+ * Criterion in a KorAP.Doc
+ */
+ function _changeKey () {
+ var doc = this.parentNode.refTo;
+ var key = doc.element().firstChild;
+ key.appendChild(fieldMenu.element());
+ fieldMenu.show();
+ fieldMenu.focus();
+ // key, matchop, type, value
+ };
+
return {
_ldType : "doc",
_obj : function () { return '???'; /*KorAP.Doc*/ },
diff --git a/dev/js/src/vc/item.js b/dev/js/src/vc/item.js
index bfefe38..7922bbd 100644
--- a/dev/js/src/vc/item.js
+++ b/dev/js/src/vc/item.js
@@ -20,6 +20,15 @@
return this;
},
+ onclick : function (e) {
+ this.menu().release(
+ this._name,
+ this._value,
+ this._type
+ );
+ e.halt();
+ },
+
name : function () {
return this._name;
},
@@ -37,6 +46,10 @@
var li = document.createElement("li");
li.setAttribute("data-type", this._type);
li.setAttribute("data-value", this._value);
+
+ // Connect action
+ li["onclick"] = this.onclick.bind(this);
+
li.appendChild(document.createTextNode(this._name));
return this._element = li;
}
diff --git a/dev/js/src/vc/menu.js b/dev/js/src/vc/menu.js
index 6f6d2bd..2cdc0e8 100644
--- a/dev/js/src/vc/menu.js
+++ b/dev/js/src/vc/menu.js
@@ -1,10 +1,17 @@
// Field menu
-define(['menu', 'menu/item'], function (menuClass, itemClass) {
+define(['menu', 'vc/item'], function (menuClass, itemClass) {
return {
create : function (params) {
return Object.create(menuClass)
.upgradeTo(this)
._init(itemClass, undefined, params)
+ },
+ released : function (cb) {
+ this._cb = cb;
+ },
+ release : function (name, value, type) {
+ if (this._cb !== undefined)
+ this._cb(name, value, type);
}
};
});
diff --git a/dev/js/src/vc/unspecified.js b/dev/js/src/vc/unspecified.js
index 9efd007..f10dcf7 100644
--- a/dev/js/src/vc/unspecified.js
+++ b/dev/js/src/vc/unspecified.js
@@ -1,13 +1,26 @@
/**
- * Unspecified criterion
+ * An unspecified criterion in a virtual collection.
+ * Inherits everything from jsonld
*/
-define(['vc/jsonld', 'vc/doc', 'util'], function (jsonldClass, docClass) {
+define([
+ 'vc/jsonld',
+ 'vc/doc',
+ 'util'
+], function (jsonldClass, docClass) {
+ // Localize empty string
var loc = KorAP.Locale;
loc.EMPTY = loc.EMPTY || '⋯';
return {
+
+ // The ld-type
_ldType : "non",
+
+ /**
+ * Create new unspecified criterion
+ * with a link to the parent object
+ */
create : function (parent) {
var obj = Object.create(jsonldClass).
upgradeTo(this);
@@ -18,7 +31,9 @@
return obj;
},
- // Set key - replace
+ /**
+ * Set the key; this will spawn a new doc
+ */
key : function (v) {
// Not replaceable
@@ -46,6 +61,10 @@
return newDoc;
},
+
+ /**
+ * Update the element
+ */
update : function () {
if (this._element === undefined)
@@ -56,6 +75,10 @@
var ellipsis = document.createElement('span');
ellipsis.appendChild(document.createTextNode(loc.EMPTY));
+
+ // Click on empty criterion
+ ellipsis.addEventListener('click', this.onclick.bind(this));
+
this._element.appendChild(ellipsis);
// Set ref - TODO: Cleanup!
@@ -77,6 +100,10 @@
return this.element();
},
+
+ /**
+ * Get the associated element
+ */
element : function () {
if (this._element !== undefined)
return this._element;
@@ -85,5 +112,30 @@
this.update();
return this._element;
},
+
+ /**
+ * Click on the unspecified object
+ */
+ onclick : function () {
+ var menu = KorAP._vcKeyMenu;
+
+ // Add keyelement at the correct position
+ this._element.insertBefore(
+ menu.element(),
+ this._element.firstChild
+ );
+
+ var that = this;
+
+ // Set released method
+ menu.released(function (name, value, type) {
+ that.key(name);
+ // + ' # ' + type);
+ this.hide();
+ });
+
+ menu.show();
+ menu.focus();
+ }
};
});