Commit 6c7d7f96 authored by Valentin Benozillo's avatar Valentin Benozillo Committed by Xiaowu Zhang

[erp5_officejs][erp5_web_renderjs_ui] Add Smart Assistant app

parent 3b78fb24
<!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">
<title>OfficeJS Smart Assistant Home</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_erp5_page_ojs_smart_assistant_home.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view_upload_audio"
data-gadget-sandbox="public"
class='ui-flex-center'>
</div>
</form>
<form class="save_form ui-body-c" novalidate>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view_image_text"
data-gadget-sandbox="public"
class='ui-flex-center'>
</div>
</form>
</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("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.allowPublicAcquisition('updateHeader', function () {
return;
})
.declareMethod("send", function (scope) {
var gadget = this,
blob,
name,
portal_type = gadget.props.portal_type,
parent_relative_url = gadget.props.parent_relative_url;
return RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget(scope);
})
.push(function (form) {
return form.getContent();
})
.push(function (result) {
if (scope === "form_view_upload_audio" && result.upload) {
blob = jIO.util.dataURItoBlob(result.upload.url);
portal_type = portal_type[3];
parent_relative_url = parent_relative_url[3];
name = result.upload.file_name;
} else if (scope === "form_view_image_text" && result.image) {
blob = jIO.util.dataURItoBlob(result.image.url);
portal_type = portal_type[1];
parent_relative_url = parent_relative_url[1];
name = result.image.file_name;
}
if (blob) {
return gadget.notifySubmitting()
.push(function () {
return gadget.jio_post({
"title": name,
portal_type: portal_type,
parent_relative_url: parent_relative_url
});
})
.push(function (id) {
return gadget.jio_putAttachment(id, 'data', blob);
})
.push(function () {
return gadget.notifySubmitted({
"message": "Data created",
"status": "success"
});
});
}
});
})
.allowPublicAcquisition('notifyChange', function (result, scope) {
/*jslint unparam: true*/
return this.send(scope);
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.ready(function (g) {
return RSVP.Queue()
.push(function () {
return RSVP.all([
g.getSetting('portal_type'),
g.getSetting('parent_relative_url')
]);
})
.push(function (result) {
g.props = {
portal_type: result[0].split(','),
parent_relative_url: result[1].split(',')
};
});
})
.declareMethod("render", function () {
var gadget = this;
return gadget.getSetting('jio_storage_name')
.push(function (result) {
if (!result) {
return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}});
}
})
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view_upload_audio'),
gadget.getDeclaredGadget('form_view_image_text')
]);
})
.push(function (result) {
return RSVP.all([
result[0].render({
erp5_document: {"_embedded": {"_view": {
"upload": {
"editable": 1,
"key": "upload",
"css_class":
"ui-view-only-label ui-label-circle ui-label-icon-files-o",
"title": " ",
"type": "FileField"
},
"audio": {
"editable": 1,
"required": 1,
"key": "",
"css_class": "invisible ui-a-circle ui-a-icon-microphone",
"default": {"target": "ojs_smart_assistant_audio",
"target_type": "audio"},
"title": " ",
"url": "gadget_erp5_page_ojs_link_field.html",
"type": "GadgetField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}},
form_definition: {
group_list: [[
"left",
[["upload"]]
], [
"right",
[["audio"]]
]]
}
}),
result[1].render({
erp5_document: {"_embedded": {"_view": {
"image": {
"editable": 1,
"key": "image",
"css_class":
"ui-view-only-label ui-label-circle ui-label-icon-camera",
"capture": "camera",
"title": " ",
"accept": "image/*",
"type": "FileField"
},
"text": {
"editable": 1,
"required": 1,
"key": "",
"css_class":
"invisible ui-a-circle ui-a-icon-pencil-square-o",
"title": " ",
"default": {"target": "smart_assistant_text",
"target_type": "text"},
"url": "gadget_erp5_page_ojs_link_field.html",
"type": "GadgetField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}},
form_definition: {
group_list: [[
"left",
[["image"]]
], [
"right",
[["text"]]
]]
}
})
]);
})
.push(function () {
return RSVP.all([
gadget.getSetting('document_title_plural'),
gadget.getUrlFor({command: 'display',
options:
{page: "ojs_smart_assistant_document_list"}
})
]);
})
.push(function (list_url) {
return gadget.updateHeader({
page_title: list_url[0],
selection_url: list_url[1],
page_icon: "exchange"
});
});
});
}(window, rJS, jIO, RSVP));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Jio File View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_jio_smart_assistant_file_view.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP, jIO, Blob*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, jIO, rJS, RSVP, URL) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
state = {
title: options.doc.title,
jio_key: options.jio_key
};
return gadget.jio_getAttachment(options.jio_key, "data")
.push(function (blob_upload) {
state.upload = URL.createObjectURL(blob_upload);
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'}),
gadget.changeState(state)
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: "Smart Assistant",
save_action: true,
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
})
.onEvent('submit', function () {
var gadget = this,
title;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (result) {
var blob_upload,
queue;
if (result.upload_) {
title = result.upload_.file_name;
blob_upload = jIO.util.dataURItoBlob(result.upload_.url);
queue = gadget.jio_putAttachment(gadget.state.jio_key,
'data', blob_upload);
} else {
title = result.title;
queue = new RSVP.Queue();
}
queue.push(function () {
return gadget.updateDocument({title: title});
});
return queue;
})
.push(function () {
return gadget.notifySubmitted({
"message": "Data updated",
"status": "success"
});
})
.push(function () {
return gadget.redirect({command: 'reload'});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {
"_view": {
"my_title": {
"description": "",
"title": "Title",
"default": gadget.state.title,
"css_class": "",
"required": 1,
"editable": 1,
"key": "title",
"hidden": 0,
"type": "StringField"
},
"my_actual_upload": {
"editable": 1,
"required": 1,
"key": "",
"title": "Download actual content",
"default": {"direct_url": gadget.state.upload,
"target_type": "download",
"textContent": gadget.state.title},
"url": "gadget_erp5_page_ojs_link_field.html",
"type": "GadgetField"
},
"my_upload": {
"description": "",
"title": "Change it",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "upload_",
"hidden": 0,
"type": "FileField"
}
}
},
"_links": {
"type": {
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_actual_upload"], ["my_upload"]]
]]
}
});
});
});
}(window, jIO, rJS, RSVP, URL));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Jio Image View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_jio_smart_assistant_image_view.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP, jIO, URL, Blob, promiseEventListener, document*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, jIO, rJS, RSVP, URL) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
state = {
title: options.doc.title,
jio_key: options.jio_key
};
gadget.type = options.doc.type;
return gadget.jio_getAttachment(options.jio_key, "data")
.push(function (blob_image) {
state.image = URL.createObjectURL(blob_image);
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'}),
gadget.changeState(state)
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: "Smart Assistant",
save_action: true,
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
})
.onEvent('submit', function () {
var gadget = this,
title;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (result) {
var blob_image,
queue;
if (result.image_) {
title = result.image_.file_name;
blob_image = jIO.util.dataURItoBlob(result.image_.url);
queue = gadget.jio_putAttachment(gadget.state.jio_key,
'data', blob_image);
} else {
title = result.title;
queue = new RSVP.Queue();
}
queue.push(function () {
return gadget.updateDocument({title: title});
});
return queue;
})
.push(function () {
return gadget.notifySubmitted({
"message": "Data updated",
"status": "success"
});
})
.push(function () {
return gadget.redirect({command: 'reload'});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {
"_view": {
"my_title": {
"description": "",
"title": "Title",
"default": gadget.state.title,
"css_class": "",
"required": 1,
"editable": 1,
"key": "title",
"hidden": 0,
"type": "StringField"
},
"my_image": {
"description": "",
"title": "Change it",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "image_",
"hidden": 0,
"accept": "image/*",
"capture": "camera",
"type": "FileField"
},
"my_image_preview": {
"description": "",