397 $('.searchclear').each(function(i) { |
397 $('.searchclear').each(function(i) { |
398 $(this).hide(); |
398 $(this).hide(); |
399 }); |
399 }); |
400 |
400 |
401 } |
401 } |
|
402 |
|
403 // |
|
404 // Functions used in the create content view. |
|
405 // |
|
406 function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label) { |
|
407 |
|
408 var upload_from_local_done = false; |
|
409 |
|
410 $("#close_button").click(function (e) { |
|
411 e.preventDefault(); |
|
412 parent.$.nmTop().close(); |
|
413 }); |
|
414 $("#submit_button_write").click(function(e) { |
|
415 $(".submitcontent-loader-content").show(); |
|
416 }); |
|
417 $(".media_fields").hide(); |
|
418 $("#media_field_"+$("#id_content-media_input_type").val()).show(); |
|
419 $("#id_content-media_input_type").change(function(e) { |
|
420 $(".media_fields").hide(); |
|
421 $("#media_field_"+$(e.target).val()).show(); |
|
422 }); |
|
423 // The textinput's id for external url is id_media-src |
|
424 $('#id_media-src').bind('textchange', function(e) { testUrlValue(e); }); |
|
425 |
|
426 // We disable the default submit |
|
427 $('#my_form').submit(function() { |
|
428 if($('#id_content-media_input_type').val()=="upload" && upload_from_local_done==false){ |
|
429 //alert("1. " + $('#id_content-media_input_type').val() + ", upload_done = " + upload_from_local_done); |
|
430 startLocalUpload(); |
|
431 return false; |
|
432 } |
|
433 else{ |
|
434 //alert("2. " + $('#id_content-media_input_type').val()); |
|
435 return true; |
|
436 } |
|
437 }); |
|
438 |
|
439 $("#upload_progress_bar").css({ width:"90%", height:"10" }); |
|
440 |
|
441 $('#media_fields_div').height(80); |
|
442 |
|
443 // We init the swfupload object |
|
444 swfupload = new SWFUpload({ |
|
445 debug: false, |
|
446 |
|
447 upload_url: url_upload, |
|
448 flash_url: media_prefix+"swf/swfupload.swf", |
|
449 |
|
450 post_params: post_added_params, |
|
451 |
|
452 button_placeholder_id: "upload_btn", |
|
453 button_width: "60", |
|
454 button_height: "16", |
|
455 button_cursor: SWFUpload.CURSOR.HAND, |
|
456 button_text : '<span class="btnText">' + btn_label + '</span>', |
|
457 button_text_style : ".btnText { font-size: 12; font-family: Arial; }", |
|
458 |
|
459 file_types : "*.flv;*.f4v;*.mp4;*.mov;*.mp3", |
|
460 file_types_description : "Media Files (flv, f4v, mov H264, mp4, mp3)", |
|
461 file_upload_limit : "1", |
|
462 file_queue_limit : "1", |
|
463 |
|
464 upload_progress_handler : uploadProgress, |
|
465 upload_error_handler : uploadError, |
|
466 upload_success_handler : function() { |
|
467 try { |
|
468 if($('#upload_progress_info').children().size()>0){ |
|
469 $('#progress_info').remove(); |
|
470 } |
|
471 $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>'); |
|
472 upload_from_local_done = true; |
|
473 // Now that the file is uploaded, we submit the form |
|
474 $('#my_form').submit(); |
|
475 } |
|
476 catch (ex) { |
|
477 //this.debug(ex); |
|
478 } |
|
479 }, |
|
480 |
|
481 file_queued_handler : displayUploadPath, |
|
482 //file_dialog_complete_handler: function() { this.startUpload(); }, |
|
483 //upload_complete_handler: function() { this.startUpload(); }, |
|
484 }); |
|
485 } |
|
486 function displayUploadPath(file) { |
|
487 try { |
|
488 $('#id_media-local_file_name').val(file.name); |
|
489 } |
|
490 catch (ex) { |
|
491 //this.debug(ex); |
|
492 } |
|
493 } |
|
494 function startLocalUpload(){ |
|
495 swfupload.startUpload(); |
|
496 } |
|
497 function uploadProgress(file, bytesLoaded, bytesTotal) { |
|
498 try { |
|
499 var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); |
|
500 $("#upload_progress_bar").progressbar({ value: percent }); |
|
501 } |
|
502 catch (ex) { |
|
503 //this.debug(ex); |
|
504 } |
|
505 } |
|
506 function uploadSuccess(success_label) { |
|
507 try { |
|
508 if($('#upload_progress_info').children().size()>0){ |
|
509 $('#progress_info').remove(); |
|
510 } |
|
511 $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>'); |
|
512 upload_from_local_done = true; |
|
513 // Now that the file is uploaded, we submit the form |
|
514 $('#my_form').submit(); |
|
515 } |
|
516 catch (ex) { |
|
517 //this.debug(ex); |
|
518 } |
|
519 } |
|
520 function uploadError(file, errorCode, message) { |
|
521 try { |
|
522 if($('#upload_progress_info').children().size()>0){ |
|
523 $('#progress_info').remove(); |
|
524 } |
|
525 switch (errorCode) { |
|
526 case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: |
|
527 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: HTTP Error, File name: " + file.name + ", Message: " + message + '</p>'); |
|
528 break; |
|
529 case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: |
|
530 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>'); |
|
531 break; |
|
532 case SWFUpload.UPLOAD_ERROR.IO_ERROR: |
|
533 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: IO Error, File name: " + file.name + ", Message: " + message + '</p>'); |
|
534 break; |
|
535 case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: |
|
536 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Security Error, File name: " + file.name + ", Message: " + message + '</p>'); |
|
537 break; |
|
538 case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: |
|
539 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>'); |
|
540 break; |
|
541 case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: |
|
542 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>'); |
|
543 break; |
|
544 case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: |
|
545 $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: FILE_CANCELLED" + '</p>'); |
|
546 break; |
|
547 case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: |
|
548 $('#upload_progress_info').append('<p id="progress_info">' + "STOPPED" + '</p>'); |
|
549 break; |
|
550 default: |
|
551 $('#upload_progress_info').append('<p id="progress_info">' + "unhandled error: File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>'); |
|
552 break; |
|
553 } |
|
554 } catch (ex) { |
|
555 //this.debug(ex); |
|
556 } |
|
557 } |
|
558 |
|
559 // Test the value of the URL from the form to load a picture in case it is a youtube video |
|
560 function testUrlValue(e){ |
|
561 // First, we remove the current thumbnail if there is one. |
|
562 if($('#media_field_create').children().size()>2){ |
|
563 $('#external_thumbnail').remove(); |
|
564 $('#media_fields_div').height(80); |
|
565 } |
|
566 // If the pasted text is a youtube url, we get the default thumbnail of the video and display it. |
|
567 url = $('#id_media-src').val(); |
|
568 if(url.match("youtube") && url.match("[\\?&]v=([^&#]*)")){ |
|
569 results = url.match("[\\?&]v=([^&#]*)"); |
|
570 vid = ( results === null ) ? url : results[1].substring(0,11); |
|
571 if(vid.length===11){ |
|
572 //$('#id_content-description').val($('#media_field_create') + '<img src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>'); |
|
573 $('#media_field_create').append('<img id="external_thumbnail" src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>'); |
|
574 $('#media_fields_div').height(150); |
|
575 } |
|
576 } |
|
577 } |