move jquery into the repo, depending on your os the link can be different
[coquelicot.git] / public / javascripts / coquelicot.js
index f84caa4..4e86975 100644 (file)
@@ -11,13 +11,13 @@ $(function($) {
         width: "250px",
         closeOnClick: false
       });
-      jQuery('#received').html("Upload starting.");
+      jQuery('#received').html(i18n.uploadStarting);
       jQuery('#percent').html("0%");
     },
     uploading: function(upload) {
       // update upload info on each /progress response
-      jQuery('#received').html("Uploading: " + parseInt(upload.received / 1024) + "/");
-      jQuery('#size').html(parseInt(upload.size / 1024) + " kB");
+      jQuery('#received').html(i18n.uploading + parseInt(upload.received / 1024) + "/");
+      jQuery('#size').html(parseInt(upload.size / 1024) + ' ' + i18n.kb);
       jQuery('#percent').html(upload.percents + "%");
     },
     interval: 2000,
@@ -30,13 +30,13 @@ $(function($) {
     progressUrl: "progress"
   });
 });
-$(document).ready(function() {
+function authenticate() {
   var link = $('<a href="#" id="gen_pass" />');
-  link.text(generateRandomPassword);
+  link.text(i18n.generateRandomPassword);
   var file_key = $('#file_key');
   file_key.after(link);
   link.click(function() {
-    link.text(generatingRandomPassword);
+    link.text(i18n.generatingRandomPassword);
     $.get('random_pass', function(pass) {
       file_key.val(pass);
       file_key.hide();
@@ -51,32 +51,37 @@ $(document).ready(function() {
   var authDiv = $('#upload-authentication').remove();
   var lb = $.lightBoxFu;
   authForm.bind('submit', function() {
-    var uploadPassword = $('#upload_password');
     jQuery.ajax({
       type: 'POST',
       url: 'authenticate',
       dataType: 'text',
-      data: { upload_password: uploadPassword.val() },
+      data: {
+        'upload_token': authenticationData.call()
+      },
       complete: function(res, status) {
         if (status === 'success') {
-          var hiddenField = $('<input type="hidden" name="upload_password" />');
-          hiddenField.val(uploadPassword.val());
+          var hiddenField = $('<input type="hidden" name="upload_token" />');
+          hiddenField.val(JSON.stringify(authenticationData.call()));
           $('#upload').append(hiddenField);
           lb.close();
         } else if (res.responseText == 'Forbidden') {
-          $('#auth-message').text('Please try again!');
+          $('#auth-message').text(i18n.pleaseTryAgain);
         } else {
-          $('#auth-message').text('Error: ' + alert(status));
+          $('#auth-message').text(i18n.error + alert(status));
         }
-        uploadPassword.val('');
+        authenticationReset();
       }
     });
     return false;
   });
   lb.open({
     html: authForm.append(authDiv).append('<div id="auth-message"></div>'),
-    width: "300px",
+    width: "430px",
     closeOnClick: false
   });
-  $('#upload_password').focus();
-});
+  authenticationFocus();
+}
+
+function authenticationReset(){
+    $('#upload_token').val('');
+}