integration/js/edition.js
changeset 111 c0e4d761bcb6
parent 110 ebbb23d32748
child 115 9144b17b390e
equal deleted inserted replaced
110:ebbb23d32748 111:c0e4d761bcb6
     2     currentChapter = undefined,
     2     currentChapter = undefined,
     3     currentAnnotation = undefined,
     3     currentAnnotation = undefined,
     4     currentSlider = undefined,
     4     currentSlider = undefined,
     5     secMiniChapter = 10;
     5     secMiniChapter = 10;
     6 
     6 
       
     7 
       
     8 
       
     9 
     7 $(function(){
    10 $(function(){
       
    11 
       
    12     var annotationsColors = {
       
    13         'video' : '#BE4477',
       
    14         'text' : '#5E90CB',
       
    15         'slideshow' : '#F69058',
       
    16         'audio' : '#63BE6C',
       
    17         'links' : '#8985BB'
       
    18     }
     8 
    19 
     9     var global = {
    20     var global = {
    10         colorsIndex : 0,
    21         colorsIndex : 0,
    11         colors : 
    22         colors : 
    12             ['#1abc9c', '#3498db', '#9b59b6', '#2ecc71',  
    23             ['#FF6138', '#FFFF9D', '#BEEB9F', '#79BD8F',  '#00A388',
    13             '#f1c40f', '#ecf0f1', '#e67e22', '#e74c3c', '#95a5a6',
    24              '#1695A3', '#ACF0F2', '#F3FFE2', '#EB7F00', '#FF8000',
    14             '#16a085', '#2980b9', '#8e44ad', '#27ae60', 
    25              '#FFD933', '#CCCC52', '#8FB359', '#FFD393', '#F54F29'
    15              '#f39c12', '#c0392b', '#bdc3c7', '#d35400', '#7f8c8d']
    26             ]
    16     };
    27     };
    17 
    28 
    18     function getTemplate(idTpl){
    29     function getTemplate(idTpl){
    19         return $('#templates').find(idTpl).html();
    30         return $('#templates').find(idTpl).html();
    20     }
    31     }
    36             chapterAnnType = anntypes[0];
    47             chapterAnnType = anntypes[0];
    37         }
    48         }
    38 
    49 
    39         //load Chapitre
    50         //load Chapitre
    40         chapters = chapterAnnType.getAnnotations();
    51         chapters = chapterAnnType.getAnnotations();
       
    52         if(!chapters.length){
       
    53             var dataChapter = {
       
    54                 title : '',
       
    55                 begin : 0,
       
    56                 end : myMedia.duration,
       
    57                 description : '',
       
    58                 keywords : []
       
    59             };
       
    60             newChapter(dataChapter, true);
       
    61         }
    41         $.each(chapters, function(k, v){
    62         $.each(chapters, function(k, v){
    42             v.color = getRandomColor();
    63             v.color = getRandomColor();
    43         });
    64         });
    44         renderChapter();
    65         renderChapter();
    45 
    66 
    56         annotations = annotationsAnnType.getAnnotations();
    77         annotations = annotationsAnnType.getAnnotations();
    57         $.each(annotations, function(k, v){
    78         $.each(annotations, function(k, v){
    58             var type = v.content.mimetype.split('-');
    79             var type = v.content.mimetype.split('-');
    59             type = type[type.length-1]
    80             type = type[type.length-1]
    60             v.type = type;
    81             v.type = type;
    61             v.color = getRandomColor();
    82             v.color = annotationsColors[type];
    62         });
    83         });
    63         renderAnnotation();
    84         renderAnnotation();
    64 
    85 
    65 
    86 
    66         IriSP.htmlPlayer(
    87         IriSP.htmlPlayer(
   421             annotation.setBegin(dataAnnotation.begin);
   442             annotation.setBegin(dataAnnotation.begin);
   422             annotation.setEnd(dataAnnotation.end);
   443             annotation.setEnd(dataAnnotation.end);
   423             annotation.title = dataAnnotation.title;
   444             annotation.title = dataAnnotation.title;
   424             annotation.description = dataAnnotation.description;
   445             annotation.description = dataAnnotation.description;
   425             annotation.type = dataAnnotation.type;
   446             annotation.type = dataAnnotation.type;
   426             annotation.color = global.colors[(global.colorsIndex<global.colors.length) ? global.colorsIndex++ : (global.colorsIndex=0)];
   447             annotation.color = annotationsColors[dataAnnotation.type];
   427             annotation.keywords = dataAnnotation.keywords;
   448             annotation.keywords = dataAnnotation.keywords;
   428             annotation.content = getContentAnnotationByType(dataAnnotation.type);
   449             annotation.content = getContentAnnotationByType(dataAnnotation.type);
   429 
   450 
   430         myProject.getAnnotations().push(annotation);
   451         myProject.getAnnotations().push(annotation);
   431         annotations.push(annotation);
   452         annotations.push(annotation);
   568         openTab(type);
   589         openTab(type);
   569     });
   590     });
   570 
   591 
   571     function openTab(type, data){
   592     function openTab(type, data){
   572         
   593         
   573         var dataView;
   594         var dataView, isNew = false;
   574         if(_.isUndefined(data)){//nouveau
   595         if(_.isUndefined(data)){//nouveau
   575 
   596 
   576             var currentTimePlusUnMin = 60 * 1000 + myMedia.currentTime,
   597             var currentTimePlusUnMin = 60 * 1000 + myMedia.currentTime,
   577                 endAnnotation = (currentTimePlusUnMin<myMedia.duration) ? currentTimePlusUnMin : myMedia.duration;
   598                 endAnnotation = (currentTimePlusUnMin<myMedia.duration) ? currentTimePlusUnMin : myMedia.duration;
   578             var dataAnnotation = {
   599             var dataAnnotation = {
   583                 type : type,
   604                 type : type,
   584                 keywords : []
   605                 keywords : []
   585             };
   606             };
   586             dataView = newAnnotation(dataAnnotation);
   607             dataView = newAnnotation(dataAnnotation);
   587             renderAnnotation();
   608             renderAnnotation();
       
   609             isNew = true;
   588         }else{//édition
   610         }else{//édition
   589             dataView = data;
   611             dataView = data;
   590         }
   612         }
   591 
   613 
   592         var idAnnotation = dataView.id,
   614         var idAnnotation = dataView.id,
   601             $(tabContent).append(output);
   623             $(tabContent).append(output);
   602             $(tabContent).find(".slider-duration").slider(configSlider(dataView));
   624             $(tabContent).find(".slider-duration").slider(configSlider(dataView));
   603             currentSlider = $(tabContent).find(".slider-duration");
   625             currentSlider = $(tabContent).find(".slider-duration");
   604             $(tabContent).find(".ui-slider-range.ui-widget-header.ui-corner-all").css('background', dataView.color);
   626             $(tabContent).find(".ui-slider-range.ui-widget-header.ui-corner-all").css('background', dataView.color);
   605             $(tabContent).find('.tag-it').tagit(tagitParam);
   627             $(tabContent).find('.tag-it').tagit(tagitParam);
       
   628             
   606             //type
   629             //type
   607             var viewType = {
   630             var viewType = {
   608                 id : idAnnotation,
   631                 id : idAnnotation,
   609                 content : dataView.content
   632                 content : dataView.content
   610             };
   633             };
   676             var tplOnglet = getTemplate('#tpl-onglet');
   699             var tplOnglet = getTemplate('#tpl-onglet');
   677             var onglet = Mustache.render(tplOnglet, dataView);
   700             var onglet = Mustache.render(tplOnglet, dataView);
   678 
   701 
   679             $(".nav-tabs li:last-child").after(onglet);
   702             $(".nav-tabs li:last-child").after(onglet);
   680             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
   703             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
       
   704 
       
   705             if(isNew){$(tabContent).find('.head-title').focus();}
   681   
   706   
   682     }//openTab()
   707     }//openTab()
   683 
   708 
   684     function getIcon(type){
   709     function getIcon(type){
   685         var icon;
   710         var icon;
   910                 links.push(link);
   935                 links.push(link);
   911 
   936 
   912         });
   937         });
   913         currentAnnotation.content.links = links;
   938         currentAnnotation.content.links = links;
   914         disabledPreview();
   939         disabledPreview();
       
   940     }
       
   941     $('.tab-content').on('focus', '.url-link', function(){
       
   942         var td = $(this).parents('td');
       
   943         if(td.hasClass('error')) td.removeClass('error')
       
   944     });
       
   945     
       
   946     $('.tab-content').on('blur', '.url-link', function(){
       
   947         var url = $(this).val(),
       
   948             td = $(this).parents('td');
       
   949         if(!isValidLink(url)){
       
   950             td.addClass('error');
       
   951         }
       
   952     });
       
   953 
       
   954     function isValidLink(url){
       
   955         return /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(url);
   915     }
   956     }
   916 
   957 
   917     //annotation audio
   958     //annotation audio
   918     $('.tab-content').on('keyup', '.annotation-audio-content input, .annotation-audio-content textarea', function(){
   959     $('.tab-content').on('keyup', '.annotation-audio-content input, .annotation-audio-content textarea', function(){
   919         var name = $(this).attr('name'),
   960         var name = $(this).attr('name'),