integration/js/edition.js
changeset 84 9f481f896e60
parent 83 8f954a0d6031
child 86 e61b3adf46f2
--- a/integration/js/edition.js	Thu Jun 06 12:35:59 2013 +0200
+++ b/integration/js/edition.js	Thu Jun 06 14:59:59 2013 +0200
@@ -1,8 +1,6 @@
 var myMedia = undefined,
     currentChapter = undefined,
-    currentAnnotation = undefined,
-    chapters = [],
-    annotations = [];
+    currentAnnotation = undefined;
 
 $(function(){
 
@@ -38,35 +36,40 @@
 
     myMedia = myProject.getCurrentMedia();
 
+    var anntypes = myProject.getAnnotationTypes().searchByTitle("chapitrage");
+    if (!anntypes.length) {
+        chapterAnnType = new IriSP.AnnotationType(false, myProject);
+        chapterAnnType.title = "chapitrage";
+    } else {
+        chapterAnnType = anntypes[0];
+    }
+
 //load Chapitre
-var _chapters = myProject.getAnnotationsByTypeTitle("chapitrage");
-if(_chapters.length){
-    $.each(_chapters, function(k, v){
+
+    chapters = chapterAnnType.getAnnotations();
+    $.each(chapters, function(k, v){
         v.color = getRandomColor();
-        chapters.push(v);
-        if((k+1) == _chapters.length){
-            renderChapter();
-        }
     });
-}
+    renderChapter();
 
 //load Annotations
-var _annotations = myProject.getAnnotationsByTypeTitle("annotations");
-if(_annotations.length){
-    $.each(_annotations, function(k, v){
+    var anntypes = myProject.getAnnotationTypes().searchByTitle("annotations");
+    if (!anntypes.length) {
+        annotationsAnnType = new IriSP.AnnotationType(false, myProject);
+        annotationsAnnType.title = "annotations";
+    } else {
+        annotationsAnnType = anntypes[0];
+    }
 
-        v.color = getRandomColor();
+    annotations = annotationsAnnType.getAnnotations();
+    $.each(annotations, function(k, v){
         var type = v.content.mimetype.split('-');
         type = type[type.length-1]
         v.type = type;
+        v.color = getRandomColor();
+    });
+    renderAnnotation();
 
-        annotations.push(v);
-        if((k+1) == _annotations.length){
-            renderAnnotation();
-        }
-
-    });
-}
 
     IriSP.htmlPlayer(
         myMedia,
@@ -315,6 +318,7 @@
             chapter.setMedia(myMedia.id);
             chapter.setBegin(dataChapter.begin);
             chapter.setEnd(dataChapter.end);
+            chapter.setAnnotationType(chapterAnnType.id);
             chapter.title = dataChapter.title;
             chapter.description = dataChapter.description;
             chapter.keywords = dataChapter.keywords;
@@ -397,6 +401,7 @@
 
     function newAnnotation(dataAnnotation){
         var annotation = new IriSP.Model.Annotation(false, myProject);
+            annotation.setAnnotationType(annotationsAnnType.id);
             annotation.setMedia(myMedia.id);
             annotation.setBegin(dataAnnotation.begin);
             annotation.setEnd(dataAnnotation.end);
@@ -886,6 +891,28 @@
 $('.btn-save-project').bind('click', function(e){
     $('.btn-apercu-projet').removeClass('disabled');
 
+    console.log(myProject.serialize().length);
+/*
+    $.ajax({
+        type: "POST",
+        url: urlSaveProject,
+        data: myProject.serialize(),
+        contentType: "application/cinelab",
+        headers: {
+            //"X-CSRFToken": options.csrf_token
+        },
+        success: function(data, status, request){
+            console.log('data : ', data);
+            console.log('status : ', status);
+            console.log('request : ', request);
+
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert(gettext("Server error\nYour hashcut couldn't be published"));
+        }
+    });
+*/
+
 });
 
 function disabledPreview(){