82 close_fn.apply(this); |
82 close_fn.apply(this); |
83 } |
83 } |
84 }; |
84 }; |
85 } |
85 } |
86 |
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 } |
87 |
111 |
88 function searchCallback(target, container_selector, url, timeout) { |
112 function searchCallback(target, container_selector, url, timeout) { |
89 |
113 |
90 timeout = typeof(timeout) !== 'undefined' ? timeout : 0; |
114 timeout = typeof(timeout) !== 'undefined' ? timeout : 0; |
91 target = $(target); |
115 target = $(target); |
154 } |
178 } |
155 }); |
179 }); |
156 } |
180 } |
157 } |
181 } |
158 }); |
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 }); |
159 |
189 |
160 $('.contenttitlelink').each(function(i){ |
190 $('.contenttitlelink').each(function(i){ |
161 $(this).attr("target","_blank"); |
191 $(this).attr("target","_blank"); |
162 }); |
192 }); |
163 $('.contenttitlelink').nyroModal({ |
193 $('.contenttitlelink').nyroModal({ |
257 } |
287 } |
258 }); |
288 }); |
259 }, |
289 }, |
260 afterClose: function(nm) { |
290 afterClose: function(nm) { |
261 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
291 searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); |
262 } |
292 } |
263 } |
293 } |
264 }); |
294 }); |
265 $('.ldt_link_create',base_node).each(function(i, e) { |
295 $('.ldt_link_create',base_node).each(function(i, e) { |
266 nm = $(e).data('nmObj'); |
296 nm = $(e).data('nmObj'); |
267 $(e).data('nmObj', $.extend(true, nm, { |
297 $(e).data('nmObj', $.extend(true, nm, { |
401 } |
431 } |
402 |
432 |
403 // |
433 // |
404 // Functions used in the create content view. |
434 // Functions used in the create content view. |
405 // |
435 // |
406 function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label) { |
436 function onCreateContentReady(url_upload, media_prefix, post_added_params, btn_label, success_label, wait_label, cancel_label, remove_url) { |
407 |
437 |
408 var upload_from_local_done = false; |
438 window.upload_from_local_done = false; |
|
439 window.submit_asked = false; |
|
440 window.remove_temp_file_url = remove_url; |
409 |
441 |
410 $("#close_button").click(function (e) { |
442 $("#close_button").click(function (e) { |
411 e.preventDefault(); |
443 e.preventDefault(); |
412 parent.$.nmTop().close(); |
444 parent.$.nmTop().close(); |
413 }); |
445 }); |
423 // The textinput's id for external url is id_media-src |
455 // The textinput's id for external url is id_media-src |
424 $('#id_media-src').bind('textchange', function(e) { testUrlValue(e); }); |
456 $('#id_media-src').bind('textchange', function(e) { testUrlValue(e); }); |
425 |
457 |
426 // We disable the default submit |
458 // We disable the default submit |
427 $('#my_form').submit(function() { |
459 $('#my_form').submit(function() { |
428 if($('#id_content-media_input_type').val()=="upload" && upload_from_local_done==false){ |
460 window.submit_asked = true; |
429 //alert("1. " + $('#id_content-media_input_type').val() + ", upload_done = " + upload_from_local_done); |
461 if($('#id_content-media_input_type').val()=="upload"){ |
430 startLocalUpload(); |
462 if(window.upload_from_local_done==false){ |
431 return 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 } |
432 } |
473 } |
433 else{ |
474 else{ |
434 //alert("2. " + $('#id_content-media_input_type').val()); |
475 //alert("2. " + $('#id_content-media_input_type').val()); |
435 return true; |
476 return true; |
436 } |
477 } |
459 file_types : "*.flv;*.f4v;*.mp4;*.mov;*.mp3", |
500 file_types : "*.flv;*.f4v;*.mp4;*.mov;*.mp3", |
460 file_types_description : "Media Files (flv, f4v, mov H264, mp4, mp3)", |
501 file_types_description : "Media Files (flv, f4v, mov H264, mp4, mp3)", |
461 file_upload_limit : "1", |
502 file_upload_limit : "1", |
462 file_queue_limit : "1", |
503 file_queue_limit : "1", |
463 |
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 }, |
464 upload_progress_handler : uploadProgress, |
517 upload_progress_handler : uploadProgress, |
465 upload_error_handler : uploadError, |
|
466 upload_success_handler : function() { |
518 upload_success_handler : function() { |
467 try { |
519 try { |
468 if($('#upload_progress_info').children().size()>0){ |
520 if($('#upload_progress_info').children().size()>0){ |
469 $('#progress_info').remove(); |
521 $('#progress_info').remove(); |
470 } |
522 } |
471 $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>'); |
523 $('#upload_progress_info').append('<p id="progress_info">' + success_label + '.</p>'); |
472 upload_from_local_done = true; |
524 $("#upload_progress_bar > div").css({ 'background': '#90ffa8' }); |
473 // Now that the file is uploaded, we submit the form |
525 window.upload_from_local_done = true; |
474 $('#my_form').submit(); |
526 // Now that the file is uploaded, we submit the form if asked |
|
527 if(window.submit_asked==true){ |
|
528 $('#my_form').submit(); |
|
529 } |
475 } |
530 } |
476 catch (ex) { |
531 catch (ex) { |
477 //this.debug(ex); |
532 //this.debug(ex); |
478 } |
533 } |
479 }, |
534 }, |
480 |
|
481 file_queued_handler : displayUploadPath, |
535 file_queued_handler : displayUploadPath, |
482 //file_dialog_complete_handler: function() { this.startUpload(); }, |
536 file_dialog_complete_handler: function() { this.startUpload(); }, |
483 //upload_complete_handler: function() { this.startUpload(); }, |
537 //upload_complete_handler: function() { this.startUpload(); }, |
484 }); |
538 }); |
485 } |
539 } |
486 function displayUploadPath(file) { |
540 function displayUploadPath(file) { |
487 try { |
541 try { |
501 } |
555 } |
502 catch (ex) { |
556 catch (ex) { |
503 //this.debug(ex); |
557 //this.debug(ex); |
504 } |
558 } |
505 } |
559 } |
506 function uploadSuccess(success_label) { |
560 function cancelSwfUpload(){ |
507 try { |
561 swfupload.cancelUpload(); |
508 if($('#upload_progress_info').children().size()>0){ |
562 if($('#media_field_upload').has($('#cancelupload')).length==0){ |
509 $('#progress_info').remove(); |
563 $('#cancelupload').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 } |
564 } |
519 } |
565 } |
520 function uploadError(file, errorCode, message) { |
566 function uploadError(file, errorCode, message) { |
521 try { |
567 try { |
522 if($('#upload_progress_info').children().size()>0){ |
568 if($('#upload_progress_info').children().size()>0){ |