comparison webapp/src/main/webapp/jquery/jquery.digilib.annotations.js @ 1084:1d3e8f853b9c

annotations basically working.
author robcast
date Thu, 31 May 2012 19:13:00 +0200
parents bab0bdac6d92
children 782593171adb
comparison
equal deleted inserted replaced
1083:bab0bdac6d92 1084:1d3e8f853b9c
89 var getAnnotationPageUrl = function(data) { 89 var getAnnotationPageUrl = function(data) {
90 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?'; 90 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?';
91 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults); 91 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults);
92 return url; 92 return url;
93 } 93 }
94
95 /** 94 /**
96 * add a mark-annotation where clicked. 95 * add a mark-annotation where clicked.
97 * 96 *
98 */ 97 */
99 var setAnnotationMark = function(data) { 98 var setAnnotationMark = function(data) {
158 }; 157 };
159 158
160 var loadAnnotations = function(data) { 159 var loadAnnotations = function(data) {
161 var settings = data.settings; 160 var settings = data.settings;
162 var url = settings.annotationServerUrl + '/search'; 161 var url = settings.annotationServerUrl + '/search';
163 var pageUrl = data.digilibBaseUrl + '/jquery/digilib.html?'; 162 var pageUrl = getAnnotationPageUrl(data);
164 pageUrl += digilib.fn.getParamString(settings, ['fn', 'pn'], digilib.defaults);
165 // send authentication token in header 163 // send authentication token in header
166 headers = { 164 headers = {
167 'x-annotator-auth-token' : data.annotationToken 165 'x-annotator-auth-token' : data.annotationToken
168 }; 166 };
169 // get only annotations with this url 167 // get only annotations with this url
196 data.annotations = annotations; 194 data.annotations = annotations;
197 }; 195 };
198 196
199 var parseAnnotation = function(ann) { 197 var parseAnnotation = function(ann) {
200 // TODO: check validity of annotation data 198 // TODO: check validity of annotation data
201 if (ann.area != null) { 199 if (ann.areas != null && ann.areas.length > 0) {
202 var pos = geom.position(ann.area.x, ann.area.y); 200 var area = ann.areas[0];
201 var pos = geom.position(area.x, area.y);
203 return newAnnotation(pos, ann.text, ann.id, ann.uri, ann.user); 202 return newAnnotation(pos, ann.text, ann.id, ann.uri, ann.user);
204 } 203 }
205 return null; 204 return null;
206 }; 205 };
207 206
214 headers = { 213 headers = {
215 'x-annotator-auth-token' : data.annotationToken 214 'x-annotator-auth-token' : data.annotationToken
216 }; 215 };
217 // create annotation object to send 216 // create annotation object to send
218 var annotData = { 217 var annotData = {
219 area : {x : annotation.pos.x, y : annotation.pos.y}, 218 areas : [{
219 x : annotation.pos.x,
220 y : annotation.pos.y
221 }],
220 text : annotation.text, 222 text : annotation.text,
221 uri : pageUrl, 223 uri : pageUrl,
222 user : settings.annotationUser 224 user : settings.annotationUser
223 }; 225 };
224 var dataString = JSON.stringify(annotData); 226 var dataString = JSON.stringify(annotData);
227 dataType : 'json', 229 dataType : 'json',
228 contentType : 'application/json', 230 contentType : 'application/json',
229 data : dataString, 231 data : dataString,
230 headers : headers, 232 headers : headers,
231 success : function(annotData, annotStatus) { 233 success : function(annotData, annotStatus) {
232 console.debug("sent annotation data, got=", annotData, " status="+annotStatus); 234 console.debug("sent annotation data, got=", annotData, " status=" + annotStatus);
233 var annot = parseAnnotation(annotData); 235 var annot = parseAnnotation(annotData);
234 // TODO: we have to add the returned data to the real annotation! 236 // TODO: we have to add the returned data to the real annotation!
235 //renderAnnotations(data); 237 //renderAnnotations(data);
236 } 238 }
237 }); 239 });