--- a/web/static/ldt/js/projectscontents.js Fri May 06 02:10:25 2011 +0200
+++ b/web/static/ldt/js/projectscontents.js Mon May 09 18:57:23 2011 +0200
@@ -84,6 +84,30 @@
};
}
+function testCreateAndClose(nm, close_fn) {
+
+ return function(force) {
+ // We get the frames vars
+ f = window.frames[0];
+ form_status = $('#content_form_status',$.nmTop().store.iframe.contents()).val();
+ // If form_status is "saved", we don't have to test anything, the form was was normally submitted.
+ // If was status is "empty" AND an upload from local was done
+ if(form_status!="saved" && f.upload_from_local_done==true && f.remove_temp_file_url){
+ // ERASE FILE
+ //alert("testCreateAndClose : " + "f = " + f + ", status = " + form_status + ", u = " + f.upload_from_local_done + ", s = " + f.submit_asked + ", url = " + f.remove_temp_file_url);
+ $.ajax({
+ type: "GET",
+ url: f.remove_temp_file_url,
+ data: "filename="+ $('#id_media-local_file_name',$.nmTop().store.iframe.contents()).val(),
+ cache: false,
+ success: function(data, status, request){
+ //alert("remove success");
+ }
+ });
+ }
+ close_fn.apply(this);
+ };
+}
function searchCallback(target, container_selector, url, timeout) {
@@ -156,6 +180,12 @@
}
}
});
+ $('.content_link_create',base_node).each(function(i, e) {
+ nm = $(e).data('nmObj');
+ $(e).data('nmObj', $.extend(true, nm, {
+ close: testCreateAndClose(nm, nm.close)
+ }));
+ });
$('.contenttitlelink').each(function(i){
$(this).attr("target","_blank");
@@ -259,7 +289,7 @@
},
afterClose: function(nm) {
searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
- }
+ }
}
});
$('.ldt_link_create',base_node).each(function(i, e) {
@@ -403,9 +433,11 @@
//
// Functions used in the create content view.
//
-function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label) {
+function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label, wait_label, cancel_label, remove_url) {
- var upload_from_local_done = false;
+ window.upload_from_local_done = false;
+ window.submit_asked = false;
+ window.remove_temp_file_url = remove_url;
$("#close_button").click(function (e) {
e.preventDefault();
@@ -425,10 +457,19 @@
// We disable the default submit
$('#my_form').submit(function() {
- if($('#id_content-media_input_type').val()=="upload" && upload_from_local_done==false){
- //alert("1. " + $('#id_content-media_input_type').val() + ", upload_done = " + upload_from_local_done);
- startLocalUpload();
- return false;
+ window.submit_asked = true;
+ if($('#id_content-media_input_type').val()=="upload"){
+ 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></p>');
+ return false;
+ }
+ else{
+ return true;
+ }
}
else{
//alert("2. " + $('#id_content-media_input_type').val());
@@ -461,25 +502,38 @@
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_error_handler : uploadError,
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_from_local_done = true;
- // Now that the file is uploaded, we submit the form
- $('#my_form').submit();
+ $("#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();
+ }
}
catch (ex) {
//this.debug(ex);
}
},
-
file_queued_handler : displayUploadPath,
- //file_dialog_complete_handler: function() { this.startUpload(); },
+ file_dialog_complete_handler: function() { this.startUpload(); },
//upload_complete_handler: function() { this.startUpload(); },
});
}
@@ -503,18 +557,10 @@
//this.debug(ex);
}
}
-function uploadSuccess(success_label) {
- try {
- if($('#upload_progress_info').children().size()>0){
- $('#progress_info').remove();
- }
- $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>');
- upload_from_local_done = true;
- // Now that the file is uploaded, we submit the form
- $('#my_form').submit();
- }
- catch (ex) {
- //this.debug(ex);
+function cancelSwfUpload(){
+ swfupload.cancelUpload();
+ if($('#media_field_upload').has($('#cancelupload')).length==0){
+ $('#cancelupload').remove();
}
}
function uploadError(file, errorCode, message) {