123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /*------------------------------------------------------------------------------------------------------------------------
- @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 (form, destinationFolderBase64, callbacks) {
- // form = $(form);
- //
- // form.attr('method', 'POST');
- // form.attr('action', this.uploaderUrl + '/upload/' + this.sessionId + '/' + destinationFolderBase64 + '/?' + this.defaultParameters);
- // form.attr('id', this.formName);
- // form.attr('enctype', 'multipart/form-data');
- // form.attr('target', 'arkiwi_hidden_iframe');
- //
- // form.append('<input type="hidden" value="' + this.formName + '" name="' + this.sessionUploadProgressName + '" />');
- //
- // $(':file', form).attr('name', this.sessionId);
- //
- // form.ajaxForm({
- // beforeSend: function () {
- // callbacks.beforeSend();
- // },
- // uploadProgress: function (event, position, total, percentComplete) {
- // callbacks.uploadProgress(event, position, total, percentComplete);
- // },
- // complete: function (xhr) {
- // callbacks.complete(xhr);
- // },
- // error: function (xhr, status, error) {
- // throw 'Arkiwi.upload(): error ' + error;
- // }
- // });
- //
- // form.submit();
- //};
- ARKIWI.Uploader.prototype.upload = function (file, destinationFolderBase64, callbacks) {
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- var self = this;
- xhr.upload.addEventListener("progress", function(e) {}, false);
- xhr.upload.addEventListener("load", function(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.metadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.uploaderUrl + '/metadata/' + this.sessionId + '/?' + this.defaultParameters,
- type: 'POST',
- async: true,
- cache: false,
- context: this,
- data: jsonKVString,
- dataType: 'json',
- error: function (xhr, status, error) {
- throw 'Arkiwi.metadata(): status ' + status + ' error ' + error;
- },
- success: function (result, status, xhr) {
- if (callback != undefined)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
- /* Cancella un metadato da un file */
- ARKIWI.Uploader.prototype.removeMetadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.uploaderUrl + '/removemetadata/' + this.sessionId + '/?' + this.defaultParameters,
- type: 'POST',
- async: true,
- cache: false,
- context: this,
- data: jsonKVString,
- dataType: 'json',
- error: function (xhr, status, error) {
- throw 'Arkiwi.removeMetadata(): status ' + status + ' error ' + error;
- },
- success: function (result, status, xhr) {
- if (callback != undefined)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
- /* Chiude la sessione con l'asset store */
- ARKIWI.Uploader.prototype.close = function (callback) {
- $.ajax({
- url: this.uploaderUrl + '/close/' + this.sessionId + '/?' + this.defaultParameters,
- type: 'GET',
- async: true,
- cache: false,
- context: this,
- data: '',
- dataType: 'json',
- error: function (xhr, status, error) {
- throw 'Arkiwi.close(): status ' + status + ' error ' + error;
- },
- success: function (result, status, xhr) {
- if (callback != undefined)
- callback(result);
- },
- complete: function (xhr, status) {}
- });
- };
|