Separata la classe arkiwi in assetStore e Aggregator

This commit is contained in:
cek 2015-09-13 01:28:29 +02:00
parent 4e662731d5
commit a05bd7ced0

View file

@ -15,10 +15,35 @@
var ARKIWI = ARKIWI || {};
ARKIWI.Arkiwi = function (aggregator, assetStore, defaultParameters, formName, sessionUploadProgressName) {
this.assetStore = assetStore;
ARKIWI.Aggregator = function (aggregator, defaultParameters) {
this.aggregator = aggregator;
this.defaultParameters = defaultParameters || '';
};
ARKIWI.Aggregator.constructor = ARKIWI.Aggregator;
/* Esegue un ricerca sull'aggregatore */
ARKIWI.Aggregator.prototype.search = function (query, callback, jailFolder) {
var sanitizedQuery = query;
if (jailFolder) {
//FIXME non c'è controllo sul contenuto di jailFolder
sanitizedQuery = '+file:' + jailFolder + '* AND ' + query;
}
sanitizedQuery = window.btoa(sanitizedQuery); //convert to Base64
$.getJSON(this.aggregator + '/search64/' + sanitizedQuery + '/json/?' + this.defaultParameters, function (result) {
if (callback != undefined)
callback(result);
}).fail(function (error) {
throw 'Arkiwi.search(): status ' + status + ' error ' + error.responseText;
});
};
ARKIWI.AssetStore = function (assetStore, defaultParameters, formName, sessionUploadProgressName) {
this.assetStore = assetStore;
this.defaultParameters = defaultParameters || '';
this.formName = formName || 'arkiwiUploadForm';
this.sessionUploadProgressName = sessionUploadProgressName || 'PHP_SESSION_UPLOAD_PROGRESS';
@ -28,10 +53,10 @@ ARKIWI.Arkiwi = function (aggregator, assetStore, defaultParameters, formName, s
$(document.body).append('<iframe id="arkiwi_hidden_iframe" name="arkiwi_hidden_iframe" src="about:blank" style="visibility: hidden;"></iframe>');
};
ARKIWI.Arkiwi.constructor = ARKIWI.Arkiwi;
ARKIWI.AssetStore.constructor = ARKIWI.AssetStore;
/* Inizializza la sessione di dialogo con l'asset store. */
ARKIWI.Arkiwi.prototype.create = function (callbacks) {
ARKIWI.AssetStore.prototype.create = function (callbacks) {
$.ajax({
url: this.assetStore + '/create/?' + this.defaultParameters,
type: 'GET',
@ -58,7 +83,7 @@ ARKIWI.Arkiwi.prototype.create = function (callbacks) {
};
/* Invia un file all'asset store. */
ARKIWI.Arkiwi.prototype.upload = function (form, destinationFolderBase64, callbacks) {
ARKIWI.AssetStore.prototype.upload = function (form, destinationFolderBase64, callbacks) {
form = $(form);
form.attr('method', 'POST');
@ -90,7 +115,7 @@ ARKIWI.Arkiwi.prototype.upload = function (form, destinationFolderBase64, callba
};
/* Aggiunge o sovrascrive i metadati di un file. */
ARKIWI.Arkiwi.prototype.metadata = function (jsonKVString, callback) {
ARKIWI.AssetStore.prototype.metadata = function (jsonKVString, callback) {
$.ajax({
url: this.assetStore + '/metadata/' + this.sessionId + '/?' + this.defaultParameters,
type: 'POST',
@ -111,7 +136,7 @@ ARKIWI.Arkiwi.prototype.metadata = function (jsonKVString, callback) {
};
/* Cancella un metadato da un file */
ARKIWI.Arkiwi.prototype.removeMetadata = function (jsonKVString, callback) {
ARKIWI.AssetStore.prototype.removeMetadata = function (jsonKVString, callback) {
$.ajax({
url: this.assetStore + '/removemetadata/' + this.sessionId + '/?' + this.defaultParameters,
type: 'POST',
@ -132,7 +157,7 @@ ARKIWI.Arkiwi.prototype.removeMetadata = function (jsonKVString, callback) {
};
/* Chiude la sessione con l'asset store */
ARKIWI.Arkiwi.prototype.close = function (callback) {
ARKIWI.AssetStore.prototype.close = function (callback) {
$.ajax({
url: this.assetStore + '/close/' + this.sessionId + '/?' + this.defaultParameters,
type: 'GET',
@ -151,33 +176,3 @@ ARKIWI.Arkiwi.prototype.close = function (callback) {
complete: function (xhr, status) {}
});
};
/* Chiede all'aggregatore i metadati su una cartella o un file. */
ARKIWI.Arkiwi.prototype.path = function (path, callback, notBase64) {
var pathType = notBase64 ? 'path' : 'path64';
$.getJSON(this.aggregator + '/' + pathType + '/' + path + '/json/?' + this.defaultParameters, function (result) {
if (callback != undefined)
callback(result);
}).fail(function (error) {
throw 'Arkiwi.path(): status ' + status + ' error ' + error.responseText;
});
};
/* Esegue un ricerca sull'aggregatore */
ARKIWI.Arkiwi.prototype.search = function (query, callback, jailFolder) {
var sanitizedQuery = query;
if (jailFolder) {
//FIXME non c'è controllo sul contenuto di jailFolder
sanitizedQuery = '+file:' + jailFolder + '* AND ' + query;
}
sanitizedQuery = window.btoa(sanitizedQuery); //convert to Base64
$.getJSON(this.aggregator + '/search64/' + sanitizedQuery + '/json/?' + this.defaultParameters, function (result) {
if (callback != undefined)
callback(result);
}).fail(function (error) {
throw 'Arkiwi.search(): status ' + status + ' error ' + error.responseText;
});
};