123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /*------------------------------------------------------------------------------------------------------------------------
- @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.Arkiwi = function (endpoint, defaultParameters, formName, sessionUploadProgressName) {
- this.endpoint = endpoint;
- 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="display: none;"></iframe>');
- };
- ARKIWI.Arkiwi.constructor = ARKIWI.Arkiwi;
- ARKIWI.Arkiwi.prototype.create = function (callbacks) {
- $.ajax({
- url: this.endpoint + '/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) {},
- });
- };
- ARKIWI.Arkiwi.prototype.upload = function (form, destinationFolderBase64, callbacks) {
- form = $(form);
- form.attr('method', 'POST');
- form.attr('action', this.endpoint + '/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.Arkiwi.prototype.metadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.endpoint + '/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) {}
- });
- };
- ARKIWI.Arkiwi.prototype.removeMetadata = function (jsonKVString, callback) {
- $.ajax({
- url: this.endpoint + '/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) {}
- });
- };
- ARKIWI.Arkiwi.prototype.close = function (callback) {
- $.ajax({
- url: this.endpoint + '/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) {}
- });
- };
- ARKIWI.Arkiwi.prototype.path = function (path, callback, notBase64) {
- var pathType = notBase64 ? 'path' : 'path64';
- $.getJSON(this.endpoint + '/' + pathType + '/' + path + '/jsonml/?' + this.defaultParameters, function (result) {
- if (callback != undefined)
- callback(result);
- }).fail(function (error) {
- throw 'Arkiwi.path(): status ' + status + ' error ' + error.responseText;
- });
- };
- 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.endpoint + '/search64/' + sanitizedQuery + '/jsonml/?' + this.defaultParameters, function (result) {
- if (callback != undefined)
- callback(result);
- }).fail(function (error) {
- throw 'Arkiwi.search(): status ' + status + ' error ' + error.responseText;
- });
- };
|