Commit 8fc8f5c6 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Allow to import/export non zipped JSON index file

parent fdec656c
......@@ -65,6 +65,7 @@
<string>gadget_field_action_js_script</string>
<string>action_description</string>
<string>my_include_content</string>
<string>my_zip_exported</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="CheckBoxField" module="Products.Formulator.StandardFields"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_zip_exported</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>This field is mandatory.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Zip index (can take longer)</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -74,7 +74,7 @@
return put_queue;
})
.declareMethod("exportIndex", function (index_doc, include_content) {
.declareMethod("exportIndex", function (index_doc, include_content, zip) {
var gadget = this,
ids,
map,
......@@ -121,6 +121,11 @@
page: result
};
if (!zip) {
file_blob = new Blob([JSON.stringify(file_dict)], {type : "application/json"});
return gadget.downloadBlob(index_id + ".json", file_blob);
}
zip_file = new JSZip();
zip_file.file(index_id + ".json", JSON.stringify(file_dict));
zip_file.generateAsync({
......@@ -159,23 +164,41 @@
return jIO.util.dataURItoBlob(dataurl);
})
.push(function (data) {
var zip = new JSZip();
return zip.loadAsync(data)
.then(function(data){
return zip.file(Object.keys(data.files)[0]).async("string");
})
.then(function(data){
index_dict = JSON.parse(data);
//console.log(data);
doc.title = index_dict.name;
doc.links = index_dict.links;
doc.status = "built";
index_id = "index-" + doc.title;
return gadget.state.model_gadget.pushIndexBlob(
index_id,
index_dict,
{});
var zip;
if (data.type === "application/zip") {
zip = new JSZip();
return zip.loadAsync(data)
.then(function(data){
return zip.file(Object.keys(data.files)[0]).async("string");
})
.then(function(data){
index_dict = JSON.parse(data);
doc.title = index_dict.name;
doc.links = index_dict.links;
doc.status = "built";
index_id = "index-" + doc.title;
return gadget.state.model_gadget.pushIndexBlob(
index_id,
index_dict,
{});
});
} else if (data.type === "application/json") {
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(data, "application/json");
})
.push(function (evt) {
index_dict = JSON.parse(evt.target.result);
doc.title = index_dict.name;
doc.links = index_dict.links;
doc.status = "built";
index_id = "index-" + doc.title;
return gadget.state.model_gadget.pushIndexBlob(
index_id,
index_dict,
{});
});
}
})
.push(function () {
return gadget.putIndexPage(index_dict.page);
......@@ -325,7 +348,8 @@
redirect: redirect
};
}
return gadget.exportIndex(index, content_dict.include_content === "on")
return gadget.exportIndex(index, content_dict.include_content === "on",
content_dict.zip_exported === "on")
.push(function () {
return {
notify: {
......
......@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_**
web_page_module/gadget_erp5_page_mynij_**
web_page_module/gadget_mynij_**
web_page_module/gadget_officejs_mynij_**
web_page_module/jszip_min_js
web_page_module/mynij-**
web_page_module/mynij_**
web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js
web_site_module/mynij_search
web_site_module/mynij_search/**
web_page_module/jszip_min_js
\ No newline at end of file
web_site_module/mynij_search/**
\ No newline at end of file
......@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_**
web_page_module/gadget_erp5_page_mynij_**
web_page_module/gadget_mynij_**
web_page_module/gadget_officejs_mynij_**
web_page_module/jszip_min_js
web_page_module/mynij-**
web_page_module/mynij_**
web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js
web_site_module/mynij_search
web_site_module/mynij_search/**
web_page_module/jszip_min_js
\ No newline at end of file
web_site_module/mynij_search/**
\ No newline at end of file
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