cms/app-client/app/serializers/transcript.js
author Chloe Laisne <chloe.laisne@gmail.com>
Wed, 17 Aug 2016 15:30:19 +0200
changeset 255 ed05b89e3299
parent 245 c9dd78a43b07
child 256 18f0c3ee9aa5
permissions -rw-r--r--
Add words to transcript

import JSONAPISerializer from 'ember-data/serializers/json-api';

export default JSONAPISerializer.extend({

	normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
		var annotations = [];
		payload.annotations.forEach(function(annotation) {
			console.log('ANNOT', annotation.content.data.words);
			var annotationObject = {
				'content': annotation.content.data.content,
				'start': annotation.begin,
				'end': annotation.end
			};
			if(annotation.content.data.transl) {
				annotationObject.translation = annotation.content.data.transl['@value'];
			}
			if(annotation.content.data.words) {
				var words = [];
				annotation.content.data.words.forEach(function(word) {
					var wordObject = {
						'content': word.content,
						'translation': word.transl['@value']
					};
					words.push(wordObject);
				})
				annotationObject.words = words;
			}
			annotations.push(annotationObject);
		});
        return {
            'data': {
	            'id': id,
	            'type': 'transcript',
	            'attributes': {
	                'title': payload.meta['dc:title']['@value'],
	                'annotations': annotations
	            }
	        }
        };
	}

});