Commit 9eb2e5dd authored by Boris Kocherov's avatar Boris Kocherov

inital add, based on work vincent.bechu@nexedi.com

parents
{
"name": "erp5_officejs_fs2erp5_gadget",
"scopes": [
{
"prefix": "fs2erp5",
"paths": [
""
]
}
]
}
\ No newline at end of file
---
---
CACHE MANIFEST
CACHE:
{% assign s_files = site.static_files | where_exp: "file", "file.exclude != true" %}{% for file in s_files %}{{ file.path | remove_first: "/"}}
{% endfor %}
\ No newline at end of file
This diff is collapsed.
/*global window, RSVP, FileReader */
/*jslint indent: 2, maxerr: 3, unparam: true */
(function (window, RSVP, FileReader) {
"use strict";
window.loopEventListener = function (target, type, useCapture, callback,
prevent_default) {
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
//////////////////////////
var handle_event_callback,
callback_promise;
if (prevent_default === undefined) {
prevent_default = true;
}
function cancelResolver() {
if ((callback_promise !== undefined) &&
(typeof callback_promise.cancel === "function")) {
callback_promise.cancel();
}
}
function canceller() {
if (handle_event_callback !== undefined) {
target.removeEventListener(type, handle_event_callback, useCapture);
}
cancelResolver();
}
function itsANonResolvableTrap(resolve, reject) {
var result;
handle_event_callback = function (evt) {
if (prevent_default) {
evt.stopPropagation();
evt.preventDefault();
}
cancelResolver();
try {
result = callback(evt);
} catch (e) {
result = RSVP.reject(e);
}
callback_promise = result;
new RSVP.Queue()
.push(function () {
return result;
})
.push(undefined, function (error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
};
window.promiseEventListener = function (target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function (evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
};
window.promiseReadAsText = function (file) {
return new RSVP.Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onload = function (evt) {
resolve(evt.target.result);
};
reader.onerror = function (evt) {
reject(evt);
};
reader.readAsText(file);
});
};
window.promiseDoWhile = function (loopFunction, input) {
// calls loopFunction(input) until it returns a non positive value
// this queue is to protect the inner loop queue from the
// `promiseDoWhile` caller, avoiding it to enqueue the inner
// loop queue.
return new RSVP.Queue()
.push(function () {
// here is the inner loop queue
var loop_queue = new RSVP.Queue();
function iterate(previous_iteration_result) {
if (!previous_iteration_result) {
return input;
}
loop_queue.push(iterate);
return loopFunction(input);
}
return loop_queue
.push(function () {
return loopFunction(input);
})
.push(iterate);
});
};
}(window, RSVP, FileReader));
\ No newline at end of file
/*globals window, RSVP, rJS, loopEventListener, URL, document
FileReader, console, navigator, jIO */
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, navigator, RSVP, rJS, jIO, URL) {
"use strict";
var origin_url = (window.location.origin + window.location.pathname)
.replace("officejs_fs2erp5_gadget/", "");
// application_list = [
// "officejs_fs2erp5_gadget",
//
// ];
function exportZip(gadget, event) {
var j,
zip_name,
// i = 0,
form_result = {},
len = event.target.length,
app_url;
for (j = 0; j < len; j += 1) {
form_result[event.target[j].name] = event.target[j].value;
}
app_url = origin_url + form_result.web_site + '/';
// len = 0;
zip_name = form_result.filename;
// function fill(zip_file) {
// if (i < len) {
// var sub_app = app.sub_gadget[i];
// return gadget.fillZip({
// cache: "erp5_/index.appcache",
// site_url: origin_url + app.url,
// zip_file: zip_file,
// prefix: sub_app + "/",
// take_installer: false
// })
// .push(function (zip_file) {
// i += 1;
// return fill(zip_file);
// });
// }
// return zip_file;
// }
//
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
dataType: "json",
url: app_url + "erp5_/erp5.json"
});
})
.push(function (response) {
gadget.props.erp5_options = response.target.response;
})
.push(function () {
return gadget.fillZip({
cache: "erp5_/index.appcache",
site_url: app_url,
take_installer: false
});
})
// .push(function (zip_file) {
// return fill(zip_file);
// })
.push(function (zip_file) {
var element = gadget.props.element,
a = document.createElement("a"),
url = URL.createObjectURL(zip_file),
default_name = gadget.props.erp5_options.name
.replace(' ', '_');
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = zip_name ? zip_name : default_name + ".zip";
a.click();
element.removeChild(a);
URL.revokeObjectURL(url);
});
}
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareMethod("fillZip", function (options) {
var gadget = this,
file_storage = jIO.createJIO({
type: "replicate",
conflict_handling: 2,
check_remote_attachment_creation: true,
check_local_creation: false,
check_local_modification: false,
check_local_deletion: false,
check_remote_deletion: false,
check_remote_modification: false,
remote_sub_storage: {
type: "fs2erp5",
document: options.site_url,
sub_storage: {
type: "appcache",
take_installer: options.take_installer,
manifest: options.cache,
origin_url: options.site_url,
prefix: options.prefix || ""
}
},
signature_sub_storage: {
type: "query",
sub_storage: {
type: "memory"
}
},
local_sub_storage: {
type: "zipfile",
file: options.zip_file
}
});
return file_storage.repair()
.push(function () {
return file_storage.getAttachment('/', '/');
});
})
/////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return loopEventListener(
gadget.props.element.querySelector('form.export-form'),
'submit',
true,
function (event) {
return exportZip(gadget, event);
}
);
});
});
}(window, navigator, RSVP, rJS, jIO, URL));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Erp5 bt export gadget</title>
<link rel="stylesheet" href="gadget_erp5_nojqm.css">
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_global.js"></script>
<script src="gadget_officejs_page_export2erp5.js"></script>
<script src="zipfilestorage-with-jszip.js"></script>
<script src="jio_fs2erp5storage.js"></script>
<script src="jio_appcachestorage.js"></script>
</head>
<body>
<article class="ui-content ui-body-c">
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-database">&nbsp;</span>
Export
</h3>
</section>
<section class="ui-body-c ui-content-section">
<form class="export-form">
<div class="ui-form">
<div class="ui-field-contain">
<label data-i18n="Site:">Site:</label>
<select name="web_site">
<option>officejs_fs2erp5_gadget</option>
<option>web-apps</option>
<option>sdkjs</option>
</select>
</div>
</div>
<div class="ui-form">
<div class="ui-field-contain">
<label data-i18n="File Name:">File Name:</label>
<input name="filename"/>
</div>
</div>
<div class="select-storage ui-controlgroup ui-controlgroup-horizontal">
<div class="ui-grid-b ui-responsive">
<div class="ui-block-a"></div>
<div class="ui-block-b"></div>
<div class="ui-block-c">
<button type="submit" data-i18n="Export" class="ui-btn-btn-right">Export</button>
</div>
</div>
</div>
</form>
</section>
</article>
<div id="global_setting_gadget" style="display: none;"></div>
</body>
</html>
\ No newline at end of file
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, window, console, Blob */
(function (window, jIO, RSVP, console, Blob) {
"use strict";
function AppCacheStorage(spec) {
this._manifest = spec.manifest;
this._take_installer = spec.take_installer || false;
this._origin_url = spec.origin_url !== undefined ? spec.origin_url :
(window.location.origin + window.location.pathname +
(window.location.pathname.endsWith('/') ? '' : '/') +
((spec.version !== undefined) ?
(spec.version + (spec.version.endsWith('/') ? '' : '/')) : ""));
this._prefix = spec.prefix || "";
this._relative_url_list = ["/", this._prefix + spec.manifest];
if (this._take_installer) {
this._relative_url_list = [
this._prefix || "/",
this._prefix + "development/" + spec.manifest,
this._prefix + "development/",
this._prefix + "gadget_officejs_bootloader.js",
this._prefix + "gadget_officejs_bootloader.appcache",
this._prefix + "gadget_officejs_bootloader_presentation.html",
this._prefix + "gadget_officejs_bootloader_presentation.js",
this._prefix + "gadget_officejs_bootloader_presentation.css",
this._prefix + "gadget_officejs_bootloader_serviceworker.js",
this._prefix + "gadget_erp5_nojqm.css",
this._prefix + "jio_appcachestorage.js"
];
}
}
AppCacheStorage.prototype.get = function (id) {
return {};
};
AppCacheStorage.prototype.hasCapacity = function (name) {
return (name === "list");
};
AppCacheStorage.prototype.getAttachment = function (doc_id, attachment_id) {
var storage = this, url = attachment_id;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: ((url.startsWith("http") || url.startsWith("//")) ?
url : storage._origin_url) + url,
dataType: "blob"
});
})
.push(function (result) {
return result.target.response;
});
};
AppCacheStorage.prototype.allAttachments = function (url) {
var result = {}, i, len = this._relative_url_list.length;
for (i = 0; i < len; i += 1) {
result[this._relative_url_list[i]] = {};
}
return result;
};
AppCacheStorage.prototype.buildQuery = function (options) {
return [{id: "/", doc: {}, value: {}}];
};
AppCacheStorage.prototype.repair = function () {
var storage = this,
prefix = storage._prefix +
(storage._take_installer ? "development/" : "");
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: storage._origin_url + storage._prefix + storage._manifest
});
})
.push(function (response) {
var text = response.target.responseText,
relative_url_list = text.split('\r\n'),
i,
take = false;
if (relative_url_list.length === 1) {
relative_url_list = text.split('\n');
}
if (relative_url_list.length === 1) {
relative_url_list = text.split('\r');
}
for (i = 0; i < relative_url_list.length; i += 1) {
if (relative_url_list[i].indexOf("NETWORK:") >= 0) {
take = false;
}
if (take &&
relative_url_list[i] !== "" &&
relative_url_list[i].charAt(0) !== '#' &&
relative_url_list[i].charAt(0) !== ' ') {
relative_url_list[i].replace("\r", "");
storage._relative_url_list.push(prefix + relative_url_list[i]);
}
if (relative_url_list[i].indexOf("CACHE:") >= 0) {
take = true;
}
}
});
};
jIO.addStorage('appcache', AppCacheStorage);
}(window, jIO, RSVP, console, Blob));
\ No newline at end of file
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, window, console, Blob */
(function (window, jIO, RSVP, console, Blob) {
"use strict";
function Fs2Erp5Storage(spec) {
this._document = spec.document;
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._id_dict = {};
this._paths = {};
}
Fs2Erp5Storage.prototype.get = function (url) {
return {};
};
Fs2Erp5Storage.prototype.hasCapacity = function (name) {
return (name === "list");
};
Fs2Erp5Storage.prototype.getAttachment = function (doc_id, attachment_id) {
// doc_id + ((attachment_id === "index.html") ?
// (doc_id.endsWith("imagelib/") ? "index.html" : "") : attachment_id)
return this._sub_storage.getAttachment(
this._document, this._id_dict[doc_id][attachment_id]
);
};
Fs2Erp5Storage.prototype.allAttachments = function (doc_id) {
return this._id_dict[doc_id] || {};
};
Fs2Erp5Storage.prototype.buildQuery = function (options) {
var id, result = [], context = this;
for (id in context._id_dict) {
if (context._id_dict.hasOwnProperty(id)) {
result.push({id: id});
}
}
return result;
};
Fs2Erp5Storage.prototype.repair = function () {
// Transform id attachment ( file path ) to id list / attachments
var context = this;
return context._sub_storage.repair()
.push(function () {
return jIO.util.ajax({
type: "GET",
dataType: "json",
url: context._document + "erp5_/erp5.json"
});
})
.push(function (response) {
var scopes, i, x, scope;
context._options = response.target.response;
scopes = context._options.scopes;
for (i = 0; i < scopes.length; i += 1) {
scope = scopes[i];
for (x = 0; x < scope.paths.length; x += 1) {
context._paths[scope.paths[x]] = scope;
}
}
})
.push(function () {
return context._sub_storage.allAttachments(context._document);
})
.push(function (result) {
var id, path, last_index, filename, filename_xml, ext, new_id, i;
for (id in result) {
if (result.hasOwnProperty(id) && !id.startsWith("http")) {
last_index = id.lastIndexOf("/") + 1;
if (last_index === id.length) {
path = id || "/";
filename = "index.html";
} else {
path = id.substring(0, last_index);
filename = id.substring(last_index);
}
new_id = path + filename;
ext = filename.substring(filename.lastIndexOf('.') + 1);
switch (ext) {
case "js":
path = "/PathTemplateItem/web_page_module/";
break;
case "ttf":
path = "/PathTemplateItem/document_module/";
ext = "bin";
break;
default:
continue;
}
for (i in context._paths) {
if (new_id.startsWith(i)) {
if (context._paths[i].prefix) {
new_id = context._paths[i].prefix + "/" + new_id;
}
}
}
filename = new_id.split("/").join("_").split(".").join("_") + '.' + ext;
filename_xml = new_id.split("/").join("_").split(".").join("_") + '.xml';
if (!context._id_dict.hasOwnProperty(path)) {
context._id_dict[path] = {};
}
context._id_dict[path][filename] = id;
context._id_dict[path][filename_xml] = id;
}
}
});
};
jIO.addStorage('fs2erp5', Fs2Erp5Storage);
}(window, jIO, RSVP, console, Blob));
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment