Get existing annotations from server, allowing the population of the tag list and allowing review. Code can be based on annotation.js
getTags : function(ev, oSelf) {
Y.detach("load");
var targetURI = this.get('target');
var field = this.get('field');
var oSelf = this;
Y.io(this.get("store.get"), {
method: 'GET',
data: {
hasTarget: targetURI,
field: field
},
on: {
success: function(e,o) {
var r = Y.JSON.parse(o.responseText);
if (r && r[field] && r[field].annotations) {
var ans = r[field].annotations;
var len = ans.length;
var user = oSelf.get('user');
var myMetaTags = oSelf.get('myMetaTags');
for (var i=0; i<len; i++) {
// look for relevant meta annotations
var annotation_target_uri = ans[i].hasTarget['@id'];
if (!annotation_target_uri) continue; // probably a fragment annotation
if (targetURI == annotation_target_uri) continue // normal annotation
var annotation_user = ans[i].annotatedBy;
if (user != annotation_user) continue // meta annotation from other user
var annotation_body = ans[i].hasBody['@id']?ans[i].hasBody['@id']:ans[i].hasBody['@value'];
var annotation_motiv = ans[i].motivatedBy;
if (!myMetaTags[annotation_target_uri])
myMetaTags[annotation_target_uri] = {};
if (annotation_motiv == Annotation.MOTIVATION.commenting)
myMetaTags[annotation_target_uri][annotation_motiv] = ans[i];
else
myMetaTags[annotation_target_uri][annotation_body] = ans[i];
}
oSelf.set('myMetaTags', myMetaTags);
for (var i=0; i<len; i++) {
if (!oSelf.enabled('showTag', ans[i])) continue; // hack for exp usage
oSelf.tags.add(ans[i]); // normal image fragment tag
oSelf.addTagFragment(ans[i], true);
}
}
}
}
}
);
}
Get existing annotations from server, allowing the population of the tag list and allowing review. Code can be based on annotation.js