Commit e98efa7e authored by Lu Xu's avatar Lu Xu :eyes:

erp5_officejs: Web share target API applying to smart assistant

parent 52e51c21
/*jslint indent: 2*/
/*global self, fetch, Request, Response */
/*global self, fetch, Request, Response, URL, Blob */
var global = self, window = self;
(function (self, fetch, Request, Response) {
(function (self, fetch, Response, Blob) {
"use strict";
self.DOMParser = {};
......@@ -52,7 +52,8 @@ var global = self, window = self;
self.addEventListener("fetch", function (event) {
var relative_url = './' + event.request.url.split("#")[0]
.replace(self.registration.scope, "")
.replace(self.version_url, "");
.replace(self.version_url, ""),
tmp;
if (relative_url === './no-cache') {
event.respondWith(new Response(self.cache_list));
return;
......@@ -80,6 +81,42 @@ var global = self, window = self;
return new Response(error, {"statusText": error.message, "status": 500});
})
);
} else if (
// postData from manifest.json
event.request.method === 'POST' &&
relative_url.split('?')[0].endsWith('postData')
) {
self.request = event.request;
event.respondWith(Response.redirect('.'));
} else if (
// Determine if it hasSharedData
event.request.url.endsWith('hasSharedData')
) {
event.respondWith(new Response(self.request ? "true" : "false"));
} else if (
// getSharedData from upload_shared_file page
// upload_shared_file page processes the data
event.request.url.endsWith('getSharedData') &&
event.request.method === 'GET'
) {
if (!self.request) {
event.respondWith(new Response(''));
} else {
tmp = self.request;
delete self.request;
event.respondWith(
new self.RSVP.Queue()
.push(function () {
return tmp.formData();
})
.push(function (data) {
return data.get('file');
})
.push(function (file) {
return new Response(new Blob([file], {type: file.type}));
})
);
}
} else {
event.respondWith(
new self.RSVP.Queue()
......@@ -101,4 +138,4 @@ var global = self, window = self;
}
});
}(self, fetch, Request, Response));
\ No newline at end of file
}(self, fetch, Response, Blob));
\ No newline at end of file
......@@ -223,7 +223,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>P0</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -237,7 +237,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.27647.29835.22169</string> </value>
<value> <string>986.49641.0.58982</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -255,7 +255,7 @@
</tuple>
<state>
<tuple>
<float>1533640296.2</float>
<float>1600683471.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,6 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="gadget_officejs_smart_assistant.css">
<link rel="manifest" href="gadget_officejs_json_manifest_smart_assistant.json">
<title>OfficeJS Smart Assistant Home</title>
......
......@@ -278,7 +278,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.64140.28065.34372</string> </value>
<value> <string>981.3464.44902.45755</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -296,7 +296,7 @@
</tuple>
<state>
<tuple>
<float>1574460415.05</float>
<float>1578607727.59</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, Handlebars, RSVP, Blob, SimpleQuery, ComplexQuery, Query*/
/*global window, rJS, jIO, navigator, Handlebars, RSVP, Blob, SimpleQuery, ComplexQuery, Query*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, rJS, jIO, RSVP, SimpleQuery, ComplexQuery, Query) {
(function (window, rJS, jIO, navigator,
RSVP, SimpleQuery, ComplexQuery, Query) {
"use strict";
rJS(window)
......@@ -46,10 +47,6 @@
type: "DateTimeField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
}
return result;
......@@ -67,7 +64,7 @@
portal_type = gadget.props.portal_type,
parent_relative_url = gadget.props.parent_relative_url;
return RSVP.Queue()
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget(scope);
})
......@@ -126,7 +123,7 @@
// declared methods
/////////////////////////////////////////////////////////////////
.ready(function (g) {
return RSVP.Queue()
return new RSVP.Queue()
.push(function () {
return RSVP.all([
g.getSetting('portal_type'),
......@@ -140,10 +137,8 @@
};
});
})
.declareMethod("render", function () {
var gadget = this;
this.getDeclaredGadget('form_list');
return gadget.getSetting('jio_storage_name')
.push(function (result) {
......@@ -151,8 +146,22 @@
return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}});
}
if ('serviceWorker' in navigator) {
if (navigator.serviceWorker.controller) {
return jIO.util.ajax({
url: 'hasSharedData'
});
}
}
})
.push(function () {
.push(function (result) {
if (result) {
if (result.target.response === 'true') {
return gadget.redirect({command: 'display', options: {
page: 'ojs_smart_assistant_upload_shared_file'
}});
}
}
return RSVP.all([
gadget.getDeclaredGadget('form_view_upload_audio'),
gadget.getDeclaredGadget('form_view_image_text'),
......@@ -328,7 +337,6 @@
page_icon: "exchange"
});
});
});
}(window, rJS, jIO, RSVP, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file
}(window, rJS, jIO, navigator, RSVP, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file
......@@ -184,7 +184,7 @@
</tuple>
<state>
<tuple>
<float>1562159205.06</float>
<float>1597277315.11</float>
<string>UTC</string>
</tuple>
</state>
......@@ -233,7 +233,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>980.55662.21812.7987</string> </value>
<value> <string>986.52650.40049.32887</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -251,7 +251,7 @@
</tuple>
<state>
<tuple>
<float>1577797510.26</float>
<float>1600864455.71</float>
<string>UTC</string>
</tuple>
</state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="gadget_officejs_smart_assistant.css">
<link rel="manifest" href="gadget_officejs_json_manifest_smart_assistant.json">
<title>OfficeJS Smart Assistant Upload Shared File</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_erp5_page_ojs_smart_assistant_upload_shared_file.js"></script>
</head>
<body>
<h1>Your file is uploading to Smart Assistant...</h1>
</body>
</html>
/*global window, rJS, jIO, Handlebars, RSVP, Blob*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, rJS, jIO, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareService(function handleWebShareFile() {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: 'GET',
url: 'getSharedData',
dataType: "blob"
});
})
.push(function (resx) {
// Condition: when there's uploaded data
if (resx.target.response.size) {
return gadget.notifySubmitting()
.push(function () {
return gadget.jio_post({
"title": Date(), //get date as title
portal_type: "Smart Assistant File",
parent_relative_url: "smart_assistant_file_module",
validation_state: 'draft'
});
})
.push(function (id) {
return gadget.jio_putAttachment(
id,
'data',
resx.target.response
);
})
.push(function () {
return gadget.notifySubmitted({
"message": "Data created",
"status": "success"
});
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {page: "ojs_smart_assistant_document_list"}
});
});
}
// Condition: if there's no data
return gadget.notifySubmitted({
"message": "No data found",
"status": "failed"
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {page: "ojs_smart_assistant_home"}
});
});
});
});
}(window, rJS, jIO, RSVP));
\ No newline at end of file
// Update web app manifest so that it can be installable
{
"short_name": "Smart Assistant",
"name": "OfficeJS Smart Assistant",
......@@ -7,6 +8,21 @@
"sizes": "any",
"type": "image/png"
}],
"start_url": "../../",
"display": "standalone"
"start_url": "../",
"theme_color": "#333",
"background_color": "#333",
"display": "standalone",
"scope": "../",
// web share target API
"share_target": {
"action": "./postData",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"files": [{
"name": "file",
"accept": ["*/*"]
}]
}
}
}
\ No newline at end of file
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>970.32880.35131.14592</string> </value>
<value> <string>986.3906.17858.11212</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1537948707.94</float>
<float>1598012587.45</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -128,7 +128,13 @@ url_list = [
"gadget_officejs_jio_smart_assistant_text_view.js",
"gadget_officejs_jio_smart_assistant_text_view.html",
"gadget_erp5_page_ojs_smart_assistant_home.html",
"gadget_erp5_page_ojs_smart_assistant_home.js"
"gadget_erp5_page_ojs_smart_assistant_home.js",
"gadget_erp5_page_ojs_smart_assistant_upload_shared_file.html",
"gadget_erp5_page_ojs_smart_assistant_upload_shared_file.js",
"gadget_erp5_page_ojs_smart_assistant_worklist.html",
"gadget_erp5_page_ojs_smart_assistant_worklist.js",
"gadget_officejs_jio_query_view.html",
"gadget_officejs_jio_smart_assistant_query_view.js"
]
return url_list
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