Commit 95a4bcac authored by lu.xu's avatar lu.xu 👀

erp5_officejs:implement Smart Assistant UI on officeJS

parent f07ebe82
......@@ -31,6 +31,17 @@
class='ui-flex-center'>
</div>
</form>
<form class="save_form ui-body-c" novalidate>
<div data-gadget-url="gadget_erp5_pt_form_list.html"
data-gadget-scope="form_list"
data-gadget-sandbox="public"
class='ui-flex-bottom'>
</div>
</form>
<div data-gadget-url="gadget_erp5_page_ojs_smart_assistant_worklist.html"
data-gadget-scope="worklist"
data-gadget-sandbox="public"
class='ui-flex-bottom'>
</div>
</body>
</html>
......@@ -62,7 +62,6 @@
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
<string>classification/collaborative/team</string>
</tuple>
</value>
......@@ -279,7 +278,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.17859.46531.61866</string> </value>
<value> <string>979.64140.28065.34372</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -297,7 +296,7 @@
</tuple>
<state>
<tuple>
<float>1525278837.04</float>
<float>1574460415.05</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, Handlebars, RSVP, Blob*/
/*global window, rJS, jIO, Handlebars, RSVP, Blob, SimpleQuery, ComplexQuery, Query*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, rJS, jIO, RSVP) {
(function (window, rJS, jIO, RSVP, SimpleQuery, ComplexQuery, Query) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
......@@ -18,8 +17,44 @@
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.allowPublicAcquisition("jio_allDocs", function (param_list) {
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, date, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("modification_date")) {
date = new Date(result.data.rows[i].value.modification_date);
result.data.rows[i].value.modification_date = {
field_gadget_param: {
allow_empty_time: 0,
ampm_time_style: 0,
css_class: "date_field",
date_only: 0,
description: "The Date",
editable: 0,
hidden: 0,
hidden_day_is_last_day: 0,
"default": date.toUTCString(),
key: "modification_date",
required: 0,
timezone_style: 0,
title: "Modification Date",
type: "DateTimeField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
}
return result;
});
})
.allowPublicAcquisition('updateHeader', function () {
return;
......@@ -57,7 +92,8 @@
return gadget.jio_post({
"title": name,
portal_type: portal_type,
parent_relative_url: parent_relative_url
parent_relative_url: parent_relative_url,
validation_state: 'draft'
});
})
.push(function (id) {
......@@ -68,6 +104,12 @@
"message": "Data created",
"status": "success"
});
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {page: "ojs_smart_assistant_document_list"}
});
});
}
});
......@@ -98,8 +140,11 @@
};
});
})
.declareMethod("render", function () {
var gadget = this;
this.getDeclaredGadget('form_list');
return gadget.getSetting('jio_storage_name')
.push(function (result) {
if (!result) {
......@@ -110,11 +155,44 @@
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view_upload_audio'),
gadget.getDeclaredGadget('form_view_image_text')
gadget.getDeclaredGadget('form_view_image_text'),
gadget.getDeclaredGadget('form_list'),
gadget.getDeclaredGadget('worklist'),
gadget.getSetting("portal_type")
]);
})
.push(function (result) {
var column_list = [
['agent_title', 'Title'],
['description', 'Reply'],
['modification_date', 'Modification Date'],
['validation_state', 'Validation State']
],
worklist_gadget = result[3],
portal_type = ["Query"],
query = "urn:jio:allDocs?query=",
i,
jio_query_list = [];
for (i = 0; i < portal_type.length; i += 1) {
jio_query_list.push(new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: portal_type[i]
}));
}
query += Query.objectToSearchText(new ComplexQuery({
operator: "OR",
query_list: jio_query_list,
type: "complex"
}));
return RSVP.all([
worklist_gadget.render(),
result[0].render({
erp5_document: {"_embedded": {"_view": {
"upload": {
......@@ -194,6 +272,43 @@
[["text"]]
]]
}
}),
result[2].render({
erp5_document: {
"_embedded": {"_view": {
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 1,
"editable_column_list": [],
"key": "field_listbox",
"lines": 10,
"list_method": "portal_catalog",
"query": query,
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"sort": [['validation_state', 'descending'],
['modification_date', 'descending']],
"title": "Notification",
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"bottom",
[["listbox"]]
]]
}
})
]);
})
......@@ -216,4 +331,4 @@
});
}(window, rJS, jIO, RSVP));
\ No newline at end of file
}(window, rJS, jIO, RSVP, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file
......@@ -58,29 +58,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
<string>classification/collaborative/team</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>cedric.le.ninivin</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_smart_assistant_home.js</string> </value>
......@@ -101,25 +84,6 @@
<none/>
</value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1455284352.18</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
......@@ -134,12 +98,6 @@
<key> <string>title</string> </key>
<value> <string>Gadget Smart Assistant JS</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
......@@ -226,7 +184,7 @@
</tuple>
<state>
<tuple>
<float>1519634719.01</float>
<float>1562159205.06</float>
<string>UTC</string>
</tuple>
</state>
......@@ -275,7 +233,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.20676.40581.32768</string> </value>
<value> <string>980.55662.21812.7987</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -293,7 +251,7 @@
</tuple>
<state>
<tuple>
<float>1525444169.16</float>
<float>1577797510.26</float>
<string>UTC</string>
</tuple>
</state>
......@@ -354,7 +312,7 @@
</tuple>
<state>
<tuple>
<float>1519633924.76</float>
<float>1562158825.48</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Worklist
data-i18n=All work caught up!
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Page Worklist</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_page_ojs_smart_assistant_worklist.js" type="text/javascript"></script>
<!-- XXX must set theme here! -->
<script id="table-template" type="text/x-handlebars-template">
{{#if document_list }}
<ul data-role="listview" data-theme="c" class="document-listview ui-listview-inset ui-corner-all">
{{#each document_list}}
<li class="ui-li-has-count" data-icon="false" ><a class="ui-body-inherit" href="{{link}}">{{title}} <span class="ui-li-count">{{count}}</span></a></li>
{{/each}}
</ul>
{{else}}
<p>All work caught up!</p>
{{/if}}
</script>
</head>
<body>
<h1 data-i18n="[value]Smart Assistant WorkLists" class="ui-title ui-override-theme worklist-title">Smart Assistant WorkLists</h1>
<section class="document_list"></section>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, Handlebars, URI */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
new RSVP.Queue().push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'display', options: {page: "ojs_smart_assistant_document_list", extended_search: 'validation_state: "draft"'}}),
gadget.getUrlFor({command: 'display', options: {page: "ojs_smart_assistant_document_list", extended_search: 'validation_state: "processing"'}}),
gadget.jio_allDocs({"query": 'portal_type: ("Smart Assistant File" OR "Smart Assistant Image" OR "Smart Assistant Text" OR "Smart Assistant Sound") AND validation_state: "draft"'}),
gadget.jio_allDocs({"query": 'portal_type: ("Smart Assistant File" OR "Smart Assistant Image" OR "Smart Assistant Text" OR "Smart Assistant Sound") AND validation_state: "processing"'})
]);
})
.push(function (result) {
var line_list = [];
line_list.push({
link: result[0],
title: "Smart Assistant Records to Start Processing",
count: result[2].data.total_rows
});
line_list.push({
link: result[1],
title: "Smart Assistant Records to Finish Processing",
count: result[3].data.total_rows
});
gadget.element.querySelector('.document_list').innerHTML = table_template({
document_list: line_list
});
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
/*global window, rJS, RSVP, jIO, Blob*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, jIO, rJS, RSVP, URL) {
(function (window, jIO, rJS, RSVP, URL, SimpleQuery, ComplexQuery, Query) {
"use strict";
rJS(window)
......@@ -23,6 +23,7 @@
var gadget = this,
state = {
title: options.doc.title,
validation_state: options.doc.validation_state,
jio_key: options.jio_key
};
......@@ -96,6 +97,35 @@
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
var column_list = [
['agent_title', 'Title'],
['description', 'Reply'],
['modification_date', 'Modification Date'],
['validation_state', 'Validation State']
],
jio_key = gadget.state.jio_key,
portal_type = ["Query"],
agent_relative_url = jio_key,
query = "urn:jio:allDocs?query=",
jio_query_list = [];
jio_query_list.push(new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: portal_type
}));
jio_query_list.push(new SimpleQuery({
key: "agent_relative_url",
operater: "",
type: "simple",
value: agent_relative_url
}));
query += Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: jio_query_list,
type: "complex"
}));
return form_gadget.render({
erp5_document: {
"_embedded": {
......@@ -115,7 +145,7 @@
"editable": 1,
"required": 1,
"key": "",
"title": "Download actual content",
"title": "Download",
"default": {"direct_url": gadget.state.upload,
"target_type": "download",
"textContent": gadget.state.title},
......@@ -124,7 +154,7 @@
},
"my_upload": {
"description": "",
"title": "Change it",
"title": "Re-upload",
"default": "",
"css_class": "",
"required": 1,
......@@ -132,6 +162,34 @@
"key": "upload_",
"hidden": 0,
"type": "FileField"
},
"my_validation_state": {
"description": "",
"title": "State",
"default": gadget.state.validation_state,
"css_class": "",
"required": 1,
"editable": 0,
"key": "validation_state",
"hidden": 0,
"type": "StringField"
},
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 0,
"editable_column_list": [],
"key": "field_listbox",
"lines": 5,
"list_method": "portal_catalog",
"query": query,
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"sort": [['modification_date', 'descending']],
"title": "Related Queries",
"type": "ListBox"
}
}
},
......@@ -144,10 +202,15 @@
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_actual_upload"], ["my_upload"]]
[["my_title"], ["my_actual_upload"],
["my_upload"], ["my_validation_state"]]
], [
"bottom",
[['listbox']]
]]
}
});
});
});
}(window, jIO, rJS, RSVP, URL));
\ No newline at end of file
}(window, jIO, rJS, RSVP, URL, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.18881.16014.512</string> </value>
<value> <string>980.55724.32706.34986</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -263,7 +263,7 @@
</tuple>
<state>
<tuple>
<float>1525355150.41</float>
<float>1577801225.85</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, jIO, URL, Blob, promiseEventListener, document*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, jIO, rJS, RSVP, URL) {
(function (window, jIO, rJS, RSVP, URL, SimpleQuery, ComplexQuery, Query) {
"use strict";
rJS(window)
......@@ -24,6 +24,7 @@
var gadget = this,
state = {
title: options.doc.title,
validation_state: options.doc.validation_state,
jio_key: options.jio_key
};
gadget.type = options.doc.type;
......@@ -94,7 +95,35 @@
})
.onStateChange(function () {
var gadget = this;
var gadget = this,
column_list = [
['agent_title', 'Title'],
['description', 'Reply'],
['modification_date', 'Modification Date'],
['validation_state', 'Validation State']
],
jio_key = gadget.state.jio_key,
portal_type = ["Query"],
agent_relative_url = jio_key,
query = "urn:jio:allDocs?query=",
jio_query_list = [];
jio_query_list.push(new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: portal_type
}));
jio_query_list.push(new SimpleQuery({
key: "agent_relative_url",
operater: "",
type: "simple",
value: agent_relative_url
}));
query += Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: jio_query_list,
type: "complex"
}));
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
......@@ -115,7 +144,7 @@
},
"my_image": {
"description": "",
"title": "Change it",
"title": "Re-upload",
"default": "",
"css_class": "",
"required": 1,
......@@ -126,9 +155,20 @@
"capture": "camera",
"type": "FileField"
},
"my_validation_state": {
"description": "",
"title": "State",
"default": gadget.state.validation_state,
"css_class": "",
"required": 1,
"editable": 0,
"key": "validation_state",
"hidden": 0,
"type": "StringField"
},
"my_image_preview": {
"description": "",
"title": "Actually",
"title": "Preview",
"default": gadget.state.image,
"css_class": "",
"height" : "10",
......@@ -137,6 +177,23 @@
"key": "image_preview",
"hidden": 0,
"type": "ImageField"