Prechádzať zdrojové kódy

Merge branch 'master' of lattuga.net:kiki/arkiwi_boilerplate

cri 8 rokov pred
rodič
commit
9d9df3c449
4 zmenil súbory, kde vykonal 166 pridanie a 47 odobranie
  1. 0 10
      app/index.html
  2. 33 37
      app/scripts/arkiwi.js
  3. 61 0
      app/scripts/upload.js
  4. 72 0
      app/upload.html

+ 0 - 10
app/index.html

@@ -25,16 +25,6 @@
 <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
     <link rel="stylesheet" href="styles/main.css">
     <!-- endbuild -->
-
-
-<!-- Latest compiled and minified CSS -->
-<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">-->
-
-<!-- Optional theme -->
-<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">-->
-
-<!-- Latest compiled and minified JavaScript -->
-<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>-->
 </head>
 
 <body>

+ 33 - 37
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('<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,32 +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) {
-        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;
-    });
-};

+ 61 - 0
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;
+    }
+};

+ 72 - 0
app/upload.html

@@ -0,0 +1,72 @@
+<!doctype html>
+<!--[if lt IE 7]>
+<html class = "no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
+<!--[if IE 7]>
+<html class = "no-js lt-ie9 lt-ie8"> <![endif]-->
+<!--[if IE 8]>
+<html class = "no-js lt-ie9"> <![endif]-->
+<!--[if gt IE 8]><!-->
+<html class="no-js">
+<!--<![endif]-->
+
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    <title>arkiwiJsBoilerplate</title>
+    <meta name="description" content="Arkiwi JS Boilerplate">
+    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
+    <!-- build:css styles/vendor.css -->
+    <!-- bower:css -->
+    <!-- endbower -->
+    <!-- endbuild -->
+    <!-- build:css(.tmp) styles/main.css -->
+    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
+    <link rel="stylesheet" href="styles/main.css">
+    <!-- endbuild -->
+</head>
+
+<body>
+    <!--[if lt IE 10]>
+        <p class = "browsehappy">You are using an <strong>outdated</strong> browser. Please
+            <a href = "http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
+        <![endif]-->
+
+    <div class="container">
+        <header>
+        </header>
+
+        <form target="arkiwi_hidden_iframe" id="arkiwifile" class="form-inline">
+
+            <input type="file" id="hiddenfileinput" style="position: absolute; top: -1000px;">
+
+            <input type="text" id="displayedfileinput"/>
+
+            <button type="button" class="btn" id="displayedbrowsebutton">Browse</button>
+
+            <!--<div class="input-xxlarge" style="margin: 0 auto; display: none;" id="fileprogressbar">
+                <div class="progress progress-striped">
+                    <div class="bar" id="fileprogressbarinternal"></div>
+                </div>
+                <div>
+                    <span id="fileuploadpart">0</span><span> of </span><span id="fileuploadtotal"></span>
+                </div>
+            </div>-->
+            <span class="help-block" id="instructions">Select a file to upload to Arkiwi asset store.</span>
+            <button type="button" class="btn" id="uploadbutton" title="Upload to Arkiwi asset store">Upload</button>
+        </form>
+    </div>
+    <!-- build:js scripts/vendor.js -->
+    <!-- bower:js -->
+    <script src="bower_components/jquery/dist/jquery.js"></script>
+    <script src="bower_components/mustache/mustache.js"></script>
+    <script src="bower_components/bower-parseuri/parseuri.js"></script>
+    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
+    <!-- endbower -->
+    <!-- endbuild -->
+
+    <script src="scripts/arkiwi.js" type="text/javascript"></script>
+    <script src="scripts/upload.js" type="text/javascript"></script>
+</body>
+</html>