enhance modal warning
authorcavaliet
Wed, 29 May 2013 11:39:49 +0200
changeset 57 ba0de15418d1
parent 56 3725e93a2987
child 58 9e14b6f964fe
enhance modal warning
src/metadatacomposer/static/metadatacomposer/css/style.css
src/metadatacomposer/static/metadatacomposer/js/common.js
src/metadatacomposer/static/metadatacomposer/js/edition.js
src/metadatacomposer/static/metadatacomposer/js/ldt-serializer.js
src/metadatacomposer/templates/metadatacomposer_project_list.html
src/metadatacomposer/templates/metadatacomposer_resource_list.html
--- a/src/metadatacomposer/static/metadatacomposer/css/style.css	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/static/metadatacomposer/css/style.css	Wed May 29 11:39:49 2013 +0200
@@ -22,7 +22,7 @@
 .tab-behavior{text-align: center;}
 .tab-behavior li{display: inline-block; float: none;}
 td ul{margin-bottom: 0;}
-.bibliotheque-image .span2:nth-child(4n+1){clear: left;}
+.bibliotheque-image .span2:nth-child(4n+1), .bibliotheque-video .span2:nth-child(4n+1){clear: left;}
 .modal.popup{width: 970px; margin-left: -485px; height: 80%;}
 .popup .modal-body{max-height: none; background-color: #fff; height: 80%;}
 .previsualisation img{max-height: 400px;}
@@ -39,7 +39,7 @@
 .project-action a:last-child{margin-right: 20px;}
 .chapter-widget-info{margin-bottom: 20px;}
 .chapter-widget form{ margin: 0;}
-.chapter-widget input, .form-info-general-annotation input, .form-info-general-annotation textarea{width: 196px; max-width: 196px;  }
+.chapter-widget input, .form-info-general-annotation input, .form-info-general-annotation textarea{width: 196px; max-width: 196px;	}
 .chapter-widget textarea{width: 426px; max-width: 426px; min-width: 426px; height: 20px;-webkit-transition: height .3s ease;-moz-transition: height .3s ease;transition: height .3s ease;}
 .form-chapter-edit{}
 .chapter-widget-info table{margin: 0; padding-top: 40px; }
@@ -95,11 +95,14 @@
 .list-current-annotations li{list-style: none; margin-top: 4px;}
 .list-current-annotations a{text-align:center; line-height:20px; color:#FFF;display: inline-block; background-color: #589; width: 20px; height: 20px; }
 .list-current-annotations a:hover{text-decoration: none;}
-.annotation-son-content textarea{max-width: 206px;}
+.annotation-audio-content textarea{max-width: 206px;}
+
+.annotation-links-content .links-form:nth-child(n+2){border-top:1px solid; padding-top: 20px;}
+
 /* Tangle */
 .time-tangle {
-    color: #2c3e50; cursor: w-resize; position: relative;
-    border-bottom: 1px dashed #2c3e50;
+	color: #2c3e50; cursor: w-resize; position: relative;
+	border-bottom: 1px dashed #2c3e50;
 }
 .time-tangle:hover, 
 .time-tangle.active {
@@ -107,8 +110,8 @@
 }
 .time-tangle:hover:after, 
 .time-tangle.active:after {
-    position: absolute;
-    display: inline-block;
+	position: absolute;
+	display: inline-block;
     color: #2c3e50;  top: 18px; left: 50%; width: 160px;
     margin-left: -80px; font-size: 10px; text-align: center;
     content: "glisser pour modifier";
--- a/src/metadatacomposer/static/metadatacomposer/js/common.js	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/static/metadatacomposer/js/common.js	Wed May 29 11:39:49 2013 +0200
@@ -42,10 +42,12 @@
     $(document).on('click','.btn-delete', function(e){
         e.preventDefault();
         var titleMedia = $(this).attr('data-title'),
-            textModal = $('<p>Êtes-vous sûr de vouloir supprimer <strong>'+titleMedia+'</strong> ?</p>'),
             urlDelete = $(this).attr('href');
+        console.log("coucou");
+        console.log(titleMedia);
+        console.log($("#modal-confirm .modal-body").find('.titleMedia'));
         $("#modal-confirm #btn-delete-modal").attr('href', urlDelete).focus();
-        $("#modal-confirm .modal-body").empty().append(textModal); 
+        $("#modal-confirm .modal-body").find('.titleMedia').text(titleMedia);
         $("#modal-confirm").modal('show');
     });
 
--- a/src/metadatacomposer/static/metadatacomposer/js/edition.js	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/static/metadatacomposer/js/edition.js	Wed May 29 11:39:49 2013 +0200
@@ -7,7 +7,6 @@
 $(function(){
 
 var global = {
-    diaporama : null,
     idAnnotation : null,
     colorsIndex : 0,
     colors : 
@@ -18,15 +17,39 @@
 };
 
 
+
+
 myProject.onLoad(function() {
 
+
+
+
+//load Annotations
+myProject.getAnnotationsByTypeTitle("annotations");
+
+
     $(".project-title").text(myProject.title);
     
     myMedia = myProject.getCurrentMedia();
-    
+
+//load Chapitre
+var _chapters = myProject.getAnnotationsByTypeTitle("chapitrage");
+if(_chapters.length){
+    $.each(_chapters, function(k, v){
+        var render = false;
+        if((k+1) == _chapters.length){
+            render = true;
+        }
+        newChapter(v, render);
+    });
+}
+
+
+
+
     //chargement des chapitres et annotations existants
-    loadInitChapters();
-    loadInitAnnotation()
+  //  loadInitChapters();
+    loadInitAnnotation();
 
     IriSP.htmlPlayer(
         myMedia,
@@ -35,7 +58,16 @@
             width: 460,
             height: 345,
             controls: true,
-            autostart: true
+            autostart: true,
+            url_transform: function(src) {
+                return [{
+                    type: "video/mp4",
+                    src: src.replace(/\.[\d\w]+$/,'.mp4')
+                }, {
+                    type: "video/webm",
+                    src: src.replace(/\.[\d\w]+$/,'.webm')
+                }];
+            }
         }
     );
 
@@ -115,12 +147,9 @@
 //########### modal
 
     $(document).on('click', 'a.open-modal', function(e){
-        var diaporama = $(this).attr('data-diaporama'),
-            idAnnotation = $(this).attr('data-id');
+        var idAnnotation = $(this).attr('data-id');
 
-        if(diaporama !== undefined){
-            global.diaporama = diaporama;
-        }
+
         if(idAnnotation !== undefined){
             global.idAnnotation = idAnnotation;
         }
@@ -133,27 +162,23 @@
         $('.input-image-'+typeImage).show();
     });
 
-//bibliotheque
+//select on bibliotheque
+
     //video
     $('.popup').on('click', '.bibliotheque-video a', function(e){
         e.preventDefault();
+
+        var url = $(this).attr('href');
+        currentAnnotation.content.url = url;
+
         $('.popup').modal('hide');
         $.get('template.html', function(templates){
             var videoWrap = $('#tab-'+global.idAnnotation).find('.annotation-video-content'),
                 tplVideo = $(templates).filter('#tpl-video-row').html();
-                console.log(videoWrap)
             videoWrap.empty().append(tplVideo);
         });
         
     });
-    //image
-    $('.popup').on('click', '.bibliotheque-image a', function(e){
-        e.preventDefault();
-        var listDiaporama = $('#'+global.diaporama);
-        addImageToDiaporama(listDiaporama);
-        $('.popup').modal('hide');
-    });
-
     
 
     //confirmation suppression
@@ -265,7 +290,7 @@
 });
 
 //nouveau chapitre
-    function newChapter(dataChapter){
+    function newChapter(dataChapter, render){
         var chapter = new IriSP.Model.Annotation(false, myProject);
             chapter.setMedia(myMedia.id);
             chapter.setBegin(dataChapter.begin);
@@ -276,7 +301,7 @@
             chapter.color = global.colors[(global.colorsIndex<global.colors.length) ? global.colorsIndex++ : (global.colorsIndex=0)];
     
         chapters.push(chapter);
-        renderChapter();
+        if(render){renderChapter();}
         loadFormChapter(chapter.id);
     }
 
@@ -291,7 +316,7 @@
                 keywords : ['tag1','tag2']
             };
 
-        newChapter(dataChapter);
+        newChapter(dataChapter, true);
 
     });
     
@@ -505,6 +530,7 @@
         currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
 
         $.get('template.html', function(templates){
+
             //head commun à tous
             var tplHead = $(templates).filter('#tpl-head').html();
             var output = Mustache.render(tplHead, dataView);
@@ -512,30 +538,59 @@
             $(tabContent).find(".slider-duration").slider(configSlider(dataView));
             $(tabContent).find('.tag-it').tagit(tagitParam);
             //type
-            var viewType = {id : idAnnotation};
+            var viewType = {
+                id : idAnnotation,
+                content : dataView.content
+            };
             var tpl = $(templates).filter('#tpl-'+type).html();
+
             tpl = Mustache.render(tpl, viewType);
             $(tabContent).append(tpl);
             $('.tab-content').append(tabContent);
 
             //particularité selon type
             switch(type){
-                case 'sound':
+                case 'audio':
                     break;
                 case 'video':
+                    
+                    if(viewType.content.url != ""){
+                        var videoWrap = $(tabContent).find('.annotation-video-content'),
+                            tplVideo = $(templates).filter('#tpl-video-row').html();
+                        videoWrap.empty().append(tplVideo);
+                    }
+
                     break;
                 case 'text': 
                     var cledit = $(tabContent).find('.wysiwyg').cleditor(wysiwygConfig)[0];
                     break;
                 case 'links': 
+                    var tbody = $(tabContent).find('tbody.links-rows'),
+                        links = viewType.content.links;
+                    if(links.length){
+                        $.each(links, function(k,v){
+                            addLinkRow(tbody, v);
+                        });
+                    }else{//il n'y a pas de lien on en ajoute 1
+                        addLinkRow(tbody);
+                    }
                     break;
+
                 case 'slideshow': 
+
                     $(tabContent).find('.number-spin').spin(spinParam);
                     $(tabContent).find('.ui-sortable').sortable({
                         stop : function(event, ui){
                             disabledBtnSortable($(this));
                         }
                     });
+                    var diaporama = $(tabContent).find('#diaporama-'+idAnnotation),
+                        images = viewType.content.images;
+                    if(images.length){
+                        $.each(images, function(k,v){
+                            addImageToDiaporama(diaporama, v);
+                        });
+                    }
                     break;
             }
 
@@ -551,7 +606,7 @@
     function getIcon(type){
         var icon;
         switch(type){
-            case 'sound': icon = 'volume-up';
+            case 'audio': icon = 'volume-up';
                 break;
             case 'video': icon = 'film';
                 break;
@@ -599,12 +654,29 @@
     }
 
 //diaporama
-    function addImageToDiaporama(diaporama){
+
+    //bibliotheque
+    $('.popup').on('click', '.bibliotheque-image a', function(e){
+        e.preventDefault();
+
+        var url = $(this).attr('href'),
+            image = {
+                id : currentAnnotation.id,
+                url : url,
+                title : 'titre image',
+                description : 'description azerty'
+            };
+        currentAnnotation.content.images.push(image);
+
+        var listDiaporama = $('#diaporama-'+currentAnnotation.id);
+        addImageToDiaporama(listDiaporama, image);
+        $('.popup').modal('hide'); 
+    });
+
+    function addImageToDiaporama(diaporama, dataView){
         $.get('template.html', function(templates){
-            var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(),
-                uniqId = 'id' + (new Date()).getTime(),
-                viewDiapo = { ridid : uniqId};
-            tplDiapo = Mustache.render(tplDiapo, viewDiapo);
+            var tplDiapo = $(templates).filter('#tpl-diaporama-row').html();
+            tplDiapo = Mustache.render(tplDiapo, dataView);
             diaporama.append(tplDiapo);
             disabledBtnSortable(diaporama);
         });
@@ -631,10 +703,48 @@
     }
 
     
-
+//links
+$('.tab-content').on('click', '.add-link', function(e){
+    e.preventDefault();
+    var tbody = $(this).parents('tfoot').siblings('tbody');
+    addLinkRow(tbody);
+});
+$('.tab-content').on('click', '.delete-link', function(e){
+    e.preventDefault();
+    var row = $(this).parents('tr'),
+        tbody = $(this).find('tbody');
+    row.remove();
+    updateLinks(tbody);
+});
+function addLinkRow(tbody, dataView){
+    $.get('template.html', function(templates){
+        //head commun à tous
+        var tplLinkRow = $(templates).filter('#tpl-links-row').html();
+        var output = Mustache.render(tplLinkRow, dataView);
+        tbody.append(output);
+    });
+}
+$('.tab-content').on('keyup', '.links-rows input', function(e){
+    var tbody = $(this).parents('.links-rows');
+    updateLinks(tbody);   
+});
+function updateLinks(tbody){
+    links = new Array();
+    $.each(tbody.find('tr'), function(k, v){
+        var urlLink = $(v).find('.url-link').val(),
+            titleLink = $(v).find('.title-link').val(),
+            link = {
+                uri : urlLink,
+                title : titleLink
+            };
+            links.push(link);
+    });
+    currentAnnotation.content.links = links;
+}
 
 
 //annotation html
+/*
 $('.tab-content').on('click', '.btn-html-apercu', function(e){
     e.preventDefault();
 
@@ -643,18 +753,33 @@
 
     apercuWrap.empty().html(htmlTextarea.val());
 });
+*/
 
-//annotation texte
-$(document).on('keyup', ".cleditorMain iframe", function(){
+//annotation audio
+$('.tab-content').on('keyup', '.annotation-audio-content input, .annotation-audio-content textarea', function(){
+    var name = $(this).attr('name'),
+        value = $(this).val();
 
-    var v = $(this).text(); // or .html() if desired
-    $('#x').html(v);
+    currentAnnotation.content[name] = value;
 });
-//annotation > diaporama (spin)
+
+//annotation slideshow
+$('.tab-content').on('click', '.btn-autostart', function(){
+    var autostart = $(this).attr('data-autostart');
+    if(autostart == "true"){ autostart = true;}
+    else {autostart = false;}
+    currentAnnotation.content.autostart = autostart;
+});
 
 
+$('.tab-content').on('change keyup', '.config-diaporama input[name=duration]', function(){
+    var value = $(this).val();
+    if(!isNaN(value)){
+        currentAnnotation.content.duration = value;
+    }
+});
+
 //################ config
-
 //tagit
 function onTagItChange(e, ui) {
     var tagitType = $(this).attr('data-type'), 
@@ -691,11 +816,11 @@
     docType:      '<!DOCTYPE HTML>',
     bodyStyle:    "margin:0; font-family: 'Helvetica Neue',​Helvetica,​Arial,​sans-serif;",
     updateTextArea : function(text){
-
+        currentAnnotation.content.text = text;
         return text;
     },
     updateFrame: function(text){
-  
+        currentAnnotation.content.text = text;
         return text;
     }
 };
@@ -736,9 +861,9 @@
 function getContentAnnotationByType(type){
     var content;
     switch(type){
-        case 'sound':
+        case 'audio':
             content = {
-                mimetype : "application/x-ldt-sound",
+                mimetype : "application/x-ldt-audio",
                 url : "",
                 embedcode : ""
             };
@@ -754,13 +879,12 @@
             content = {
                 mimetype : "application/x-ldt-text",
                 markup : "html",
-                text : ""
+                text : "azerty"
             };
             break;
         case 'links': 
             content = {
                 mimetype : "application/x-ldt-links",
-                markup : "html",
                 links : []
             };
             break;
@@ -778,7 +902,7 @@
 
 
 //test
-a = $(".wysiwyg").cleditor(wysiwygConfig);
+//a = $(".wysiwyg").cleditor(wysiwygConfig);
 
 
 $('.number-spin').spin(spinParam);
@@ -794,4 +918,13 @@
 
 $(".tag-it").tagit();
 
+$('.log-annotations').bind('click', function(e){
+    e.preventDefault();
+    console.log(annotations.length + ' annotations', annotations);
+});
+
+$('.log-chapters').bind('click', function(e){
+    e.preventDefault();
+    console.log(chapters.length + ' chapitres',chapters);
+});
 });//ready
\ No newline at end of file
--- a/src/metadatacomposer/static/metadatacomposer/js/ldt-serializer.js	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/static/metadatacomposer/js/ldt-serializer.js	Wed May 29 11:39:49 2013 +0200
@@ -131,6 +131,7 @@
                     }
                     _res.color = '#' + _c;
                 }
+                _res.content = _data.content;
                 _res.setMedia(_data.media);
                 _res.setAnnotationType(_data.meta["id-ref"]);
                 _res.setTags(IriSP._(_data.tags).pluck("id-ref"));
@@ -153,14 +154,22 @@
                     id : _data.id,
                     begin : _data.begin.milliseconds,
                     end : _data.end.milliseconds,
-                    content : {
-                        title : _data.title || "",
-                        description : _data.description || "",
-                        audio : _data.audio,
-                        img: {
-                            src: _data.thumbnail
+                    content : IriSP._.defaults(
+                        {},
+                        {
+                            title : _data.title,
+                            description : _data.description,
+                            audio : _data.audio,
+                            img: {
+                                src: _data.thumbnail
+                            }
+                        },
+                        _data.content,
+                        {
+                            title: "",
+                            description: ""
                         }
-                    },
+                    ),
                     color: _color,
                     media : _data.media.id,
                     meta : {
@@ -177,6 +186,7 @@
                        } 
                     })
                 }
+                _res.content.title = _data.title || _res.content.title || "";
                 _dest.annotations.push(_res);
             }
         },
--- a/src/metadatacomposer/templates/metadatacomposer_project_list.html	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/templates/metadatacomposer_project_list.html	Wed May 29 11:39:49 2013 +0200
@@ -90,7 +90,9 @@
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
             <h3><i class="icon-warning-sign"></i> Confirmation de la suppression</h3>
         </div>
-        <div class="modal-body"></div>
+        <div class="modal-body">
+            <p>Êtes-vous sûr de vouloir supprimer <strong class="titleMedia"></strong> ?<br/>Attention, cette action est <strong>irréversible</strong>.</p>
+        </div>
         <div class="modal-footer">
             <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button>
             <a id="btn-delete-modal" class="btn btn-primary">Supprimer</a>
--- a/src/metadatacomposer/templates/metadatacomposer_resource_list.html	Tue May 28 18:51:57 2013 +0200
+++ b/src/metadatacomposer/templates/metadatacomposer_resource_list.html	Wed May 29 11:39:49 2013 +0200
@@ -54,9 +54,7 @@
             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
             <h3></h3>
         </div>
-        <div class="modal-body">
-
-        </div>
+        <div class="modal-body"></div>
     </div>
 
     <div id="modal-confirm" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
@@ -64,7 +62,9 @@
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
             <h3><i class="icon-warning-sign"></i> Confirmation de la suppression</h3>
         </div>
-        <div class="modal-body"></div>
+        <div class="modal-body">
+            <p>Êtes-vous sûr de vouloir supprimer <strong class="titleMedia"></strong> ?<br/>Attention, cette action est <strong>irréversible</strong>.</p>
+        </div>
         <div class="modal-footer">
             <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button>
             <a id="btn-delete-modal" class="btn btn-primary">Supprimer</a>