123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*------------------------------------------------------------------------------------------------------------------------
- @package: Arkiwi Upload
- @author: cek
- @www: arkiwi.org
- @copyright: COPYRIGHT 25 cek
- @license: MIT
- =============================================================================
- Filename: arkiwi.js
- =============================================================================
- /*------------------------------------------------------------------------------------------------------------------------*/
- var ARKIWI = ARKIWI || {};
- ARKIWI.Uploader = function (uploaderUrl, defaultParameters, formName, sessionUploadProgressName) {
- this.uploaderUrl = uploaderUrl;
- this.defaultParameters = defaultParameters || '';
- this.formName = formName || 'arkiwiUploadForm';
- this.sessionUploadProgressName = sessionUploadProgressName || 'PHP_SESSION_UPLOAD_PROGRESS';
- };
- ARKIWI.Uploader.constructor = ARKIWI.Uploader;
- /* Invia un file all'uploader. */
- ARKIWI.Uploader.prototype.upload = function (file, destinationFolderBase64, callbacks) {
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- var self = this;
- if (callbacks) {
- xhr.upload.addEventListener("progress", function(e) {
- callbacks.progress(e);
- }, false);
- //we need to add the event listener to xhr, not to xhr.upload
- xhr.addEventListener("load", function(e){
- callbacks.load(e);
- }, false);
- xhr.upload.addEventListener("error", function(e){
- callbacks.error(e);
- }, false);
- }
- xhr.open("POST", this.uploaderUrl + '/upload/' + destinationFolderBase64 + '/?' + this.defaultParameters, true);
- var fileData = new FormData();
- fileData.append("arkiwiuploadedfile", file);
- // These extra params aren't necessary but show that you can include other data.
- fileData.append("arkiwiuploadedfilename", file.name);
- xhr.send(fileData);
- };
- /* Aggiunge o sovrascrive i metadati di un file. */
- ARKIWI.Uploader.prototype.listMetadata = function (item64, callback) {
- $.ajax({
- url: this.uploaderUrl + '/listmetadata/' + item64 + '/?' + this.defaultParameters,
- type: 'GET',
- async: true,
- cache: false,
- context: this,
- data: '',
- dataType: 'json',
- error: function (xhr, status, error) {
- if (status != 'parsererror')
- throw 'Arkiwi.listMetadata(): status ' + status + ' error ' + error;
- else {
- if (callback)
- callback(JSON.parse("[]"));
- }
- },
- success: function (result, status, xhr) {
- if (callback != undefined)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
- /* Aggiunge o sovrascrive i metadati di un file. */
- ARKIWI.Uploader.prototype.modifyMetadata = function (item64, jsonKVString, callback) {
- $.ajax({
- url: this.uploaderUrl + '/modifymetadata/' + item64 + '/?' + this.defaultParameters,
- type: 'POST',
- async: true,
- cache: false,
- context: this,
- data: jsonKVString,
- dataType: 'json',
- contentType: "application/json",
- error: function (xhr, status, error) {
- throw 'Arkiwi.modifyMetadata(): status ' + status + ' error ' + error;
- },
- success: function (result, status, xhr) {
- if (callback)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
- /* Aggiunge o sovrascrive i metadati di un file. */
- ARKIWI.Uploader.prototype.createDirectory = function (item64, newDirectory, callback) {
- $.ajax({
- url: this.uploaderUrl + '/createdirectory/' + item64 + '/?' + this.defaultParameters,
- type: 'POST',
- async: true,
- cache: false,
- context: this,
- data: JSON.stringify({directory : newDirectory}),
- dataType: 'text',
- contentType: "html/text",
- error: function (xhr, status, error) {
- throw 'Arkiwi.createDirectory(): status ' + status + ' error ' + error;
- },
- success: function (result, status, xhr) {
- if (callback != undefined)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
|