From 0f7c4de112f4c8a2bb6a98a58d4a89a9fb33f505 Mon Sep 17 00:00:00 2001 From: cek Date: Sun, 13 Sep 2015 00:41:33 +0200 Subject: [PATCH 1/2] blah --- app/index.html | 10 ------ app/scripts/arkiwi.js | 1 + app/scripts/upload.js | 61 ++++++++++++++++++++++++++++++++++++ app/upload.html | 72 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 app/scripts/upload.js create mode 100644 app/upload.html diff --git a/app/index.html b/app/index.html index b94d91c..2085b96 100644 --- a/app/index.html +++ b/app/index.html @@ -25,16 +25,6 @@ - - - - - - - - - - diff --git a/app/scripts/arkiwi.js b/app/scripts/arkiwi.js index a099155..2dacb02 100644 --- a/app/scripts/arkiwi.js +++ b/app/scripts/arkiwi.js @@ -168,6 +168,7 @@ ARKIWI.Arkiwi.prototype.path = function (path, callback, notBase64) { 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; } diff --git a/app/scripts/upload.js b/app/scripts/upload.js new file mode 100644 index 0000000..4c9f580 --- /dev/null +++ b/app/scripts/upload.js @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------------------------------------------------------ + @package: arkiwiJsBoilerplate + + @author: cek + @www: arkiwi.oeg + + @copyright: COPYRIGHT 18 cek + @license: MIT + + ============================================================================= + Filename: upload.js + ============================================================================= + This file is the main entry point for js on the arkiwiJsBoilerplate app. + --------------------------------------------------------------------------------------------------------------------- */ + +/* MODIFICARE CON GLI URL DESIDERATI */ +var ASSETSTORE = 'http://upload.arkiwi.org/arav_up_api'; +var AGGREGATOR = 'http://www.arkiwi.org'; +/*************************************/ + +var arkiwi = {}; +var currentFileName = ''; + +$(document).ready(function () { + arkiwi = new ARKIWI.Arkiwi(AGGREGATOR, ASSETSTORE); + + //prepara le cose per il finto input file + $('#displayedbrowsebutton').click(function () { + $('input[id=hiddenfileinput]').click(); + }); + + $('input[id=hiddenfileinput]').change(function() { + $('#displayedfileinput').val($(this).val()); + //this.files[0].size gets the size of your file. + $('#fileuploadtotal').text(this.files[0].size + ' bytes.'); + currentFileName = this.files[0].name; + }); + + $('#uploadbutton').click(function() { + upload(); + }); + + var callbacks = { + success: function(id) { + //$('#status').html('Session id ' + id); + console.log('DEBUG: Session id ' + id); + }, + unauthorized: function() { + arkiwi.create(callbacks); + }, + }; + + arkiwi.create(callbacks); +}); + +function upload() { + if ($('input[id=hiddenfileinput]').val() == '') { + alert('Select a file to upload.\n (KIKI non vuoi sostituirmi con qualcosa di meglio di un alert?)'); + return false; + } +}; diff --git a/app/upload.html b/app/upload.html new file mode 100644 index 0000000..abd16c3 --- /dev/null +++ b/app/upload.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + arkiwiJsBoilerplate + + + + + + + + + + + + + + + +
+
+
+ +
+ + + + + + + + + Select a file to upload to Arkiwi asset store. + +
+
+ + + + + + + + + + + + + From a05bd7ced08e3143017321c970cab10cb70c0a5f Mon Sep 17 00:00:00 2001 From: cek Date: Sun, 13 Sep 2015 01:28:29 +0200 Subject: [PATCH 2/2] Separata la classe arkiwi in assetStore e Aggregator --- app/scripts/arkiwi.js | 71 ++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/app/scripts/arkiwi.js b/app/scripts/arkiwi.js index 2dacb02..31ee770 100644 --- a/app/scripts/arkiwi.js +++ b/app/scripts/arkiwi.js @@ -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(''); }; -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; - }); -};