Commit 3c35e24e authored by Vincent Bechu's avatar Vincent Bechu

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

parent 60b28416
......@@ -12,19 +12,20 @@
((spec.version !== undefined) ?
(spec.version + (spec.version.endsWith('/') ? '' : '/')) : ""));
this._relative_url_list = [this._origin_url, spec.manifest];
this._prefix = spec.prefix;
if (this._take_installer) {
this._relative_url_list = [
this._origin_url,
"development/" + spec.manifest,
this._origin_url + "development/",
"gadget_officejs_bootloader.js",
"gadget_officejs_bootloader.appcache",
"gadget_officejs_bootloader_presentation.html",
"gadget_officejs_bootloader_presentation.js",
"gadget_officejs_bootloader_presentation.css",
"gadget_officejs_bootloader_serviceworker.js",
"gadget_erp5_nojqm.css",
"jio_appcachestorage.js"
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"
];
}
}
......@@ -67,7 +68,7 @@
AppCacheStorage.prototype.repair = function () {
var storage = this,
prefix = storage._take_installer ? "development/" : "";
prefix = storage._take_installer ? this._prefix + "development/" : "";
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>958.64585.2539.29713</string> </value>
<value> <string>959.27850.19778.42888</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1493380404.6</float>
<float>1495022155.16</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -32,14 +32,19 @@
<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/>
<label data-i18n="Site:">Site:</label>
<select name="web_site">
<option>Text Editor</option>
<option>Illustration Editor</option>
<option>PDF Viewer</option>
<option>Cribjs</option>
<option>Bookmark Manager</option>
<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 class="ui-form">
......
......@@ -231,7 +231,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>958.33099.10317.11264</string> </value>
<value> <string>959.28004.53691.26077</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -249,7 +249,7 @@
</tuple>
<state>
<tuple>
<float>1491491237.19</float>
<float>1495031755.24</float>
<string>UTC</string>
</tuple>
</state>
......
/*globals window, RSVP, rJS, loopEventListener, URL, document
FileReader, console */
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, jIO) {
(function (window, RSVP, rJS, jIO, URL) {
"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)
var origin_url = (window.location.origin + window.location.pathname).replace(
"officejs_export/", ""),
application_dict = {
"Text Editor": {
"url": "officejs_text_editor/",
"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) {
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";
url = URL.createObjectURL(zip_file);
element.appendChild(a);
a.style = "display: none";
a.href = url;
......@@ -34,12 +152,12 @@
g.props.element = element;
});
})
.declareMethod("exportZip", function (cache_file, site_url) {
.declareMethod("fillZip", function (cache_file, site_url, zip_file,
prefix) {
var gadget = this,
file_storage = jIO.createJIO({
type: "replicate",
parallel_operation_attachment_amount: 400,
parallel_operation_amount: 400,
conflict_handling: 2,
check_remote_attachment_creation: true,
check_local_creation: false,
check_local_modification: false,
......@@ -53,14 +171,16 @@
type: "appcache",
take_installer: true,
manifest: cache_file,
origin_url: site_url
origin_url: site_url,
prefix: prefix || ""
}
},
signature_storage: {
type: "memory"
},
local_sub_storage: {
type: "zipfile"
type: "zipfile",
file: zip_file
}
});
return file_storage.repair()
......@@ -81,10 +201,10 @@
'submit',
true,
function (event) {
return exportZip(gadget);
return exportZip(gadget, event);
}
);
});
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
}(window, RSVP, rJS, jIO, URL));
\ No newline at end of file
......@@ -227,7 +227,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>958.64457.39610.60262</string> </value>
<value> <string>959.28011.47989.42752</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -245,7 +245,7 @@
</tuple>
<state>
<tuple>
<float>1493379956.25</float>
<float>1495097433.8</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -6,10 +6,7 @@
function FileSystemStorage(spec) {
this._document = spec.document;
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._id_dict = {
"/": {"index.html": {}},
"/development/": {"index.html": {}}
};
this._id_dict = {};
}
FileSystemStorage.prototype.get = function (url) {
......@@ -23,9 +20,8 @@
FileSystemStorage.prototype.getAttachment = function (doc_id, attachment_id) {
return this._sub_storage.getAttachment(
this._document,
(attachment_id === "index.html") ? ((doc_id === "/") ?
"/" : "development/") : ((doc_id === "/") ?
attachment_id : doc_id + attachment_id)
doc_id + ((attachment_id === "index.html") ?
(doc_id.endsWith("imagelib/") ? "index.html" : "") : attachment_id)
);
};
......@@ -51,19 +47,19 @@
return context._sub_storage.allAttachments(context._document);
})
.push(function (result) {
var id, path, last_slash_index, filename;
var id, path, last_index, filename;
for (id in result) {
if (result.hasOwnProperty(id)) {
last_slash_index = id.lastIndexOf("/") + 1;
if (last_slash_index === 0) {
path = "/";
filename = id;
last_index = id.lastIndexOf("/") + 1;
if (last_index === id.length) {
path = id || "/";
filename = "index.html";
} else {
path = id.substring(0, last_slash_index);
filename = id.substring(last_slash_index);
path = id.substring(0, last_index);
filename = id.substring(last_index);
}
}
if (!path.startsWith("http") && id !== "/") {
if (!id.includes("http")) {
if (path.charAt(0) !== '/') {
path = '/' + path;
}
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>958.64589.19815.17083</string> </value>
<value> <string>959.27838.40575.32000</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1493382071.89</float>
<float>1495033483.29</float>
<string>UTC</string>
</tuple>
</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