Modify vc
diff --git a/public/js/demo/vc.html b/public/js/demo/vc.html
index 6c306b0..d4924e4 100644
--- a/public/js/demo/vc.html
+++ b/public/js/demo/vc.html
@@ -29,6 +29,24 @@
"key":"Veröffentlichungsort",
"value":"hihi",
"match":"match:eq"
+ },
+ {
+ "@type":"korap:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"korap:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"korap:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ }
+ ]
}
]
},
diff --git a/public/js/spec/vcSpec.js b/public/js/spec/vcSpec.js
index ce2ca4a..2010adf 100644
--- a/public/js/spec/vcSpec.js
+++ b/public/js/spec/vcSpec.js
@@ -631,7 +631,46 @@
it('should be based on a nested docGroup', function () {
var vc = KorAP.VirtualCollection.render({
"@type" : "korap:docGroup",
- "operation" : "operation:or",
+ "operation" : "operation:and",
+ "operands" : [
+ {
+ "@type": 'korap:doc',
+ "key": 'pubDate',
+ "match": 'match:geq',
+ "value": '2014-05-12',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'korap:doc',
+ "key": 'pubDate',
+ "match": 'match:leq',
+ "value": '2014-12-05',
+ "type": 'type:date'
+ },
+ {
+ "@type": 'korap:doc',
+ "key": 'foo',
+ "match": 'match:eq',
+ "value": 'bar',
+ "type": 'type:string'
+ }
+ ]
+ });
+
+ var docGroup = vc.root();
+ var doc = docGroup.getOperand(1);
+ expect(doc.key()).toEqual("pubDate");
+ expect(docGroup.delOperand(doc)).toEqual(true);
+ doc = docGroup.getOperand(1);
+ expect(doc.key()).toEqual("foo");
+ });
+
+ it('should be modifiable', function () {
+ var vc = KorAP.VirtualCollection.render();
+
+ var vc = KorAP.VirtualCollection.render({
+ "@type" : "korap:docGroup",
+ "operation" : "operation:and",
"operands" : [
{
"@type": 'korap:doc',
@@ -641,37 +680,19 @@
"type": 'type:string'
},
{
- "@type" : "korap:docGroup",
- "operation" : "operation:and",
- "operands" : [
- {
- "@type": 'korap:doc',
- "key": 'pubDate',
- "match": 'match:geq',
- "value": '2014-05-12',
- "type": 'type:date'
- },
- {
- "@type": 'korap:doc',
- "key": 'pubDate',
- "match": 'match:leq',
- "value": '2014-12-05',
- "type": 'type:date'
- }
- ]
+ "@type": 'korap:doc',
+ "key": 'pubDate',
+ "match": 'match:eq',
+ "value": '2014-12-05',
+ "type": 'type:date'
}
]
});
+
expect(vc.element().getAttribute('class')).toEqual('vc');
- expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
- expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
- var dg = vc.element().firstChild.children[1];
- expect(dg.getAttribute('class')).toEqual('docGroup');
- expect(dg.children[0].getAttribute('class')).toEqual('doc');
- expect(dg.children[1].getAttribute('class')).toEqual('doc');
- expect(dg.children[2].getAttribute('class')).toEqual('operators');
- expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators');
- });
+ expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
+ expect(vc.root().operation()).toEqual('and');
+ });
});
describe('KorAP.Operators', function () {
diff --git a/public/js/src/vc.js b/public/js/src/vc.js
index fe702a7..fbdc118 100644
--- a/public/js/src/vc.js
+++ b/public/js/src/vc.js
@@ -96,6 +96,20 @@
}
};
+ KorAP._or = function (e) {
+ var obj = this.parentNode.refTo;
+ };
+
+ KorAP._and = function (e) {
+ var obj = this.parentNode.refTo;
+ };
+
+ KorAP._delete = function (e) {
+ var obj = this.parentNode.refTo;
+ obj.parent().delOperand(obj);
+ // Todo: CLEAR ALL THE THINGS!
+ };
+
/**
* Operators for criteria
*/
@@ -115,6 +129,8 @@
var op = this._element;
+ op.refTo = this.parent();
+
// Remove everything underneath
_removeChildren(op);
@@ -122,6 +138,7 @@
if (this._and === true) {
var andE = document.createElement('span');
andE.setAttribute('class', 'and');
+ andE.addEventListener('click', KorAP._and, false);
andE.appendChild(document.createTextNode(KorAP.Locale.AND));
op.appendChild(andE);
};
@@ -130,6 +147,7 @@
if (this._or === true) {
var orE = document.createElement('span');
orE.setAttribute('class', 'or');
+ orE.addEventListener('click', KorAP._or, false);
orE.appendChild(document.createTextNode(KorAP.Locale.OR));
op.appendChild(orE);
};
@@ -139,11 +157,19 @@
var delE = document.createElement('span');
delE.setAttribute('class', 'delete');
delE.appendChild(document.createTextNode(KorAP.Locale.DEL));
+ delE.addEventListener('click', KorAP._delete, false);
op.appendChild(delE);
};
return op;
},
+
+ // Be aware! This may be cyclic
+ parent : function (obj) {
+ if (arguments.length === 1)
+ this._parent = obj;
+ return this._parent;
+ },
element : function () {
// Return existing element
@@ -208,7 +234,6 @@
op.element()
);
-
return this.element();
},
element : function () {
@@ -564,6 +589,21 @@
return this._operands[index];
},
+ // Delete operand from group
+ delOperand : function (obj) {
+ for (var i in this._operands) {
+ if (this._operands[i] === obj) {
+ this._operands.splice(i,1);
+
+ // Todo: Update has to check
+ // that this may mean the group is empty etc.
+ this.update();
+ return true;
+ };
+ };
+ return false;
+ },
+
// Deserialize from json
fromJson : function (json) {
if (json === undefined)
@@ -638,12 +678,15 @@
this._parent = obj;
return this._parent;
},
+
+ // Be aware! This may be cyclic
operators : function (and, or, del) {
if (arguments === 0)
return this._ops;
this._ops = KorAP.Operators.create(
and, or, del
);
+ this._ops.parent(this);
return this._ops;
},
toJson : function () {