move jquery into the repo, depending on your os the link can be different
[coquelicot.git] / public / javascripts / coquelicot.js
index ec76e67..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,3 +30,58 @@ $(function($) {
     progressUrl: "progress"
   });
 });
+function authenticate() {
+  var link = $('<a href="#" id="gen_pass" />');
+  link.text(i18n.generateRandomPassword);
+  var file_key = $('#file_key');
+  file_key.after(link);
+  link.click(function() {
+    link.text(i18n.generatingRandomPassword);
+    $.get('random_pass', function(pass) {
+      file_key.val(pass);
+      file_key.hide();
+      var show = $('<div class="random-pass" />');
+      show.text(pass);
+      link.before(show);
+      link.remove();
+    });
+  });
+
+  var authForm = $('<form></form>')
+  var authDiv = $('#upload-authentication').remove();
+  var lb = $.lightBoxFu;
+  authForm.bind('submit', function() {
+    jQuery.ajax({
+      type: 'POST',
+      url: 'authenticate',
+      dataType: 'text',
+      data: {
+        'upload_token': authenticationData.call()
+      },
+      complete: function(res, status) {
+        if (status === 'success') {
+          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(i18n.pleaseTryAgain);
+        } else {
+          $('#auth-message').text(i18n.error + alert(status));
+        }
+        authenticationReset();
+      }
+    });
+    return false;
+  });
+  lb.open({
+    html: authForm.append(authDiv).append('<div id="auth-message"></div>'),
+    width: "430px",
+    closeOnClick: false
+  });
+  authenticationFocus();
+}
+
+function authenticationReset(){
+    $('#upload_token').val('');
+}