integration/js/edition.js
changeset 9 e3d551eda5a6
parent 6 547b3ddedf7f
child 16 c66274d0d850
equal deleted inserted replaced
8:7a5de13173b1 9:e3d551eda5a6
     1 (function(){
     1 $(function(){
     2 
     2 
     3 var global = {
     3 var global = {
     4     diaporama : null,
     4     diaporama : null,
     5     idAnnotation : null
     5     idAnnotation : null
     6 };
     6 };
     7 
     7 
     8 //modal
     8 //modal
     9     $('.popup').on('click', '.popup-content a', function(e){
     9     $(document).on('click', 'a.open-modal', function(e){
    10     	e.preventDefault();
    10         var diaporama = $(this).attr('data-diaporama'),
    11     	if($(this).hasClass('btn-cancel')){
    11             idAnnotation = $(this).attr('data-id');
    12     		$(this).parents('.popup').modal('hide');
    12 
    13     	}
    13         if(diaporama !== undefined){
    14     	if($(this).hasClass('btn-previsualisation')){
    14             global.diaporama = diaporama;
    15     		var imgPrev = $('<img src="img/520x520.gif" alt="" />');
    15         }
    16     		$('.previsualisation').empty().append(imgPrev);
    16         if(idAnnotation !== undefined){
    17     	}
    17             global.idAnnotation = idAnnotation;
    18     });
    18         }
       
    19     })
    19 //edition image
    20 //edition image
    20     $('.popup').on('change', '#media-type-select', function(e){
    21     $('.popup').on('change', '#media-type-select', function(e){
    21         var typeImage = $(this).val();
    22         var typeImage = $(this).val();
    22         $('.input-image-url, .input-image-upload').hide();
    23         $('.input-image-url, .input-image-upload').hide();
    23         $('.input-image-'+typeImage).show();
    24         $('.input-image-'+typeImage).show();
    42         $('.popup').modal('hide');
    43         $('.popup').modal('hide');
    43     });
    44     });
    44 
    45 
    45     $(document).on('click','.btn-delete', function(e){
    46     $(document).on('click','.btn-delete', function(e){
    46         e.preventDefault();
    47         e.preventDefault();
    47         var titleMedia = $(this).attr('data-title'),
       
    48             textModal = $('<p>Êtes-vous sûr de vouloir supprimer <strong>'+titleMedia+'</strong> ?</p>'),
       
    49             eltDelete = $(this).attr('href');
       
    50         $("#modal-confirm #btn-delete-modal").attr('data-id-elt-delete', eltDelete);
       
    51         $("#modal-confirm .modal-body").empty().append(textModal); 
       
    52         $("#modal-confirm").modal('show');
       
    53 
       
    54         //si c'est une annotation et que la tab est ouverte, on la ferme
    48         //si c'est une annotation et que la tab est ouverte, on la ferme
    55         var type = $(this).attr('data-type');
    49         var type = $(this).attr('data-type');
    56         if(type == 'annotation'){
    50         if(type == 'annotation'){
    57             var idAnnotation = $(this).attr('data-id');
    51             var idAnnotation = $(this).attr('data-id');
    58             $('a[href=#annotation-'+idAnnotation+']').closest('li').remove();
    52             $('a[href=#annotation-'+idAnnotation+']').closest('li').remove();
    61         }
    55         }
    62     });
    56     });
    63 
    57 
    64     //confirmation suppression
    58     //confirmation suppression
    65     $("#modal-confirm").on('click', '#btn-delete-modal', function(e){
    59     $("#modal-confirm").on('click', '#btn-delete-modal', function(e){
    66         e.preventDefault();
    60 
    67         var idEltDelete = $(this).attr('data-id-elt-delete');
    61     });
    68         $(idEltDelete).remove();
       
    69         $("#modal-confirm").modal('hide');
       
    70     });
       
    71 
       
    72     
       
    73 
       
    74 //page edition
       
    75 
    62 
    76 //title-editor
    63 //title-editor
    77 $('.project-title-editor ._popover').bind('click',function(e){e.preventDefault()});
    64 $('.project-title-editor ._popover').bind('click',function(e){e.preventDefault()});
    78     $('.project-title-editor ._popover').popover({
    65     $('.project-title-editor ._popover').popover({
    79         html : true,
    66         html : true,
   101     });
    88     });
   102 
    89 
   103     $(document).on('keyup', '.project-title-editor-input', function() {
    90     $(document).on('keyup', '.project-title-editor-input', function() {
   104         $('.project-title').html($(this).val());
    91         $('.project-title').html($(this).val());
   105     });
    92     });
       
    93 
   106 //chapter
    94 //chapter
   107     $('.list-chapter-wrap').on('click', '.edit-chapter', function(e){
    95     $('.list-chapter-wrap').on('click', '.edit-chapter', function(e){
   108         e.preventDefault();
    96         e.preventDefault();
   109         var viewChapter = {
    97         var viewChapter = {
   110             titre : 'titre du chapitre',
    98             titre : 'titre du chapitre',
   129             var tpl = $(templates).filter('#tpl-chapter-row').html();
   117             var tpl = $(templates).filter('#tpl-chapter-row').html();
   130             var tpl = Mustache.render(tpl, viewChapterRow);
   118             var tpl = Mustache.render(tpl, viewChapterRow);
   131             $('.list-chapter-rows-wrap').append(tpl);
   119             $('.list-chapter-rows-wrap').append(tpl);
   132         });
   120         });
   133     });
   121     });
   134 //tab
   122 
   135     $('#annotation-tab').on('click', 'a', function(e){
       
   136         e.preventDefault();
       
   137         $(this).tab('show');
       
   138     });
       
   139     $('#annotation-tab a:last-child').tab('show');
       
   140 
       
   141     //fermer tab
       
   142     $('#annotation-tab').on('click', 'span.close-tab', function(e){
       
   143         e.preventDefault();e.stopPropagation();
       
   144         var idTab = $(this).parents('a').attr('href');
       
   145         $(this).closest('li').remove();
       
   146         $('.tab-content '+idTab).remove();
       
   147         $('#tab-list-annotation').tab('show');
       
   148     });
       
   149     
   123     
   150     //ouvrir tab
       
   151     $(document).on('click', '.open-tab', function(e){
       
   152         e.preventDefault();
       
   153         var type = $(this).attr('data-type');
       
   154         var data = $(this).attr('data-data'); // à définir
       
   155         openNewTab(type);
       
   156     });
       
   157 
       
   158     //edit annotation
   124     //edit annotation
   159     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   125     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   160         e.preventDefault();
   126         e.preventDefault();
   161 
   127 
   162         var idAnnotation = $(this).attr('data-id');
   128         var idAnnotation = $(this).attr('data-id');
   166         }else{
   132         }else{
   167             var typeAnnotation = $(this).attr('data-type'),
   133             var typeAnnotation = $(this).attr('data-type'),
   168                 data = {id:idAnnotation};
   134                 data = {id:idAnnotation};
   169             openNewTab(typeAnnotation, data);
   135             openNewTab(typeAnnotation, data);
   170         } 
   136         } 
       
   137     });
       
   138 
       
   139 //tab
       
   140     $('#annotation-tab').on('click', 'a', function(e){
       
   141         e.preventDefault();
       
   142         $(this).tab('show');
       
   143     });
       
   144 
       
   145     //ouvrir tab
       
   146     $(document).on('click', '.open-tab', function(e){
       
   147         e.preventDefault();
       
   148         var type = $(this).attr('data-type');
       
   149         var data = $(this).attr('data-data'); // à définir
       
   150         openNewTab(type);
   171     });
   151     });
   172 
   152 
   173     function openNewTab(type, data){
   153     function openNewTab(type, data){
   174 
   154 
   175         var uniqId = 'id' + (new Date()).getTime(),
   155         var uniqId = 'id' + (new Date()).getTime(),
   218             $(".nav-tabs li:last-child").after('<li><a href="#annotation-'+idAnnotation+'"><i class="icon-'+iconTab+'"></i> New <span class="close-tab">&times;</span></a></li>');
   198             $(".nav-tabs li:last-child").after('<li><a href="#annotation-'+idAnnotation+'"><i class="icon-'+iconTab+'"></i> New <span class="close-tab">&times;</span></a></li>');
   219             $('a[href=#annotation-'+idAnnotation+']').tab('show');
   199             $('a[href=#annotation-'+idAnnotation+']').tab('show');
   220         });
   200         });
   221     }//openNewTab()
   201     }//openNewTab()
   222 
   202 
       
   203     //fermer tab
       
   204     $('#annotation-tab').on('click', 'span.close-tab', function(e){
       
   205         e.preventDefault();e.stopPropagation();
       
   206         var idTab = $(this).parents('a').attr('href');
       
   207         $(this).closest('li').remove();
       
   208         $('.tab-content '+idTab).remove();
       
   209         $('#tab-list-annotation').tab('show');
       
   210     });
       
   211 
       
   212 
   223 //diaporama
   213 //diaporama
   224 function addImageToDiaporama(diaporama){
   214     function addImageToDiaporama(diaporama){
   225         $.get('template.html', function(templates){
   215         $.get('template.html', function(templates){
   226             var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(),
   216             var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(),
   227                 uniqId = 'id' + (new Date()).getTime(),
   217                 uniqId = 'id' + (new Date()).getTime(),
   228                 viewDiapo = { ridid : uniqId};
   218                 viewDiapo = { ridid : uniqId};
   229             tplDiapo = Mustache.render(tplDiapo, viewDiapo);
   219             tplDiapo = Mustache.render(tplDiapo, viewDiapo);
   230             diaporama.append(tplDiapo);
   220             diaporama.append(tplDiapo);
   231             disabledBtnSortable(diaporama);
   221             disabledBtnSortable(diaporama);
   232         });
   222         });
   233     };
   223     };
   234 
   224 
       
   225     //bouton up / down
   235     $(document).on('click', '.ui-sortable .btn-sort', function(e){
   226     $(document).on('click', '.ui-sortable .btn-sort', function(e){
   236         e.preventDefault();
   227         e.preventDefault();
   237         var row = $(this).parents('tr.row-image-diaporama'),
   228         var row = $(this).parents('tr.row-image-diaporama'),
   238             listDiaporama = $(this).parents('.list-image-diaporama');
   229             listDiaporama = $(this).parents('.list-image-diaporama');
   239 
   230 
   249         listDiaporama.find('.btn-sort.disabled').removeClass('disabled');
   240         listDiaporama.find('.btn-sort.disabled').removeClass('disabled');
   250         listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled');
   241         listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled');
   251         listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled');
   242         listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled');
   252     }
   243     }
   253 
   244 
   254     $(document).on('click', 'a.open-modal', function(e){
   245     
   255         e.preventDefault();
       
   256         var modalRemote = $(this).attr('href'),
       
   257             typeMedia = $(this).attr('data-type-media'),
       
   258             modalTitleInfo = $(this).attr('data-title'),
       
   259             diaporama = $(this).attr('data-diaporama'),
       
   260             idAnnotation = $(this).attr('data-id'),
       
   261             titleFront;
       
   262 
       
   263         if(diaporama !== undefined){
       
   264             global.diaporama = diaporama;
       
   265         }
       
   266         if(idAnnotation !== undefined){
       
   267             global.idAnnotation = idAnnotation;
       
   268         }
       
   269 
       
   270         switch(typeMedia){
       
   271             case 'video' : titleFront = '<i class="icon-film"></i> Vidéo - '+modalTitleInfo; break;
       
   272             case 'image' : titleFront = '<i class="icon-picture"></i> Image - '+modalTitleInfo; break;
       
   273         }
       
   274         $('#modal-template .modal-header h3').html(titleFront);
       
   275 
       
   276         $("#modal-template .modal-body").load(modalRemote, function() { 
       
   277             $("#modal-template").modal("show"); 
       
   278         });
       
   279 
       
   280     });
       
   281 
   246 
   282 //sauvegarder annotation
   247 //sauvegarder annotation
   283 $('.tab-content').on('click', '.btn-save-annotation', function(e){
   248 $('.tab-content').on('click', '.btn-save-annotation', function(e){
   284     e.preventDefault();
   249     e.preventDefault();
   285     var idAnnotation = $(this).attr('data-id');
   250     var idAnnotation = $(this).attr('data-id');
   339         $( '#'+ idSlider +'-end' ).html(endString);
   304         $( '#'+ idSlider +'-end' ).html(endString);
   340         
   305         
   341     }
   306     }
   342 };
   307 };
   343 
   308 
   344 
   309 //milliseconds To 12h12m12s
   345 //test
       
   346 if($(".wysiwyg").length){
       
   347     $(".wysiwyg").cleditor(wysiwygConfig);
       
   348 }
       
   349 
       
   350 if($(".number-spin").length){
       
   351     $('.number-spin').spin(spinParam);
       
   352 }
       
   353 
       
   354 
       
   355 disabledBtnSortable($('.ui-sortable'))
       
   356 $('.ui-sortable').sortable({
       
   357     stop : function(event, ui){
       
   358         disabledBtnSortable($(this));
       
   359     }
       
   360 });
       
   361 
       
   362 
       
   363 
       
   364 
       
   365 $('.slider-duration').slider(configSlider);
       
   366 
       
   367 function millisecondsToString(milliseconds) {
   310 function millisecondsToString(milliseconds) {
   368     var oneHour = 3600000;
   311     var oneHour = 3600000;
   369     var oneMinute = 60000;
   312     var oneMinute = 60000;
   370     var oneSecond = 1000;
   313     var oneSecond = 1000;
   371     var seconds = 0;
   314     var seconds = 0;
   406     if (seconds > 0) {
   349     if (seconds > 0) {
   407         result += (seconds > 9 ? seconds : "0" + seconds) + "s";
   350         result += (seconds > 9 ? seconds : "0" + seconds) + "s";
   408     } else {
   351     } else {
   409         result += "00s";
   352         result += "00s";
   410     }
   353     }
   411 /*
   354 
   412     if (milliseconds > 0) {
       
   413         result += (milliseconds > 9 ? milliseconds : "0" + milliseconds);
       
   414     } else {
       
   415 
       
   416         result += "00";
       
   417     }
       
   418 */
       
   419     return result;
   355     return result;
   420 }
   356 }
   421 })(jQuery);
   357 
       
   358 //test
       
   359 $(".wysiwyg").cleditor(wysiwygConfig);
       
   360 
       
   361 $('.number-spin').spin(spinParam);
       
   362 
       
   363 disabledBtnSortable($('.ui-sortable'))
       
   364 $('.ui-sortable').sortable({
       
   365     stop : function(event, ui){
       
   366         disabledBtnSortable($(this));
       
   367     }
       
   368 });
       
   369 
       
   370 $('.slider-duration').slider(configSlider);
       
   371 
       
   372 $('#annotation-tab a:last-child').tab('show');
       
   373 
       
   374 });