1 function(newDoc, oldDoc, userCtx)
3 String.prototype.trim = function()
5 return this.replace(/^\s+|\s+$/g,"");
8 function require(field, message)
10 message = message || "Document must have a " + field;
11 if (newDoc[field] == void 0 || newDoc[field] == null)
13 throw({forbidden: message});
17 function check(cond, message)
19 message = message || "Condition check failed";
22 throw({forbidden: message});
26 function checkTrimmed(field)
28 if (newDoc[field] != newDoc[field].trim())
30 throw({forbidden: field + " must be trimmed"});
34 function checkUnique(arr, field)
38 function f(x) {return x==arr[n];};
39 if(arr.filter(f).length > 1)
41 throw({forbidden: field + " must be unique"});
47 if(newDoc.doc_type == "Category")
50 check(newDoc.label != "", "label must not be empty");
51 checkTrimmed("label");
57 check(newDoc.spellings.indexOf(newDoc.label) < 0,
58 "The label should not be contained in the alternative spellings");
59 checkUnique(newDoc.spellings, "spellings");