Fix syncing of search conditions

This commit is contained in:
Dan Stillman 2016-06-20 01:08:25 -05:00
parent 2225f459b7
commit 8e0e69332e
2 changed files with 21 additions and 6 deletions

View file

@ -836,7 +836,7 @@ Zotero.Search.prototype.fromJSON = function (json) {
} }
} }
Zotero.Collection.prototype.toResponseJSON = function (options = {}) { Zotero.Search.prototype.toResponseJSON = function (options = {}) {
var json = this.constructor._super.prototype.toResponseJSON.apply(this, options); var json = this.constructor._super.prototype.toResponseJSON.apply(this, options);
return json; return json;
}; };
@ -851,8 +851,14 @@ Zotero.Search.prototype.toJSON = function (options = {}) {
obj.version = this.version; obj.version = this.version;
obj.name = this.name; obj.name = this.name;
var conditions = this.getConditions(); var conditions = this.getConditions();
obj.conditions = Object.keys(conditions).map(x => conditions[x]); obj.conditions = Object.keys(conditions)
.map(x => ({
condition: conditions[x].condition
+ (conditions[x].mode !== false ? "/" + conditions[x].mode : ""),
operator: conditions[x].operator,
// TODO: Change joinMode to use 'is' + 'any' instead of operator 'any'?
value: conditions[x].value ? conditions[x].value : ""
}));
return this._postToJSON(env); return this._postToJSON(env);
} }

View file

@ -195,15 +195,24 @@ describe("Zotero.Search", function() {
let s = new Zotero.Search(); let s = new Zotero.Search();
s.name = "Test"; s.name = "Test";
s.addCondition('joinMode', 'any'); s.addCondition('joinMode', 'any');
s.addCondition('fulltextWord', 'contains', 'afsgagsdg'); s.addCondition('fulltextContent/regexp', 'contains', 's.+');
let json = s.toJSON(); let json = s.toJSON();
assert.equal(json.name, "Test"); assert.equal(json.name, "Test");
assert.lengthOf(json.conditions, 2); assert.lengthOf(json.conditions, 2);
assert.equal(json.conditions[0].condition, 'joinMode'); assert.equal(json.conditions[0].condition, 'joinMode');
assert.equal(json.conditions[0].operator, 'any'); assert.equal(json.conditions[0].operator, 'any');
assert.equal(json.conditions[1].condition, 'fulltextWord'); // TODO: Change to 'is' + 'any'?
assert.strictEqual(json.conditions[0].value, '');
assert.notProperty(json.conditions[0], 'id');
assert.notProperty(json.conditions[0], 'required');
assert.notProperty(json.conditions[0], 'mode');
assert.equal(json.conditions[1].condition, 'fulltextContent/regexp');
assert.equal(json.conditions[1].operator, 'contains'); assert.equal(json.conditions[1].operator, 'contains');
assert.equal(json.conditions[1].value, 'afsgagsdg'); assert.equal(json.conditions[1].value, 's.+');
assert.notProperty(json.conditions[1], 'mode');
}); });
}); });