move jquery into the repo, depending on your os the link can be different
[coquelicot.git] / public / javascripts / coquelicot.js
index 2431b30..4e86975 100644 (file)
@@ -30,7 +30,7 @@ $(function($) {
     progressUrl: "progress"
   });
 });
-$(document).ready(function() {
+function authenticate() {
   var link = $('<a href="#" id="gen_pass" />');
   link.text(i18n.generateRandomPassword);
   var file_key = $('#file_key');
@@ -51,16 +51,17 @@ $(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') {
@@ -68,15 +69,19 @@ $(document).ready(function() {
         } else {
           $('#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('');
+}