123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /*------------------------------------------------------------------------------------------------------------------------
- @package: arkiwiJsBoilerplate
- @author: cek
- @www: arkiwi.oeg
- @copyright: COPYRIGHT 18 cek
- @license: MIT
- =============================================================================
- Filename: arkiwi.js
- =============================================================================
- This file is the main entry point for js on the arkiwiJsBoilerplate app.
- --------------------------------------------------------------------------------------------------------------------- */
- var ARKIWI = ARKIWI || {};
- ARKIWI.Aggregator = function (aggregator, defaultParameters) {
- this.aggregator = aggregator;
- this.defaultParameters = defaultParameters || '';
- };
- ARKIWI.Aggregator.constructor = ARKIWI.Aggregator;
- /* Chiede all'aggregatore i metadati su una cartella o un file. */
- ARKIWI.Aggregator.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.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';
- this.sessionId = '';
- if ($('#arkiwi_hidden_iframe').length == 0)
- $(document.body).append('<iframe id="arkiwi_hidden_iframe" name="arkiwi_hidden_iframe" src="about:blank" style="visibility: hidden;"></iframe>');
- };
- ARKIWI.AssetStore.constructor = ARKIWI.AssetStore;
- /* Inizializza la sessione di dialogo con l'asset store. */
- ARKIWI.AssetStore.prototype.create = function (callbacks) {
- $.ajax({
- url: this.assetStore + '/create/?' + this.defaultParameters,
- type: 'GET',
- async: false,
- cache: false,
- context: this,
- data: '',
- dataType: 'json',
- error: function (xhr, status, error) {
- if (error != 'Unauthorized')
- throw 'Arkiwi.create(): error ' + error;
- else {
- if (callbacks != undefined && callbacks.unauthorized != undefined)
- callbacks.unauthorized();
- }
- },
- success: function (result, status, xhr) {
- this.sessionId = result.id;
- if (callbacks != undefined && callbacks.success != undefined)
- callbacks.success(this.sessionId);
- },
- complete: function (xhr, status) {},
- });
- };
- /* Invia un file all'asset store. */
- ARKIWI.AssetStore.prototype.upload = function (form, destinationFolderBase64, callbacks) {
- form = $(form);
- form.attr('method', 'POST');
- form.attr('action', this.assetStore + '/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();
- };
- /* Aggiunge o sovrascrive i metadati di un file. */
- ARKIWI.AssetStore.prototype.metadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.assetStore + '/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.AssetStore.prototype.removeMetadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.assetStore + '/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.AssetStore.prototype.close = function (callback) {
- $.ajax({
- url: this.assetStore + '/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) {}
- });
- };
|