web/static/ldt/js/projectscontents.js
changeset 104 b62a2a3e272d
parent 103 5578dcb54f4d
child 105 6094ab306d77
equal deleted inserted replaced
103:5578dcb54f4d 104:b62a2a3e272d
     1 
       
     2 $.fn.realVal = function() {
       
     3     var obj = $(this[0]);
       
     4     if(obj.val) {
       
     5         if(obj.val() === obj.attr('defaultText')) {
       
     6             return '';
       
     7         }
       
     8         else {
       
     9             return obj.val();
       
    10         }
       
    11     }
       
    12     else {
       
    13         return null;
       
    14     }
       
    15 };
       
    16 
       
    17 
       
    18 function init_events_base(base_node, embed_url) {
       
    19 
       
    20     $('.ldt_link_embed',base_node).click(function(e) {
       
    21         e.preventDefault();
       
    22         var link = $(e.target);
       
    23         var json_url = link.attr("href");
       
    24         var player_id = link.attr("id");
       
    25         var ldt_id = player_id.substring(15);
       
    26         $('<a />', {
       
    27             href: embed_url+'?json_url='+escape(json_url)+'&player_id='+escape(player_id)+'&ldt_id='+escape(ldt_id),
       
    28             target: "_blank"
       
    29         }).nyroModal({
       
    30             filters: ['iframe'],
       
    31             sizes: {
       
    32                 minW: '750',
       
    33                 minH: '662'
       
    34             },
       
    35             callbacks: {
       
    36                 afterShowCont: function(nm) {
       
    37                     nm.store.iframe.height(662);
       
    38                     nm.store.iframe.width(750);
       
    39                 }
       
    40             }
       
    41             }).trigger('nyroModal');
       
    42         return false;
       
    43     });
       
    44 
       
    45 
       
    46     $('.imageline',base_node).each(function(i) {
       
    47         var tr = $(this);
       
    48         tr.mouseover(function() {
       
    49             $('.cellimgdiv',this).css('visibility', 'visible');
       
    50         }); 
       
    51         tr.mouseout(function() {
       
    52             $('.cellimgdiv',this).css('visibility', 'hidden');
       
    53         });
       
    54     });
       
    55     
       
    56     $('.cellimgdiv img').qtip({ 
       
    57         style: { 
       
    58             'name': 'dark',
       
    59             'filter':'alpha(opacity=70)',
       
    60             '-moz-opacity':'0.7',
       
    61             '-khtml-opacity': '0.7',
       
    62             'opacity': '0.7',
       
    63             'border': {
       
    64                 'width' : '0',
       
    65                 'color': '#505050'
       
    66             }, 
       
    67             'tip': true
       
    68         } 
       
    69     });
       
    70 }
       
    71 
       
    72 function testAndClose(close_fn) {
       
    73 	
       
    74 	return function(force) {
       
    75 	    // Here we ask LDT if the current work is modified and if the user want to save it.
       
    76 	    var ldtSwf =  $('#ldtInitSwf',$.nmTop().store.iframe.contents()).get(0);
       
    77 	    // In the ldt_link_create case, the modal page can be the form, or the ldt swf. So we have to test.
       
    78 	    if (!force && ldtSwf && ldtSwf.name==="ldtInitSwf" && ldtSwf.isModified()==="true") {
       
    79 	        ldtSwf.askSave();
       
    80 	    }
       
    81 	    else {
       
    82             close_fn.apply(this);
       
    83 	    }
       
    84 	};
       
    85 }
       
    86 
       
    87 function testCreateAndClose(nm, close_fn) {
       
    88 	
       
    89 	return function(force) {
       
    90 	    // We get the frames vars
       
    91         f = window.frames[0];
       
    92         form_status =  $('#content_form_status',$.nmTop().store.iframe.contents()).val();
       
    93 	    // If form_status is "saved", we don't have to test anything, the form was was normally submitted.
       
    94         // If was status is "empty" AND an upload from local was done
       
    95         if(form_status!="saved" && f.upload_from_local_done==true && f.remove_temp_file_url){
       
    96             // ERASE FILE
       
    97             //alert("testCreateAndClose : " + "f = " + f + ", status = " + form_status + ", u = " + f.upload_from_local_done + ", s = " + f.submit_asked + ", url = " + f.remove_temp_file_url);
       
    98             $.ajax({
       
    99                 type: "GET",
       
   100                 url: f.remove_temp_file_url,
       
   101                 data: "filename="+ $('#id_media-local_file_name',$.nmTop().store.iframe.contents()).val(),
       
   102                 cache: false,
       
   103                 success: function(data, status, request){
       
   104                     //alert("remove success");
       
   105                 }
       
   106             });
       
   107         }
       
   108         close_fn.apply(this);
       
   109 	};
       
   110 }
       
   111 
       
   112 function searchCallback(target, container_selector, url, timeout) {
       
   113 
       
   114     timeout = typeof(timeout) !== 'undefined' ? timeout : 0;
       
   115     target = $(target);
       
   116     
       
   117     // remove all qtip
       
   118     $(".qtip").remove();
       
   119     
       
   120     if(target.realVal().length > 0) {
       
   121         target.nextAll(".searchclear").show();
       
   122     }
       
   123 
       
   124     if(target.attr('timer')) {
       
   125         clearTimeout(target.attr('timer'));
       
   126     }
       
   127 
       
   128     target.attr(
       
   129         'timer',
       
   130         setTimeout(function() {
       
   131             target.next(".searchajaxloader").show();
       
   132             target.nextAll(".searchclear").hide();
       
   133             var filterVal = "_" + escape(target.realVal());
       
   134             url = url.replace('__FILTER__',filterVal);
       
   135             $.ajax({
       
   136                 url: url,
       
   137                 cache: false,
       
   138                 success: function(data, status, request) {
       
   139                     $(container_selector).html(data);
       
   140                     target.next(".searchajaxloader").hide();
       
   141                     if(target.realVal().length > 0) {
       
   142                         target.nextAll(".searchclear").show();
       
   143                     }
       
   144                     init_events($(container_selector));
       
   145                     target.removeAttr('timer');
       
   146                 }
       
   147             });    
       
   148         },
       
   149         300)
       
   150     );
       
   151 }
       
   152 
       
   153 
       
   154 function init_events_contents(base_node, embed_url, content_filter_url) {
       
   155     
       
   156     init_events_base(base_node, embed_url);
       
   157     
       
   158     $('.content_link_create').each(function(i){
       
   159         $(this).attr("target","_blank");
       
   160     });
       
   161     $('.content_link_create').nyroModal({
       
   162         filters: ['iframe'],
       
   163         sizes: {
       
   164             minW: 770,
       
   165             minH: 550
       
   166         },
       
   167         callbacks: {
       
   168             afterClose: function(nm) {
       
   169                 searchCallback($('#searchprojectsinput'), "#contentslistcontainer", content_filter_url);
       
   170             },
       
   171             afterShowCont: function(nm) {
       
   172                 nm.store.iframe.width(770);
       
   173                 nm.store.iframe.height(550);
       
   174                 nm.store.iframe.load(function() {
       
   175                     var form_status = $(this).contents().find("#content_form_status").val(); 
       
   176                     if(form_status === 'saved' || form_status === 'deleted' ) {
       
   177                         $.nmTop().close();
       
   178                     }
       
   179                 });
       
   180             }
       
   181         }
       
   182     });
       
   183     $('.content_link_create',base_node).each(function(i, e) {
       
   184         nm = $(e).data('nmObj');
       
   185         $(e).data('nmObj', $.extend(true, nm, {
       
   186             close: testCreateAndClose(nm, nm.close)
       
   187         }));
       
   188     });  
       
   189     
       
   190     $('.contenttitlelink').each(function(i){
       
   191         $(this).attr("target","_blank");
       
   192     });
       
   193     $('.contenttitlelink').nyroModal({
       
   194         filters: ['iframe'],
       
   195         sizes: {
       
   196             minW: 770,
       
   197             minH: 550
       
   198         },
       
   199         callbacks: {
       
   200             afterClose: function(nm) {
       
   201                 searchCallback($("#searchcontentsinput"),"#contentslistcontainer",content_filter_url,0);    
       
   202             },
       
   203             afterShowCont: function(nm) {
       
   204                 nm.store.iframe.width(770);
       
   205                 nm.store.iframe.height(550);
       
   206                 nm.store.iframe.load(function() {
       
   207                       var form_status = $(this).contents().find("#content_form_status").val(); 
       
   208                       if(form_status === 'saved' || form_status === 'deleted') {
       
   209                           $.nmTop().close();
       
   210                       }
       
   211                   });
       
   212             }
       
   213         }
       
   214     });
       
   215     
       
   216 }
       
   217 
       
   218 function init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) {
       
   219 
       
   220     // These are the functions called when we display a project in an LDT modal window
       
   221     $('.ldt_link',base_node).each(function(i){
       
   222         $(this).attr("target","_iri");
       
   223     });
       
   224     $('.ldt_link',base_node).nyroModal({
       
   225         filters: ['iriIframe'],
       
   226         sizes: {
       
   227             minW: '1025',
       
   228             minH: '665'
       
   229         },
       
   230         showCloseButton: true,
       
   231         closeOnEscape:false,
       
   232         closeOnClick:false,
       
   233         callbacks: {
       
   234             afterShowCont: function(nm) {
       
   235                 nm.store.iframe.width(1025);
       
   236                 nm.store.iframe.height(665);
       
   237             },
       
   238             close: function(nm) {
       
   239                 // We don't do anything here, we hack the callback directly from the close function.
       
   240             },
       
   241             afterClose: function(nm) {
       
   242                 // Can't do that because searchprojectfilterurl is not defined in init_events_base params
       
   243                 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
       
   244             }
       
   245         }
       
   246     });
       
   247 
       
   248 
       
   249     $('.ldt_link',base_node).each(function(i, e) {
       
   250         nm = $(e).data('nmObj');
       
   251         $(e).data('nmObj', $.extend(true, nm, {
       
   252             close: testAndClose(nm.close)
       
   253         }));
       
   254     });    
       
   255 
       
   256 
       
   257     $('.ldt_link_create',base_node).each(function(i){
       
   258         $(this).attr("target","_iri");
       
   259     });
       
   260     $('.ldt_link_create',base_node).nyroModal({
       
   261          
       
   262         filters: ['iriIframe'],
       
   263         sizes: {
       
   264             minW: '600',
       
   265             minH: '500'
       
   266         },
       
   267         showCloseButton:true,
       
   268         closeOnEscape:false,
       
   269         closeOnClick:false,
       
   270         callbacks: {
       
   271             afterShowCont: function(nm) {
       
   272                 nm.store.iframe.width(600);
       
   273                 nm.store.iframe.height(600);
       
   274                 var iframe = nm.store.iframe;
       
   275                 iframe.load(function(){
       
   276                     var form_status = $(this).contents().find("#project_form_status").val(); 
       
   277                     if(form_status === 'saved' || form_status === 'deleted' ) {
       
   278                         $.nmTop().close();
       
   279                     }
       
   280                     var swfobject = $(this).contents().find("#ldtInitSwf"); 
       
   281                     if (swfobject.length) {
       
   282                         nm['sizes']['initW'] = 1025;
       
   283                         nm['sizes']['initH'] = 665;
       
   284                         nm.resize();
       
   285                         nm.store.iframe.width(1025);
       
   286                         nm.store.iframe.height(665);
       
   287                     }
       
   288                 });
       
   289             },
       
   290             afterClose: function(nm) {
       
   291                 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
       
   292             }
       
   293         }        
       
   294     });
       
   295     $('.ldt_link_create',base_node).each(function(i, e) {
       
   296         nm = $(e).data('nmObj');
       
   297         $(e).data('nmObj', $.extend(true, nm, {
       
   298             close: testAndClose(nm.close)
       
   299         }));
       
   300     });
       
   301 
       
   302     
       
   303     $('.publishedproject', base_node).click(function(e) {
       
   304         e.preventDefault();
       
   305         var target = $(e.target);
       
   306         var project_id = target.attr('id').replace('project_','');
       
   307         var url = unpublishprojecturl.replace('__PROJECT_ID__', project_id);
       
   308         $.ajax({
       
   309             url: url,
       
   310             type: 'POST',
       
   311             data: {csrfmiddlewaretoken:global_csrf_token},
       
   312             // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
       
   313             //dataType: 'json',
       
   314             success: function(json, textStatus, XMLHttpRequest) {
       
   315                 if(json.res) {
       
   316                     searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
       
   317                 }
       
   318             }
       
   319         });
       
   320     });
       
   321     
       
   322     $('.unpublishedproject', base_node).click(function(e) {
       
   323         e.preventDefault();
       
   324         var target = $(e.target);
       
   325         var project_id = target.attr('id').replace('project_','');
       
   326         var url = publishprojecturl.replace('__PROJECT_ID__', project_id);
       
   327         $.ajax({
       
   328             url: url,
       
   329             type: 'POST',
       
   330             data: {csrfmiddlewaretoken:global_csrf_token},
       
   331             // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
       
   332             //dataType: 'json',
       
   333             success: function(json, textStatus, XMLHttpRequest) {
       
   334                 if(json.res) {
       
   335                     searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
       
   336                 }
       
   337             }
       
   338         });
       
   339     });
       
   340 
       
   341     $('.projecttitlelink').each(function(i){
       
   342         $(this).attr("target","_blank");
       
   343     });
       
   344     $('.projecttitlelink').nyroModal({
       
   345         filters: ['iframe'],
       
   346         sizes: {
       
   347             minH:680, 
       
   348             minW:600
       
   349         },
       
   350         callbacks: {
       
   351             afterClose: function(nm) {
       
   352                 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
       
   353             },
       
   354             afterShowCont: function(nm) {
       
   355                 nm.store.iframe.height(680);
       
   356                 nm.store.iframe.width(600);
       
   357                 var iframe = nm.store.iframe;
       
   358                 iframe.load(function(){
       
   359                       var form_status = $(this).contents().find("#project_form_status").val(); 
       
   360                       if(form_status === 'saved' || form_status === 'deleted') {
       
   361                           $.nmTop().close();
       
   362                       }
       
   363                   });
       
   364             }
       
   365         }
       
   366     });
       
   367     
       
   368 }
       
   369 
       
   370 function init_events_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) {
       
   371     init_events_base(base_node, embed_url);
       
   372     init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl);
       
   373 }
       
   374 
       
   375 function init_events_all(base_node, embed_url, searchcontentfilterurl, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) {
       
   376     init_events_contents(base_node, embed_url, searchcontentfilterurl);
       
   377     init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl);
       
   378 }
       
   379 
       
   380 function searchFieldInit(input_list_init) {
       
   381 
       
   382     $(".searchfieldinputbase").keydown(function (e) {
       
   383          if(e.which === 27) {
       
   384               $(e.target).blur();
       
   385               $(e.target).next(".searchajaxloader").hide();
       
   386          }
       
   387     });        
       
   388      
       
   389     $('.searchfieldinput').each(function(i) {
       
   390          var sbox = $(this);
       
   391          if(sbox.val() !== '') {
       
   392              sbox.attr('defaultText', sbox.val());
       
   393          }
       
   394     
       
   395          sbox.focus(function() {
       
   396              box = $(this);
       
   397              if(box.val() === box.attr('defaultText')) {
       
   398                  box.val('');
       
   399                  box.toggleClass("searchfieldinput");
       
   400              }
       
   401          });
       
   402     
       
   403          sbox.blur(function() {
       
   404              var box = $(this);
       
   405              if(box.val() === '' && box.attr('defaultText')) {
       
   406                  box.val(box.attr('defaultText'));
       
   407                  box.toggleClass("searchfieldinput");
       
   408              }
       
   409          });
       
   410                   
       
   411     });
       
   412 
       
   413     $.each(input_list_init, function(index, value) {
       
   414         $(value['input_selector']).keyup(function (e) {
       
   415             searchCallback(e.target, value['container_selector'], value['url']);
       
   416         });
       
   417     });
       
   418     
       
   419     $('.searchclear').click(function(e) {
       
   420         var box = $(e.target).parent().find("input");
       
   421         box.val(box.attr('defaultText'));
       
   422         box.addClass("searchfieldinput");
       
   423         box.blur();
       
   424         box.keyup();
       
   425     });
       
   426     
       
   427     $('.searchclear').each(function(i) {
       
   428         $(this).hide();
       
   429     });
       
   430     
       
   431 }
       
   432 
       
   433 //
       
   434 // Functions used in the create content view.
       
   435 //
       
   436 function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label, wait_label, cancel_label, remove_url) {
       
   437 	
       
   438     window.upload_from_local_done = false;
       
   439     window.submit_asked = false;
       
   440     window.remove_temp_file_url = remove_url;
       
   441     
       
   442     $("#close_button").click(function (e) {
       
   443         e.preventDefault();
       
   444         parent.$.nmTop().close();
       
   445     });
       
   446     $("#submit_button_write").click(function(e) {
       
   447         $(".submitcontent-loader-content").show();
       
   448     });
       
   449     $(".media_fields").hide();
       
   450     $("#media_field_"+$("#id_content-media_input_type").val()).show();
       
   451     $("#id_content-media_input_type").change(function(e) {
       
   452         $(".media_fields").hide();
       
   453         $("#media_field_"+$(e.target).val()).show();
       
   454     });
       
   455     // The textinput's id for external url is id_media-src
       
   456     $('#id_media-src').bind('textchange', function(e) { testUrlValue(e); });
       
   457     
       
   458     // We disable the default submit
       
   459     $('#my_form').submit(function() {
       
   460         window.submit_asked = true;
       
   461         if($('#id_content-media_input_type').val()=="upload"){
       
   462             if(window.upload_from_local_done==false){
       
   463                 // The form has sent but the uploading has not ended.
       
   464                 if($('#upload_progress_info').children().size()>0){
       
   465                     $('#progress_info').remove();
       
   466                 }
       
   467                 $('#upload_progress_info').append('<p id="progress_info"><font color="red"><strong>' + wait_label + '.</strong></font></p>');
       
   468                 return false;
       
   469             }
       
   470             else{
       
   471                 return true;
       
   472             }
       
   473         }
       
   474         else{
       
   475             //alert("2. " + $('#id_content-media_input_type').val());
       
   476             return true;
       
   477         }
       
   478     });
       
   479     
       
   480     $("#upload_progress_bar").css({ width:"90%", height:"10" });
       
   481     
       
   482     $('#media_fields_div').height(80);
       
   483     
       
   484     // We init the swfupload object
       
   485     swfupload = new SWFUpload({
       
   486         debug: false,
       
   487         
       
   488         upload_url: url_upload,
       
   489         flash_url: media_prefix+"swf/swfupload.swf",
       
   490         
       
   491         post_params: post_added_params,
       
   492         
       
   493         button_placeholder_id: "upload_btn",
       
   494         button_width: "60",
       
   495         button_height: "16",
       
   496         button_cursor: SWFUpload.CURSOR.HAND,
       
   497         button_text : '<span class="btnText">' + btn_label + '</span>',
       
   498         button_text_style : ".btnText { font-size: 12; font-family: Arial; }",
       
   499         
       
   500         file_types : "*.flv;*.f4v;*.mp4;*.mov;*.mp3",
       
   501         file_types_description : "Media Files (flv, f4v, mov H264, mp4, mp3)",
       
   502         file_upload_limit : "1",
       
   503         file_queue_limit : "1",
       
   504         
       
   505         upload_error_handler : uploadError,
       
   506         upload_start_handler : function(file) {
       
   507             try {
       
   508                 if($('#upload_progress_info').children().size()>0){
       
   509                     $('#progress_info').remove();
       
   510                 }
       
   511                 $('#upload_progress_info').append('<p id="progress_info"><a href="javascript:cancelSwfUpload()">' + cancel_label + '.</a></p>');
       
   512             }
       
   513             catch (ex) {
       
   514                 //this.debug(ex);
       
   515             }
       
   516         },
       
   517         upload_progress_handler : uploadProgress,
       
   518         upload_success_handler : function() {
       
   519                 try {
       
   520                     if($('#upload_progress_info').children().size()>0){
       
   521                         $('#progress_info').remove();
       
   522                     }
       
   523                     $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>');
       
   524                     $("#upload_progress_bar > div").css({ 'background': '#90ffa8' });
       
   525                     window.upload_from_local_done = true;
       
   526                     // Now that the file is uploaded, we submit the form if asked
       
   527                     if(window.submit_asked==true){
       
   528                         $('#my_form').submit();
       
   529                     }
       
   530                 }
       
   531                 catch (ex) {
       
   532                     //this.debug(ex);
       
   533                 }
       
   534             },
       
   535         file_queued_handler : displayUploadPath,
       
   536         file_dialog_complete_handler: function() { this.startUpload(); },
       
   537         //upload_complete_handler: function() { this.startUpload(); },
       
   538     });
       
   539 }
       
   540 function displayUploadPath(file) {
       
   541     try {
       
   542         $('#id_media-local_file_name').val(file.name);
       
   543     }
       
   544     catch (ex) {
       
   545         //this.debug(ex);
       
   546     }
       
   547 }
       
   548 function startLocalUpload(){
       
   549     swfupload.startUpload();
       
   550 }
       
   551 function uploadProgress(file, bytesLoaded, bytesTotal) {
       
   552     try {
       
   553         var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
       
   554         $("#upload_progress_bar").progressbar({ value: percent });
       
   555     }
       
   556     catch (ex) {
       
   557         //this.debug(ex);
       
   558     }
       
   559 }
       
   560 function cancelSwfUpload(){
       
   561     swfupload.cancelUpload();
       
   562     if($('#media_field_upload').has($('#cancelupload')).length==0){
       
   563         $('#cancelupload').remove();
       
   564     }
       
   565 }
       
   566 function uploadError(file, errorCode, message) {
       
   567     try {
       
   568         if($('#upload_progress_info').children().size()>0){
       
   569             $('#progress_info').remove();
       
   570         }
       
   571         switch (errorCode) {
       
   572         case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
       
   573             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: HTTP Error, File name: " + file.name + ", Message: " + message + '</p>');
       
   574             break;
       
   575         case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
       
   576             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
       
   577             break;
       
   578         case SWFUpload.UPLOAD_ERROR.IO_ERROR:
       
   579             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: IO Error, File name: " + file.name + ", Message: " + message + '</p>');
       
   580             break;
       
   581         case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
       
   582             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Security Error, File name: " + file.name + ", Message: " + message + '</p>');
       
   583             break;
       
   584         case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
       
   585             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
       
   586             break;
       
   587         case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
       
   588             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
       
   589             break;
       
   590         case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
       
   591             $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: FILE_CANCELLED" + '</p>');
       
   592             break;
       
   593         case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
       
   594             $('#upload_progress_info').append('<p id="progress_info">' + "STOPPED" + '</p>');
       
   595             break;
       
   596         default:
       
   597             $('#upload_progress_info').append('<p id="progress_info">' + "unhandled error: File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
       
   598             break;
       
   599         }
       
   600     } catch (ex) {
       
   601         //this.debug(ex);
       
   602     }
       
   603 }
       
   604 
       
   605 // Test the value of the URL from the form to load a picture in case it is a youtube video
       
   606 function testUrlValue(e){
       
   607     // First, we remove the current thumbnail if there is one.
       
   608     if($('#media_field_create').children().size()>2){
       
   609         $('#external_thumbnail').remove();
       
   610         $('#media_fields_div').height(80);
       
   611     }
       
   612     // If the pasted text is a youtube url, we get the default thumbnail of the video and display it.
       
   613     url = $('#id_media-src').val();
       
   614     if(url.match("youtube") && url.match("[\\?&]v=([^&#]*)")){
       
   615         results = url.match("[\\?&]v=([^&#]*)");
       
   616         vid = ( results === null ) ? url : results[1].substring(0,11);
       
   617         if(vid.length===11){
       
   618             //$('#id_content-description').val($('#media_field_create') + '<img src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>');
       
   619             $('#media_field_create').append('<img id="external_thumbnail" src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>');
       
   620             $('#media_fields_div').height(150);
       
   621         }
       
   622     }
       
   623 }