Skip to content

Commit

Permalink
Prevent adding duplicate higher order annotations when only one is al…
Browse files Browse the repository at this point in the history
…lowed (#3)
  • Loading branch information
proycon committed Oct 31, 2016
1 parent e5f156b commit d316ad4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 10 additions & 0 deletions flat/style/flat.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ function addhigherorderfield(set, index, type) {
} else if (folia_isspanrole(type)) {
newchildannotation = {'type':type,'targets': []};
}
if (folia_occurrences(type) == 1) {
//ensure we don't add a duplicate
var exists = false;
for (var i = 0; i < editdata[index].children.length; i++) {
if (editdata[index].children[i].type == type) {
alert("An annotation of this type already exists, there can be only one");
return false;
}
}
}
if (newchildannotation !== null) {
$('#higherorderfields' + index + "placeholder")[0].outerHTML =
"<tr class=\"higherorderrow\">" +
Expand Down
3 changes: 1 addition & 2 deletions flat/style/folia.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ function folia_required_spanroles(tag) {
return spanroles;
}

}

function folia_occurrences_class(elementclass) {
/* Get the maximum amount of occurrences for this element class (0=unlimited) */
if ((foliaelements[elementclass]) && (foliaelements[elementclass].properties) && (foliaelements[elementclass].properties.occurrences)) {
if ((foliaelements[elementclass]) && (foliaelements[elementclass].properties) && (foliaelements[elementclass].properties.occurrences !== undefined)) {
return foliaelements[elementclass].properties.occurrences;
} else if (foliaelements[elementclass].ancestors.length >= 1) {
return folia_occurrences_class(foliaelements[elementclass].ancestors[0]);
Expand Down

0 comments on commit d316ad4

Please sign in to comment.