Commit c8c19219 authored by Vincent Bechu's avatar Vincent Bechu

erp5_officejs: add web site officejs_export prototype

parent 2e82312a
......@@ -5,13 +5,15 @@
function AppCacheStorage(spec) {
this._manifest = spec.manifest;
this._url = window.location.origin + window.location.pathname +
this._origin_url = spec.origin_url !== undefined ? spec.origin_url :
(window.location.origin + window.location.pathname +
(window.location.pathname.endsWith('/') ? '' : '/') +
spec.version + (spec.version.endsWith('/') ? '' : '/');
this._url_list = ["/"];
((spec.version !== undefined) ?
(spec.version + (spec.version.endsWith('/') ? '' : '/')) : ""));
this._relative_url_list = [this._origin_url, spec.manifest];
}
AppCacheStorage.prototype.get = function (url) {
AppCacheStorage.prototype.get = function (id) {
return {};
};
......@@ -21,74 +23,64 @@
AppCacheStorage.prototype.getAttachment = function (doc_id, attachment_id) {
var storage = this, url = attachment_id;
if (this._url === doc_id) {
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: (url.startsWith("http") || url.startsWith("//")) ?
url : storage._url + url,
dataType: "blob"
});
})
.push(function (result) {
return result.target.response;
})
.push(undefined, function (error) {
if (error.target.status === 404) {
throw new jIO.util.jIOError("Can't find attachment: " + url, 404);
}
throw error;
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"
});
}
throw new jIO.util.jIOError("Can not find " + doc_id, 404);
})
.push(function (result) {
return result.target.response;
});
};
AppCacheStorage.prototype.allAttachments = function (url) {
var result = {}, i, len = this._url_list.length;
var result = {}, i, len = this._relative_url_list.length;
for (i = 0; i < len; i += 1) {
result[this._url_list[i]] = {};
result[this._relative_url_list[i]] = {};
}
return result;
};
AppCacheStorage.prototype.buildQuery = function (options) {
return [{id: this._url, doc: {}, value: {}}];
return [{id: "/", doc: {}, value: {}}];
};
AppCacheStorage.prototype.repair = function () {
var storage = this;
console.log("start getting cache");
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: storage._url + storage._manifest
url: storage._origin_url + storage._manifest
});
})
.push(function (response) {
var text = response.target.responseText,
url_list = text.split('\r\n'),
relative_url_list = text.split('\r\n'),
i,
take = false;
if (url_list.length === 1) {
url_list = text.split('\n');
if (relative_url_list.length === 1) {
relative_url_list = text.split('\n');
}
if (url_list.length === 1) {
url_list = text.split('\r');
if (relative_url_list.length === 1) {
relative_url_list = text.split('\r');
}
for (i = 0; i < url_list.length; i += 1) {
if (url_list[i].indexOf("NETWORK:") >= 0) {
for (i = 0; i < relative_url_list.length; i += 1) {
if (relative_url_list[i].indexOf("NETWORK:") >= 0) {
take = false;
}
if (take &&
url_list[i] !== "" &&
url_list[i].charAt(0) !== '#' &&
url_list[i].charAt(0) !== ' ') {
url_list[i].replace("\r", "");
storage._url_list.push(url_list[i]);
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(relative_url_list[i]);
}
if (url_list[i].indexOf("CACHE:") >= 0) {
if (relative_url_list[i].indexOf("CACHE:") >= 0) {
take = true;
}
}
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>958.24259.25538.21094</string> </value>
<value> <string>958.41792.31362.1314</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1491383378.56</float>
<float>1492082677.03</float>
<string>UTC</string>
</tuple>
</state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Export Page</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_export.js"></script>
<script src="zipfilestorage-with-jszip.js"></script>
<script src="jio_filesystemstorage.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="Cache File:">Cache File:</label>
<input name="cachefile" required/>
</div>
</div>
<div class="ui-form">
<div class="ui-field-contain">
<label data-i18n="Site Url:">Site Url:</label>
<input name="site_url" required/>
</div>
</div>
<div class="ui-form">
<div class="ui-field-contain">
<label data-i18n="Storage format for Export:">Storage format for export:</label>
<select name="storage_type">
<option value="zipfile">Export as zipfile</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
/*globals window, RSVP, rJS, loopEventListener, URL, document
FileReader, console */
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, jIO) {
"use strict";
function exportZip(gadget) {
var cache_file = gadget.props.element.querySelector(
'form input[name="cachefile"]').value,
site_url = gadget.props.element.querySelector(
'form input[name="site_url"]').value;
return gadget.exportZip(cache_file, site_url)
.push(function (zip_file) {
var element = gadget.props.element,
a = document.createElement("a"),
url = URL.createObjectURL(zip_file),
zip_name = gadget.props.element.querySelector(
'form input[name="filename"]').value || "source_code";
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = zip_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("exportZip", function (cache_file, site_url) {
var gadget = this,
file_storage = jIO.createJIO({
type: "replicate",
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: "filesystem",
document: site_url,
sub_storage: {
type: "appcache",
manifest: cache_file,
url: site_url
}
},
signature_storage: {
type: "memory"
},
local_sub_storage: {
type: "zipfile"
}
});
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);
}
);
});
});
}(window, RSVP, rJS, jIO));
\ 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 FileSystemStorage(spec) {
this._document = spec.document;
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._id_dict = {"/": {"index.html": {}}};
}
FileSystemStorage.prototype.get = function (url) {
return {};
};
FileSystemStorage.prototype.hasCapacity = function (name) {
return (name === "list");
};
FileSystemStorage.prototype.getAttachment = function (doc_id, attachment_id) {
return this._sub_storage.getAttachment(
this._document,
(attachment_id === "index.html") ?
"/" : (doc_id === "/") ?
attachment_id : doc_id + attachment_id
);
};
FileSystemStorage.prototype.allAttachments = function (doc_id) {
return this._id_dict[doc_id] || {};
};
FileSystemStorage.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;
};
FileSystemStorage.prototype.repair = function () {
// Transform id attachment ( file path ) to id list / attachments
var context = this;
return context._sub_storage.repair()
.push(function () {
return context._sub_storage.allAttachments(context._document);
})
.push(function (result) {
var id, path, last_slash_index, filename;
for (id in result) {
if (result.hasOwnProperty(id)) {
last_slash_index = id.lastIndexOf("/") + 1;
if (last_slash_index === 0) {
path = "/";
filename = id;
} else {
path = id.substring(0, last_slash_index);
filename = id.substring(last_slash_index);
}
}
if (!path.startsWith("http") && id !== "/") {
if (path.charAt(0) !== '/') {
path = '/' + path;
}
if (!context._id_dict.hasOwnProperty(path)) {
context._id_dict[path] = {};
} else {
context._id_dict[path][filename] = {};
}
}
}
});
};
jIO.addStorage('filesystem', FileSystemStorage);
}(window, jIO, RSVP, console, Blob));
\ No newline at end of file
......@@ -2,7 +2,7 @@ web_page_module/ckeditor_*
image_module/ckeditor_*
web_page_module/gadget_ckeditor_*
web_page_module/gadget_officejs_*
web_page_module/jio_mappingstorage_js
web_page_module/jio_*
web_site_module/officejs_bookmark_manager
web_site_module/officejs_bookmark_manager/**
web_site_module/officejs_text_editor
......@@ -21,4 +21,5 @@ web_site_module/officejs_codemirror
web_site_module/officejs_codemirror/**
web_site_module/officejs_cribjs
web_site_module/officejs_cribjs/**
web_site_module/officejs_whiteboard
\ No newline at end of file
web_site_module/officejs_whiteboard
web_site_module/officejs_export
\ No newline at end of file
......@@ -2,7 +2,7 @@ web_page_module/ckeditor_*
image_module/ckeditor_*
web_page_module/gadget_ckeditor_*
web_page_module/gadget_officejs_*
web_page_module/jio_mappingstorage_js
web_page_module/jio_*
web_site_module/officejs_bookmark_manager
web_site_module/officejs_bookmark_manager/**
web_site_module/officejs_text_editor
......@@ -21,4 +21,5 @@ web_site_module/officejs_codemirror
web_site_module/officejs_codemirror/**
web_site_module/officejs_cribjs
web_site_module/officejs_cribjs/**
web_site_module/officejs_whiteboard
\ No newline at end of file
web_site_module/officejs_whiteboard
web_site_module/officejs_export
\ No newline at end of file
......@@ -2,7 +2,7 @@ image_module/ckeditor_*
web_page_module/ckeditor_*
web_page_module/gadget_ckeditor_*
web_page_module/gadget_officejs_*
web_page_module/jio_mappingstorage_js
web_page_module/jio_*
web_site_module/officejs_bookmark_manager
web_site_module/officejs_bookmark_manager/**
web_site_module/officejs_ckeditor_gadget
......@@ -11,6 +11,7 @@ web_site_module/officejs_codemirror
web_site_module/officejs_codemirror/**
web_site_module/officejs_cribjs
web_site_module/officejs_cribjs/**
web_site_module/officejs_export
web_site_module/officejs_pdf_viewer
web_site_module/officejs_pdf_viewer/**
web_site_module/officejs_pdf_viewer_gadget
......
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