Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files.calref integration #17

Open
sylae opened this issue Jul 13, 2015 · 2 comments
Open

files.calref integration #17

sylae opened this issue Jul 13, 2015 · 2 comments
Assignees

Comments

@sylae
Copy link

sylae commented Jul 13, 2015

A calref-specific extension to allow uploading files to files.calref directly through the chat. The user would most likely interface with this by drag-dropping a file into inputField, which would trigger a function similar to that used on files.calref (shown below). The bulk of this code is for rendering a progress bar, but strip that away and it should work perfectly well.

// Assuming #filesCalref has an <input type="file" name="pic" /> in it.
(function() {

var bar = $('#progress');

$('#filesCalref').ajaxForm({
    beforeSend: function() {
        var percentVal = '0%';
        bar.addClass("active progress-bar-striped").removeClass("progress-bar-success progress-bar-danger");
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.css("width", percentVal);
        bar.html(percentVal);
    },
    success: function() {
        var percentVal = '100%';
        bar.css("width", percentVal);
        bar.html(percentVal);
    },
  complete: function(xhr) {
    var payload = $.parseJSON(xhr.responseText);
    if (payload[0] == 1) {
      bar.html("Complete");
      bar.removeClass("active progress-bar-striped progress-bar-danger").addClass("progress-bar-success");
      $("#regURL").val("https://c312441.ssl.cf1.rackcdn.com/files.calref/" + payload[1]).css("cursor", "default");
      $("#lURL").val("https://c312441.ssl.cf1.rackcdn.com/files.calref/" + payload[1]).css("cursor", "default");
      $("#urls").css("display","");
    } else {
      bar.html("Failure :(");
      bar.removeClass("active progress-bar-striped progress-bar-success").addClass("progress-bar-danger");
    }
  }
}); 

})(); 

The above code would require a new submodule to https://github.com/malsup/form/

@sylae sylae self-assigned this Jul 13, 2015
@cburschka
Copy link
Collaborator

Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants