corrections new-model
authorveltr
Fri, 08 Jun 2012 19:03:03 +0200
branchnew-model
changeset 915 ba7aab923d08
parent 914 3238d1625df9
child 916 ec6849bbbdcc
corrections
src/js/model.js
src/js/serializers/ldt_annotate.js
src/widgets/CreateAnnotation.js
--- a/src/js/model.js	Thu Jun 07 18:52:46 2012 +0200
+++ b/src/js/model.js	Fri Jun 08 19:03:03 2012 +0200
@@ -5,8 +5,26 @@
     _SOURCE_STATUS_WAITING : 1,
     _SOURCE_STATUS_READY : 2,
     _ID_AUTO_INCREMENT : 0,
+    _ID_BASE : (function(_d) {
+        function pad(n){return n<10 ? '0'+n : n}
+        function fillrand(n) {
+            var _res = ''
+            for (var i=0; i<n; i++) {
+                _res += Math.floor(16*Math.random()).toString(16);
+            }
+            return _res;
+        }
+        return _d.getUTCFullYear() + '-'  
+            + pad(_d.getUTCMonth()+1) + '-'  
+            + pad(_d.getUTCDate()) + '-'
+            + fillrand(16);
+    })(new Date()),
     getUID : function() {
-        return "autoid-" + (++this._ID_AUTO_INCREMENT);
+        var _n = (++this._ID_AUTO_INCREMENT).toString();
+        while (_n.length < 4) {
+            _n = '0' + _n
+        }
+        return "autoid-" + this._ID_BASE + '-' + _n;
     },
     regexpFromTextOrArray : function(_textOrArray) {
         function escapeText(_text) {
@@ -47,7 +65,7 @@
         _res.setTime(Number(time));
         return _res;
     },
-    dateToIso : function(d) {  
+    dateToIso : function(d) {
         function pad(n){return n<10 ? '0'+n : n}  
         return d.getUTCFullYear()+'-'  
             + pad(d.getUTCMonth()+1)+'-'  
--- a/src/js/serializers/ldt_annotate.js	Thu Jun 07 18:52:46 2012 +0200
+++ b/src/js/serializers/ldt_annotate.js	Fri Jun 08 19:03:03 2012 +0200
@@ -13,13 +13,14 @@
                     begin: _data.begin.milliseconds,
                     end: _data.end.milliseconds,
                     content: {
-                        data: _data.description
+                        data: _data.description,
+                        audio: _data.audio
                     },
                     tags: _data.getTagTexts(),
                     media: _source.unNamespace(_data.getMedia().id),
                     title: _data.title,
                     type_title: _data.getAnnotationType().title,
-                    type: _source.unNamespace(_data.getAnnotationType().id)
+                    type: ( typeof _data.getAnnotationType().dont_send_id !== "undefined" && _data.getAnnotationType().dont_send_id ? "" : _source.unNamespace(_data.getAnnotationType().id) )
                 }
             }
         }
@@ -79,6 +80,9 @@
             _ann.setBegin(_anndata.begin);
             _ann.setEnd(_anndata.end);
             _ann.creator = _data.meta.creator;
+            if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) {
+                _ann.audio = _anndata.content.audio;
+            }
             _source.getAnnotations().push(_ann);
         }
     }
--- a/src/widgets/CreateAnnotation.js	Thu Jun 07 18:52:46 2012 +0200
+++ b/src/widgets/CreateAnnotation.js	Fri Jun 08 19:03:03 2012 +0200
@@ -216,9 +216,14 @@
     var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager);
         _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}),
         _annotation = new IriSP.Model.Annotation(false, _export),
-        _annotationType = new IriSP.Model.AnnotationType(false, _export),
+        _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type),
+        _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)),
         _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId});
 
+    if (!_annotationTypes.length) {
+        _annotationType.dont_send_id = true;
+    }
+    
     _annotationType.title = this.annotation_type;
     _annotation.setBegin(this.begin);
     _annotation.setEnd(this.end);