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

Allow option passing to resumable.js #2

Merged
merged 2 commits into from Oct 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions resumable/static/resumable/js/django-resumable.js
Expand Up @@ -10,7 +10,8 @@ var DjangoResumable = function (options) {
onFileError: this.onFileError,
onFileAdded: this.onFileAdded,
onFileSuccess: this.onFileSuccess,
onProgress: this.onProgress
onProgress: this.onProgress,
resumableOptions: {}
};
this.options = this.extend(defaults, options);
this.csrfToken = document.querySelector('input[name=' + this.options.csrfInputName + ']').value;
Expand All @@ -32,10 +33,10 @@ DjangoResumable.prototype.each = function (elements, fn) {

DjangoResumable.prototype.extend = function (target, source) {
"use strict";
var key;
for (key in source) {
if (source[key] !== undefined) {
target[key] = source[key];
var property;
for (property in source) {
if (source.hasOwnProperty(property)) {
target[property] = source[property];
}
}
return target;
Expand All @@ -45,10 +46,10 @@ DjangoResumable.prototype.extend = function (target, source) {
DjangoResumable.prototype.getErrorList = function (el, create) {
"use strict";
var errorList = el.parentNode.previousSibling;
while (errorList.tagName === undefined) {
while (errorList && errorList.tagName === undefined) {
errorList = errorList.previousSibling;
}
if (!errorList.classList.contains(this.options.errorListClass)) {
if (errorList && !errorList.classList.contains(this.options.errorListClass)) {
if (create === true) {
errorList = document.createElement('ul');
errorList.classList.add(this.options.errorListClass);
Expand Down Expand Up @@ -104,12 +105,15 @@ DjangoResumable.prototype.initResumable = function (el, progress, filePath, file
"use strict";
var elements = Array.prototype.slice.call(arguments),
self = this,
r = new Resumable({
target : el.getAttribute(this.options.urlAttribute),
opts = {
target: el.getAttribute(this.options.urlAttribute),
query: {
'csrfmiddlewaretoken': this.csrfToken
}
});
};

opts = this.extend(this.options.resumableOptions, opts);
var r = new Resumable(opts);
r.assignBrowse(el);
this.each(['fileAdded', 'progress', 'fileSuccess', 'fileError'], function (eventType) {
var callback = this.options['on' + eventType.substring(0, 1).toUpperCase() + eventType.substring(1)];
Expand Down Expand Up @@ -154,4 +158,4 @@ DjangoResumable.prototype.onFileSuccess = function (r, file, message, el, progre
DjangoResumable.prototype.onProgress = function (r, el, progress, filePath, fileName) {
"use strict";
progress.setAttribute('value', r.progress());
};
};
2 changes: 1 addition & 1 deletion resumable/views.py
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings

from django.views.generic import View
from django.http import Http404, HttpResponse
from django.http import HttpResponse
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import FileSystemStorage

Expand Down
7 changes: 3 additions & 4 deletions resumable/widgets.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import magic

from django.forms.widgets import FileInput, HiddenInput
from django.forms.widgets import FileInput
from django.core.files.storage import FileSystemStorage
from django.core.files.uploadedfile import UploadedFile
from django.utils.safestring import mark_safe
from django.template import loader


Expand Down Expand Up @@ -37,9 +36,9 @@ def value_from_datadict(self, data, files, name):
self.filename = filepath.lstrip('%s_' % unicode(size))
return UploadedFile(
file=file,
name = self.filename,
name=self.filename,
content_type=self.guess_type(file.name),
size = size
size=size
)
return files.get(name, None)

Expand Down