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 @@ ...@@ -65,6 +65,7 @@
<string>gadget_field_action_js_script</string> <string>gadget_field_action_js_script</string>
<string>action_description</string> <string>action_description</string>
<string>my_include_content</string> <string>my_include_content</string>
<string>my_zip_exported</string>
</list> </list>
</value> </value>
</item> </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 @@ ...@@ -74,7 +74,7 @@
return put_queue; return put_queue;
}) })
.declareMethod("exportIndex", function (index_doc, include_content) { .declareMethod("exportIndex", function (index_doc, include_content, zip) {
var gadget = this, var gadget = this,
ids, ids,
map, map,
...@@ -121,6 +121,11 @@ ...@@ -121,6 +121,11 @@
page: result 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 = new JSZip();
zip_file.file(index_id + ".json", JSON.stringify(file_dict)); zip_file.file(index_id + ".json", JSON.stringify(file_dict));
zip_file.generateAsync({ zip_file.generateAsync({
...@@ -159,23 +164,41 @@ ...@@ -159,23 +164,41 @@
return jIO.util.dataURItoBlob(dataurl); return jIO.util.dataURItoBlob(dataurl);
}) })
.push(function (data) { .push(function (data) {
var zip = new JSZip(); var zip;
return zip.loadAsync(data) if (data.type === "application/zip") {
.then(function(data){ zip = new JSZip();
return zip.file(Object.keys(data.files)[0]).async("string"); return zip.loadAsync(data)
}) .then(function(data){
.then(function(data){ return zip.file(Object.keys(data.files)[0]).async("string");
index_dict = JSON.parse(data); })
//console.log(data); .then(function(data){
doc.title = index_dict.name; index_dict = JSON.parse(data);
doc.links = index_dict.links; doc.title = index_dict.name;
doc.status = "built"; doc.links = index_dict.links;
index_id = "index-" + doc.title; doc.status = "built";
return gadget.state.model_gadget.pushIndexBlob( index_id = "index-" + doc.title;
index_id, return gadget.state.model_gadget.pushIndexBlob(
index_dict, 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 () { .push(function () {
return gadget.putIndexPage(index_dict.page); return gadget.putIndexPage(index_dict.page);
...@@ -325,7 +348,8 @@ ...@@ -325,7 +348,8 @@
redirect: redirect 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 () { .push(function () {
return { return {
notify: { notify: {
......
...@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_** ...@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_**
web_page_module/gadget_erp5_page_mynij_** web_page_module/gadget_erp5_page_mynij_**
web_page_module/gadget_mynij_** web_page_module/gadget_mynij_**
web_page_module/gadget_officejs_mynij_** web_page_module/gadget_officejs_mynij_**
web_page_module/jszip_min_js
web_page_module/mynij-** web_page_module/mynij-**
web_page_module/mynij_** web_page_module/mynij_**
web_page_module/rss-parser.min.js.map web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js web_page_module/webtorrent_min_js
web_site_module/mynij_search web_site_module/mynij_search
web_site_module/mynij_search/** web_site_module/mynij_search/**
web_page_module/jszip_min_js \ No newline at end of file
\ No newline at end of file
...@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_** ...@@ -4,10 +4,10 @@ web_page_module/gadget_erp5_mynij_**
web_page_module/gadget_erp5_page_mynij_** web_page_module/gadget_erp5_page_mynij_**
web_page_module/gadget_mynij_** web_page_module/gadget_mynij_**
web_page_module/gadget_officejs_mynij_** web_page_module/gadget_officejs_mynij_**
web_page_module/jszip_min_js
web_page_module/mynij-** web_page_module/mynij-**
web_page_module/mynij_** web_page_module/mynij_**
web_page_module/rss-parser.min.js.map web_page_module/rss-parser.min.js.map
web_page_module/webtorrent_min_js web_page_module/webtorrent_min_js
web_site_module/mynij_search web_site_module/mynij_search
web_site_module/mynij_search/** web_site_module/mynij_search/**
web_page_module/jszip_min_js \ No newline at end of file
\ 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