Commit a33463cb authored by Vincent Bechu's avatar Vincent Bechu

erp5_officejs: update export site to have full application in one zip

parent 51fca8cf
...@@ -12,19 +12,20 @@ ...@@ -12,19 +12,20 @@
((spec.version !== undefined) ? ((spec.version !== undefined) ?
(spec.version + (spec.version.endsWith('/') ? '' : '/')) : "")); (spec.version + (spec.version.endsWith('/') ? '' : '/')) : ""));
this._relative_url_list = [this._origin_url, spec.manifest]; this._relative_url_list = [this._origin_url, spec.manifest];
this._prefix = spec.prefix;
if (this._take_installer) { if (this._take_installer) {
this._relative_url_list = [ this._relative_url_list = [
this._origin_url, this._prefix || "/",
"development/" + spec.manifest, this._prefix + "development/" + spec.manifest,
this._origin_url + "development/", this._prefix + "development/",
"gadget_officejs_bootloader.js", this._prefix + "gadget_officejs_bootloader.js",
"gadget_officejs_bootloader.appcache", this._prefix + "gadget_officejs_bootloader.appcache",
"gadget_officejs_bootloader_presentation.html", this._prefix + "gadget_officejs_bootloader_presentation.html",
"gadget_officejs_bootloader_presentation.js", this._prefix + "gadget_officejs_bootloader_presentation.js",
"gadget_officejs_bootloader_presentation.css", this._prefix + "gadget_officejs_bootloader_presentation.css",
"gadget_officejs_bootloader_serviceworker.js", this._prefix + "gadget_officejs_bootloader_serviceworker.js",
"gadget_erp5_nojqm.css", this._prefix + "gadget_erp5_nojqm.css",
"jio_appcachestorage.js" this._prefix + "jio_appcachestorage.js"
]; ];
} }
} }
...@@ -67,7 +68,7 @@ ...@@ -67,7 +68,7 @@
AppCacheStorage.prototype.repair = function () { AppCacheStorage.prototype.repair = function () {
var storage = this, var storage = this,
prefix = storage._take_installer ? "development/" : ""; prefix = storage._take_installer ? this._prefix + "development/" : "";
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
......
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.64585.2539.29713</string> </value> <value> <string>959.27850.19778.42888</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1493380404.6</float> <float>1495022155.16</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -32,14 +32,19 @@ ...@@ -32,14 +32,19 @@
<form class="export-form"> <form class="export-form">
<div class="ui-form"> <div class="ui-form">
<div class="ui-field-contain"> <div class="ui-field-contain">
<label data-i18n="Cache File:">Cache File:</label> <label data-i18n="Site:">Site:</label>
<input name="cachefile" required/> <select name="web_site">
</div> <option>Text Editor</option>
</div> <option>Illustration Editor</option>
<div class="ui-form"> <option>PDF Viewer</option>
<div class="ui-field-contain"> <option>Cribjs</option>
<label data-i18n="Site Url:">Site Url:</label> <option>Bookmark Manager</option>
<input name="site_url" required/> <option>Onlyoffice Text</option>
<option>Onlyoffice Spreadsheet</option>
<option>Onlyoffice Presentation</option>
<option>Web Table Editor</option>
<option>Image Editor</option>
</select>
</div> </div>
</div> </div>
<div class="ui-form"> <div class="ui-form">
......
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.33099.10317.11264</string> </value> <value> <string>959.28004.53691.26077</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1491491237.19</float> <float>1495031755.24</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*globals window, RSVP, rJS, loopEventListener, URL, document /*globals window, RSVP, rJS, loopEventListener, URL, document
FileReader, console */ FileReader, console */
/*jslint indent: 2, nomen: true, maxlen: 80*/ /*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, jIO) { (function (window, RSVP, rJS, jIO, URL) {
"use strict"; "use strict";
function exportZip(gadget) { var origin_url = (window.location.origin + window.location.pathname).replace(
var cache_file = gadget.props.element.querySelector( "officejs_export/", ""),
'form input[name="cachefile"]').value, application_dict = {
site_url = gadget.props.element.querySelector( "Text Editor": {
'form input[name="site_url"]').value; "url": "officejs_text_editor/",
return gadget.exportZip(cache_file, site_url) "cache": "gadget_officejs_text_editor.appcache",
"sub_gadget": ["officejs_ckeditor_gadget", "officejs_setting_gadget"]
},
"Illustration Editor": {
"url": "officejs_svg_editor/",
"cache": "gadget_officejs_illustration.appcache",
"sub_gadget": ["officejs_svg_editor_gadget", "officejs_setting_gadget"]
},
"PDF Viewer": {
"url": "officejs_pdf_viewer/",
"cache": "gadget_officejs_pdf_viewer.appcache",
"sub_gadget": ["officejs_pdf_viewer_gadget", "officejs_setting_gadget"]
},
"Cribjs": {
"url": "officejs_cribjs/",
"cache": "gadget_officejs_crib.appcache",
"sub_gadget": ["officejs_codemirror", "officejs_setting_gadget"]
},
"Bookmark Manager": {
"url": "officejs_bookmark_manager/",
"cache" : "gadget_officejs_bookmark_manager.appcache",
"sub_gadget": []
},
"Onlyoffice Text": {
"url": "ooffice_text/",
"cache": "gadget_ooffice_text.appcache",
"sub_gadget": ["ooffice_text_gadget", "officejs_setting_gadget"]
},
"Onlyoffice Spreadsheet": {
"url": "ooffice_spreadsheet/",
"cache": "gadget_ooffice_spreadsheet.appcache",
"sub_gadget": ["ooffice_spreadsheet_gadget", "officejs_setting_gadget"]
},
"Onlyoffice Presentation": {
"url": "ooffice_presentation/",
"cache": "gadget_ooffice_presentation.appcache",
"sub_gadget": ["ooffice_presentation_gadget", "officejs_setting_gadget"]
},
"Web Table Editor": {
"url": "officejs_web_table_editor/",
"cache": "gadget_officejs_web_table.appcache",
"sub_gadget": [
"officejs_web_table_editor_gadget",
"officejs_setting_gadget"
]
},
"Image Editor": {
"url": "officejs_image_editor/",
"cache": "gadget_officejs_image_editor.appcache",
"sub_gadget": [
"officejs_image_editor_gadget",
"officejs_setting_gadget"
]
},
"officejs_ckeditor_gadget": {
"cache": "gadget_ckeditor.appcache"
},
"officejs_setting_gadget": {
"cache": "gadget_officejs_setting.appcache"
},
"officejs_svg_editor_gadget": {
"cache": "gadget_officejs_svg_editor.appcache"
},
"officejs_pdf_viewer_gadget": {
"cache": "gadget_officejs_pdf_viewer_gadget.appcache"
},
"officejs_codemirror": {
"cache": "gadget_officejs_codemirror.appcache"
},
"ooffice_text_gadget": {
"cache": "gadget_ooffice_text_gadget.appcache"
},
"ooffice_spreadsheet_gadget": {
"cache": "gadget_ooffice_spreadsheet_gadget.appcache"
},
"ooffice_presentation_gadget": {
"cache": "gadget_ooffice_presentation_gadget.appcache"
},
"officejs_web_table_editor_gadget": {
"cache": "gadget_officejs_web_table_editor.appcache"
},
"officejs_image_editor_gadget": {
"cache": "gadget_officejs_image_editor_gadget.appcache"
}
};
function exportZip(gadget, event) {
var j,
zip_name,
i = 0,
form_result = {},
len = event.target.length,
app;
for (j = 0; j < len; j += 1) {
form_result[event.target[j].name] = event.target[j].value;
}
app = application_dict[form_result.web_site];
zip_name = form_result.filename;
len = app.sub_gadget.length;
function fill(zip_file) {
if (i < len) {
var sub_app = app.sub_gadget[i];
return gadget.fillZip(
application_dict[sub_app].cache,
origin_url + app.url,
zip_file,
sub_app + "/"
)
.push(function (zip_file) {
i += 1;
return fill(zip_file);
});
}
return zip_file;
}
return gadget.fillZip(app.cache, origin_url + app.url)
.push(function (zip_file) {
return fill(zip_file);
})
.push(function (zip_file) { .push(function (zip_file) {
var element = gadget.props.element, var element = gadget.props.element,
a = document.createElement("a"), a = document.createElement("a"),
url = URL.createObjectURL(zip_file), url = URL.createObjectURL(zip_file);
zip_name = gadget.props.element.querySelector(
'form input[name="filename"]').value || "source_code";
element.appendChild(a); element.appendChild(a);
a.style = "display: none"; a.style = "display: none";
a.href = url; a.href = url;
...@@ -34,12 +152,12 @@ ...@@ -34,12 +152,12 @@
g.props.element = element; g.props.element = element;
}); });
}) })
.declareMethod("exportZip", function (cache_file, site_url) { .declareMethod("fillZip", function (cache_file, site_url, zip_file,
prefix) {
var gadget = this, var gadget = this,
file_storage = jIO.createJIO({ file_storage = jIO.createJIO({
type: "replicate", type: "replicate",
parallel_operation_attachment_amount: 400, conflict_handling: 2,
parallel_operation_amount: 400,
check_remote_attachment_creation: true, check_remote_attachment_creation: true,
check_local_creation: false, check_local_creation: false,
check_local_modification: false, check_local_modification: false,
...@@ -53,14 +171,16 @@ ...@@ -53,14 +171,16 @@
type: "appcache", type: "appcache",
take_installer: true, take_installer: true,
manifest: cache_file, manifest: cache_file,
origin_url: site_url origin_url: site_url,
prefix: prefix || ""
} }
}, },
signature_storage: { signature_storage: {
type: "memory" type: "memory"
}, },
local_sub_storage: { local_sub_storage: {
type: "zipfile" type: "zipfile",
file: zip_file
} }
}); });
return file_storage.repair() return file_storage.repair()
...@@ -81,10 +201,10 @@ ...@@ -81,10 +201,10 @@
'submit', 'submit',
true, true,
function (event) { function (event) {
return exportZip(gadget); return exportZip(gadget, event);
} }
); );
}); });
}); });
}(window, RSVP, rJS, jIO)); }(window, RSVP, rJS, jIO, URL));
\ No newline at end of file \ No newline at end of file
...@@ -227,7 +227,7 @@ ...@@ -227,7 +227,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.64457.39610.60262</string> </value> <value> <string>959.28011.47989.42752</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1493379956.25</float> <float>1495097433.8</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
function FileSystemStorage(spec) { function FileSystemStorage(spec) {
this._document = spec.document; this._document = spec.document;
this._sub_storage = jIO.createJIO(spec.sub_storage); this._sub_storage = jIO.createJIO(spec.sub_storage);
this._id_dict = { this._id_dict = {};
"/": {"index.html": {}},
"/development/": {"index.html": {}}
};
} }
FileSystemStorage.prototype.get = function (url) { FileSystemStorage.prototype.get = function (url) {
...@@ -23,9 +20,8 @@ ...@@ -23,9 +20,8 @@
FileSystemStorage.prototype.getAttachment = function (doc_id, attachment_id) { FileSystemStorage.prototype.getAttachment = function (doc_id, attachment_id) {
return this._sub_storage.getAttachment( return this._sub_storage.getAttachment(
this._document, this._document,
(attachment_id === "index.html") ? ((doc_id === "/") ? doc_id + ((attachment_id === "index.html") ?
"/" : "development/") : ((doc_id === "/") ? (doc_id.endsWith("imagelib/") ? "index.html" : "") : attachment_id)
attachment_id : doc_id + attachment_id)
); );
}; };
...@@ -51,19 +47,19 @@ ...@@ -51,19 +47,19 @@
return context._sub_storage.allAttachments(context._document); return context._sub_storage.allAttachments(context._document);
}) })
.push(function (result) { .push(function (result) {
var id, path, last_slash_index, filename; var id, path, last_index, filename;
for (id in result) { for (id in result) {
if (result.hasOwnProperty(id)) { if (result.hasOwnProperty(id)) {
last_slash_index = id.lastIndexOf("/") + 1; last_index = id.lastIndexOf("/") + 1;
if (last_slash_index === 0) { if (last_index === id.length) {
path = "/"; path = id || "/";
filename = id; filename = "index.html";
} else { } else {
path = id.substring(0, last_slash_index); path = id.substring(0, last_index);
filename = id.substring(last_slash_index); filename = id.substring(last_index);
} }
} }
if (!path.startsWith("http") && id !== "/") { if (!id.includes("http")) {
if (path.charAt(0) !== '/') { if (path.charAt(0) !== '/') {
path = '/' + path; path = '/' + path;
} }
......
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.64589.19815.17083</string> </value> <value> <string>959.27838.40575.32000</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1493382071.89</float> <float>1495033483.29</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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