-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pablo Camino
committed
Nov 3, 2017
0 parents
commit 5281c70
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
ai-django-fileupload | ||
========= | ||
|
||
This package is intended to be used along with [ai-django-fileupload](https://pypi.python.org/pypi) python package in a Django project. | ||
|
||
Initializes the uploader widget, and renders the attachments table. | ||
|
||
## Usage | ||
|
||
For a minimal setup, please import the following scripts. Order is important. | ||
|
||
``` | ||
<!-- jQuery --> | ||
<script src="/static/node_modules/jquery/dist/jquery.js"></script> | ||
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> | ||
<script src="/static/node_modules/blueimp-file-upload/js/vendor/jquery.ui.widget.js"></script> | ||
<!-- The Templates plugin is included to render the upload/download listings --> | ||
<script src="/static/node_modules/blueimp-tmpl/js/tmpl.min.js"></script> | ||
<!-- The Load Image plugin is included for the preview images and image resizing functionality --> | ||
<script src="/static/node_modules/blueimp-load-image/js/load-image.all.min.js"></script> | ||
<!-- The Canvas to Blob plugin is included for image resizing functionality --> | ||
<script src="/static/node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.min.js"></script> | ||
<!-- The basic File Upload plugin and components--> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-process.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-image.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-audio.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-video.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-validate.js"></script> | ||
<script src="/static/node_modules/blueimp-file-upload/js/jquery.fileupload-ui.js"></script> | ||
<!-- Locale --> | ||
<script src="/static/node_modules/ai-django-fileupload/locale.js"></script> | ||
<!-- CSRF token --> | ||
<script src="/static/node_modules/ai-django-fileupload/csrf.js"></script> | ||
<!-- The main application script --> | ||
<script src="/static/node_modules/ai-django-fileupload/index.js"></script> | ||
<!-- The XDomainRequest Transport is included for cross-domain file deletion for IE8+ --> | ||
<!--[if gte IE 8]> | ||
<script src="/static/node_modules/blueimp-file-upload/js/cors/jquery.xdr-transport.js"></script> | ||
<![endif]--> | ||
``` | ||
|
||
## License | ||
|
||
Released under the [MIT license](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// modify jquery ajax to add csrf token when doing "local" requests | ||
|
||
$('html').ajaxSend(function(event, xhr, settings) { | ||
function getCookie(name) { | ||
var cookieValue = null; | ||
if (document.cookie && document.cookie != '') { | ||
var cookies = document.cookie.split(';'); | ||
for (var i = 0; i < cookies.length; i++) { | ||
var cookie = jQuery.trim(cookies[i]); | ||
// Does this cookie string begin with the name we want? | ||
if (cookie.substring(0, name.length + 1) == (name + '=')) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
} | ||
} | ||
return cookieValue; | ||
} | ||
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { | ||
// Only send the token to relative URLs i.e. locally. | ||
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* jQuery File Upload Plugin JS | ||
* Copyright 2010, Sebastian Tschan | ||
* Copyright 2017, Ambient Innovation GmbH | ||
* Licensed under the MIT license: | ||
* http://www.opensource.org/licenses/MIT | ||
*/ | ||
|
||
/*jslint nomen: true, regexp: true */ | ||
/*global $, window, blueimp */ | ||
|
||
$(function () { | ||
'use strict'; | ||
// TODO: The usage of IDS in many places will let us only use one file uploader per screen | ||
var fileuploadElement = $('#ai-fileupload'); | ||
|
||
// Initialize the jQuery File Upload widget: | ||
// Uncomment the following to send cross-domain cookies: | ||
fileuploadElement.fileupload({ | ||
// xhrFields: {withCredentials: true}, | ||
// url: 'server/php/' | ||
}); | ||
|
||
// Enable iframe cross-domain access via redirect option: | ||
fileuploadElement.fileupload( | ||
'option', | ||
'redirect', | ||
window.location.href.replace( | ||
/\/[^\/]*$/, | ||
'/cors/result.html?%s' | ||
) | ||
); | ||
|
||
|
||
// Load existing files: | ||
fileuploadElement.addClass('fileupload-processing'); | ||
var content_type_id = $('#content_type_id').val(); | ||
var object_id = $('#object_id').val(); | ||
$.ajax({ | ||
// Uncomment the following to send cross-domain cookies: | ||
// xhrFields: {withCredentials: true}, | ||
// url: fileuploadElement.fileupload('option', 'url'), | ||
|
||
url: '/upload/view/?content_type_id=' + content_type_id + '&object_id=' + object_id, | ||
dataType: 'json', | ||
context: fileuploadElement[0] | ||
}).always(function () { | ||
$(this).removeClass('fileupload-processing'); | ||
}).done(function (result) { | ||
$(this).fileupload('option', 'done') | ||
.call(this, $.Event('done'), {result: result}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
window.locale = { | ||
"fileupload": { | ||
"errors": { | ||
"maxFileSize": "File is too big", | ||
"minFileSize": "File is too small", | ||
"acceptFileTypes": "Filetype not allowed", | ||
"maxNumberOfFiles": "Max number of files exceeded", | ||
"uploadedBytes": "Uploaded bytes exceed file size", | ||
"emptyResult": "Empty file upload result" | ||
}, | ||
"error": "Error", | ||
"start": "Start", | ||
"cancel": "Cancel", | ||
"destroy": "Delete" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "ai-django-fileupload", | ||
"version": "0.1.11", | ||
"description": "Initializes the uploader widget, and renders the attachments table. Must be used with ai-django-fileupload python package.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"[\"uploader\"", | ||
"\"ai-django-fileupload\"", | ||
"\"jquery-fileuploader\"]", | ||
"jquery", | ||
"file", | ||
"upload", | ||
"widget", | ||
"multiple", | ||
"selection", | ||
"drag", | ||
"drop", | ||
"progress", | ||
"preview" | ||
], | ||
"author": "Ambient Innovation GmbH", | ||
"dependencies": { | ||
"jquery": "^3.2.1", | ||
"bootstrap": "^3.3.7", | ||
"blueimp-file-upload": "^9.19.1", | ||
"blueimp-canvas-to-blob": "^3.5.0", | ||
"blueimp-load-image": "^2.12.2", | ||
"blueimp-tmpl": "^3.6.0" | ||
}, | ||
"license": "MIT" | ||
} |