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": "",
"title": "Actually",
"default": gadget.state.image,
"css_class": "",
"height" : "10",
"required": 1,
"editable": 1,
"key": "image_preview",
"hidden": 0,
"type": "ImageField"
}
}
},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_image"], ["my_image_preview"]]
]]
}
});
});
});
}(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 Sound View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_jio_smart_assistant_sound_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*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, jIO, rJS, RSVP) {
"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_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 RSVP.Queue()
.push(function () {
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_audio,
queue;
if (result.audio_) {
title = result.audio_.file_name;
blob_audio = jIO.util.dataURItoBlob(result.audio_.url);
queue = gadget.jio_putAttachment(gadget.state.jio_key,
'data', blob_audio);
} 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_audio": {
"default": gadget.state.jio_key,
"css_class": "",
"required": 1,
"editable": 0,
"key": "player_content",
"hidden": 0,
"title": "Listen actual content",
"type": "GadgetField",
"renderjs_extra": '{"name": "data"}',
"url": "gadget_custom_player.html",
"sandbox": "public"
},
"my_audio": {
"description": "",
"title": "Audio",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "audio_",
"hidden": 0,
"accept": "audio/*",
"capture": "microphone",
"type": "FileField"
}
}
},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_actual_audio"], ["my_audio"]]
]]
}
});
});
});
}(window, jIO, rJS, 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 Text View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_jio_smart_assistant_text_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, URL,
promiseEventListener, document*/
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("jio_get", "jio_get")
/////////////////////////////////////////////////////////////////
// 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_get(options.jio_key)
.push(function (content) {
state.content = content;
state.text = content.text_content;
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) {
title = result.title;
if (result.text_ === "") {
result.text_ = " ";
}
return gadget.updateDocument({
'text_content': result.text_,
title: title
});
})
.push(function () {
return gadget.notifySubmitted({
"message": "Data Updated",
"status": "success"
});
});
})
.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_text": {
"default": gadget.state.text,
"css_class": "",
"required": 0,
"editable": 1,
"key": "text_",
"hidden": 0,
"renderjs_extra": '{"editor": "fck_editor",' +
'"maximize": "auto"}',
"type": "GadgetField",
"url": "gadget_editor.html",
"sandbox": "public"
}
}
},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"]]
], [
"bottom",
[["my_text"]]
]]
}
});
});
});
}(window, rJS, RSVP));
\ No newline at end of file
{
"short_name": "OfficeJS Smart Assistant",
"name": "OfficeJS Smart Assistant",
"icons": [{
"src": "image_module/gadget_officejs_smart_assistant_icon_png?quality=75&format=png",
"sizes": "any",
"type": "image/png"
}],
"start_url": "./",
"display": "standalone"
}
\ No newline at end of file
{
"short_name": "OfficeJS Smart Assistant",
"name": "OfficeJS Smart Assistant",
"icons": [{
"src": "image_module/gadget_officejs_smart_assistant_icon_png?quality=75&format=png",
"sizes": "any",
"type": "image/png"
}],
"start_url": "../",
"display": "standalone"
}
\ 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 Link Input</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_erp5_page_ojs_link_field.js"></script>
</head>
<body>
<a></a>
</body>
</html>
/*global window, rJS, jIO, Handlebars, navigator, MediaRecorder, Blob, loopEventListener*/
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS) {
"use strict";
rJS(window)
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod('render', function (params) {
var gadget = this,
a = gadget.element.querySelector("a");
a.setAttribute('id', params.value.target_type);
a.textContent = params.value.textContent || "";
if (params.value.target_type === "download") {
a.setAttribute('download', params.value.textContent);
}
if (!params.value.direct_url) {
return gadget.getUrlFor({
command: 'display',
options: {page: params.value.target}
})
.push(function (url) {
a.setAttribute('href', url);
});
}
a.setAttribute('href', params.value.direct_url);
})
.declareMethod('getContent', function () {
return {};
});
}(window, rJS));
\ No newline at end of file
<!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 Jio Spreadsheet View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_erp5_page_ojs_smart_assistant_audio.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 class="ui-record-circle">
<div>
00:00
</div>
</div>
</form>
</body>
</html>
/*global document, window, rJS, RSVP, loopEventListener, navigator, MediaRecorder, Blob, setInterval, Promise */
/*jslint indent:2, maxlen: 80, nomen: true */
(function (window, rJS, RSVP) {
"use strict";
function promiseMyStream(stream_options, callback) {
var stream,
callback_queue;
function canceller() {
if ((callback_queue !== undefined) &&
(typeof callback_queue.cancel === "function")) {
callback_queue.cancel();
}
if (stream !== undefined) {
stream.getTracks().forEach(function (track) { track.stop(); });
}
}
return new RSVP.Promise(function (resolve, reject) {
/*jslint unparam: true*/
navigator.mediaDevices.getUserMedia(stream_options)
.then(function (result) {
stream = result;
callback_queue = new RSVP.Queue()
.push(function () {
return callback(stream);
});
return callback_queue;
})
.then(undefined, function (error) {
canceller();
reject(error);
});
}, canceller);
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.onLoop(function () {
var gadget = this,
div = gadget.element.querySelector("div[class='ui-record-circle']")
.firstElementChild,
now = new Date().getTime(),
distance = now - gadget.state.start,
minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60))
.toString(),
seconds = Math.floor((distance % (1000 * 60)) / 1000).toString();
minutes = ("00" + minutes).slice(-2);
seconds = ("00" + seconds).slice(-2);
div.textContent = minutes + ":" + seconds;
}, 1000)
.onEvent('submit', function () {
var gadget = this;
gadget.state.record.stop();
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
})
.push(function () {
return gadget.notifySubmitting();
})
.push(function () {
return RSVP.all([
gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
var portal_type = result[0].split(',')[2],
parent_relative_url = result[1].split(',')[2],
date,
title;
if (gadget.state.audio) {
date = new Date();
title = date.getFullYear() + "_" + date.getMonth() + "_" +
date.getDate() + "_" + date.getHours() + ":" +
date.getMinutes() + ":" + date.getSeconds();
return gadget.jio_post({
"title": "record_" + title,
portal_type: portal_type,
parent_relative_url: parent_relative_url
});
}
})
.push(function (id_audio) {
if (id_audio) {
return gadget.jio_putAttachment(id_audio, 'data',
gadget.state.audio);
}
})
.push(function () {
return RSVP.all([
gadget.redirect({command: 'display',
options: {page: 'ojs_smart_assistant_home'}}),
gadget.notifySubmitted({"message": "Data created",
"status": "success"})
]);
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareJob('record', function () {
var gadget = this,
stream,
record;
return RSVP.Queue()
.push(function () {
return gadget.notifyChange();
})
.push(function () {
return promiseMyStream({audio: true}, function (result) {
stream = result;
record = new MediaRecorder(stream);
record.start();
gadget.state.record = record;
return RSVP.any([
loopEventListener(record,
'stop',
false,
function () {
return gadget.props.deferred.resolve();
}),
loopEventListener(record,
'dataavailable',
false,
function (event) {
gadget.state.audio = event.data;
})
]);
});
})
.push(undefined, function (error) {
if (!(error instanceof RSVP.CancellationError)) {
return RSVP.all([
gadget.redirect({command: 'display',
options: {page: 'ojs_smart_assistant_home'}}),
gadget.notifySubmitted({
"message": "We can't access to your microphone",
"status": "fail"
})
]);
}
throw error;
});
})
.declareMethod("render", function () {
var gadget = this;
gadget.state.start = new Date().getTime();
gadget.props = {
deferred: RSVP.defer()
};
return gadget.getUrlFor(({command: 'display',
options: {page: 'ojs_smart_assistant_home'}}))
.push(function (url) {
return gadget.updateHeader({
page_title: 'Recording audio',
save_action: true,
selection_url: url
});
})
.push(function () {
return gadget.record();
});
});
}(window, rJS, 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">
<script src="jiodev.js"></script>
<title>OfficeJS Smart Assistant List</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_smart_assistant_document_list.js"></script>
</head>
<body>
<div data-gadget-url="gadget_erp5_pt_form_list.html" data-gadget-scope="form_list"></div>
</body>
</html>
This diff is collapsed.
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