Merge with 38afc7be4a886c9cdfe7a76abd5102488f25be8e (chunked_upload)
authorrougeronj
Thu, 14 Feb 2013 16:37:27 +0100
changeset 1111 5bb3aec02883
parent 1110 7ef5c69b73b3 (diff)
parent 1109 38afc7be4a88 (current diff)
child 1112 3b88847289d1
Merge with 38afc7be4a886c9cdfe7a76abd5102488f25be8e (chunked_upload)
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html
--- a/src/ldt/ldt/static/ldt/css/ldtform.css	Thu Feb 14 16:26:20 2013 +0100
+++ b/src/ldt/ldt/static/ldt/css/ldtform.css	Thu Feb 14 16:37:27 2013 +0100
@@ -163,7 +163,7 @@
 }
 
 #media_fields_div {
-	width : 300px;
+	width : 338px;
 	height : 50px;
 	margin-top: 10px 0px;
 	padding-left: 10px;
--- a/src/ldt/ldt/static/ldt/js/projectscontents.js	Thu Feb 14 16:26:20 2013 +0100
+++ b/src/ldt/ldt/static/ldt/js/projectscontents.js	Thu Feb 14 16:37:27 2013 +0100
@@ -386,6 +386,7 @@
 
 
 function resize_modal_window (element, createcontent) {
+    var nm = parent.$.nmTop();
     var iframe = $("iframe", window.parent.document);
     if ( $('#init_ldt_view', element).size() > 0) { // if contains ldt lpayer
     	var h = 660;
@@ -394,9 +395,17 @@
     	var h = $(element).innerHeight() + 10;
     	var w = $(element).innerWidth() + 10;
 	}
-
+        
+    nm.sizes.minH = h + 10;
+    nm.sizes.minW = w;
     iframe.height(h);
     iframe.width(w);
+    
+    if ($.browser.mozilla && createcontent) {
+    	$(".nyroModalCont", parent.window.document).height(h+10);
+    } else {
+    	nm.resize(true);
+    }
 }
 
 //
@@ -408,7 +417,11 @@
     window.submit_asked = false;
     window.remove_temp_file_url = remove_url;
     window.ask_duration_url = ask_dur_url;
-     
+    
+    $("#close_button").click(function (e) {
+        e.preventDefault();
+        parent.$.nmTop().close();
+    });    
     $("#submit_button_write").click(function(e) {
         $(".submitcontent-loader-content").show();
         resize_modal_window($("#add_content"), true);
@@ -426,22 +439,103 @@
     $('#my_form').bind('submit', function() {
         window.submit_asked = true;
         if($('#id_content-media_input_type').val()=="upload"){
-            /*if(chunked_upload_complete == true){
-                return true;
+            if(window.upload_from_local_done==false){
+                // The form has sent but the uploading has not ended.
+                if($('#upload_progress_info').children().size()>0){
+                    $('#progress_info').remove();
+                }
+                $('#upload_progress_info').append('<p id="progress_info"><font color="red"><strong>' + wait_label + '.</strong></font><br/><a href="javascript:cancelSwfUpload()">' + cancel_label + '.</a></p>');
+                return false;
             }
             else{
-                return false;
-            }*/
-        	return false;
+                return true;
+            }
         }
         else{
+            //alert("2. " + $('#id_content-media_input_type').val());
             return true;
         }
     });
     
+    $("#upload_progress_bar").css({ width:"90%", height:"10" });
+    
     $('#media_fields_div').height(80);
+    
+    // We init the swfupload object
+    swfupload = new SWFUpload({
+        debug: false,
+        
+        upload_url: url_upload,
+        flash_url: media_prefix+"swf/swfupload.swf",
+        
+        post_params: post_added_params,
+        
+        button_placeholder_id: "upload_btn",
+        button_width: "60",
+        button_height: "16",
+        button_cursor: SWFUpload.CURSOR.HAND,
+        button_text : '<span class="btnText">' + btn_label + '</span>',
+        button_text_style : ".btnText { font-size: 12; font-family: Arial; }",
+        
+        file_types : "*.flv;*.f4v;*.mp4;*.mov;*.mp3",
+        file_types_description : "Media Files (flv, f4v, mov H264, mp4, mp3)",
+        file_upload_limit : "1",
+        file_queue_limit : "1",
+        
+        upload_error_handler : uploadError,
+        upload_start_handler : function(file) {
+            try {
+                if($('#upload_progress_info').children().size()>0){
+                    $('#progress_info').remove();
+                }
+                $('#upload_progress_info').append('<p id="progress_info"><a href="javascript:cancelSwfUpload()">' + cancel_label + '.</a></p>');
+            }
+            catch (ex) {
+                //this.debug(ex);
+            }
+        },
+        upload_progress_handler : uploadProgress,
+        upload_success_handler : function() {
+                try {
+                    if($('#upload_progress_info').children().size()>0){
+                        $('#progress_info').remove();
+                    }
+                    $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>');
+                    $("#upload_progress_bar > div").css({ 'background': '#90ffa8' });
+                    window.upload_from_local_done = true;
+                    // Now that the file is uploaded, we submit the form if asked
+                    if(window.submit_asked==true){
+                        $('#my_form').submit();
+                    }
+                    else{
+                        // We ask the uploaded media's duration
+                        if(window.ask_duration_url){
+                            $.ajax({
+                                type: "GET",
+                                url: window.ask_duration_url,
+                                data: "filename="+ $('#id_media-local_file_name').val(),
+                                cache: false,
+                                success: function(data, status, request){
+                                    if(data && data!=""){
+                                        $('#id_content-duration').val(data);
+                                    }
+                                }
+                            });
+                        }
+                    }
+                }
+                catch (ex) {
+                    //this.debug(ex);
+                }
+            },
+        file_queued_handler : displayUploadPath,
+        file_dialog_complete_handler: function() { 
+            window.submit_asked = false;
+            this.startUpload();
+        }
+        //upload_complete_handler: function() { this.startUpload(); },
+    });
 }
-
 function displayUploadPath(file) {
     try {
         $('#id_media-local_file_name').val(file.name);
@@ -450,6 +544,62 @@
         //this.debug(ex);
     }
 }
+function startLocalUpload(){
+    swfupload.startUpload();
+}
+function uploadProgress(file, bytesLoaded, bytesTotal) {
+    try {
+        var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
+        $("#upload_progress_bar").progressbar({ value: percent });
+    }
+    catch (ex) {
+        //this.debug(ex);
+    }
+}
+function cancelSwfUpload(){
+    swfupload.cancelUpload();
+    if($('#media_field_upload').has($('#cancelupload')).length==0){
+        $('#cancelupload').remove();
+    }
+}
+function uploadError(file, errorCode, message) {
+    try {
+        if($('#upload_progress_info').children().size()>0){
+            $('#progress_info').remove();
+        }
+        switch (errorCode) {
+        case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: HTTP Error, File name: " + file.name + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.IO_ERROR:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: IO Error, File name: " + file.name + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Security Error, File name: " + file.name + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
+            $('#upload_progress_info').append('<p id="progress_info">' + "Error Code: FILE_CANCELLED" + '</p>');
+            break;
+        case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
+            $('#upload_progress_info').append('<p id="progress_info">' + "STOPPED" + '</p>');
+            break;
+        default:
+            $('#upload_progress_info').append('<p id="progress_info">' + "unhandled error: File name: " + file.name + ", File size: " + file.size + ", Message: " + message + '</p>');
+            break;
+        }
+    } catch (ex) {
+        //this.debug(ex);
+    }
+}
 
 // Test the value of the URL from the form to load a picture in case it is a youtube video
 function testUrlValue(e){
@@ -554,4 +704,3 @@
 		$(checkbox_names).trigger("change");
 	});		
 }
-