Skip to content

Commit

Permalink
Refactored folia_label calls, function now takes set label into accou…
Browse files Browse the repository at this point in the history
…nt directly (refactors #37) + Render features in viewer (start of #43)
  • Loading branch information
proycon committed Oct 26, 2016
1 parent 99db8c6 commit 41ff49f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 53 deletions.
27 changes: 4 additions & 23 deletions flat/style/flat.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ function setaddablefields() {
Object.keys(declarations).forEach(function(annotationtype){
Object.keys(declarations[annotationtype]).forEach(function(set){
if ((annotationtype != "correction") && (viewannotations[annotationtype + "/" + set]) && (folia_accepts(editedelementtype,annotationtype))) {
if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) {
label = setdefinitions[set].label;
} else {
label = folia_label(annotationtype);
}
label = folia_label(annotationtype, set);
setname = shorten(set);
//check if it already exists
found = false;
Expand Down Expand Up @@ -398,11 +394,7 @@ function showeditor(element) {
if ((annotation.type != "correction") && ((editannotations[annotation.type+"/" + annotation.set]) || (isannotationfocus))) {

//Get the human-presentable label for the annotation type
if ((setdefinitions) && (setdefinitions[annotation.set]) && (setdefinitions[annotation.set].label)) {
label = setdefinitions[annotation.set].label;
} else {
label = folia_label(annotation.type);
}
label = folia_label(annotation.type, annotation.set);

if (annotation.set) {
setname = annotation.set;
Expand Down Expand Up @@ -722,13 +714,7 @@ function closeeditor() {

function addeditorfield(index) {
/* add a new field to the editor, populated by setaddablefields() */
if ((setdefinitions) && (setdefinitions[editoraddablefields[index].set]) && (setdefinitions[editoraddablefields[index].set].label)) {
label = setdefinitions[editoraddablefields[index].set].label;
} else if (folia_label(editoraddablefields[index].type)) {
label = folia_label(editoraddablefields[index].type);
} else {
label = editoraddablefields[index].type;
}
label = folia_label(editoraddablefields[index].type, editoraddablefields[index].set);
if (editoraddablefields[index].set) {
setname = editoraddablefields[index].set;
} else {
Expand Down Expand Up @@ -946,11 +932,7 @@ function editor_loadmenus() {
if ((configuration.initialeditannotations === true) || (configuration.initialeditannotations.indexOf(annotationtype + '/' + set) != -1) || (configuration.initialeditannotations.indexOf(annotationtype) != -1)) {
editannotations[annotationtype + "/" + set] = true;
}
if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) {
label = setdefinitions[set].label;
} else {
label = folia_label(annotationtype);
}
label = folia_label(annotationtype, set);
s = s + "<li id=\"annotationtypeedit_" +annotationtype+"_" + hash(set) + "\" class=\"on\"><a href=\"javascript:toggleannotationedit('" + annotationtype + "', '" + set + "')\">" + label + "<span class=\"setname\">" + set + "</span></a></li>";
}
});
Expand Down Expand Up @@ -1574,7 +1556,6 @@ function editor_oninit() {

var s = "";
folia_annotationlist().forEach(function(annotationtype){
//TODO: restrict using ACCEPTED_DATA
s = s + "<option value=\"" + annotationtype + "\">" + folia_label(annotationtype) + "</option>";
});
$('#newdeclarationannotationtype').html(s);
Expand Down
16 changes: 15 additions & 1 deletion flat/style/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@ function folia_parse(element, ancestors) {
}
}

function folia_label(tag) {
function folia_label(tag, set) {
//Get the human-readable label for an annotation type (corresponding to a FoLiA XML tag), if defined
var foliaclass = foliatag2class[tag];

if ((set) && (setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) {
//Grab the label from the set definition
return setdefinitions[set].label;
}

if ((foliaelements[foliaclass]) && (foliaelements[foliaclass].properties.label)) {
return foliaelements[foliaclass].properties.label;
} else {
return tag; //fallback
}
}

function folia_subset_label(set, subset) {
if ((set) && (setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].subsets) && (setdefinitions[set].subsets[subset]) && (setdefinitions[set].subsets[subset].label)) {
return setdefinitions[set].subsets[subset].label;
} else {
return subset;
}
}

function folia_isspan(tag) {
//Is the element a first order span element?
var foliaclass = foliatag2class[tag];
Expand Down
44 changes: 15 additions & 29 deletions flat/style/flat.viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) {
if (viewannotations[e.type+"/"+e.set]) {
s = s + "<tr><th>New";
if (addlabels) {
s = s + " " + folia_label(e.type);
s = s + " " + folia_label(e.type, e.set);
}
s = s + ":</th><td> ";
s = s + "<div class=\"correctionchild\">";
Expand All @@ -275,7 +275,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) {
if (viewannotations[e.type+"/"+e.set]) {
s = s + "<tr><th>Current";
if (addlabels) {
s = s + " " + folia_label(e.type);
s = s + " " + folia_label(e.type, e.set);
}
s = s + ":</th><td> ";
s = s + "<div class=\"correctionchild\">";
Expand All @@ -290,7 +290,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) {
if (viewannotations[original.type+"/"+original.set]) {
s = s + "<tr><th>Original";
if (addlabels) {
s = s + " " + folia_label(original.type);
s = s + " " + folia_label(original.type, original.set);
}
s = s + ":</th><td> ";
s = s + "<div class=\"correctionchild\">";
Expand All @@ -309,13 +309,13 @@ function rendercorrection(correctionid, addlabels, explicitnew) {
s = s + "<div class=\"correctionchild\">";
suggestion.children.forEach(function(child){
s = s + "<table>";
label = folia_label(child.type);
label = folia_label(child.type, child.set);
s = s + "<tr><th>" + label + "</th><td>";
s = s + renderannotation(child,true);
s = s + "</td></tr>";
if ((folia_isstructure(child.type)) && (child.children)) {
child.children.forEach(function(subchild){
s = s + "<tr><th>" + folia_label(subchild.type) + "</th><td>";
s = s + "<tr><th>" + folia_label(subchild.type, subchild.set) + "</th><td>";
s = s + renderannotation(subchild,true);
s = s + "</td></tr>";
});
Expand Down Expand Up @@ -411,7 +411,7 @@ function renderannotation(annotation, norecurse) {
if (subannotation.type) { //filter out invalid elements
if (subannotation.type != "correction") {
s = s + "<table>";
label = folia_label(subannotation.type);
label = folia_label(subannotation.type, subannotation.set);
if (subannotation.set) {
setname = subannotation.set;
} else {
Expand All @@ -431,12 +431,13 @@ function renderannotation(annotation, norecurse) {
s = s + "</div>";
}
if (annotation.children) {
//Render higher order annotation
for (i = 0; i < annotation.children.length; i++) {
if (annotation.children[i].type) {
if (annotation.children[i].type == "comment") {
s = s + "<br/><span class=\"higherorder\">Comment: " + annotation.children[i].value + "</span>";
} else if (annotation.children[i].type == "desc") {
s = s + "<br/><span class=\"higherorder\">Description: " + annotation.children[i].value + "</span>";
if ((annotation.children[i].type == "comment") || (annotation.children[i].type == "desc")) {
s = s + "<br/><span class=\"higherorder\">" + folia_label(annotation.children[i].type) + ": " + annotation.children[i].value + "</span>";
} else if (annotation.children[i].type == "feat") {
s = s + "<br/><span class=\"higherorder\">" + folia_label(annotation.children[i].type) + " " + annotation.children[i].subset + ": <span class=\"class\">" + annotation.children[i].class + "</span></span>";
}
}
}
Expand Down Expand Up @@ -473,16 +474,12 @@ function showinfo(element) {
if (element.id) {
var s = "";
if (annotations[element.id]) {
s = "<div id=\"id\">" + folia_label(annotations[element.id].self.type) + " &bull; " + element.id + " &bull; " + annotations[element.id].self.class + "</div><table>";
s = "<div id=\"id\">" + folia_label(annotations[element.id].self.type, annotations[element.id].self.set) + " &bull; " + element.id + " &bull; " + annotations[element.id].self.class + "</div><table>";
Object.keys(annotations[element.id]).forEach(function(annotationid){
annotation = annotations[element.id][annotationid];
if ((annotation.type != 'str') || ((annotation.type == 'str') && (annotationid == hoverstr))) { //strings too
if ((viewannotations[annotation.type+"/" + annotation.set]) && (annotation.type != "correction")) { //corrections get special treatment
if ((setdefinitions) && (setdefinitions[annotation.set]) && (setdefinitions[annotation.set].label)) {
label = setdefinitions[annotation.set].label;
} else {
label = folia_label(annotation.type);
}
label = folia_label(annotation.type, annotation.set);
if (annotation.set) {
setname = annotation.set;
} else {
Expand Down Expand Up @@ -633,14 +630,7 @@ function setclasscolors() {

var legendtype = annotationfocus.type;
var legendset = annotationfocus.set;
var legendtitle;
if ((setdefinitions[legendset]) && (setdefinitions[legendset].label)) {
legendtitle = setdefinitions[legendset].label;
} else if (folia_label(legendtype)) {
legendtitle = folia_label(legendtype);
} else {
legendtitle = annotationfocus.type;
}
var legendtitle = folia_label(legendtype, legendset);
var classfreq = computeclassfreq();

s = "<span class=\"title\">Legend &bull; " + legendtitle + "</span>"; //text for legend
Expand Down Expand Up @@ -1007,11 +997,7 @@ function viewer_loadmenus() {
} else {
state = "";
}
if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) {
label = setdefinitions[set].label;
} else {
label = folia_label(annotationtype);
}
label = folia_label(annotationtype, set);
s = s + "<li id=\"annotationtypeview_" +annotationtype+"_" + hash(set) + "\" " + state + "><a href=\"javascript:toggleannotationview('" + annotationtype + "', '" + set + "')\">" + label + "<span class=\"setname\">" + set + "</span></a></li>";
if (globannotationsorder.indexOf(annotationtype) != -1) {
if (('initialglobviewannotations' in configuration ) && ((configuration.initialglobviewannotations === true) || (configuration.initialglobviewannotations.indexOf(annotationtype + '/' + set) != -1) || (configuration.initialglobviewannotations.indexOf(annotationtype) != -1))) {
Expand Down

0 comments on commit 41ff49f

Please sign in to comment.