/* * Based on FancyUpload Showcase * * @license MIT License * @authors Harald Kirschner * Damien Corpataux * Nimag Networks Sarl * @copyright Authors * */ log.debug("script.js initialisation"); log.debug(navigator.appName + " " + navigator.appVersion + " " + navigator.userAgent); log.debug(jQuery.support); var email_domain = 'loro.ch'; function display_message_success() { log.debug("display_message_success()"); $('#message-sent').fadeIn(); $('#gui').hide(); } function display_message_failure(message) { log.error("display_message_failure(): " + message) $('#message-sent').hide(); $('#message-failure').show().fadeIn(); $('#gui').hide(); } function log_file_list(fileList) { fileList.each(function (file) { log.debug(" name:" + file.name + ", size: " + file.size + ", status: " + file.status) }) } function mkdir() { var session; $.ajax({ type: "POST", url: '/send/mkdir', async: false, success: function(responseText, responseXML) { session = responseText; }, error : function(responseText, responseXML) { display_message_failure("mkdir failed"); } }); return session; } //function send_email(session, email, comment) { function send_email(session, email) { log.debug("send_email(" + session + ", " + email + ")"); //alert("send_email(" + session + ", " + email + ")"); var comment = $('#comment').val(); $.ajax({ type: 'POST', url: '/send/email', async: false, data: { session: session, email: email + '@' + email_domain, comment: comment }, success: function(responseText, responseXML) { log.debug("responseText: " + responseText); if (responseText.match("OK")) { display_message_success(); } else { display_message_failure(); } }, error : function(responseText, responseXML) { display_message_failure("Email was not sent"); } }); log.debug("send_email to " + email); } $(document).bind('ready', function() { log.debug("domready event received"); var session = mkdir(); $("#uploader").pluploadQueue({ // General settings runtimes : 'html5,flash,silverlight,html4', url : '/send/upload?session='+session, rename : true, dragdrop: true, filters : { // Maximum file size max_file_size : '0 (unlimited)', // Specify what files to browse for mime_types: [] }, flash_swf_url : '/static//static/Source/js/Moxie.swf', silverlight_xap_url : '/static//static/Source/js/Moxie.xap', // Events init : { UploadComplete: function(up, files) { send_email(session, $('#email-field').val()); if ($('#email-copy-field').val()) { send_email(session, $('#email-copy-field').val()); } } //UploadComplete: function(up, files) { send_email(session, $('#email-field').val()); } // UploadComplete: function(up, files) { send_email(session, $('#email-field').val()) if ($('#email-copy-field').val()) { send_email(session, $('email-copy-field').value) } }, } }); $("#demo-send").click(function() { log.debug("demo-send button was clicked"); if (!$('#email-field').val()) { log.error("No email address -> alert"); alert("Veuillez entrer une adresse email"); return false; } if (!($('#email-field').val().match(/^([a-zA-Z-_]+|[a-zA-Z-_]+\.[a-zA-Z0-9-_]+|[a-z]{4}[0-9])$/))) { log.error("Invalid email address -> alert, email: " + $('#email-field').val()); alert("L'adresse email entrée n'est pas valide, entrez une adresse email au format 'prénom.nom'"); return false; } if ($('#email-field').val().search('@') !== -1) { log.error("Invalid email address (@ sign) -> alert, email: " + $('#email-field').val()); alert("L'adresse email entrée ne doit pas contenir le signe '@'"); return false; } if ($('#email-copy-field').val()) { log.debug("Email copy was given, email: " + $('#email-copy-field').val()); if (!($('#email-copy-field').val().match(/^([a-zA-Z-_]+|[a-zA-Z-_]+\.[a-zA-Z-_]+|[a-z]{4}[0-9])$/))) { log.error("Invalid email address -> alert, email: " + $('#email-copy-field').val()); alert("L'adresse email copie entrée n'est pas valide, entrez une adresse email au format 'prenom.nom'"); return false; } if ($('#email-copy-field').val().search('@') !== -1) { log.error("Invalid email address (@ sign) -> alert, email: " + $('#email-copy-field').val()); alert("L'adresse email copie entrée ne doit pas contenir le signe '@'"); return false; } } if (up==0) { log.error("No file selected -> alert"); alert("Veuillez choisir des fichiers à envoyer"); return false; } log.debug("Starting upload"); $('#uploader').pluploadQueue().start(); // start upload return false; }); }); log.debug("script.js EOF");