integration/js/edition.js
changeset 35 6eb0de10e9f8
parent 34 e3a17ec94cd8
child 36 4c2428524c22
--- a/integration/js/edition.js	Thu May 23 18:11:55 2013 +0200
+++ b/integration/js/edition.js	Fri May 24 11:02:32 2013 +0200
@@ -98,17 +98,7 @@
         $('.popup').modal('hide');
     });
 
-    $(document).on('click','.btn-delete-annotation', function(e){
-        e.preventDefault();
-        //si c'est une annotation et que la tab est ouverte, on la ferme
-        var type = $(this).attr('data-type');
-     
-        var idAnnotation = $(this).attr('data-id');
-        $('a[href=#tab-annotation-'+idAnnotation+']').closest('li').remove();
-        $('.tab-content #annotation'+idAnnotation).remove();
-        $('#tab-list-annotation').tab('show');
-        
-    });
+    
 
     //confirmation suppression
     $("#modal-confirm").on('click', '#btn-delete-modal', function(e){
@@ -327,6 +317,7 @@
             };
 
         newAnnotation(dataAnnotation);
+        renderAnnotation();
     }
 
     function newAnnotation(dataAnnotation){
@@ -341,7 +332,8 @@
             annotation.keywords = dataAnnotation.keywords;
 
         annotations.push(annotation);
-        renderAnnotation();
+        
+        return annotation;
     }
 
     function renderAnnotation(){
@@ -404,6 +396,18 @@
         }
     });
 
+    //delete annotation
+    $(document).on('click','.btn-delete-annotation', function(e){
+        e.preventDefault();
+
+        var idAnnotation = $(this).attr('data-id');
+        annotations = _(annotations).reject(function(c) { return c.id == idAnnotation; });
+        closeTab(idAnnotation);
+        if(!$(this).hasAttr('data-no-render'))//si on ferme à partir de la tab renderAnnotation sera appelé 2 fois
+            renderAnnotation();
+
+    });
+
 //tab
     $('#onglet-annotations').on('click', 'a', function(e){
         e.preventDefault();
@@ -419,10 +423,18 @@
 
     function openTab(type, data){
         
-        var dataView = {};
+        var dataView;
         if(_.isUndefined(data)){//nouveau
-            dataView.id = 'id' + (new Date()).getTime();
-            dataView.title = 'New';
+            var dataAnnotation = {
+                title : 'Nouveau',
+                begin : 60 * 1000,
+                end : 60 * 1000 * 2,
+                description : 'description',
+                type : type,
+                keywords : []
+            };
+            dataView = newAnnotation(dataAnnotation);
+            renderAnnotation();
         }else{//édition
             dataView = data;
         }
@@ -449,6 +461,8 @@
 
             //particularité selon type
             switch(type){
+                case 'son': iconTab = 'volume-up';
+                    break;
                 case 'video': iconTab = 'film';
                     break;
                 case 'text':